diff options
Diffstat (limited to 'src/audioinputenginemidi.cc')
-rw-r--r-- | src/audioinputenginemidi.cc | 58 |
1 files changed, 21 insertions, 37 deletions
diff --git a/src/audioinputenginemidi.cc b/src/audioinputenginemidi.cc index 4f8ff1f..564a5d6 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); + mmap.swap(instrmap, midimap_parser.midimap, midimap_parser.controlthreshmap); midimap = file; is_valid = true; @@ -108,11 +108,6 @@ static const std::uint8_t TypeMask = 0xF0; // See: // https://www.midi.org/specifications-old/item/table-1-summary-of-midi-message - -// 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; - void AudioInputEngineMidi::processNote(const std::uint8_t* midi_buffer, std::size_t midi_buffer_length, std::size_t offset, @@ -123,24 +118,6 @@ void AudioInputEngineMidi::processNote(const std::uint8_t* midi_buffer, return; } -const bool use_edrumulus_debugging_output = false; -if(use_edrumulus_debugging_output) -{ - auto type = midi_buffer[0] & TypeMask; - auto key = midi_buffer[1]; - auto velocity = midi_buffer[2]; - if((type == ControlChange) && (key == 16)) - { - std::string bar = "--------------------"; - bar[static_cast<int>(static_cast<float>(velocity) / 128 * 20)] = '*'; - printf(std::string(" " + bar + "\n").c_str()); - } - else - { - printf("key: %d, velocity: %d\n", key, velocity); - } -} - switch(midi_buffer[0] & TypeMask) { case NoteOff: @@ -151,7 +128,7 @@ if(use_edrumulus_debugging_output) { auto key = midi_buffer[1]; auto velocity = midi_buffer[2]; - auto instrument_idx = mmap.lookup(key); + auto instrument_idx = mmap.lookup(key, controller4_value); if(velocity != 0 && instrument_idx != -1) { // maps velocities to [.5/127, 126.5/127] @@ -159,16 +136,21 @@ if(use_edrumulus_debugging_output) events.push_back({ EventType::OnSet, (std::size_t)instrument_idx, offset, centered_velocity, positional_information }); + +/* +// TODO better implementation: use member variable for controller value, set MIDI key on command line +int hihat_midi_key = 26; // quick hack, add 1000000 to offset to transport hi-hat controller value 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 }); } } +*/ } } @@ -200,18 +182,20 @@ 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 < mmap.getMaxControlthresh() && value >= mmap.getMaxControlthresh()) + { + for(auto instrument_idx : mmap.getInstWithControlthresh()) + { + events.push_back({ EventType::Choke, (std::size_t)instrument_idx, + offset, .0f, .0f }); + } + } -// 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(value > 100 && instrument_idx != -1) // quick hack: hard-coded value -{ - events.push_back({ EventType::Choke, (std::size_t)instrument_idx, - offset, .0f, .0f }); -} - + // Store value for use in next NoteOn event. + controller4_value = value; } } break; |