1
0
Fork 0

Add a channel getter to the NoteEvent implementation

This commit is contained in:
Stephane Albanese 2023-03-17 13:58:44 +01:00
parent 15c859a8e6
commit 77ea503de0

View file

@ -386,6 +386,30 @@ impl<S> NoteEvent<S> {
NoteEvent::MidiSysEx { .. } => None, NoteEvent::MidiSysEx { .. } => None,
} }
} }
/// Returns the event's channel, if it has any.
pub fn channel(&self) -> Option<u8> {
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<S: SysExMessage> NoteEvent<S> { impl<S: SysExMessage> NoteEvent<S> {