Section MIDI
MIDI utility functions.
Summary
Return type | Function and summary |
---|---|
table | 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. |
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:
- message you don't need, e.g. aftertouch
- 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.
Parameter | Type | Default | Description |
---|---|---|---|
allowNoteOn | boolean | true | Allow Note On events? |
allowNoteOff | boolean | true | Allow Note Off events? |
allowCC | boolean | true | Allow controller change events? |
allowProgramChange | boolean | true | Allow PC event? |
allowAftertouch | boolean | true | Allow aftertouch event? |
allowPitchBend | boolean | true | Allow pitch bend event? |
allowOthers | boolean | true | Allow other events? |
delay | int | 0 | Delay 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. |
allowedSources | table | nil | The accepted sources (nil means all - no filter):
|
- 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
- Event, int: type of event :
MidiSendCC(int interface, int channel, int controller, int value)
Send a control change (CC) message to a MIDI device.
Parameter | Type | Default | Description |
---|---|---|---|
interface | int | 1-based to match the numbering in hardware configuration (1-12) | |
channel | int | 1-based to match the usual chanel numbering (1-16) | |
controller | int | 0 for bank select, 1 for modulation wheel, 2 for breath control... See https://anotherproducer.com/online-tools-for-musicians/midi-cc-list/ | |
value | int | between 0 and 127 |