From 27cd372b72c8108260eb5198d43d059ecbff2a77 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Tue, 3 Oct 2023 09:45:35 +0200 Subject: fix issue with hi-hat choking on press of the control pedal --- src/midimapper.cc | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/midimapper.cc') diff --git a/src/midimapper.cc b/src/midimapper.cc index 62b9d87..1f75461 100644 --- a/src/midimapper.cc +++ b/src/midimapper.cc @@ -47,13 +47,13 @@ int MidiMapper::lookup(int note, int controller) // find instrument where controller is above threshold with smallest distance to threshold int diff = 10000; std::string instr = controlthreshmap[note].begin()->first; - for(auto& c : controlthreshmap[note]) + for(auto& control_thresh : controlthreshmap[note]) { - int cur_diff = controller - c.second; + int cur_diff = controller - control_thresh.second; if(cur_diff >= 0 && cur_diff < diff) { diff = cur_diff; - instr = c.first; + instr = control_thresh.first; } } instrmap_it = instrmap.find(instr); @@ -69,6 +69,26 @@ void MidiMapper::swap(instrmap_t& instrmap, midimap_t& midimap, controlthreshmap std::swap(this->instrmap, instrmap); std::swap(this->midimap, midimap); std::swap(this->controlthreshmap, controlthreshmap); + + // find instruments which define a control threshold and store it + for(auto& control_thresh : this->controlthreshmap) + { + for(auto& instr : control_thresh.second) + { + auto instrmap_it = this->instrmap.find(instr.first); + if(instrmap_it != this->instrmap.end()) + { + instwithcontrolthresh.push_back(instrmap_it->second); + } + maxcontrolthresh = std::max(maxcontrolthresh, instr.second); + } + } + + // in case no controller threshold is defined, use fix definition + if(maxcontrolthresh == 0) + { + maxcontrolthresh = 100; + } } const midimap_t& MidiMapper::getMap() -- cgit v1.2.3