Skip to main content

Class: MidiPort

The MidiPort class provides functionality to manage MIDI ports, including opening, closing, sending, and receiving MIDI packets. It is part of the Matrix OS MIDI system.

The source file for this utility is located in os/framework/MidiPort.h


Member Variables​

name​

string name;

The name of the MIDI port.


id​

uint16_t id = MIDI_PORT_INVALID;

The ID of the MIDI port. Defaults to MIDI_PORT_INVALID. - See MidiPacket for more information.


Constructors​

Default Constructor​

MidiPort();

Creates an uninitialized MidiPort.


Constructor with Name and ID​

MidiPort(string name, uint16_t id, uint16_t queue_size = 64);

Creates a MidiPort with a specified name and ID.

Parameters:

  • name (string): The name of the MIDI port.
  • id (uint16_t): The ID to assign to the MIDI port.
  • queue_size (uint16_t, optional): The size of the MIDI buffer. Defaults to 64.

Constructor with Name and Port Class​

MidiPort(string name, EMidiPortID port_class, uint16_t queue_size = 64);

Creates a MidiPort with a specified name and port class.

Parameters:

  • name (string): The name of the MIDI port.
  • port_class (EMidiPortID): The port class identifier.
  • queue_size (uint16_t, optional): The size of the MIDI buffer. Defaults to 64.

Destructor​

~MidiPort();

Closes the MIDI port and releases resources.


Member Functions​

Open​

uint16_t Open(uint16_t id, uint16_t queue_size = 64, uint16_t id_range = 1);

Opens a MIDI port with the specified ID.

Parameters:

  • id (uint16_t): The base ID to use.
  • queue_size (uint16_t, optional): The size of the MIDI buffer. Defaults to 64.
  • id_range (uint16_t, optional): The range of IDs to check for availability. Defaults to 1.

Returns:

  • uint16_t: The assigned port ID, or MIDI_PORT_INVALID if the port could not be opened.

Close​

void Close();

Closes the MIDI port and releases resources.


SetName​

void SetName(string name);

Sets the name of the MIDI port.

Parameters:

  • name (string): The new name of the MIDI port.

Get​

bool Get(MidiPacket* midipacket_dest, uint32_t timeout_ms = 0);

Retrieves a MIDI packet from the port's buffer.

Parameters:

  • midipacket_dest (MidiPacket*): Pointer to store the retrieved MIDI packet.
  • timeout_ms (uint32_t, optional): Timeout in milliseconds. Defaults to 0.

Returns:

  • bool: true if a packet was successfully retrieved, otherwise false.

Send​

bool Send(MidiPacket midipacket, uint32_t timeout_ms = 0);

Sends a MIDI packet from the port. The packet will be sent to the port specified in the packet.

Parameters:

  • midipacket (MidiPacket): The MIDI packet to send.
  • timeout_ms (uint32_t, optional): Timeout in milliseconds. Defaults to 0.

Returns:

  • bool: true if the packet was sent successfully, otherwise false.

Comments