Skip to main content
Version: Matrix OS 3.2

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