Next: , Previous: , Up: High-Level Configuration   [Contents][Index]


5.1.2 Callbacks

Callbacks are functions to be called when a given device control triggers an event. They all must take the same list of arguments (see below) to be compatible with the connect-control procedure (see Defining Devices). The procedures in this function are contained in the module ‘(librekontrol device)’.

Function: midi-note-button device input-event input-value alsa-ctl options
Function: make-midi-note-button-toggle [init-state]

Send a MIDI event to device’s MIDI sequencer: if input-value is non-zero, send a MIDI note-on event, otherwise send a note-off event. If alsa-ctl is not ‘#f’ and its descriptor points to an open ctl, toggle the ctl (i.e. turn the LED on or off).

options is a list that can contain the following optional keyword arguments: channel, the MIDI channel on which to send the event (default: 0); note, the MIDI note to send (default: note-c4; see MIDI Events); and velocity, the velocity of the note (default: 127).

make-midi-note-button-toggle returns a callback function that takes the same optional arguments as midi-note-button. The function sends a MIDI note-on event and turns on alsa-ctl when the button is toggled on and it sends a note-off event and turns off alsa-ctl when it is toggled off. The initial toggle state (on or off) is determined by the optional argument init-state (default: ‘#f’).

Function: remap-button device input-event input-value alsa-ctl options
Function: make-remap-button-toggle [init-state]

Send a key/button input event to device’s input remapper. If alsa-ctl is not ‘#f’ and its descriptor points to an open ctl, toggle the ctl (i.e. turn the LED on or off).

options is a list that can contain the following optional keyword arguments: event-code, the event code (default: ‘#f’); mod-keys, a list of event codes of modifier keys to apply (e.g. ‘key-alt’, ‘key-leftctrl’, etc.); on-value, the event value for when the button is pressed (default: 1); and off-value, the event value for when the button is released (default: 0)"

make-remap-button-toggle returns a callback function that takes the same optional arguments as remap-button. The function sends a key/button event when the button is toggled on and again when it is toggled off. If the optional argument hold-down is true, on-value is sent when the button is toggled on and off-value is sent when it’s toggled off. The effect is like holding down a button, such that the event repeats until toggled off. Otherwise, on-value and off-value are sent in sequence when toggled both on and off. In both cases, alsa-ctl is turned on when the button is toggled on and turned off when the button is toggled off. The initial toggle state (on or off) is determined by the optional argument init-state (default: ‘#f’).

Function: system-button device input-event input-value alsa-ctl options
Function: make-system-button-toggle [init-state]

Execute a system command when a button is pressed. If alsa-ctl is not ‘#f’ and its descriptor points to an open ctl, toggle the ctl (i.e. turn the LED on or off).

options is a list that can contain the following optional keyword arguments: cmd, a string containing the full command to be executed (default: ‘"echo 'Hello, world!'"’).

make-system-button-toggle returns a callback function. The function executes a system command on-cmd (default: ‘"echo 'Hello, world!'"’) and turns on alsa-ctl when the button is toggled on. It executes a system command off-cmd (default: ‘"echo 'Goodbye, world!'"’) and turns off alsa-ctl when it is toggled off. The initial toggle state (on or off) is determined by the optional argument init-state (default: ‘#f’).

Function: rel-knob-to-button device input-event input-value alsa-ctl options

Remap a relative-position event to a button/key event. Different events can be sent for negative and positive values. If alsa-ctl is not ‘#f’ and its descriptor points to an open ctl, turn on the ctl (i.e. turn the LED on).

options is a list that can contain the following optional keyword arguments: neg-event-code, the event code for negative values (default: ‘#f’); pos-event-code, the event code for positive values (default: ‘#f’); neg-mod-keys, a list of event codes for modifier keys to apply for negative values (e.g. key-alt, key-leftctrl, etc.); pos-mod-keys, a list of event codes for modifier keys to apply for negative values repeat, send multiple key events based on the magnitude of input-value (default: ‘#f’).

Function: make-abs-knob-to-button

Return a callback function that remaps an absolute-position event to a button event. The absolute position is first converted to a relative position. Different events can be sent for negative and positive values. If alsa-ctl is not ‘#f’ and its descriptor points to an open ctl, turn on the ctl (i.e. turn the LED on).

options is a list that can contain the following optional keyword arguments: neg-event-code, the event code for negative values (default: ‘#f’); pos-event-code, the event code for positive values (default: ‘#f’); neg-mod-keys, a list of event codes for modifier keys to apply for negative values (e.g. key-alt, key-leftctrl, etc.); pos-mod-keys, a list of modifier keys to apply for negative values; repeat, send multiple key events based on the magnitude of input-value (default: ‘#f’); knob-max, the knob maximum value (default: 127); wrap-tol, the relative-position tolerance before deciding that the absolute position has wrapped on an “infinite-rotary”-style knob, expressed as a fraction of KNOB-MAX (default: 0.01); and invert, whether to invert the sign of the relative position (set if the sign is not what you expect for the direction of rotation) (default: ‘#f’)

Function: system-abs-knob device input-event input-value alsa-ctl options
Function: system-rel-knob device input-event input-value alsa-ctl options
Function: make-abs-to-rel-system-knob

Send a system event when a knob is changed. The input value is added to the system command via standard text formatting. If alsa-ctl is not #f and its descriptor points to an open ctl, toggle the ctl (i.e. turn the LED on or off).

system-abs-knob applies to knobs (or other continuous inputs) that generate absolute position values (i.e. they give values between a fixed minimum and maximum value). system-rel-knob applies to controls that generate relative position values (i.e. they give values relative to their previous position).

options is a list that can contain the following optional keyword arguments: cmdproc, the command to execute using the event value (default: ‘(lambda (x) (simple-format #f "printf '%d\n' ~A" x)’); max-value (system-abs-knob only), the maximum value to send to the command (default: 127); knob-max (system-abs-knob only), the knob maximum value (default: 127)"

make-abs-to-rel-system-knob returns a callback function that converts an absolute-position event to a relative-position event and then executes a system command. In addition to the optional arguments that system-abs-knob takes, this callback can also receive the following optional arguments: wrap-tol, the relative-position tolerance before deciding that the absolute position has wrapped on an “infinite-rotary”-style knob, expressed as a fraction of KNOB-MAX (default: 0.01); and invert, whether to invert the sign of the relative position (set if the sign is not what you expect for the direction of rotation) (default: ‘#f’).

Function: midi-control-abs-knob device input-event input-value alsa-ctl options
Function: make-finite-midi-control-abs-knob
Function: make-rel-to-abs-midi-control-knob [init-value]

Send a MIDI control event when a knob is changed. If alsa-ctl is not ‘#f’ and its descriptor points to an open ctl, toggle the ctl (i.e. turn the LED on or off). This procedure applies to knobs (or other continuous inputs) that generate absolute position values (i.e. they give values between a fixed minimum and maximum value).

options is a list that can contain the following optional keyword arguments: channel, the MIDI channel (default: 0), control, the MIDI control (default: mod-wheel); and knob-max, the knob maximum value (default: 127)

make-finite-midi-control-abs-knob returns a callback function that behaves like midi-control-abs-knob, however it prevents the absolute position values from “wrapping around” when using an infinite rotary knob. The callback function accepts one additional option, wrap-tol, which determines the sensitivity of the detection of wrapping around and is expressed as a fraction of knob-max (default: 0.1).

make-rel-to-abs-midi-control-knob returns a callback function that converts relative-position events to absolute-position events, given the initial value init-value (default: 0). The callback function supports the channel and control options as described above.

Function: midi-note-pad device input-event input-value alsa-ctl options

Send a MIDI note when a pad or other velocity-sensitive control is triggered. If alsa-ctl is not ‘#f’ and its descriptor points to an open ctl, set the ctl appropriately.

options is a list that can contain the following optional keyword arguments: ‘channel’, the MIDI channel on which to send the event (default: 0); note, the MIDI note to send (default: ‘note-c4’); and pad-max, the pad event maximum value (default: 127).


Next: , Previous: , Up: High-Level Configuration   [Contents][Index]