From 644742033b73eb19485b47277fb1a33343e8b356 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Mon, 2 Oct 2023 16:12:18 +0200 Subject: introduce controlthresh in MIDI mapping XML to support playing different hi-hat sounds depending on the MIDI controller 4 input --- src/midimapper.cc | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/midimapper.cc') diff --git a/src/midimapper.cc b/src/midimapper.cc index 9593aae..12c1452 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 guard(mutex); @@ -42,15 +42,34 @@ int MidiMapper::lookup(int note) return -1; } + if(controller >= 0 && midimultimap.count(note) > 1) + { + // 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]) + { + int cur_diff = controller - c.second; + if(cur_diff >= 0 && cur_diff < diff) + { + diff = cur_diff; + instr = c.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, midimultimap_t& midimultimap, controlthreshmap_t& controlthreshmap) { std::lock_guard guard(mutex); std::swap(this->instrmap, instrmap); std::swap(this->midimap, midimap); + std::swap(this->midimultimap, midimultimap); + std::swap(this->controlthreshmap, controlthreshmap); } const midimap_t& MidiMapper::getMap() -- cgit v1.2.3