Hooks are functions you write to make your scripts respond to various events while it is executed by Kodtrol.
Hooks must be written as top-level functions in your scripts in order to be valid and properly executed:
// Good
function frame(devices) {
}
// Bad
function myOtherFunction() {
function frame(devices) {
}
}
// Also bad
var frame = function(devices) {
}
frame
( devices, blockInfo, triggers, curves )
When the script is in a timeline, this hook is continuously executed on each frame for the whole duration of the script block.
When the script is in a board, this hook is continuously executed on each frame as long as the script block is active.
When running standalone, this hook is continuously executed on each frame.
This hook is used to set and output device data.
Arguments |
|
Example |
function frame(devices, blockInfo, triggers, curves) {
devices.forEach((device) => {
device.setDimmer(255);
});
}
|
start
( devices )
This hook is executed once, immediately before the first execution of any other hook.
You can use this hook to prepare certain device data, before the actual script execution begins.
Arguments |
|
Example |
function start(devices) {
devices.forEach((device) => {
device.setDimmer(255);
});
}
|
leadInFrame
( devices, blockInfo, triggers, curves )
When the script is in a timeline, this hook is continuously executed on each frame for the lead-in duration of the script block.
When the script is in a board, this hook is continuously executed on each frame for the lead-in duration of the script block after it is activated.
When running standalone, this hook is not executed.
This hook is used to set and output device data.
Arguments |
|
Example |
function leadInFrame(devices) {
devices.forEach((device) => {
device.setPan(127);
});
}
|
leadOutFrame
( devices, blockInfo, triggers, curves )
When the script is in a timeline, this hook is continuously executed on each frame for the lead-out duration of the script block.
When the script is in a board, this hook is continuously executed on each frame for the lead-out duration of the script block after it is deactivated.
When running standalone, this hook is not executed.
This hook is used to set and output device data.
Arguments |
|
Example |
function leadOutFrame(devices) {
devices.forEach((device) => {
device.setPan(127);
});
}
|
beat
( devices, beatInfo )
This hook is executed on each 1/24th of a beat, respective of the set tempo of the timeline, board or standalone setting.
Use this hook to create beat-based automations and set or alter global or device variables; you can then use those values afterwards in the frame() hook. You cannot set device output content within this hook.
Arguments |
|
Example |
function beat(devices, beatInfo) {
if (isBeatDivision(beatInfo.localBeat, 24)) {
devices.forEach((device) => {
device.setVar('flash', true);
});
}
}
|
input
( devices, inputType, inputData )
This hook is executed each time input content is received from any of your active inputs.
Use this hook to create interactive automations and set or alter global or device variables; you can then use those values afterwards in the frame() hook. You cannot set device output content within this hook.
Arguments |
|
Example |
function input(devices, inputType, inputData) {
if (inputType === 'midi') {
if (inputData.getNoteOn()) {
devices.forEach((device) => {
device.setVar('flash', true);
});
}
}
}
|