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);

Get underlying buffer capacity in bytes

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");

Clears the buffer, removing all packets. Note that this method has no effect on the allocated capacity of the buffer.

Methods from Deref<Target = PacketList>

Check if the packet list is empty.

Get the number of packets in the list.

Get an iterator for the packets in the list.

Trait Implementations

Performs the conversion.

The resulting type after dereferencing.

Dereferences the value.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.