MidiPacket
Preview noticeβ
The MatrixOS Python API is in preview and is subject to change; it may contain errors.
Overviewβ
The MidiPacket class encapsulates a MIDI message, including its port, status, and data. It provides utility methods for creating, analyzing, and manipulating MIDI messages for both input and output operations.
The Python MidiPacket class is implemented in Applications/Python/PikaPython/MatrixOS_MidiPacket.py with type hints in Applications/Python/PikaPython/_MatrixOS_MidiPacket.pyi.
Constructorβ
MidiPacket(*val)β
def __init__(self, *val) -> None
Creates a MIDI packet with variable arguments depending on the message type.
Parameters:
*val: Variable arguments for constructing different types of MIDI messages
Static Factory Methodsβ
Note Messagesβ
NoteOnβ
def NoteOn(self, channel: int, note: int, velocity: int = 127) -> MidiPacket
Creates a MIDI Note On message.
Parameters:
channel(int): MIDI channel (0-15)note(int): MIDI note number (0-127)velocity(int, optional): Note velocity (0-127, defaults to 127)
Returns:
MidiPacket: Note On packet
NoteOffβ
def NoteOff(self, channel: int, note: int, velocity: int = 0) -> MidiPacket
Creates a MIDI Note Off message.
Parameters:
channel(int): MIDI channel (0-15)note(int): MIDI note number (0-127)velocity(int, optional): Release velocity (0-127, defaults to 0)
Control Messagesβ
ControlChangeβ
def ControlChange(self, channel: int, controller: int, value: int) -> MidiPacket
Creates a MIDI Control Change message.
Parameters:
channel(int): MIDI channel (0-15)controller(int): Controller number (0-127)value(int): Controller value (0-127)
ProgramChangeβ
def ProgramChange(self, channel: int, program: int) -> MidiPacket
Creates a MIDI Program Change message.
Parameters:
channel(int): MIDI channel (0-15)program(int): Program number (0-127)
PitchBendβ
def PitchBend(self, channel: int, value: int) -> MidiPacket
Creates a MIDI Pitch Bend message.
Parameters:
channel(int): MIDI channel (0-15)value(int): Pitch bend value (0-16383, 8192 = center)
Pressure Messagesβ
AfterTouchβ
def AfterTouch(self, channel: int, note: int, pressure: int) -> MidiPacket
Creates a MIDI Polyphonic Key Pressure (Aftertouch) message.
Parameters:
channel(int): MIDI channel (0-15)note(int): MIDI note number (0-127)pressure(int): Pressure value (0-127)
ChannelPressureβ
def ChannelPressure(self, channel: int, pressure: int) -> MidiPacket
Creates a MIDI Channel Pressure message.
Parameters:
channel(int): MIDI channel (0-15)pressure(int): Pressure value (0-127)
System Real-Time Messagesβ
Clockβ
def Clock(self) -> MidiPacket
Creates a MIDI Clock message for tempo synchronization.
Startβ
def Start(self) -> MidiPacket
Creates a MIDI Start message to begin sequencer playback.
Continueβ
def Continue(self) -> MidiPacket
Creates a MIDI Continue message to resume sequencer playback.
Stopβ
def Stop(self) -> MidiPacket
Creates a MIDI Stop message to halt sequencer playback.
ActiveSenseβ
def ActiveSense(self) -> MidiPacket
Creates a MIDI Active Sensing message.
Resetβ
def Reset(self) -> MidiPacket
Creates a MIDI System Reset message.
System Common Messagesβ
SongPositionβ
def SongPosition(self, position: int) -> MidiPacket
Creates a MIDI Song Position Pointer message.
Parameters:
position(int): Song position in MIDI beats
SongSelectβ
def SongSelect(self, song: int) -> MidiPacket
Creates a MIDI Song Select message.
Parameters:
song(int): Song number (0-127)
TuneRequestβ
def TuneRequest(self) -> MidiPacket
Creates a MIDI Tune Request message.
Getter Methodsβ
Portβ
def Port(self) -> MidiPortID
Gets the MIDI port identifier for this packet.
Returns:
MidiPortID: The port identifier
Statusβ
def Status(self) -> MidiStatus
Gets the MIDI status/message type.
Returns:
MidiStatus: The message status type
Channelβ
def Channel(self) -> int
Gets the MIDI channel number.
Returns:
int: Channel number (0-15)
Noteβ
def Note(self) -> int
Gets the MIDI note number or controller number.
Returns:
int: Note/controller value (0-127)
Controllerβ
def Controller(self) -> int
Gets the MIDI controller number (alias for Note()).
Returns:
int: Controller number (0-127)
Velocityβ
def Velocity(self) -> int
Gets the velocity or pressure value.
Returns:
int: Velocity/pressure value (0-127)
Valueβ
def Value(self) -> int
Gets the value associated with the MIDI message (e.g., pitch bend, control change value).
Returns:
int: The message value
Setter Methodsβ
SetStatusβ
def SetStatus(self, status: MidiStatus) -> None
Sets the MIDI status/message type.
SetChannelβ
def SetChannel(self, channel: int) -> None
Sets the MIDI channel number.
SetNoteβ
def SetNote(self, note: int) -> None
Sets the MIDI note or controller number.
SetControllerβ
def SetController(self, controller: int) -> None
Sets the MIDI controller number.
SetVelocityβ
def SetVelocity(self, velocity: int) -> None
Sets the velocity or pressure value.
SetValueβ
def SetValue(self, value: int) -> None
Sets the message value.
Helper Methodsβ
Lengthβ
def Length(self) -> int
Gets the length of the MIDI message based on its status.
Returns:
int: Message length in bytes
SysExβ
def SysEx(self) -> bool
Checks if the message is a System Exclusive (SysEx) message.
Returns:
bool: True if SysEx message
SysExStartβ
def SysExStart(self) -> bool
Checks if the message is the start of a SysEx message.
Returns:
bool: True if SysEx start message
Comments