Section MIDI

MIDI utility functions.

Summary

Return typeFunction and summary
tableMidiGetEventFiltered(boolean allowNoteOn, boolean allowNoteOff, boolean allowCC, boolean allowProgramChange, boolean allowAftertouch, boolean allowPitchBend, boolean allowOthers, int delay, table allowedSources)
Apply a filter to Midi.GetEvent to exclude some Midi messages and return all events since last call.
 MidiSendCC(int interface, int channel, int controller, int value)
Send a control change (CC) message to a MIDI device.

Functions

MidiGetEventFiltered(boolean allowNoteOn, boolean allowNoteOff, boolean allowCC, boolean allowProgramChange, boolean allowAftertouch, boolean allowPitchBend, boolean allowOthers, int delay, table allowedSources)

Apply a filter to Midi.GetEvent to exclude some Midi messages and return all events since last call.

You can exclude:

  1. message you don't need, e.g. aftertouch
  2. a lot of steps while moving a controller (slider, knob, pitch bend).
    To do this, set a delay in milliseconds. This result in a loss of data, note suitable for fine control of sound, but useful when hardware controllers replace mouse or computer keyboard inputs.

ParameterTypeDefaultDescription
allowNoteOnbooleantrueAllow Note On events?
allowNoteOffbooleantrueAllow Note Off events?
allowCCbooleantrueAllow controller change events?
allowProgramChangebooleantrueAllow PC event?
allowAftertouchbooleantrueAllow aftertouch event?
allowPitchBendbooleantrueAllow pitch bend event?
allowOthersbooleantrueAllow other events?
delayint0Delay in milliseconds for CC and pitch bend, reduce the number of events returned while the wheel or controller is sliding / rotating.
If delay is set, then only the last value is returned.
allowedSourcestablenilThe accepted sources (nil means all - no filter):
  • INPUT_SOURCE_UNKNOWN: none/unknown
  • INPUT_SOURCE_MIDI: from an external MIDI device
  • INPUT_SOURCE_VIRTUAL_KBD: from a click on a virtual keyboard
  • INPUT_SOURCE_COMPUTER_KBD: from the computer keyboard
  • INPUT_SOURCE_PLAYED_MUSIC: from the played score
Return
table: Table of Midi events, each item are structured as:
  • Event, int: type of event :
    • 1 mean note on (key pressed),
    • 2 mean note off or note on with velocity = 0 (key released)
    • 10 means polyphonic aftertouch
    • 11 means CC, Controller Change (modulation wheel, pedal, knobs, cursors, bank change...)
    • 12 means PC, Program Change
    • 13 means channel aftertouch
    • 14 means pitch bend
  • Channel, int: the channel from 0 to 15
  • Pitch, int: the note pitch / selected controller / program from 0 to 127
  • Velocity, int: the velocity / controller value from 0 to 127
  • TimeMs, int: the time position in millisecond of the event
  • TimePos, number: the time position in the playing score (-1 if no score currently playing)
  • Source, int: the source for this event (MSDefine constant):
    • INPUT_SOURCE_UNKNOWN: none/unknown
    • INPUT_SOURCE_MIDI: from an external MIDI device
    • INPUT_SOURCE_VIRTUAL_KBD: from a click on a virtual keyboard
    • INPUT_SOURCE_COMPUTER_KBD: from the computer keyboard
    • INPUT_SOURCE_PLAYED_MUSIC: from the played score

MidiSendCC(int interface, int channel, int controller, int value)

Send a control change (CC) message to a MIDI device.

ParameterTypeDefaultDescription
interfaceint 1-based to match the numbering in hardware configuration (1-12)
channelint 1-based to match the usual chanel numbering (1-16)
controllerint 0 for bank select, 1 for modulation wheel, 2 for breath control...
See https://anotherproducer.com/online-tools-for-musicians/midi-cc-list/
valueint between 0 and 127