Enum wmidi::MidiMessage

source ·
pub enum MidiMessage<'a> {
Show 20 variants NoteOff(Channel, Note, Velocity), NoteOn(Channel, Note, Velocity), PolyphonicKeyPressure(Channel, Note, Velocity), ControlChange(Channel, ControlFunction, ControlValue), ProgramChange(Channel, ProgramNumber), ChannelPressure(Channel, Velocity), PitchBendChange(Channel, PitchBend), SysEx(&'a [U7]), OwnedSysEx(Vec<U7>), MidiTimeCode(U7), SongPositionPointer(SongPosition), SongSelect(Song), Reserved(u8), TuneRequest, TimingClock, Start, Continue, Stop, ActiveSensing, Reset,
}
Expand description

Holds information based on the Midi 1.0 spec.

Variants§

§

NoteOff(Channel, Note, Velocity)

This message is sent when a note is released (ended).

§

NoteOn(Channel, Note, Velocity)

This message is sent when a note is depressed (start).

§

PolyphonicKeyPressure(Channel, Note, Velocity)

This message is most often sent by pressing down on the key after it “bottoms out”.

§

ControlChange(Channel, ControlFunction, ControlValue)

This message is sent when a controller value changes. Controllers include devices such as pedals and levers.

Controller numbers 120-127 are reserved as “Channel Mode Messages”.

§

ProgramChange(Channel, ProgramNumber)

This message is sent when the patch number changes.

§

ChannelPressure(Channel, Velocity)

This message is most often sent by pressing down on the key after it “bottoms out”. This message is different from polyphonic after-touch. Use this message to send the single greatest pressure value (of all the current depressed keys).

§

PitchBendChange(Channel, PitchBend)

This message is sent to indicate a change in the pitch bender (wheel or level, typically). The pitch bender is measured by a fourteen bit value. Center is 8192.

§

SysEx(&'a [U7])

This message type allows manufacturers to create their own messages (such as bulk dumps, patch parameters, and other non-spec data) and provides a mechanism for creating additional MIDI Specification messages.

In the data held by the SysEx message, the Manufacturer’s ID code (assigned by MMA or AMEI) is either 1 byte or 3 bytes. Two of the 1 Byte IDs are reserved for extensions called Universal Exclusive Messages, which are not manufacturer-specific. If a device recognizes the ID code as its own (or as a supported Universal message) it will listen to the rest of the message. Otherwise the message will be ignored.

§

OwnedSysEx(Vec<U7>)

This message type allows manufacturers to create their own messages (such as bulk dumps, patch parameters, and other non-spec data) and provides a mechanism for creating additional MIDI Specification messages.

In the data held by the SysEx message, the Manufacturer’s ID code (assigned by MMA or AMEI) is either 1 byte or 3 bytes. Two of the 1 Byte IDs are reserved for extensions called Universal Exclusive Messages, which are not manufacturer-specific. If a device recognizes the ID code as its own (or as a supported Universal message) it will listen to the rest of the message. Otherwise the message will be ignored.

§

MidiTimeCode(U7)

MIDI Time Code Quarter Frame.

The data is in the format 0nnndddd where nnn is the Message Type and dddd is the Value.

TODO: Interpret data instead of providing the raw format.

§

SongPositionPointer(SongPosition)

This is an internal 14 bit value that holds the number of MIDI beats (1 beat = six MIDI clocks) since the start of the song.

§

SongSelect(Song)

The Song Select specifies which sequence or song is to be played.

§

Reserved(u8)

The u8 data holds the status byte.

§

TuneRequest

Upon receiving a Tune Request, all analog synthesizers should tune their oscillators.

§

TimingClock

Timing Clock. Sent 24 times per quarter note when synchronization is required.

§

Start

Start the current sequence playing. (This message will be followed with Timing Clocks).

§

Continue

Continue at the point the sequence was Stopped.

§

Stop

Stop the current sequence.

§

ActiveSensing

This message is intended to be sent repeatedly to tell the receiver that a connection is alive. Use of this message is optional. When initially received, the receiver will expect to receive another Active Sensing message each 300ms (max), and if it idoes not, then it will assume that the connection has been terminated. At termination, the receiver will turn off all voices and return to normal (non-active sensing) operation.

§

Reset

Reset all receivers in the system to power-up status. This should be used sparingly, preferably under manual control. In particular, it should not be sent on power-up.

Implementations§

source§

impl<'a> MidiMessage<'a>

source

pub fn from_bytes(bytes: &'a [u8]) -> Result<Self, Error>

Construct a midi message from bytes.

source

pub fn copy_to_slice(&self, slice: &mut [u8]) -> Result<usize, ToSliceError>

Copies the message as bytes to slice. If slice does not have enough capacity to fit the message, then an error is returned. On success, the number of bytes written will be returned. This should be the same number obtained from self.bytes_size().

source

pub fn drop_unowned_sysex(self) -> Option<MidiMessage<'static>>

Return Some(midi_message) if self is not a SysEx message, or None if it is. This expands the lifetime of the MidiMessage from 'a to 'static.

source

pub fn to_owned(&self) -> MidiMessage<'static>

Take ownership of the SysEx data. This expands the lifetime of the message to 'static. If 'static lifetime is needed but SysEx messages can be dropped, consider using self.drop_unowned_sysex().

source

pub fn bytes_size(&self) -> usize

The number of bytes the MIDI message takes when converted to bytes.

source

pub fn wire_size(&self) -> usize

👎Deprecated since 3.1.0: Function has been renamed to MidiMessage::bytes_size().

The number of bytes the MIDI message takes when encoded with the std::io::Read trait.

source

pub fn channel(&self) -> Option<Channel>

The channel associated with the MIDI message, if applicable for the message type.

source

pub fn to_vec(&self) -> Vec<u8>

Convert the message to a vector of bytes. Prefer using copy_to_slice if possible for better performance.

Trait Implementations§

source§

impl<'a> Clone for MidiMessage<'a>

source§

fn clone(&self) -> MidiMessage<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for MidiMessage<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> PartialEq for MidiMessage<'a>

source§

fn eq(&self, other: &MidiMessage<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> Read for MidiMessage<'a>

source§

fn read(&mut self, buf: &mut [u8]) -> Result<usize>

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
1.36.0 · source§

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>

Like read, except that it reads into a slice of buffers. Read more
source§

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
1.0.0 · source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>

Read all bytes until EOF in this source, placing them into buf. Read more
1.0.0 · source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

Read all bytes until EOF in this source, appending them to buf. Read more
1.6.0 · source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

Read the exact number of bytes required to fill buf. Read more
source§

fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
source§

fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Read the exact number of bytes required to fill cursor. Read more
1.0.0 · source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adaptor for this instance of Read. Read more
1.0.0 · source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more
source§

impl<'a> TryFrom<&'a [u8]> for MidiMessage<'a>

source§

fn try_from(bytes: &'a [u8]) -> Result<Self, Self::Error>

Construct a midi message from bytes.

§

type Error = FromBytesError

The type returned in the event of a conversion error.
source§

impl<'a> Eq for MidiMessage<'a>

source§

impl<'a> StructuralEq for MidiMessage<'a>

source§

impl<'a> StructuralPartialEq for MidiMessage<'a>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for MidiMessage<'a>

§

impl<'a> Send for MidiMessage<'a>

§

impl<'a> Sync for MidiMessage<'a>

§

impl<'a> Unpin for MidiMessage<'a>

§

impl<'a> UnwindSafe for MidiMessage<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.