summaryrefslogtreecommitdiff
path: root/src/audioinputenginemidi.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2019-04-08 17:42:00 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2019-04-08 18:08:43 +0200
commit723343269d161b2bba7aee4597357ffc32f26f04 (patch)
tree65b25278bcf029ce5f34420a0caaee634b0c9c04 /src/audioinputenginemidi.cc
parent10d483417fa70bb4c357d598f3bdfcf4f0b75f21 (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/audioinputenginemidi.cc')
-rw-r--r--src/audioinputenginemidi.cc49
1 files changed, 49 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;
+ }
+}