summaryrefslogtreecommitdiff
path: root/src/midimapper.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/midimapper.cc')
-rw-r--r--src/midimapper.cc42
1 files changed, 40 insertions, 2 deletions
diff --git a/src/midimapper.cc b/src/midimapper.cc
index 9593aae..1f75461 100644
--- a/src/midimapper.cc
+++ b/src/midimapper.cc
@@ -26,7 +26,7 @@
*/
#include "midimapper.h"
-int MidiMapper::lookup(int note)
+int MidiMapper::lookup(int note, int controller)
{
std::lock_guard<std::mutex> guard(mutex);
@@ -42,15 +42,53 @@ int MidiMapper::lookup(int note)
return -1;
}
+ if(controller >= 0 && !controlthreshmap[note].empty())
+ {
+ // find instrument where controller is above threshold with smallest distance to threshold
+ int diff = 10000;
+ std::string instr = controlthreshmap[note].begin()->first;
+ for(auto& control_thresh : controlthreshmap[note])
+ {
+ int cur_diff = controller - control_thresh.second;
+ if(cur_diff >= 0 && cur_diff < diff)
+ {
+ diff = cur_diff;
+ instr = control_thresh.first;
+ }
+ }
+ instrmap_it = instrmap.find(instr);
+ }
+
return instrmap_it->second;
}
-void MidiMapper::swap(instrmap_t& instrmap, midimap_t& midimap)
+void MidiMapper::swap(instrmap_t& instrmap, midimap_t& midimap, controlthreshmap_t& controlthreshmap)
{
std::lock_guard<std::mutex> guard(mutex);
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()