Clamps Packages
MIDI Ports
Before being able to work with MIDI in/output in Clamps, its MIDI Ports have to get opened. In Clamps, a MIDI port is a struct which contains slots for its id, its midi-input, midi-output and arrays capturing the state of the last MIDI input.
A port gets opened with the open-midi-port function. The function takes an id (a keyword or symbol) and registers the Midi Port depending on the default MIDI API with Jack, using the id plus the extensions -in and -out for the in- and output, or creates a virtual MIDI Port in the case of portmidi (see the following sections on jackmidi and portmidi). It also starts MIDI responders, which capture all incoming cc, noteon, noteoff, pitch-bend and after-touch messages in arrays of ref-objects, which are part of the midi-port struct. In addition it creates arrays with lists of functions to call on an incoming cc, note-on, note-off, pitch-bend or after-touch MIDI message, also part of the struct. These lists are initially empty, but the user can push functions with four arguments, denoting opcode, channel, d1 and d2 onto these lists and they will be called automatically, when MIDI messages of the respective type are received at the midi-input of the port.
On startup, Clamps automatically opens 2 ports, using the function rts, which is called by the clamps function at the beginning of the session. The number of ports can be specified using the :num-midi-ports keyword of the #'clamps function, or by setting the *num-midi-ports* parameter in the file ~/.clampsinit.
Closing, accessing and finding the midi ports an be achieved with the close-midi-port, list-midi-ports and find-midi-port functions.