Bring your panel to the next level with the power of JavaScript!
With scripts in Commands and Events, you can run simple JavaScript code.
You have access to all Swaps inside your script and can use them like variables – just refer to the exact name.
Command Script
A command script is executed when the command is triggered.
The output of the script is ignored – command scripts are not used to control an item directly.
Instead, they typically update Swaps and control other elements of the panel.
Send Local Command
You can send a local value command directly from any command script.
sendCommand("/test", "Hello") // sends "Hello" to /test
sendCommand("/test", 10) // sends 10 to /test
sendCommand("/test", 10, "float") // sends 10 as float to /test
sendCommand("/test", 10.5, "int") // sends 10 as int to /test
sendCommand("/test", 1, "bool") // sends true as bool to /test
sendCommand("/test", true, "bool") // sends true as bool to /test
Art-Net Commands
When using Art-Net interfaces, an Art-Net script command allows you to update DMX channel values.
sendArtNet(128, 1) // updates channel 1 to 128 in 8Bit sendArtNet(128, 1, 2) // updates channels 1 and 2 to 128 16-bit. Decimal places are possible.
OSC Commands
OSC Out interfaces and Behringer/Midas interfaces allow you to send OSC commands using OSC Script or BX Script commands.
// Send OSC command:
let arguments = [["Example"], [10, "int32"], [20, "float"], [true, "bool"]]
sendOSC("/test", arguments)
Event Script
Event scripts run automatically. For example, when switching to Live Mode, powering up Interfaces, or whenever a Swap used in the script changes. The return value of the script is used to control the item.
The following example sets a slider to the middle position:
let slider = 0.5 slider // this sets the slider to the middle
You could also write this shorter:
0.5 // sets the slider directly
Or use a more complex calculation:
if (DLY_MidiSync == 1) {
let time = 60 / midiBPM
let range = 3
let sliderValue = time / range
sliderValue
}
void 0 // use this line to return "nothing"
Local Events
An event script can respond to local events.
Use the function getEventValue(path), where path is the local event’s path.
You’ll receive the value that was sent to that path.
let value = getEventValue("/test") // get the value sent by "/test"
// Checking whether you have received a value from "/test" before reacting is important!
if (typeof value !== "undefined") {
// value received from that path
} else {
// no value received from that path
}
Remote Options
Inside your script, you can also configure remote options, which determine which commands should be triggered by this event script:
remote("all", true) // enables "send all triggers"
remote("all", false) // disables all
remote("d", true/false) // sets "disable control"
remote("s", true/false) // sets "system event"
remote("1".."20", true/false) // enables or disables trigger 1–20
Set Item Color
Set the color of your Item with the following functions:
// RGB // background color let red = 255 // 0..255 let green = 0 // 0..255 let blue = 0 // 0..255 // optional textcolor let redTxt = 255 // 0..255 let greenTxt = 0 // 0..255 let blueTxt = 0 // 0..255 setColorRGB(red, green, blue) // colors only the Item setColorRGB(red, green, blue, redTxt, greenTxt, blueTxt) // colors the Item and the text // HSL // background color let hue = 360 // 0..360 let saturation = 100 // 0..100 let lightness = 50 // 0..100 // optional textcolor let hueTxt = 360 // 0..360 let saturationTxt = 100 // 0..100 let lightnessTxt = 50 // 0..100 setColorHSL(hue, saturation, lightness, hueTxt, saturationTxt, lightnessTxt) // colors the Item and the text setColorHSL(hue, saturation, lightness) // colors only the Item
Behringer/Midas and OSC Label
In the Label Event of the Behringer/Midas and the OSC interface, you can format the incoming arguments using a script.
The first received argument is available as labelValue. Get all arguments as an array with oscArguments.
The output of your script will be displayed as the label.
Example
Converting a value from 0–1 into a frequency from 200 Hz to 20 kHz.
You will get 200 to 999, 1k, 1.5k, 20k
const maxF = 20000
const minF = 200
const x = Math.min(Math.max(0.0, labelValue), 1.0)
const m = maxF / minF
const frequency = minF * Math.pow(10.0, x * Math.log10(m))
formatFrequency(frequency)
function formatFrequency(frequency) {
if (frequency < 1000) {
return Math.round(frequency).toString()
} else {
const k = frequency / 1000
const rounded = Math.round(k * 10) / 10
return (rounded % 1 === 0 ? rounded.toFixed(0) : rounded.toFixed(1)) + 'k'
}
}
console.log(oscArguments) // Print all received arguments in the logging view
Behringer/Midas and OSC Script
Process the OSC event in the script. You can access the received arguments with the oscArguments array.
MIDI Clock
With the MIDI In interface, you can use a script inside the MIDI Clock event to process MIDI Clock data.
midiBar // current bar midiBeat // current beat midiBPM // current BPM midiStarted // true if clock started from stop midiStopped // true if clock stopped midiContinued // true if clock continued from pause
console.log(swapA) // shows "swapB" console.log(getSwapValue(swapA)) // shows 10
Swaps In Scripts
You can use swaps in scripts in two ways:
Swap Name
Use the swap name directly to read or change a swap’s value.
console.log(mySwap) // The value of the swap, e.g. 10 or “Hello”
mySwap = “Hello world” // Sets the value of the swap to “Hello world”
Escaped Swap \(swapName)
Use the escaped swap name if you want to replace part of the script with the swap’s value.
console.log( “Hello \(mySwap)” ) // “Hello world”
Swap Values
Example
swapA = \(swapB)
swapB = 10
You always get the swap value when you use the variable name.
Use the getSwapValue() function to retrieve the fully replaced value.
console.log(swapA) // Prints \(swapB)
console.log( getSwapValue(swapA) // Prints 10
Functions And Variables in Scripts
Item Status
Retrieve the item status in a script.
All variables are read-only. The item status can not be set.
Depending on the item type, some values may not be available.
itemValue // e.g. slider position (0–1) or toggle state (0 = off, 1 = on) itemSelected // true for toggled on, false for off itemLight // true if item’s light is on itemProtected // true if the item is protected and can’t be controlled
console.log
Use console.log() to write messages to the panel’s logging window.
The local interface must be selected in the log view to see the messages.
console.log("This is a status out of the script")
console.log(itemValue) console.log(itemSelected) console.log(itemLight) console.log(itemProtected)
Convert RGB HSL
Use the following functions to convert RGB to HSL and vice versa:
// RGB to HSL let hsl = rgb2hsl(red,green,blue) hue = hsl["h"] saturation = hsl["s"] lightness = hsl["l"] //HSL to RGB
let rgb = hsl2rgb(hue,saturation,lightness) red = rgb["r"] green = rgb["g"] blue = rgb["b"]
