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”
TrackEvent
s stored in a .mid
file.
See the live
module for more information.
Variants§
Midi
Fields
message: MidiMessage
The MIDI message type and associated data.
A MIDI message associated with a channel, carrying musical data.
Status byte in the range 0x80 ..= 0xEF
.
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>
impl<'a> LiveEvent<'a>
sourcepub fn parse(raw: &'a [u8]) -> Result<LiveEvent<'a>>
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.
sourcepub fn write<W: Write>(&self, out: &mut W) -> WriteResult<W>
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.
sourcepub fn write_with_running_status<W: Write>(
&self,
running_status: &mut Option<u8>,
out: &mut W
) -> WriteResult<W>
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.
sourcepub fn write_std<W: Write>(&self, out: W) -> Result<()>
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.
sourcepub fn write_std_with_running_status<W: Write>(
&self,
running_status: &mut Option<u8>,
out: W
) -> Result<()>
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.
sourcepub fn to_static(&self) -> LiveEvent<'static>
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.
sourcepub fn as_track_event<'b>(&self, arena: &'b Arena) -> TrackEventKind<'b>
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.