Skip to content

MIDI codes

These constants can be used to match against status codes for MIDI messages, accessed from fl_classes.FlMidiMsg.status.

import midi

def OnMidiIn(msg: FlMidiMsg):
    # Use a bitwise and to discard the channel number
    if msg.status & 0xF0 == midi.MIDI_NOTEON:
        print("event is a note on event")

MIDI_NOTEON module-attribute

MIDI_NOTEON = 144

MIDI note-on

  • data1 is note number
  • data2 is velocity (0 for note off)

MIDI_NOTEOFF module-attribute

MIDI_NOTEOFF = 128

MIDI note-off

  • data1 is note number
  • data2 is release value

MIDI_KEYAFTERTOUCH module-attribute

MIDI_KEYAFTERTOUCH = 160

MIDI key after-touch

  • data1 is note number
  • data2 is after-touch value

MIDI_CONTROLCHANGE module-attribute

MIDI_CONTROLCHANGE = 176

MIDI control change

MIDI_PROGRAMCHANGE module-attribute

MIDI_PROGRAMCHANGE = 192

MIDI program change

  • data1 contains the program number (instrument) to select

MIDI_CHANAFTERTOUCH module-attribute

MIDI_CHANAFTERTOUCH = 208

MIDI channel after-touch

  • data1 is after-touch value

MIDI_PITCHBEND module-attribute

MIDI_PITCHBEND = 224

MIDI pitch-bend

Both data1 and data2 are combined to produce a 14-bit pitch-bend value.

def pitch_bend_event_to_float(event: FlMidiMsg) -> float:
    return (event.data1 + (event.data2 << 7)) / 16383

MIDI_SYSTEMMESSAGE module-attribute

MIDI_SYSTEMMESSAGE = 240

MIDI system-exclusive (sysex) message.

Remaining data is included in the event.sysex property.

MIDI_BEGINSYSEX module-attribute

MIDI_BEGINSYSEX = 240

MIDI system-exclusive message start.

This should be the first byte of all sysex messages.

MIDI_ENDSYSEX module-attribute

MIDI_ENDSYSEX = 247

MIDI system-exclusive message end.

This should be the final byte of all sysex messages.

MIDI_MTCQUARTERFRAME module-attribute

MIDI_MTCQUARTERFRAME = 241

MIDI Time Code quarter-frame message.

  • data1 contains a time code value

MIDI_SONGPOSPTR module-attribute

MIDI_SONGPOSPTR = 242

TODO

MIDI_SONGSELECT module-attribute

MIDI_SONGSELECT = 243

TODO

MIDI_TIMINGCLOCK module-attribute

MIDI_TIMINGCLOCK = 248

TODO

MIDI_START module-attribute

MIDI_START = 250

TODO

MIDI_CONTINUE module-attribute

MIDI_CONTINUE = 251

TODO

MIDI_STOP module-attribute

MIDI_STOP = 252

TODO

MIDI_ACTIVESENSING module-attribute

MIDI_ACTIVESENSING = 254

TODO

MIDI_SYSTEMRESET module-attribute

MIDI_SYSTEMRESET = 255

A system reset message. This is a single byte 0xFF that instructs the recipient to reset itself to the default state.

EventNameT module-attribute

EventNameT = ['Note Off', 'Note On ', 'Key Aftertouch', 'Control Change', 'Program Change', 'Channel Aftertouch', 'Pitch Bend', 'System Message']

A list of event names, used by some scripts to show information about events.