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 to64.
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 to64.
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 to64.id_range(uint16_t, optional): The range of IDs to check for availability. Defaults to1.
Returns:
uint16_t: The assigned port ID, orMIDI_PORT_INVALIDif 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 to0.
Returns:
bool:trueif a packet was successfully retrieved, otherwisefalse.
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 to0.
Returns:
bool:trueif the packet was sent successfully, otherwisefalse.
Comments