usb_midi – MIDI over USB

The usb_midi module contains classes to transmit and receive MIDI messages over USB.

usb_midi.ports :Tuple[Union[PortIn, PortOut], ...]

Tuple of all MIDI ports. Each item is ether PortIn or PortOut.

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(self, nbytes: Optional[int] = None) → Optional[bytes]

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.

Returns

Data read

Return type

bytes or None

readinto(self, buf: WriteableBuffer, nbytes: Optional[int] = None) → Optional[bytes]

Read bytes into the buf. If nbytes is specified then read at most that many bytes. Otherwise, read at most len(buf) bytes.

Returns

number of bytes read and stored into buf

Return type

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(self, buf: ReadableBuffer) → Optional[int]

Write the buffer of bytes to the bus.

Returns

the number of bytes written

Return type

int or None