CloudLase scripts are plain JavaScript that runs inside the app.
A script can fire cues, move the live masters, arm live effects, follow the beat clock, react to audio and MIDI, draw its own laser look a frame at a time, or bend the points of whatever is already playing.
Everything a script can reach lives on one object, cl.
Scripts run in the desktop app only.
The same scripts can be saved, exported and shared as .js files.
Where scripts run
There are four ways to start a script, and they all run the same code with the same rules.
- The Scripts tab. Scripts is a mode, the last tab in the title bar. Write, save and run scripts here; the console shows what they log and where they failed. It has its own laser monitor, pinned to the script's target device, so you can see what a script draws without leaving it, and the monitor pops out into a window of its own. Press Open in a window to move Scripts beside another mode, for example to keep a script in view while you play the deck; Dock in the tab brings it back.
- A MIDI control. In the MIDI re-map dialog, give a pad, a note or a controller the "Run or stop a script" action and pick the script. A press starts it, a second press stops it, in every MIDI mode. The message that started the run is available as
cl.trigger. - A timeline clip. Drag a saved script from the SCRIPTS palette in the Timeline sidebar onto a track. The show runs the script for the clip's window and stops it when the playhead leaves.
cl.cliptells the script where in the clip it is. - At launch. A script marked "Run at launch" starts with the app, unarmed, so it reaches simulators only until you arm the lasers.
A running script never takes over the Editor. The Editor's own preview keeps showing the frame you are drawing; a script's output shows in the Scripts monitor, on the Timeline's monitor while a show plays, and on the lasers themselves.
Your first script
Pick a target device in the Scripts settings column (the Simulator is a good first target), paste this, and press Run.
cl.cues.fire('Rainbow Cube')
await cl.sleep(4000)
cl.cues.stop()
cl.log('done')
The cue lights the target, the script waits four seconds, stops the cue and finishes.
Top-level await works, so a script reads like a list of things to do in order.
A script keeps running while it has something pending: a timer, a beat handler, a MIDI binding, an animation or a frame session.
Stop it with the Stop button, Cmd+., a second press on the control that started it, or the install-wide blackout.
Building with blocks
You do not have to type a script to make one. The Scripts Blocks mode builds a script from steps: Fire cue, Stop cues, Wait, Wait beats, Set master, Animate master, Arm FX, Disarm FX, Blackout, Log and Notify, inside containers that hold steps of their own: Repeat, Forever, On every beat, On every bar, On MIDI note and On MIDI controller. Press New, then Blocks, pick a step and add it; every step's settings are rows beside it, and a container has its own Add inside. The JavaScript beside the blocks is generated as you build and is what is saved and run, so a block-built script runs exactly as a typed one does and reads as one. Switch to Code at any time to keep that text and go on editing it by hand; a script that already holds typed code is not replaced by blocks, so start those from New. A loop that holds no wait is given a short one, so a block program cannot run away.
Cues
Cues are fired by name, by their position on a deck page, or by id.
cl.cues.fire('Spirograph') // by name, on the target device
cl.cues.fire({ page: 1, slot: 4 }) // page and slot as the deck numbers them
cl.cues.fire('Spirograph', { device: 'Floor' })
cl.cues.fire('Spirograph', { broadcast: true }) // every device that is playing, plus simulators
cl.cues.stop() // the target's cues
cl.cues.stopAll() // everywhere
A name that two cues share is refused with a sentence naming both pages; fire it by page and slot instead. A cue only draws into a running stream, so firing one on an idle device starts the device first.
cl.cues.list() returns every library cue with its name, page and slot.
cl.cues.isPlaying(name) and await cl.cues.waitUntilStopped(name) let a script follow a cue's life.
Library cues loop until something stops them, so a script that waits for a cue to end must also be the thing that ends it, or leave that to a pad.
Masters and live effects
The live masters are the same controls the Beam Deck's device band moves: intensity, speed, hue and scale, plus the per-device blackout.
cl.masters.set({ intensity: 0.5, hueDegrees: 120 })
const m = cl.masters.get() // { intensity, speed, hueDegrees, scale, blackout }
await cl.masters.animate('hueDegrees', 0, 360, 8000, 'easeInOut').done
animate glides one master over a number of milliseconds and returns a handle with cancel() and a done promise.
Every write echoes the fields you did not name, so a script that sets intensity leaves speed where the operator put it.
Live FX chips are armed and disarmed by the names the effect rack uses.
cl.fx.arm('Strobe')
cl.fx.disarm('Strobe')
cl.fx.armed() // ['Strobe', ...]
cl.fx.names() // every chip the runtime knows
cl.blackout(true) presses the install-wide blackout, the same latch as the header segment and Cmd+0.
cl.blackout(false) releases it and cl.blackout() toggles.
The beat clock
cl.clock reads the shared beat clock, the one the deck's BPM chip, tap tempo and Link write.
if (!cl.clock.bpm) cl.clock.setBpm(120) // the clock only ticks once it has a tempo
cl.clock.onBeat(beat => cl.cues.fire(beat % 2 ? 'Spinning Cube' : 'Rainbow Cube'))
cl.clock.onBar(() => cl.fx.arm('Strobe'))
await cl.clock.nextBar()
const fourBeats = 4 * cl.clock.beatMs
beat, bar, beatPhase and barPhase read the clock's position.
Handlers return a handle with cancel().
Audio
cl.audio reads the live bands: bass, mid, treble and amplitude, each 0 to 1, plus band(i) for one of the sixteen sub-bands.
The bands need a live input (Spectra or the Synth audio tab) or a playing track; with nothing feeding them they read zero.
cl.every(40, () => cl.masters.set({ intensity: 0.3 + 0.7 * cl.audio.bass }))
MIDI
Bind a raw note or controller on any channel, or on one channel.
cl.midi.on({ cc: 7 }, m => cl.masters.set({ intensity: m.norm })) // m.value is 0..127, m.norm is 0..1
cl.midi.on({ note: 36, channel: 1 }, m => { if (m.on) cl.cues.fire('Star Burst') })
A script started by a MIDI control finds the message that started it in cl.trigger (kind, number, value, norm, channel); a script started from the window sees null.
Bindings are released when the run stops.
Drawing your own look
cl.onFrame turns a script into a look: the function you pass is called up to fifty times a second and returns what to draw.
Shapes come from cl.shapes, paths from cl.points.path, colours from cl.color.hsv or a #rrggbb string.
Geometry is in canvas units: the field runs from -300 to 300 on both axes, the same units the editor uses.
The callback's t is elapsed seconds.
cl.shapes uses the editor's Y-down coordinates, while cl.points.path and the point buffer in cl.onPoints use Y-up coordinates in the same range.
Negate a reference drawing's canvas Y when constructing raw paths, but keep shape positions in canvas coordinates.
cl.points.path emits the vertices supplied; it does not fit curves, so sample curved contours deliberately rather than expecting sparse points to become smooth.
For MCP authoring, trace_image converts a local image into editable workspace paths and returns a rendered PNG for inspection.
Use snapshot_workspace to inspect workspace effects at chosen times, or snapshot_script after starting a generator to inspect its current frame.
Script capture does not run or seek the script and does not capture the entire output of cue-fire actions.
cl.onFrame(t => {
const rings = []
for (let i = 0; i < 4; i++) {
const r = 60 + 50 * i + 25 * Math.sin(t * 2 + i)
rings.push(cl.shapes.ellipse({ radius: r, color: cl.color.hsv(t * 40 + i * 60, 1, 1) }))
}
rings.push(cl.shapes.preset('Spirograph', { scale: 0.5, rotation: t * 30 }))
return rings
})
cl.shapes.ellipse, rect, line and polygon take a position (x, y), rotation in degrees, scale, a color and an effects list.
cl.shapes.preset(name) places any shape from the editor's library by its label, and cl.effects.preset(name) attaches any effect preset, so a script shape is the same shape the editor would have placed.
cl.shapes.presets() and cl.effects.presets() list the labels.
A frame that takes longer than the device reads one (20 milliseconds) is reported once on the console and frames are dropped until it is faster; keep per-frame work small.
Custom effects
cl.onPoints turns a script into an effect: the function you pass receives the points the device is about to draw and edits them in place.
Points arrive as a Float32Array of x, y, r, g, b per point, in canvas units with colours from 0 to 1.
A point left black is blanked, and a point moved off the field is blanked too.
cl.cues.fire('Spirograph') // something to bend
cl.onPoints((p, t) => {
for (let i = 0; i < p.length; i += 5) {
p[i] += 20 * Math.sin(t * 3 + p[i + 1] / 40) // x wobbles with y
}
})
Off the timeline a points script works on the cues playing on its target device. On the timeline it works on the layers beneath its clip and replaces them.
Timeline clips
A script clip runs the script for the clip's window on the track's device, whatever device the script was saved with. A script that draws its own look composes with the other tracks like a visualizer clip; a points script bends the layers beneath it. Opacity, fades, Override and attached Live FX apply to a script clip the way they apply to a visualizer clip.
cl.onFrame(t => {
const c = cl.clip // null when the script was not started by a clip
const progress = c ? c.time / c.duration : 0
return [cl.shapes.polygon({ radius: 60 + 200 * progress, sides: 6 })]
})
cl.clip carries time (seconds into the clip, from the show's playhead), duration and start.
Scrubbing the show moves cl.clip.time; t keeps counting from when the run started.
A script clip may fire cues instead of drawing (a beat chase on a track): the show composes the cues it fires while the clip is under the playhead, and they end with the clip. A script that only fires a cue and finishes fires it once for the clip, not once per frame.
Timers, state and the console
await cl.sleep(250)
const tick = cl.every(1000, () => cl.log('tick')) // tick.cancel() stops it
cl.after(2000, () => cl.cues.stopAll())
cl.now() // milliseconds since the run started
setTimeout, setInterval, clearTimeout and clearInterval are the same timers under their usual names.
cl.state is a bag of values saved with the script: it survives runs and restarts.
cl.shared is a bag every script shares.
Both hold anything JSON can.
cl.state.runs = (cl.state.runs || 0) + 1
cl.shared.mode = 'night'
cl.log(...) and console.log(...) write to the Scripts console; console.warn and console.error mark their lines.
cl.notify(text) puts one line on the window's notice.
cl.onStop(fn) runs when the script is stopped, which is where a script puts its cues and masters back.
Safety
- The arm gate. A script started while the lasers are not armed reaches simulators only; every start-shaped call aimed at hardware is skipped and says so on the console. Arming or disarming the lasers reaches every running script at once.
cl.armedreads the state. - Stops are never gated.
cl.cues.stop,cl.cues.stopAll,cl.blackoutand the script's own stop always work. - Blackout stops scripts. When the install-wide blackout engages, every running script stops (a script's "Stop on blackout" setting can opt it out). Releasing the blackout restarts nothing.
- Budgets. One synchronous slice of a script (the top level up to its first
await, a handler, a frame) may not run longer than a quarter of a second or execute more than a few million statements. An overrun is reported; three in a row stop the run. A script cannot take the app down. - No files, no network, no settings. A script sees
cl,console, the timers,Math,JSONandDate, and nothing else.
Examples
Scripts ships worked examples that cover each of these areas, from a scheduled show and a beat chase to a custom look and a custom effect. Every one of them draws on the simulator as shipped; open one, run it, and change it.
API reference
Every member of cl, by group.
This table is generated from the runtime's own catalog, the same table the Scripts window's reference pane and completion list read, so it cannot drift from what runs.
Devices
cl.devices.list(): Every device: { name, type, playing }. Example:const sims = cl.devices.list().filter(d => d.type === 'Simulator')cl.devices.isPlaying(name): True while the device streams. Example:if (cl.devices.isPlaying('Simulator')) cl.log('live')cl.target(name?): Set or read the device the script's cue and master calls use. Example:cl.target('Simulator')
Cues
cl.cues.list(): Every library cue: { id, name, page, slot }. Example:cl.cues.list().map(c => c.name)cl.cues.fire(nameOrRef, options?): Fire a cue by name or { page, slot }; options: device, zones, broadcast. Example:cl.cues.fire('Rainbow Cube', { device: 'Simulator' })cl.cues.stop(device?): Stop the cues on the target device. Example:cl.cues.stop()cl.cues.stopAll(): Stop the cues on every device. Example:cl.cues.stopAll()cl.cues.isPlaying(nameOrRef, device?): True while that cue is active on the device. Example:while (cl.cues.isPlaying('Opener')) await cl.sleep(100)cl.cues.waitUntilStopped(nameOrRef, device?): Resolves when the cue is no longer active. Example:await cl.cues.waitUntilStopped('Opener')
Masters
cl.masters.get(device?): Current masters: { intensity, speed, hueDegrees, scale, blackout }. Example:const m = cl.masters.get()cl.masters.set(fields, device?): Write one or more of intensity, speed, hueDegrees, scale, blackout. Example:cl.masters.set({ intensity: 0.5 })cl.masters.animate(field, from, to, ms, easing?): Glide a master over time; returns a handle with cancel() and a done promise. Example:cl.masters.animate('hueDegrees', 0, 360, 8000)cl.fx.arm(name, device?): Arm a Live FX chip by name. Example:cl.fx.arm('Strobe')cl.fx.disarm(name, device?): Disarm a Live FX chip. Example:cl.fx.disarm('Strobe')cl.fx.armed(device?): Names of the armed chips. Example:cl.fx.armed()cl.fx.names(): Every chip name the runtime knows. Example:cl.fx.names()cl.blackout(engage?): Press the install-wide blackout (true engages, false releases, none toggles). Example:cl.blackout(true)
Clock
cl.clock.bpm: Tempo of the shared beat clock, 0 when unset. Example:cl.log(cl.clock.bpm)cl.clock.beatMs: Milliseconds per beat, 0 when the clock is unset. Example:await cl.sleep(4 * cl.clock.beatMs)cl.clock.beat: Beats since the clock started. Example:cl.clock.beatcl.clock.beatPhase: 0..1 inside the current beat. Example:cl.clock.beatPhasecl.clock.bar: Bars since the clock started. Example:cl.clock.barcl.clock.barPhase: 0..1 inside the current bar. Example:cl.clock.barPhasecl.clock.setBpm(bpm): Set the shared tempo. Example:cl.clock.setBpm(128)cl.clock.onBeat(fn): Call fn on every beat; returns a handle with cancel(). Example:cl.clock.onBeat(b => cl.cues.fire(b % 2 ? 'A' : 'B'))cl.clock.onBar(fn): Call fn on every bar; returns a handle with cancel(). Example:cl.clock.onBar(() => cl.fx.arm('Strobe'))cl.clock.nextBeat(): Resolves on the next beat. Example:await cl.clock.nextBeat()cl.clock.nextBar(): Resolves on the next bar. Example:await cl.clock.nextBar()
Audio
cl.audio.bass: Live bass band, 0..1. Example:cl.audio.basscl.audio.mid: Live mid band, 0..1. Example:cl.audio.midcl.audio.treble: Live treble band, 0..1. Example:cl.audio.treblecl.audio.amplitude: Live overall level, 0..1. Example:cl.masters.set({ intensity: cl.audio.amplitude })cl.audio.band(index): One of the sixteen sub-bands, 0..1. Example:cl.audio.band(3)
MIDI
cl.midi.on(selector, fn): Call fn for a note ({ note, channel? }) or controller ({ cc, channel? }); returns a handle with cancel(). Example:cl.midi.on({ cc: 7 }, m => cl.masters.set({ intensity: m.norm }))cl.trigger: The message that started this run: { kind, number, value, norm, channel }, or null. Example:const v = cl.trigger ? cl.trigger.norm : 1
Frames
cl.onFrame(fn): Draw a look: fn(t) receives elapsed seconds and returns shapes and paths, up to 50 frames a second until the run stops. Example:cl.onFrame(t => [cl.shapes.ellipse({ radius: 100 + 50 * Math.sin(t) })])cl.onPoints(fn): A custom effect: fn(points, t) edits the active cues' points in place, a Float32Array of x, y, r, g, b per point (canvas units, colours 0..1). Example:cl.onPoints((p, t) => { for (let i = 0; i < p.length; i += 5) p[i] += 20 * Math.sin(t * 3 + p[i + 1] / 40) })
Shapes
cl.shapes.ellipse({ radius or radiusX, radiusY, x, y, rotation, scale, color, effects }): An ellipse in canvas units (the field is ±300). Example:cl.shapes.ellipse({ radius: 120, color: '#00ff88' })cl.shapes.rect({ width, height, x, y, rotation, scale, color, effects }): A rectangle. Example:cl.shapes.rect({ width: 200, height: 120 })cl.shapes.line({ x1, y1, x2, y2, color }): A line between two points. Example:cl.shapes.line({ x1: -200, y1: 0, x2: 200, y2: 0 })cl.shapes.polygon({ radius, sides, innerRadius, x, y, rotation, color, effects }): A regular polygon, or a star with innerRadius. Example:cl.shapes.polygon({ radius: 150, sides: 5, innerRadius: 60 })cl.shapes.preset(name, { x, y, rotation, scale, color, effects }?): A shape from the catalog by its label, the same shape the editor's library places. Example:cl.shapes.preset('Spirograph', { scale: 0.6 })cl.shapes.presets(): Every shape preset label. Example:cl.shapes.presets()cl.effects.preset(name): An effect from the catalog by its label, to attach through a shape's effects list. Example:cl.shapes.polygon({ sides: 6, effects: [cl.effects.preset('Rotation')] })cl.effects.presets(): Every effect preset label. Example:cl.effects.presets()cl.points.path([[x, y, r, g, b], ...]): A lit polyline of supplied vertices in -300..300 Y-up coordinates with 0..1 colours; no curve fitting, unlike cl.shapes which uses Y-down canvas coordinates. Example:cl.points.path([[-100, 0, 1, 0, 0], [100, 0, 0, 0, 1]])cl.color.hsv(hueDegrees, s, v): A '#rrggbb' colour from hue, saturation and value. Example:cl.color.hsv(t * 60, 1, 1)
Time
cl.sleep(ms): Resolves after ms milliseconds. Example:await cl.sleep(500)cl.every(ms, fn): Call fn every ms milliseconds; returns a handle with cancel(). Example:cl.every(1000, () => cl.log('tick'))cl.after(ms, fn): Call fn once after ms milliseconds; returns a handle with cancel(). Example:cl.after(2000, () => cl.cues.stopAll())cl.now(): Milliseconds since the run started. Example:cl.now()
State
cl.state: This script's persisted bag; survives runs and restarts. Example:cl.state.count = (cl.state.count || 0) + 1cl.shared: The bag every script shares; persisted. Example:cl.shared.mode = 'night'cl.log(...values): Write to the script console (console.log does the same). Example:cl.log('speed', cl.masters.get().speed)cl.notify(text): One line on the Scripts window's notice. Example:cl.notify('Chase armed')cl.armed: True when the lasers are armed; unarmed runs reach simulators only. Example:if (!cl.armed) cl.log('simulators only')cl.onStop(fn): Call fn when the run is stopped. Example:cl.onStop(() => cl.cues.stopAll())cl.clip: On the timeline, the clip this run plays for: { time, duration, start } in seconds; null when the script was started any other way. Example:const t = cl.clip ? cl.clip.time : cl.now() / 1000