pub struct MidiClass<'d, D: Driver<'d>> { /* private fields */ }Expand description
Packet level implementation of a USB MIDI device supporting MIDI 1.0 and 2.0.
The MIDI 1.0 (Alternate Setting 0) and MIDI 2.0 (Alternate Setting 1)
protocols share one pair of bulk endpoints; the host selects which protocol
is carried over them with SET_INTERFACE.
This class can be used directly and it has the least overhead due to directly reading and writing USB packets with no intermediate buffers, but it will not act like a stream-like port.
Implementations§
Source§impl<'d, D: Driver<'d>> MidiClass<'d, D>
impl<'d, D: Driver<'d>> MidiClass<'d, D>
Sourcepub fn new(builder: &mut Builder<'d, D>, config: MidiClassConfig<'d>) -> Self
pub fn new(builder: &mut Builder<'d, D>, config: MidiClassConfig<'d>) -> Self
Creates a new MidiClass with the provided UsbBuilder and configuration.
The names in config are ignored, use MidiClass::new_with_names if you need to name jacks
or configure MIDI 2.0.
Sourcepub fn new_with_names(
builder: &mut Builder<'d, D>,
state: &'d mut MidiClassState<'d>,
config: MidiClassConfig<'d>,
) -> Self
pub fn new_with_names( builder: &mut Builder<'d, D>, state: &'d mut MidiClassState<'d>, config: MidiClassConfig<'d>, ) -> Self
Creates a new MidiClass with the provided UsbBuilder that names its interface, jacks,
and Group Terminal Blocks.
Sourcepub fn new_with_state(
builder: &mut Builder<'d, D>,
state: &'d mut MidiClassState<'d>,
config: MidiClassConfig<'d>,
) -> Self
pub fn new_with_state( builder: &mut Builder<'d, D>, state: &'d mut MidiClassState<'d>, config: MidiClassConfig<'d>, ) -> Self
Creates a new MidiClass with the provided UsbBuilder and state.
Sourcepub fn active_alternate_setting(&self) -> u8
pub fn active_alternate_setting(&self) -> u8
Returns the currently active alternate setting (0 for MIDI 1.0, 1 for MIDI 2.0).
The host selects it with SET_INTERFACE (USB MIDI 2.0 §3.1.1).
Sourcepub fn is_midi2_active(&self) -> bool
pub fn is_midi2_active(&self) -> bool
Returns whether MIDI 2.0 (Alternate Setting 1) is currently active.
Sourcepub fn max_packet_size(&self) -> u16
pub fn max_packet_size(&self) -> u16
Gets the maximum packet size in bytes for the bulk endpoints.
The MIDI 1.0 and MIDI 2.0 alternate settings share the same endpoints, so they have the same maximum packet size.
Sourcepub async fn write_packet(&mut self, data: &[u8]) -> Result<(), EndpointError>
pub async fn write_packet(&mut self, data: &[u8]) -> Result<(), EndpointError>
Writes a single packet into the MIDI 1.0 IN endpoint.
Sourcepub async fn read_packet(
&mut self,
data: &mut [u8],
) -> Result<usize, EndpointError>
pub async fn read_packet( &mut self, data: &mut [u8], ) -> Result<usize, EndpointError>
Reads a single packet from the MIDI 1.0 OUT endpoint.
Sourcepub async fn write_ump(
&mut self,
packets: &[UmpPacket],
) -> Result<(), EndpointError>
pub async fn write_ump( &mut self, packets: &[UmpPacket], ) -> Result<(), EndpointError>
Writes UMPs to the host, cut between packets at the packet size, with a ZLP after a full last transfer.
Only meaningful while Alternate Setting 1 (MIDI 2.0) is active.
Sourcepub async fn write_ump_bytes(
&mut self,
data: &[u8],
) -> Result<(), EndpointError>
pub async fn write_ump_bytes( &mut self, data: &[u8], ) -> Result<(), EndpointError>
Writes raw UMP bytes to the host as one transfer, with a ZLP after a full last packet.
This is only meaningful while Alternate Setting 1 (MIDI 2.0) is active.
Sourcepub async fn read_ump<'a>(
&mut self,
data: &'a mut [u8],
) -> Result<UmpReader<'a>, EndpointError>
pub async fn read_ump<'a>( &mut self, data: &'a mut [u8], ) -> Result<UmpReader<'a>, EndpointError>
Reads Universal MIDI Packets from the host.
This is only meaningful while Alternate Setting 1 (MIDI 2.0) is active.
Sourcepub async fn wait_connection(&mut self)
pub async fn wait_connection(&mut self)
Waits for the USB host to enable this interface.
Sourcepub fn split(self) -> (Option<Sender<'d, D>>, Option<Receiver<'d, D>>)
pub fn split(self) -> (Option<Sender<'d, D>>, Option<Receiver<'d, D>>)
Split the endpoints into a sender and receiver.
The same endpoints carry both MIDI 1.0 and MIDI 2.0 data, so a single sender/receiver pair serves both alternate settings. This allows concurrently sending and receiving packets from separate tasks.