From 442d54ba50e0eb0546ff362c663c30341596cdd3 Mon Sep 17 00:00:00 2001 From: rbmj Date: Sun, 28 Jan 2024 18:46:25 -0800 Subject: [PATCH] Fix bug where aftertouch messages may not be processed --- src/midi.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/midi.rs b/src/midi.rs index 77848258..134ba541 100644 --- a/src/midi.rs +++ b/src/midi.rs @@ -419,11 +419,11 @@ impl NoteEvent { pub fn from_midi(timing: u32, midi_data: &[u8]) -> Result { let status_byte = midi_data.first().copied().unwrap_or_default(); let event_type = status_byte & midi::EVENT_TYPE_MASK; + let channel = status_byte & midi::MIDI_CHANNEL_MASK; if midi_data.len() >= 3 { // TODO: Maybe add special handling for 14-bit CCs and RPN messages at some // point, right now the plugin has to figure it out for itself - let channel = status_byte & midi::MIDI_CHANNEL_MASK; match event_type { // You thought this was a note on? Think again! This is a cleverly disguised note off // event straight from the 80s when Baud rate was still a limiting factor! @@ -464,13 +464,6 @@ impl NoteEvent { pressure: midi_data[2] as f32 / 127.0, }); } - midi::CHANNEL_KEY_PRESSURE => { - return Ok(NoteEvent::MidiChannelPressure { - timing, - channel, - pressure: midi_data[1] as f32 / 127.0, - }); - } midi::PITCH_BEND_CHANGE => { return Ok(NoteEvent::MidiPitchBend { timing, @@ -487,6 +480,18 @@ impl NoteEvent { value: midi_data[2] as f32 / 127.0, }); } + _ => (), + } + } + if midi_data.len() >= 2 { + match event_type { + midi::CHANNEL_KEY_PRESSURE => { + return Ok(NoteEvent::MidiChannelPressure { + timing, + channel, + pressure: midi_data[1] as f32 / 127.0, + }); + } midi::PROGRAM_CHANGE => { return Ok(NoteEvent::MidiProgramChange { timing,