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 {