Sound Byte Libs 0.5.1-121-g3358a44
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
sbl::usb::MidiPort Class Reference

USB MIDI device port (static class) More...

Detailed Description

USB MIDI device port (static class)

All methods are safe to call from main loop context. Not ISR-safe — TinyUSB device stack is not reentrant.

Definition at line 43 of file midi.hpp.

#include <midi.hpp>

Static Public Member Functions

static bool connected ()
 Check if USB MIDI interface is mounted by host.
 
static uint32_t read (uint8_t *buf, uint32_t max_len)
 Read decoded MIDI bytes from USB (RX)
 
static bool send (const sbl::midi::MidiEvent &event, uint8_t port=0)
 Send a MidiEvent over USB MIDI (TX)
 
static uint32_t write (const uint8_t *data, uint32_t len, uint8_t port=0)
 Write raw MIDI bytes to USB MIDI (TX)
 
static uint8_t out_port_count ()
 How many output ports this target has.
 

Member Function Documentation

◆ connected()

bool sbl::usb::MidiPort::connected ( )
static

Check if USB MIDI interface is mounted by host.

Returns
true if host has enumerated and configured the MIDI interface

Definition at line 24 of file midi.cpp.

◆ read()

uint32_t sbl::usb::MidiPort::read ( uint8_t *  buf,
uint32_t  max_len 
)
static

Read decoded MIDI bytes from USB (RX)

TinyUSB unpacks 4-byte USB MIDI Event Packets into standard MIDI byte stream. Feed the output directly to sbl::midi::Parser::push().

Parameters
bufBuffer to receive MIDI bytes
max_lenMaximum bytes to read
Returns
Number of bytes read (0 if nothing available)

Definition at line 28 of file midi.cpp.

◆ send()

bool sbl::usb::MidiPort::send ( const sbl::midi::MidiEvent &  event,
uint8_t  port = 0 
)
static

Send a MidiEvent over USB MIDI (TX)

Converts the event to standard MIDI bytes and writes them via tud_midi_stream_write(), which handles USB packet framing.

Parameters
eventThe MIDI event to send
portOutput port, 0 to out_port_count() - 1
Returns
true if all bytes were written, false if the buffer is full or the port does not exist

Definition at line 33 of file midi.cpp.

◆ write()

uint32_t sbl::usb::MidiPort::write ( const uint8_t *  data,
uint32_t  len,
uint8_t  port = 0 
)
static

Write raw MIDI bytes to USB MIDI (TX)

TinyUSB packs bytes into 4-byte USB MIDI Event Packets.

Parameters
dataRaw MIDI bytes to send
lenNumber of bytes
portOutput port, 0 to out_port_count() - 1
Returns
Number of bytes written (0 if the port does not exist)

Definition at line 43 of file midi.cpp.

◆ out_port_count()

uint8_t sbl::usb::MidiPort::out_port_count ( )
static

How many output ports this target has.

One on a USB device. A port existing does not mean anything is listening to it.

Definition at line 48 of file midi.cpp.


The documentation for this class was generated from the following files: