MidiPacket
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
Example:
# Play middle C on channel 1 with medium velocity
packet = MidiPacket()
note_on = packet.NoteOn(0, 60, 64)
MatrixOS.MIDI.Send(note_on)
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)
Example:
# Stop middle C on channel 1
packet = MidiPacket()
note_off = packet.NoteOff(0, 60, 0)
MatrixOS.MIDI.Send(note_off)
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)
Example:
# Set volume (CC 7) to maximum on channel 1
packet = MidiPacket()
volume_cc = packet.ControlChange(0, 7, 127)
MatrixOS.MIDI.Send(volume_cc)
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)
Example:
# Change to program 1 (piano) on channel 1
packet = MidiPacket()
program_change = packet.ProgramChange(0, 0)
MatrixOS.MIDI.Send(program_change)
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)
Example:
# Bend pitch up on channel 1
packet = MidiPacket()
pitch_bend = packet.PitchBend(0, 10000)
MatrixOS.MIDI.Send(pitch_bend)
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.