usb_midi
– MIDI over USB¶
The usb_midi
module contains classes to transmit and receive MIDI messages over USB.
Available on these boards
- usb_midi.ports :Tuple[Union[PortIn, PortOut], Ellipsis]¶
Tuple of all MIDI ports. Each item is ether
PortIn
orPortOut
.
- usb_midi.disable() None ¶
Disable presenting a USB MIDI device to the host. The device is normally enabled by default, but on some boards with limited endpoints including ESP32-S2 and certain STM boards, it is disabled by default. Can be called in
boot.py
, before USB is connected.
- usb_midi.enable() None ¶
Enable presenting a USB MIDI device to the host. The device is enabled by default, so you do not normally need to call this function. Can be called in
boot.py
, before USB is connected.If you enable too many devices at once, you will run out of USB endpoints. The number of available endpoints varies by microcontroller. CircuitPython will go into safe mode after running boot.py to inform you if not enough endpoints are available.
- class usb_midi.PortIn¶
Receives midi commands over USB
You cannot create an instance of
usb_midi.PortIn
.PortIn objects are constructed for every corresponding entry in the USB descriptor and added to the
usb_midi.ports
tuple.- read(nbytes: int | None = None) bytes | None ¶
Read characters. If
nbytes
is specified then read at most that many bytes. Otherwise, read everything that arrives until the connection times out. Providing the number of bytes expected is highly recommended because it will be faster.- Renvoie:
Data read
- Type renvoyé:
bytes or None
- class usb_midi.PortOut¶
Sends midi messages to a computer over USB
You cannot create an instance of
usb_midi.PortOut
.PortOut objects are constructed for every corresponding entry in the USB descriptor and added to the
usb_midi.ports
tuple.- write(buf: _typing.ReadableBuffer) int | None ¶
Write the buffer of bytes to the bus.
- Renvoie:
the number of bytes written
- Type renvoyé:
int or None