Enum tune::midi::ChannelMessageType [−][src]
A parsed representation of the channel-agnostic part of a MIDI message.
Variants
Fields of ProgramChange
program: u8
Fields of ChannelPressure
pressure: u8
Fields of PitchBendChange
value: i16
Implementations
impl ChannelMessageType
[src]
pub fn in_channel(self, channel: u8) -> Option<ChannelMessage>
[src]
Creates a new ChannelMessage
from self
with the given channel
.
None
is returned if the channel value is outside the range [0..16).
Examples
let message_type = ChannelMessageType::NoteOn { key: 77, velocity: 88 }; let message = message_type.in_channel(15).unwrap(); assert_eq!(message.channel(), 15); assert_eq!(message.message_type(), message_type); let channel_out_of_range = message_type.in_channel(16); assert!(channel_out_of_range.is_none());
pub fn transform(
&self,
tuning: impl KeyboardMapping<PianoKey>
) -> TransformResult
[src]
&self,
tuning: impl KeyboardMapping<PianoKey>
) -> TransformResult
Applies a tuning transformation to a MIDI message.
This operation only succeeds for polyphonic messages whose transformed note is in the allowed MIDI range [0..128). If the transformation is successful the deviation from the accurate transformed note is reported.
Examples
let tuning = ( Scl::builder().push_cents(120.0).build().unwrap(), KbmRoot::from(Note::from_midi_number(62)).to_kbm(), ); // Usually, polyphonic messages are transformed let in_range = ChannelMessageType::NoteOn { key: 100, velocity: 88 }; match in_range.transform(&tuning) { TransformResult::Transformed { message_type, deviation, orig_key, mapped_note } => { assert_eq!( message_type, ChannelMessageType::NoteOn { key: 108, velocity: 88 } ); assert_approx_eq!(deviation.as_cents(), -40.0); assert_eq!(orig_key, 100); assert_eq!(mapped_note, 108); }, _ => unreachable!(), } // When the transformed note is out of range messages are not transformed let out_of_range = ChannelMessageType::NoteOn { key: 120, velocity: 88 }; assert!(matches!(out_of_range.transform(&tuning), TransformResult::NoteOutOfRange)); // Monophonic messages are never transformed let not_transformed = ChannelMessageType::ProgramChange { program: 42 }; assert!(matches!(not_transformed.transform(&tuning), TransformResult::NotKeyBased));
pub fn distribute(
&self,
tuner: &ChannelTuner<PianoKey>,
channel_offset: u8
) -> Vec<ChannelMessage>
[src]
&self,
tuner: &ChannelTuner<PianoKey>,
channel_offset: u8
) -> Vec<ChannelMessage>
Distributes the given ChannelMessageType
to multiple channels depending on the state of the provided ChannelTuner
.
The parameter channel_offset
specifies the amount by which the channel number returned by tuner
will be raised.
Messages that cannot be mapped to a valid MIDI message will be discarded.
Examples
let mut tuning = ( Scl::builder().push_cents(25.0).build().unwrap(), KbmRoot::from(Note::from_midi_number(62)).to_kbm(), ); let (tuner, _) = ChannelTuner::apply_full_keyboard_tuning( &tuning, (0..128).map(PianoKey::from_midi_number), ); // Usually, polyponic messages are distributed let in_range = ChannelMessageType::NoteOn { key: 91, velocity: 88, }; let distributed = in_range.distribute(&tuner, 4); assert_eq!(distributed.len(), 1); assert_eq!( distributed[0].message_type(), ChannelMessageType::NoteOn { key: 69, velocity: 88, } ); assert_eq!(distributed[0].channel(), 6); // When mapped channel is out of range messages are discarded assert!(in_range.distribute(&tuner, 14).is_empty()); // When transformed note is out of range messages are discarded let mut macrotuning = ( Scl::builder().push_cents(120.0).build().unwrap(), KbmRoot::from(Note::from_midi_number(62)).to_kbm(), ); let (macrotuner, _) = ChannelTuner::apply_full_keyboard_tuning( ¯otuning, (0..128).map(PianoKey::from_midi_number), ); let out_of_range = ChannelMessageType::NoteOn { key: 120, velocity: 88, }; assert!(out_of_range.distribute(¯otuner, 4).is_empty()); // Monophonic messages are distributed to multiple channels let monophonic = ChannelMessageType::ProgramChange { program: 42 }; let distributed = monophonic.distribute(&tuner, 4); assert_eq!(distributed.len(), 4); for (index, channel) in (0..4).zip(4..8) { assert_eq!( distributed[index].message_type(), ChannelMessageType::ProgramChange { program: 42 } ); assert_eq!(distributed[index].channel(), channel); } // When mapped channel is out of range messages are discarded let distributed = monophonic.distribute(&tuner, 14); assert_eq!(distributed.len(), 2); for (index, channel) in (0..2).zip(14..16) { assert_eq!( distributed[index].message_type(), ChannelMessageType::ProgramChange { program: 42 } ); assert_eq!(distributed[index].channel(), channel); }
Trait Implementations
impl Clone for ChannelMessageType
[src]
fn clone(&self) -> ChannelMessageType
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for ChannelMessageType
[src]
impl Debug for ChannelMessageType
[src]
impl Eq for ChannelMessageType
[src]
impl PartialEq<ChannelMessageType> for ChannelMessageType
[src]
fn eq(&self, other: &ChannelMessageType) -> bool
[src]
fn ne(&self, other: &ChannelMessageType) -> bool
[src]
impl StructuralEq for ChannelMessageType
[src]
impl StructuralPartialEq for ChannelMessageType
[src]
Auto Trait Implementations
impl RefUnwindSafe for ChannelMessageType
impl Send for ChannelMessageType
impl Sync for ChannelMessageType
impl Unpin for ChannelMessageType
impl UnwindSafe for ChannelMessageType
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,