Skip to content

Messages

MidiType

Bases: AttrEnum

MIDI message type enumerator to use as MidiMsg type attribute.

NOTE_ON = 'NOTE_ON'

NOTE_OFF = 'NOTE_OFF'

CONTROL_CHANGE = 'CONTROL_CHANGE'

POLYTOUCH = 'POLYTOUCH'

AFTERTOUCH = 'AFTERTOUCH'

PROGRAM_CHANGE = 'PROGRAM_CHANGE'

PITCH_BEND = 'PITCH_BEND'

SYSEX = 'SYSEX'

MidiMsg

Bases: Msg

The base class for MIDI messages that will produce ChannelMsg or SysexMsg objects depending on init arguments.

It is advised to use ChannelMsg or SysexMsg classes to create own MIDI messages for clarity.

ChannelMsg

ChannelMsg(
    type: MidiType = MidiType.CONTROL_CHANGE,
    channel: int = 1,
    data1: int = 0,
    data2: int = 64,
    *,
    combined_data: None | int = None,
    source: None | MidiIn = None
)

Bases: MidiMsg

Channel voice/mode MIDI message. The most common MIDI message.

Parameters:

  • type (MidiType, default: CONTROL_CHANGE ) –

    MIDI message type

  • channel (int, default: 1 ) –

    MIDI message channel (1-16)

  • data1 (int, default: 0 ) –

    First data byte: note, control, program or aftertouch value depending on MIDI message type (0-127)

  • data2 (int, default: 64 ) –

    Second data byte: velocity, value depending on MIDI message type (0-127)

  • combined_data (None | int, default: None ) –

    Both data bytes combined to 14-bit number - pitch value for pitch bend MIDI message (0-16383)

  • source (None | MidiIn, default: None ) –

    The MidiIn instance that generated the message

ctime

ctime: float

Message creation time in "Unix time" format

source

source: None | MidiIn

Input port instance that generated the message

type

type: MidiType

MIDI message type.

channel

channel: int = channel

MIDI message channel (1-16).

data1

data1: int

First data byte: note, control, program or aftertouch value depending on MIDI message type (0-127).

data2

data2: int

Second data byte: velocity, value depending on MIDI message type (0-127).

combined_data

combined_data: int | tuple[int, ...]

Both data bytes combined to 14-bit number - pitch value for pitch bend MIDI message (0-16383).

matches

matches(
    type: None | Container[MidiType] | MidiType = None,
    channel: None | Container[int] | int = None,
    data1: None | Container[int] | int = None,
    data2: None | Container[int] | int = None,
    *,
    combined_data: None | Container[int] | int = None
) -> bool

Checks if message's attributes match all provided attribute conditions:

  1. If condition is None or omitted, it matches anything.

  2. If condition equals attribute, it matches the attribute.

  3. If condition is a container and contains the attribute, it matches the attribute.

Use Not(condition) to invert condition matching.

Returns:

  • bool

    True if all attributes match, False if any does not match

SysexMsg

SysexMsg(combined_data: Sequence[int, ...], *, source: None | MidiIn = None)

Bases: MidiMsg

System exclusive MIDI message

Parameters:

  • combined_data (Sequence[int, ...]) –

    Whole sysex message including opening (240) and closing (247) bytes

  • source (None | MidiIn, default: None ) –

    The MidiIn instance that generated the message

ctime

ctime: float

Message creation time in "Unix time" format

source

source: None | MidiIn

Input port instance that generated the message

type

type = SYSEX

MIDI message type.

channel

channel: tuple[int, ...]

Manufacturer ID (protocol).

data1

data1: tuple[int, ...]

Sub ID (model, device, command, etc.).

data2

data2: tuple[int, ...]

Message data.

combined_data

combined_data: tuple[int, ...]

Whole sysex message including opening 240 and closing 247 bytes.

matches

matches(
    type: None | Container[MidiType] | MidiType = None,
    channel: None | Container[tuple[int, ...]] | tuple[int, ...] = None,
    data1: None | Container[tuple[int, ...]] | tuple[int, ...] = None,
    data2: None | Container[tuple[int, ...]] | tuple[int, ...] = None,
    *,
    combined_data: None | Container[tuple[int, ...]] | tuple[int, ...] = None
) -> bool

Checks if message's attributes match all provided attribute conditions:

  1. If condition is None or omitted, it matches anything.

  2. If condition equals attribute, it matches the attribute.

  3. If condition is a container and contains the attribute, it matches the attribute.

Use Not(condition) to invert condition matching.

Returns:

  • bool

    True if all attributes match, False if any does not match