diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/audioinputenginemidi.cc | 46 | ||||
-rw-r--r-- | src/audioinputenginemidi.h | 1 | ||||
-rw-r--r-- | src/midimapparser.cc | 1 | ||||
-rw-r--r-- | src/midimapparser.h | 1 | ||||
-rw-r--r-- | src/midimapper.cc | 5 | ||||
-rw-r--r-- | src/midimapper.h | 4 |
6 files changed, 41 insertions, 17 deletions
diff --git a/src/audioinputenginemidi.cc b/src/audioinputenginemidi.cc index 4297ced..820273c 100644 --- a/src/audioinputenginemidi.cc +++ b/src/audioinputenginemidi.cc @@ -78,7 +78,7 @@ bool AudioInputEngineMidi::loadMidiMap(const std::string& file, instrmap[instruments[i]->getName()] = i; } - mmap.swap(instrmap, midimap_parser.midimap, midimap_parser.midimultimap, midimap_parser.controlthreshmap); + mmap.swap(instrmap, midimap_parser.midimap, midimap_parser.controlthreshmap); midimap = file; is_valid = true; @@ -110,8 +110,7 @@ static const std::uint8_t TypeMask = 0xF0; // TODO better implementation: use member variable for controller value, set MIDI key on command line -int hihat_controller = 0; // open hi-hat -int hihat_midi_key = 26; +int hihat_midi_key = 26; void AudioInputEngineMidi::processNote(const std::uint8_t* midi_buffer, std::size_t midi_buffer_length, @@ -133,7 +132,7 @@ void AudioInputEngineMidi::processNote(const std::uint8_t* midi_buffer, { auto key = midi_buffer[1]; auto velocity = midi_buffer[2]; - auto instrument_idx = mmap.lookup(key, hihat_controller); + auto instrument_idx = mmap.lookup(key, controller4_value); if(velocity != 0 && instrument_idx != -1) { // maps velocities to [.5/127, 126.5/127] @@ -147,10 +146,10 @@ void AudioInputEngineMidi::processNote(const std::uint8_t* midi_buffer, auto instrument_idx1 = mmap.lookup(hihat_midi_key); if(instrument_idx == instrument_idx1) { - if(hihat_controller < 100) // quick hack: hard-coded value + if(controller4_value < 100) // quick hack: hard-coded value { events.push_back({ EventType::Choke, (std::size_t)instrument_idx, - 1000000 + hihat_controller, .0f, .0f }); + 1000000 + controller4_value, .0f, .0f }); } } */ @@ -185,18 +184,47 @@ if(instrument_idx == instrument_idx1) return; } - if(controller_number == 4) // hi-hat pedal + if(controller_number == 4) // usually, controller 4 is the hi-hat controller { - +/* + // in case the hi-hat was just closed, choke current hi-hat samples + if(controller4_value < 100 && value > 100) + { +// TODO // quick hack: if hi-hat control pedal is down, choke hi-hat instrument auto instrument_idx = mmap.lookup(hihat_midi_key); -hihat_controller = value; +if(instrument_idx != -1) +{ + events.push_back({ EventType::Choke, (std::size_t)instrument_idx, + offset, .0f, .0f }); +} + } +*/ + + // Store value for use in next NoteOn event. + controller4_value = value; + + +// TODO here, we only apply the choke on controller4 == 0 but we have to apply it to all possible hi-hat instruments + +// quick hack: if hi-hat control pedal is down, choke hi-hat instrument +auto instrument_idx = mmap.lookup(hihat_midi_key, 0); if(value > 100 && instrument_idx != -1) // quick hack: hard-coded value { + +/* +// TEST to force hihat group choke -> does not work +events.push_back({ EventType::OnSet, (std::size_t)instrument_idx, + offset, .0f, .0f }); +*/ + events.push_back({ EventType::Choke, (std::size_t)instrument_idx, offset, .0f, .0f }); + +//printf("choke on instrument index: %d\n", instrument_idx); } + } } break; diff --git a/src/audioinputenginemidi.h b/src/audioinputenginemidi.h index 12efd66..7656f8d 100644 --- a/src/audioinputenginemidi.h +++ b/src/audioinputenginemidi.h @@ -72,4 +72,5 @@ private: ConfigFile refs; float positional_information{0.0f}; + int controller4_value{0}; }; diff --git a/src/midimapparser.cc b/src/midimapparser.cc index 551af0a..2361199 100644 --- a/src/midimapparser.cc +++ b/src/midimapparser.cc @@ -57,7 +57,6 @@ bool MidiMapParser::parseFile(const std::string& filename) } midimap[note] = instr; - midimultimap.insert(std::make_pair(note, instr)); } return true; diff --git a/src/midimapparser.h b/src/midimapparser.h index 061c619..d13b4f5 100644 --- a/src/midimapparser.h +++ b/src/midimapparser.h @@ -35,6 +35,5 @@ public: bool parseFile(const std::string& filename); midimap_t midimap; - midimultimap_t midimultimap; controlthreshmap_t controlthreshmap; }; diff --git a/src/midimapper.cc b/src/midimapper.cc index 12c1452..62b9d87 100644 --- a/src/midimapper.cc +++ b/src/midimapper.cc @@ -42,7 +42,7 @@ int MidiMapper::lookup(int note, int controller) return -1; } - if(controller >= 0 && midimultimap.count(note) > 1) + if(controller >= 0 && !controlthreshmap[note].empty()) { // find instrument where controller is above threshold with smallest distance to threshold int diff = 10000; @@ -62,13 +62,12 @@ int MidiMapper::lookup(int note, int controller) return instrmap_it->second; } -void MidiMapper::swap(instrmap_t& instrmap, midimap_t& midimap, midimultimap_t& midimultimap, controlthreshmap_t& controlthreshmap) +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->midimultimap, midimultimap); std::swap(this->controlthreshmap, controlthreshmap); } diff --git a/src/midimapper.h b/src/midimapper.h index 659d9c8..5c81fd0 100644 --- a/src/midimapper.h +++ b/src/midimapper.h @@ -31,7 +31,6 @@ #include <mutex> typedef std::map<int, std::string> midimap_t; -typedef std::multimap<int, std::string> midimultimap_t; typedef std::map<std::string, int> instrmap_t; typedef std::map<int, std::map<std::string, int> > controlthreshmap_t; @@ -43,14 +42,13 @@ public: int lookup(int note, int controller = -1); //! Set new map sets. - void swap(instrmap_t& instrmap, midimap_t& midimap, midimultimap_t& midimultimap, controlthreshmap_t& controlthreshmap); + void swap(instrmap_t& instrmap, midimap_t& midimap, controlthreshmap_t& controlthreshmap); const midimap_t& getMap(); private: instrmap_t instrmap; midimap_t midimap; - midimultimap_t midimultimap; controlthreshmap_t controlthreshmap; std::mutex mutex; |