LiveEvent

Enum LiveEvent 

Source
pub enum LiveEvent<'a> {
    Midi {
        channel: u4,
        message: MidiMessage,
    },
    Common(SystemCommon<'a>),
    Realtime(SystemRealtime),
}
Expand description

A live event produced by an OS API or generated on-the-fly, in contrast with “dead” TrackEvents stored in a .mid file.

See the live module for more information.

Variants§

§

Midi

A MIDI message associated with a channel, carrying musical data.

Status byte in the range 0x80 ..= 0xEF.

Fields

§channel: u4

The MIDI channel that this message is associated with.

§message: MidiMessage

The MIDI message type and associated data.

§

Common(SystemCommon<'a>)

A System Common message, as defined by the MIDI spec, including System Exclusive events.

Status byte in the range 0xF0 ..= 0xF7.

§

Realtime(SystemRealtime)

A one-byte System Realtime message.

Status byte in the range 0xF8 ..= 0xFF.

Implementations§

Source§

impl<'a> LiveEvent<'a>

Source

pub fn parse(raw: &'a [u8]) -> Result<LiveEvent<'a>>

Parse a complete MIDI message from its raw bytes.

This method can be used to parse raw MIDI bytes coming from an OS API (ie. a status byte in the range 0x80 ..= 0xFF followed by data bytes in the range 0x00 ..= 0x7F).

Note that this function will not read the “meta messages” present in .mid files, since those cannot appear in a live MIDI connection, only in offline files.

Also see the example in the root crate documentation.

Source

pub fn write<W: Write>(&self, out: &mut W) -> WriteResult<W>

Write a standalone message to the given output.

This method can be used to write messages to be consumed by OS APIs. Also see the example in the root crate documentation.

Source

pub fn write_with_running_status<W: Write>( &self, running_status: &mut Option<u8>, out: &mut W, ) -> WriteResult<W>

Write a message, skipping the status if it shares the status with the previous message.

Note that it’s usually discouraged to feed messages with running status to OS APIs.

Source

pub fn write_std<W: Write>(&self, out: W) -> Result<()>

Write a standalone message to the given std::io::Write output.

This method is only available with the std feature enabled.

Source

pub fn write_std_with_running_status<W: Write>( &self, running_status: &mut Option<u8>, out: W, ) -> Result<()>

Write a message, skipping the status if it shares the status with the previous message.

Note that it’s usually discouraged to feed messages with running status to OS APIs.

This method is only available with the std feature enabled.

Source

pub fn to_static(&self) -> LiveEvent<'static>

Remove any lifetimed data from this event to create a LiveEvent with 'static lifetime that can be stored and moved everywhere, solving borrow checker issues.

WARNING: Any bytestrings, including SysEx dumps, will be replaced by empty bytestrings.

Source

pub fn as_track_event<'b>(&self, arena: &'b Arena) -> TrackEventKind<'b>

Convert this LiveEvent into a static TrackEventKind, which can be written to a .mid file.

This method takes an Arena allocator, since all LiveEvent variants other than Midi require allocation to be converted.

Unlike as_live_event, this method does not return an Option. Any messages that do not have an analogous TrackEventKind variant will be encoded into their raw bytes and converted as TrackEventKind::Escape.

This method is only available with the alloc feature enabled.

Trait Implementations§

Source§

impl<'a> Clone for LiveEvent<'a>

Source§

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

Returns a duplicate 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 LiveEvent<'a>

Source§

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

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

impl<'a> Hash for LiveEvent<'a>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> PartialEq for LiveEvent<'a>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Copy for LiveEvent<'a>

Source§

impl<'a> Eq for LiveEvent<'a>

Source§

impl<'a> StructuralPartialEq for LiveEvent<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for LiveEvent<'a>

§

impl<'a> RefUnwindSafe for LiveEvent<'a>

§

impl<'a> Send for LiveEvent<'a>

§

impl<'a> Sync for LiveEvent<'a>

§

impl<'a> Unpin for LiveEvent<'a>

§

impl<'a> UnwindSafe for LiveEvent<'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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

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>,

Source§

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>,

Source§

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.