From 77ea503de014130a411a49948ecf486f32ef90e0 Mon Sep 17 00:00:00 2001 From: Stephane Albanese Date: Fri, 17 Mar 2023 13:58:44 +0100 Subject: [PATCH] Add a channel getter to the NoteEvent implementation --- src/midi.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/midi.rs b/src/midi.rs index 1a612b0c..de84c503 100644 --- a/src/midi.rs +++ b/src/midi.rs @@ -386,6 +386,30 @@ impl NoteEvent { NoteEvent::MidiSysEx { .. } => None, } } + + /// Returns the event's channel, if it has any. + pub fn channel(&self) -> Option { + match self { + NoteEvent::NoteOn { channel, .. } => Some(*channel), + NoteEvent::NoteOff { channel, .. } => Some(*channel), + NoteEvent::Choke { channel, .. } => Some(*channel), + NoteEvent::VoiceTerminated { channel, .. } => Some(*channel), + NoteEvent::PolyModulation { .. } => None, + NoteEvent::MonoAutomation { .. } => None, + NoteEvent::PolyPressure { channel, .. } => Some(*channel), + NoteEvent::PolyVolume { channel, .. } => Some(*channel), + NoteEvent::PolyPan { channel, .. } => Some(*channel), + NoteEvent::PolyTuning { channel, .. } => Some(*channel), + NoteEvent::PolyVibrato { channel, .. } => Some(*channel), + NoteEvent::PolyExpression { channel, .. } => Some(*channel), + NoteEvent::PolyBrightness { channel, .. } => Some(*channel), + NoteEvent::MidiChannelPressure { channel, .. } => Some(*channel), + NoteEvent::MidiPitchBend { channel, .. } => Some(*channel), + NoteEvent::MidiCC { channel, .. } => Some(*channel), + NoteEvent::MidiProgramChange { channel, .. } => Some(*channel), + NoteEvent::MidiSysEx { .. } => None, + } + } } impl NoteEvent {