diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2019-04-08 17:42:00 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2019-04-08 18:08:43 +0200 |
commit | 723343269d161b2bba7aee4597357ffc32f26f04 (patch) | |
tree | 65b25278bcf029ce5f34420a0caaee634b0c9c04 /src | |
parent | 10d483417fa70bb4c357d598f3bdfcf4f0b75f21 (diff) |
Move midi note process to one common place in AudioInputEngineMidi::processNote and use it in the four input engines (plugin, midifile, ossmidi and jackmidi)
Diffstat (limited to 'src')
-rw-r--r-- | src/audioinputenginemidi.cc | 49 | ||||
-rw-r--r-- | src/audioinputenginemidi.h | 5 |
2 files changed, 54 insertions, 0 deletions
diff --git a/src/audioinputenginemidi.cc b/src/audioinputenginemidi.cc index 6e76f19..7b8cbcb 100644 --- a/src/audioinputenginemidi.cc +++ b/src/audioinputenginemidi.cc @@ -95,3 +95,52 @@ bool AudioInputEngineMidi::isValid() const { return is_valid; } + +// Note types: +static const std::uint8_t NoteOff = 0x80; +static const std::uint8_t NoteOn = 0x90; +static const std::uint8_t NoteAftertouch = 0xA0; + +// Note type mask: +static int const NoteMask = 0xF0; + +void AudioInputEngineMidi::processNote(const std::uint8_t* midi_buffer, + std::size_t midi_buffer_length, + std::size_t offset, + std::vector<event_t>& events) +{ + if(midi_buffer_length != 3) + { + return; + } + + auto key = midi_buffer[1]; + auto velocity = midi_buffer[2]; + auto instrument_idx = mmap.lookup(key); + + switch(midi_buffer[0] & NoteMask) + { + case NoteOff: + // Ignore for now + break; + + case NoteOn: + if(instrument_idx != -1) + { + events.push_back({EventType::OnSet, (std::size_t)instrument_idx, + offset, velocity / 127.0f}); + } + break; + + case NoteAftertouch: + if(velocity == 0 && instrument_idx != -1) + { + events.push_back({EventType::Choke, (std::size_t)instrument_idx, + offset, .0f}); + } + break; + + default: + break; + } +} diff --git a/src/audioinputenginemidi.h b/src/audioinputenginemidi.h index e02ba21..8da7bd2 100644 --- a/src/audioinputenginemidi.h +++ b/src/audioinputenginemidi.h @@ -57,6 +57,11 @@ public: bool isValid() const; + void processNote(const std::uint8_t* note_data, + std::size_t note_data_size, + std::size_t offset, + std::vector<event_t>& events); + protected: MidiMapper mmap; |