pub struct ChannelMessage { /* private fields */ }Expand description
A type-safe representation of MIDI messages that aren’t System Common messages.
Implementations§
Source§impl ChannelMessage
impl ChannelMessage
Sourcepub fn from_raw_message(message: &[u8]) -> Option<ChannelMessage>
pub fn from_raw_message(message: &[u8]) -> Option<ChannelMessage>
Parses a MIDI message.
When no valid Channel Voice or Channel Mode message is provided None is returned.
§Examples
let message = ChannelMessage::from_raw_message(&[0b1001_1000, 77, 88]).unwrap();
assert_eq!(message.channel(), 8);
assert_eq!(
message.message_type(),
ChannelMessageType::NoteOn {
key: 77,
velocity: 88
}
);
let invalid_message = [1, 2, 3];
assert_eq!(ChannelMessage::from_raw_message(&invalid_message), None);Sourcepub fn to_raw_message(&self) -> [u8; 3]
pub fn to_raw_message(&self) -> [u8; 3]
Returns the byte representation of a MIDI message.
§Examples
let message = ChannelMessageType::NoteOn {
key: 77,
velocity: 88
}
.in_channel(7)
.unwrap();
assert_eq!(message.to_raw_message(), [0b1001_0111, 77, 88]);Sourcepub fn channel(&self) -> u8
pub fn channel(&self) -> u8
Returns the channel of a MIDI message.
§Examples
let message = ChannelMessage::from_raw_message(&[0b1001_1000, 77, 88]).unwrap();
assert_eq!(message.channel(), 8);Sourcepub fn message_type(&self) -> ChannelMessageType
pub fn message_type(&self) -> ChannelMessageType
Returns the channel-agnostic part of a MIDI message.
§Examples
let message = ChannelMessage::from_raw_message(&[0b1001_1000, 77, 88]).unwrap();
assert!(matches!(message.message_type(), ChannelMessageType::NoteOn { .. }));Trait Implementations§
Source§impl Clone for ChannelMessage
impl Clone for ChannelMessage
Source§fn clone(&self) -> ChannelMessage
fn clone(&self) -> ChannelMessage
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ChannelMessage
impl Debug for ChannelMessage
Source§impl PartialEq for ChannelMessage
impl PartialEq for ChannelMessage
impl Copy for ChannelMessage
impl Eq for ChannelMessage
impl StructuralPartialEq for ChannelMessage
Auto Trait Implementations§
impl Freeze for ChannelMessage
impl RefUnwindSafe for ChannelMessage
impl Send for ChannelMessage
impl Sync for ChannelMessage
impl Unpin for ChannelMessage
impl UnwindSafe for ChannelMessage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more