Clamps Packages
MIDI Input
Receiving and handling MIDI Input
After the Ports have been opened, MIDI input handling is started using the function start-midi-receive, which gets called automatically on startup using the clamps or open-midi-port function. MIDI input handling can be suspended using the stop-midi-receive function. Note that this will not close the MIDI ports, so connections to external devices or programs will be persistent. A later call to start-midi-receive will continue to process MIDI input.
A midi-port in Clamps handles MIDI input in 3 different stages:
- All note and cc input is captured in the cc-state and note-state arrays of the port struct. Both contain a 2-dimensional array of 16x128 ref-objects which capture the last received values of the 128 controller numbers or note numbers of all 16 MIDI channels. Inspect this value to see the current state of the MIDI input of Clamps.
- In addition two other special variables, the cc-fns and note-fns slots contain 16x128 lists, intially empty. When receiving MIDI cc or MIDI note input, Clamps will address these arrays and call all functions stored in the list of the corresponding channel and CC number or keynum with the received controller value or note velocity as arguments.
- At last, the #'handle-midi-in method of all midi controller instances registered with the function add-midi-controller will get called.
For convenience, *midi-cc-state*, *midi-cc-fns*, *midi-note-state* and *midi-note-fns* are special variables pointing to the cc-state, cc-fns, note-state and note-fns slot of the midi-port :midi-1, opened by the clamps function.