Skip to content

Commit

Permalink
Fix bug where aftertouch messages may not be processed
Browse files Browse the repository at this point in the history
  • Loading branch information
rbmj authored and robbert-vdh committed May 5, 2024
1 parent 916dfc1 commit 442d54b
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/midi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,11 @@ impl<S: SysExMessage> NoteEvent<S> {
pub fn from_midi(timing: u32, midi_data: &[u8]) -> Result<Self, u8> {
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!
Expand Down Expand Up @@ -464,13 +464,6 @@ impl<S: SysExMessage> NoteEvent<S> {
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,
Expand All @@ -487,6 +480,18 @@ impl<S: SysExMessage> NoteEvent<S> {
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,
Expand Down

0 comments on commit 442d54b

Please sign in to comment.