Struct coremidi::PacketBuffer [−][src]
pub struct PacketBuffer { /* fields omitted */ }
Expand description
A mutable PacketList
builder.
A PacketList
is an immutable reference to a MIDIPacketList structure,
while a PacketBuffer
is a mutable structure that allows to build a PacketList
by adding packets.
It dereferences to a PacketList
, so it can be used whenever a PacketList
is needed.
Implementations
Create a PacketBuffer
with a single packet containing the provided timestamp and data.
According to the official documentation for CoreMIDI, the timestamp represents the time at which the events are to be played, where zero means “now”. The timestamp applies to the first MIDI byte in the packet.
Example on how to create a PacketBuffer
with a single packet for a MIDI note on for C-5:
use coremidi::PacketBuffer;
let buffer = PacketBuffer::new(0, &[0x90, 0x3c, 0x7f]);
assert_eq!(buffer.len(), 1);
assert_eq!(buffer.iter().next().map(|packet| packet.data().to_vec()), Some(vec![0x90, 0x3c, 0x7f]))
Create an empty PacketBuffer
with no packets.
Example on how to create an empty PacketBuffer
with a capacity for 128 bytes in total (including headers):
let buffer = coremidi::PacketBuffer::with_capacity(128);
assert_eq!(buffer.len(), 0);
assert_eq!(buffer.capacity(), 128);
Add a new event containing the provided timestamp and data.
According to the official documentation for CoreMIDI, the timestamp represents the time at which the events are to be played, where zero means “now”. The timestamp applies to the first MIDI byte in the packet.
An event must not have a timestamp that is smaller than that of a previous event
in the same PacketList
Example:
let mut chord = coremidi::PacketBuffer::new(0, &[0x90, 0x3c, 0x7f]);
chord.push_data(0, &[0x90, 0x40, 0x7f]);
assert_eq!(chord.len(), 1);
let repr = format!("{}", &chord as &coremidi::PacketList);
assert_eq!(repr, "PacketList(len=1)\n 0000000000000000: 90 3c 7f 90 40 7f");
Methods from Deref<Target = PacketList>
pub fn iter(&self) -> PacketListIterator<'_>ⓘNotable traits for PacketListIterator<'a>impl<'a> Iterator for PacketListIterator<'a> type Item = &'a Packet;
pub fn iter(&self) -> PacketListIterator<'_>ⓘNotable traits for PacketListIterator<'a>impl<'a> Iterator for PacketListIterator<'a> type Item = &'a Packet;
impl<'a> Iterator for PacketListIterator<'a> type Item = &'a Packet;
Get an iterator for the packets in the list.
Trait Implementations
Performs the conversion.
type Target = PacketList
type Target = PacketList
The resulting type after dereferencing.
Dereferences the value.