embassy-usb

Crates

git

Versions

default

Flavors

Skip to main content

MidiHost

Struct MidiHost 

Source
pub struct MidiHost<'d, A: UsbHostAllocator<'d>> { /* private fields */ }
Expand description

Friendly host driver for one USB MIDI 1.0 streaming interface.

Input-only and output-only devices are represented by an empty port slice on the unsupported direction.

It uses alternate setting 0 and sends no control request, so a device last used as MIDI 2.0 must first go through MidiInfo::deactivate.

This convenience API supports one alternate-setting-zero MIDIStreaming interface with at most one bulk endpoint per direction. Use raw for devices with multiple streaming interfaces or same-direction endpoints.

Implementations§

Source§

impl<'d, A: UsbHostAllocator<'d>> MidiHost<'d, A>

Source

pub fn new( alloc: &A, config_desc: &[u8], enum_info: &EnumerationInfo, ) -> Result<Self, MidiError>

Discover the MIDI ports and allocate the available bulk pipes.

Source

pub fn from_info( alloc: &A, info: MidiInfo, enum_info: &EnumerationInfo, ) -> Result<Self, MidiError>

Allocate the bulk pipes for a MIDI 1.0 function described by info.

Source

pub fn info(&self) -> &MidiInfo

The function this host was opened from.

Source

pub fn input_ports(&self) -> &[MidiInputPort]

Logical device-to-host MIDI ports.

Source

pub fn output_ports(&self) -> &[MidiOutputPort]

Logical host-to-device MIDI ports.

Source

pub async fn read_transfer( &mut self, buf: &mut [u8], ) -> Result<usize, MidiError>

Receive one bulk transfer containing USB-MIDI event packets.

Source

pub async fn write_packet(&mut self, packets: &[u8]) -> Result<(), MidiError>

Send one or more complete USB-MIDI event packets.

Source

pub async fn send( &mut self, port: MidiOutputPort, message: &[u8], ) -> Result<(), MidiError>

Encode and send one MIDI message, or a SysEx fragment of up to three bytes, to a logical port.

Source

pub async fn send_sysex( &mut self, port: MidiOutputPort, message: &[u8], ) -> Result<(), MidiError>

Source

pub fn split( self, ) -> (Option<MidiSender<'d, A>>, Option<MidiReceiver<'d, A>>, MidiInfo)

Split into independently owned sender and receiver halves, plus the discovery info.

This allows sending and receiving from separate tasks.

Trait Implementations§

Source§

impl<'d, A: UsbHostAllocator<'d>> HostClass<'d, A> for MidiHost<'d, A>

Source§

const NAME: &'static str = "MIDI 1.0"

Human-readable class name, used for logging.
Source§

type Info = MidiInfo

Cheap, owned description of the interface(s) and endpoints to use. Read more
Source§

fn probe(enum_info: &EnumerationInfo, cfg: &[u8]) -> Option<MidiInfo>

Find the class in an enumerated device. Returns None when the class is not present. This must not allocate pipes or issue control requests. Read more
Source§

async fn open( alloc: &A, _cfg: &[u8], info: MidiInfo, enum_info: &EnumerationInfo, ) -> Result<Self, ClassError>

Allocate pipes and perform any class-specific setup.
Source§

fn is_present(enum_info: &EnumerationInfo, cfg: &[u8]) -> bool

Convenience wrapper around probe.

Auto Trait Implementations§

§

impl<'d, A> Forget for MidiHost<'d, A>

§

impl<'d, A> Freeze for MidiHost<'d, A>
where Option<MidiSender<'d, A>>: Freeze, Option<MidiReceiver<'d, A>>: Freeze,

§

impl<'d, A> Move for MidiHost<'d, A>

§

impl<'d, A> RefUnwindSafe for MidiHost<'d, A>

§

impl<'d, A> Send for MidiHost<'d, A>
where Option<MidiSender<'d, A>>: Send, Option<MidiReceiver<'d, A>>: Send,

§

impl<'d, A> Sync for MidiHost<'d, A>
where Option<MidiSender<'d, A>>: Sync, Option<MidiReceiver<'d, A>>: Sync,

§

impl<'d, A> Unpin for MidiHost<'d, A>
where Option<MidiSender<'d, A>>: Unpin, Option<MidiReceiver<'d, A>>: Unpin,

§

impl<'d, A> UnsafeUnpin for MidiHost<'d, A>

§

impl<'d, A> UnwindSafe for MidiHost<'d, 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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.