Scripts
JavaScript nodes: read the live data, change it, control nodes and devices, draw graphics.
Scripts (JavaScript)#
Scripts run on JavaScriptCore (the macOS system JS engine). That is currently the only language, the old Lua/Python popup entries were placeholders and have been removed.
A Script node transforms the frame, written with bare names: Reads see the current data, writes become the node's output (and drive devices/nodes via writeback). Typos on reads throw with the full path. Unset fields pass through unchanged.
system.beep = CDJ1.beat.bar; // beep every bar
value.inChorus = (CDJ1.phrase.current == "CHORUS") ? 1 : 0;
if (CDJ1.beat.currentBpm > 130) { CDJ1.select.id = 2; }
CDJ1.status.isQuantizeOn = 1; // device write via CDJ1's deck
source.* and output.* still exist for the one case needing both sides of a key, original vs. changed: metadata.title = source.metadata.title + " [LIVE]";
The inline script box is fine for one-liners; for real work press Editor ⤢ (under the Script label in the inspector), or just double-click the Script node: And the Patch swaps for a full-size editor styled like the other panels:
- Line numbers in the left gutter.
- Syntax coloring (comments, strings, numbers, keywords,
source/output/g), refreshed shortly after you stop typing. - Live validation: ~0.6 s after the last keystroke the script is compiled AND test-run against the node's current live frame, so garbage, ReferenceErrors and
source.*typos all show as the red error in the footer (✓ runs on live data when clean). Your node keeps running its last good code while you type. - Tab completion: Press Tab mid-word to complete against this node's actual data keys (
source.beat.…), theg.*helpers and JS basics; the candidates appear in the footer. - ▶ Run (top right) applies the code and test-fires the node once, same as the node's ▶ button.
- Save (left of ▶ Run) writes the code in the editor to a
.jsfile. Import loads a script file into the editor and replaces its code. Like typing, the imported code is applied on ▶ Run or Close. - Templates ▾ (left of Import) opens a menu of ready-made scripts, grouped into families. Graphics has Beat Tunnel 3D, Broadcast Overlay (Heavy), Music Video Credits, Phrase Countdown and Two Deck Mix Monitor, which draw on a Graphic node. Music Video Credits never clears the frame, so the rest of the picture stays transparent for the video under it. Control has Beat LFO, Drop Detector (counts down to the next drop and gives build-up, riser and hit values), Jogwheel Flash and Pitch to 0-1. Picking one replaces the code in the editor. The comment at the top of each template says how to wire it and which settings to change. Like Import, it is applied on ▶ Run or Close. The templates live in
Documents/TC Supply/TEMPLATE/SCRIPT, and Show Templates Folder at the bottom of the menu opens it. Add your own.jsfiles there: a subfolder becomes a new family. The templates that come with ShowKontrol are replaced when an update brings new ones, so rename one before you change it. - Close (bottom right) applies the code and returns to the Patch. Changes are otherwise not live while you type.
JS Engine node (macOS)#
The JS Engine node (Add Processor → JS Engine) shows a web page on a Graphic node. Pages can do what scripts cannot: real 3D with three.js, real fonts, smooth fades and transparency, CSS animation. The page gets the data coming into the JS Engine node, so it can follow the beat, the track and anything else a Script can read.
On Windows the JS Engine is not available yet. The node face says so, and the Graphic shows no page. It was called HTML Page before.
Wire it like a Script, into the Graphic node's input:
- Device → JS Engine → Graphic: The Graphic shows the page.
- Device → JS Engine → Script → Graphic: The Script's
g.*drawing goes on top of the page (a score, a logo, a lower third over the 3D).
Settings:
Page: A page that comes with ShowKontrol, or Own File for your own page:
- Stage Lights: A 3D club stage that runs its own light show from the data. Moving heads on a truss with beams in haze, strobes, blinders, floor washes and an LED wall that shows the cover art, artist and title on the section colour. The look follows the track's sections:
- Breaks: no flashes on the beat, slow glides and a gentle breathing.
- Build-ups (and the last 16 beats before a drop): the strobes fire, 1, then 2, then 4 flashes per beat, the heads close in and strobe along, and the last beat before the drop is a blackout.
- Drop: the blinders hit once, big, then the full look with the heads fanned out.
- The rest: the heads flash on every beat and sweep with the bar.
- Cover Cube: The deck's cover on a spinning cube that kicks on the beat and flips to the new cover on a track change.
- Particle Drop: A cloud of particles that pulls in and heats up through the build-up and bursts in the phrase colour on the drop.
- Lower Third: A now-playing credit with the cover, artist, title, BPM and key, real fonts and fades. It slides in on every new track and comes back near the end. The rest of the frame stays transparent.
- Bulb Clock: The deck's timecode (HH MM SS FF) in big warm seven-segment digits made of glowing glass tubes (unlit tubes stay visible as dark glass) under hanging Edison bulbs, mirrored in a black floor, with a slow camera pan. The bulbs chase the beats of the bar and flash on the drop; the digits turn red in the last 30 seconds of the track and blink in the last 10. At the top of the page: MODE shows the time remaining, the time played or the time of day instead, PAN_SPEED sets the camera pan (0 = still), CHECKER = true gives a black and white tiled floor.
- Beat Cube: A lit 3D cube that kicks on every beat.
- Jog Pong: Classic Pong for two players, played with the decks' jog wheels. Wire the decks into a Merge, the Merge into the JS Engine node. The Merge's inputs are the players: the deck on In 1 plays left, the deck on In 2 right. To swap players, swap the wires. (PLAYERS at the top of the page can pick decks by player number instead.) Turning a jog moves that player's paddle (clockwise = up). It works best with the decks paused. A side without a deck, or whose jog is not touched for 10 seconds, is played by the computer, so one deck plays against the computer. First to 11 wins.
- Space Invaders: The arcade classic, played on one deck. Wire the deck into a Merge (it plays from In 1), or use the page's own deck. The jog wheel moves the cannon (clockwise = right) and the CUE button fires. Hold CUE down for auto fire. CUE jumps the playhead back to the cue point; the page sees that jump as a shot, so the cannon stays where you aimed it. A hot cue, a loop or a quick seek fires too. It works best with the deck paused. The invaders march on the beat. A build-up makes them flash and march faster, a break slows them down, and the drop sends the mothership across with a flash. The track title shows at the top. When nobody touches the jog or CUE for 20 seconds, the computer plays; turn the jog or press CUE to start a new game. PLAYER at the top of the page can pick the deck by player number instead.
Festival Stage: A night-time festival mainstage seen from the crowd, on the infield of an oval motor speedway. Around it: the banked track with walls, a catch fence, big light ropes (three strands of coloured bulbs swagging between tall poles all around the track), a grandstand close behind the stage and one on the far straight, light towers, side stages with their own beams, ferris wheels, neon art and camps in the infield, and hills on the horizon with the Las Vegas skyline in front of them: the tall tower with its pod and blinking needle, the glass pyramid with its beam into the sky, the giant LED sphere (it changes its show every 16 seconds: a planet, the yellow smiley that blinks now and then, the moon, colour rings, the smiley again, a starfield), the observation wheel, the half-size Eiffel tower, dark casino towers with a few lit floors, a low-rise city with an orange street grid and traffic, and planes on approach with blinking lights, under a warm city glow. The moving heads are real beam fixtures: a base, a yoke that pans and a head that tilts, moving at real motor speed. Each beam has a tight bright core in a soft glow, the lens flares when a beam points at the camera, and in a drop the roof fixtures split their beams with a prism every other 8 bars. LED arches with pixel dots around a big centre screen, LED wings, truss towers, a DJ and haze. When the deck has cover art, it shows in the middle of the centre screen, slowly zooming and drifting, with the visuals running over it. The PA towers fly a main line array in a J curve with an outfill hang beside it, on chain hoists, with subs stacked on the ground. A packed dance floor fills the whole view: everyone bounces on every beat, raised arms pump on the beat, some sit on shoulders, and country flags from around the world, phones and glow sticks wave in the crowd (the Dutch and USA flags are always there). Light totems go up too: poles with an LED panel, a ring, a star, a glowing ball or an LED tube on top, flashing on the beat in a drop. It runs a full show of beam moving heads, lasers, strobes, blinders, pyro and fireworks from the track's sections:
- Breaks: slow moves over 8 bars, soft colours, no strobes. The lasers are slow sheets over the crowd, the phones come up and the blinders glow softly on the crowd.
- Build-ups: the beams and lasers gather and rise to the sky, the strobes fire 1, then 2, 4 and 8 times per beat, the blinders warm up, and the last beat before the drop is a blackout.
- Drop: the blinders hit, flames shoot up from the stage floor, silver fountains run on the roof, CO2 jets blast white plumes, and fireworks burst right on the drop. Fast moves on every bar, lasers scan the crowd on the beat and the crowd jumps. A flame chase runs again every 8 bars.
- 2nd drop: on top of that, a big fireworks show high over the stage for 16 bars and confetti over the whole crowd. Every shell bursts on a beat, with a finale on the last bar.
- The rest: moves over 2 bars and beams that pulse on the beat.
The camera works like a festival video crew. In normal parts it makes slow jib (crane) moves between shots from the crowd. In a drop it cuts to a new jib shot every 8 bars: a push through the crowd, sweeps over the heads, rises to a high wide view, and an aerial view of the whole speedway. In a build-up it pulls back and up as the drop gets closer, and the drop cuts back in. In a break it slowly pulls back over the crowd. At the top of the page: PYRO and FIREWORKS turn them off, PYRO_EVERY_BARS sets the flame chase (0 = only on the drop), BIG_FIREWORKS_DROP picks which drop gets the big show (0 = none), CO2, CONFETTI, FLAGS and TOTEMS turn those off (FLAGS and TOTEMS = how many), and CROWD sets how packed the dance floor is (1 = full). CAMERA_MOVE = false keeps the camera still at the front of house.
Stage Lights, Festival Stage, Particle Drop and Bulb Clock find the build-ups, breaks and drops in the track's sections. They read rekordbox phrases (UP = build-up, DOWN and BRIDGE = break, CHORUS = drop) or ShowKontrol's own structure analysis (Buildup, Break, Drop), whichever the deck has. The Internal Player brings ShowKontrol's analysis; CDJs bring rekordbox phrases. A track without either still runs; it just has no build-ups or drops.
- Stage Lights: A 3D club stage that runs its own light show from the data. Moving heads on a truss with beams in haze, strobes, blinders, floor washes and an LED wall that shows the cover art, artist and title on the section colour. The look follows the track's sections:
- Page File: Your own
.htmlfile, when Page is Own File. The page can load files from its own folder (scripts, images, fonts).
The pages live in Documents/TC Supply/TEMPLATE/HTML, one folder per page with an index.html. A folder you add there shows up in the Page menu (a name starting with _ is a library folder, like _lib with three.js). The pages that come with ShowKontrol are replaced when an update brings new ones, so copy a page folder under a new name before you change it.
- Page FPS: How often the page gets new data and draws, and how often ShowKontrol takes its picture. 30 is right for most shows.
- Background: Transparent keeps whatever is under the page visible (video lanes, NDI with alpha). Black fills behind the page.
- Reload Page: Loads the page again, for example after you edited your own file.
The page draws at the Graphic node's Render Width / Height. It runs hidden, nothing opens on screen. It starts when the Graphic node is drawn (in the Patch, the big viewer, or on its Screen / NDI output) and stops a few seconds after nothing shows it any more.
Writing your own page. ShowKontrol adds an sk object to every page. A hidden page never gets requestAnimationFrame, so draw in sk.on("frame", …), which runs every time new data arrives:
<script src="three.min.js"></script>
<script>
var renderer = new THREE.WebGLRenderer({ alpha: true, preserveDrawingBuffer: true });
document.body.appendChild(renderer.domElement);
// … build your scene …
sk.on("resize", function (w, h) { renderer.setPixelRatio(sk.dpr); renderer.setSize(w, h); });
sk.on("frame", function (deck) {
var kick = 1 - sk.beatPhase(); // 1 on the beat, 0 just before the next
var t = sk.now() / 1000; // seconds, for anything that moves over time
// … move things with kick, deck.beat.currentBpm, deck.metadata.title …
renderer.render(scene, camera);
});
</script>
sk.data: The whole frame, the same shape a Script sees assource.sk.deck: The deck the data belongs to (a Script'sparent).sk.on(event, fn):"frame"(every update),"beat","bar","track"(a new track),"resize".sk.now(): The time of this frame in ms. Animate with it instead ofperformance.now(): frames are taken on a steady schedule, andsk.now()steps evenly from frame to frame.sk.beatPhase()/sk.barPhase(): 0 to 1 through the beat / bar.sk.beatInBar()/sk.bar()/sk.beatPos(): the beat in the bar, the bar, and beats since the start. They come from a smooth beat clock that runs at the BPM and follows the deck gently, so a late or early beat report never makes the picture jump. It only jumps when the deck does (a seek, a loop, a new track).sk.get("deck.metadata.title", ""): Reads a value without failing when it is missing.sk.dpr: The pixel ratio to draw at (2 on a Retina Mac).sk.dataAge: How old the deck data was at this frame, in ms. Add it to a position or timecode while playing so counters step evenly.sk.art/sk.on("art", fn): The deck's cover art as an image URL (empty when there is none). It arrives on every track change.sk.section(): The section playing now:kind(intro, build, break, drop, groove or outro),label, the next one and the beats to it. It works the same with rekordbox phrases and ShowKontrol's analysis.sk.nextDrop()/sk.inDrop(): Beats to the next drop (a drop after something else, -1 when none is ahead) and whether one is playing.sk.phrase(): The raw rekordbox phrase values, when the deck has them.sk.log("text"): Writes a line to ShowKontrol's log. Page errors are logged too.
Pages work offline, so do not load libraries from the internet. A page in the templates folder can use ../_lib/three.min.js; for a page elsewhere, copy three.min.js next to it. A hidden page also gets no CSS animations you can rely on: animate from sk.on("frame", …) with sk.now(), as the Lower Third page does.
Run in Background (macOS)#
A heavy script can slow the screens, because it runs on the same thread that draws them. Switch Run in Background on (Script section of the node) and the script runs on its own thread instead. It is off by default.
What changes:
- The script's own changes arrive one engine tick later (about 33 ms). Data that only passes through the node is not delayed.
- Runs fired by a trigger stay immediate.
- On Windows the setting has no effect: scripts always run on the main thread.
Leave it off for a script whose result must land in the same tick (for example a timecode offset), and for scripts that switch other nodes in a fixed order.
Node parameters in the data stream#
Node names are identifiers: Spaces and symbols are stripped automatically (type "CDJ 1" → the name becomes CDJ1). The Description field (in the Node section of every node) is free text, when set, the canvas shows it instead of the name; the name stays the address. New nodes get unique lowercase numbered names (device1, router1, matrix1, source1, group1, …) rename them to whatever address you like (CDJ1, MainDeck). One reserved corner: a BARE all-lowercase data-namespace word (device, value, select, …) can't be a node name, the trailing number in the defaults is what keeps them safe, so keep a digit or a capital in yours.
As a frame passes through a node, all of that node's settings ride along as <Name>.<setting> keys, so any downstream Live Data monitor shows the upstream chain's state, and scripts read and control those nodes with plain dot syntax:
var active = source.CDJ1.select.id; // read an upstream node's state
output.CDJ1.select.id = 2; // control any node by NAME
output.MainRouter.router.active = "Input 2";
output.FXScript.node.bypassed = true; // bypass/stop work too
Addressing is by node name. Works on every setting you see in the inspector, for every node in the Patch, from any script (a cue's included), whether or not the data passed through that node. Reading works the same way: source.FXScript.node.bypassed gives that node's current setting.
output.OSC.node.bypassed = true; // bypass the OSC node while the cue runs
output.Resolume.node.stopped = true; // stop a node
output.MainRouter.router.active = "Input 2";
A script inside a cue only runs while the cue is active, and a node keeps the last value it was given. To put it back when the cue ends, use a Trigger on cue.active State Off feeding a script that writes output.OSC.node.bypassed = false;. Overriding a <Name>.* row in the Live Data monitor drives the node the same way. Nested data also uses plain dots now: source.mixer.ch1.fader, source.cue.1.color.
parent and child (name-free addressing)#
Two aliases spare you hard-coding names in scripts:
parent= whichever identity node OWNS the incoming data (the Device, or the last Router/Matrix it passed through, delays/triggers in between don't count). Read and write:var bar = source.parent.beat.bar; // same as source.device1.beat.bar output.parent.led.play = 1; // press Play on the routed deck output.parent.select.id = 2; // retarget the feeding Device node
child= the node(s) wired directly after this script, WRITE-ONLY (data flows downstream, so there is nothing to read). A write fans out to every direct child; settings a child doesn't have are ignored:output.child.gen.fps = "30"; // configure the MTC node after me output.child.node.bypassed = true; // bypass whatever I feed
Scripts that should survive rewiring use parent/child; scripts that target one specific node use its name.
Writing device settings from a script#
Changing a util.* (DJM utility) or setting.* (CDJ player setting) key in a script writes it to the hardware:
output.util.digitalLevel = 1; // on the mixer's frame
output.setting.quantize = 1; // on a deck's frame (deck = device.number)
Only keys the script changes (vs. its input) are sent. The write repeats every 2 s until the device's polled state confirms it, then goes quiet, so a script that keeps setting a value effectively enforces it. The same applies to a Live-Data override on a util.*/setting.* key: overriding it pushes it to the device. The output.setting / output.util / output.led / output.status / output.playback sections always exist (pre-created), so the assignments above work even before the device has reported those keys.
Panel states too: Setting a led.* / status.* key drives the deck until it matches, settings-backed toggles (status.isMasterTempoOn, status.isQuantizeOn, status.isAutoCueOn, status.isVinylModeOn) ride the settings write; the rest press the real button only while the deck disagrees (max one press per 2 s):
output.led.play = 1; // deck not playing? → press Play/Pause
output.led.sync = 1; // sync off? → press Sync
output.led.loop = 0; // looping? → press Reloop/Exit
output.status.isQuantizeOn = 1; // via the settings write
Transport also works by name via playback.state, accepted values: "playing", "paused", "cued" (other states aren't commandable):
output.playback.state = "paused"; // playing? → press Play/Pause
One-way states: led.cue and led.master only act on 1 (a deck can't un-cue or hand off master by button). led.onAir isn't controllable (that's the mixer fader). A persistent script value or override enforces the state, pausing the deck by hand gets re-pressed within 2 s until you remove the line or revert the override.
Any device, from any script, a cue's included. Name the Device node (its title in the Patch) in front of the section. output.<Device>.setting / .util / .led / .status / .playback always exist, whatever the script is wired to. Reading source.<Device>.… works too: a key the script's own input doesn't carry is filled in from that Device node's live data.
var periodMs = 600; // each on AND each off phase
var on = Math.floor(Date.now() / periodMs) % 2 === 0;
output.cdj2.setting.jogRingBrightness = on ? 2 : 0; // 0-2
output.cdj2.setting.jogLcdBrightness = on ? 5 : 1; // 1-5 (no "off")
if (source.cdj2.status.isQuantizeOn) { /* … */ }
A script inside a cue runs only while the cue is active. Outside it, its input passes through untouched and nothing is written. A Trigger-fired script still runs, e.g. one fired on cue.active State Off to put a setting back. The same goes for a Schedule item's graph (item.active). A device setting keeps the last value the script sent, so write the "normal" value back from a State-Off trigger if you want it restored.
Mind the setting. part: output.cdj2.jogRingBrightness (without it) is a setting of the cdj2 node, not of the player. Values outside a setting's range are clamped. Player settings are written over the network and take a moment to land, so very fast blinking (well under half a second) will skip steps.
Drawing to a Graphic node#
A Script can draw on a Graphic node wired after it, using the g helper. Coordinates are canvas pixels (top-left origin); colors are "#RRGGBB".
g.clear("#101014");
g.rect(4, 4, source.beat.beatInBar * 40, 24, "#33aaff");
g.circle(180, 60, 20 + source.beat.currentBpm % 20, "#ff3399");
g.text(8, 110, source.metadata.title, "#ffffff");
Helpers: g.clear(color), g.rect(x,y,w,h,color), g.line(x1,y1,x2,y2,color), g.circle(x,y,r,color), g.text(x,y,string,color), g.waveform(x,y,w,h,mode,zoom) (cached waveform, mode "detail"/"overview"), g.artwork(x,y,w,h) (the track's cover art, when cached). Wire Script → Graphic; the Graphic node renders the commands live.
After a Merge of several decks, add the deck's name to pick its cover: g.artwork(40, 100, 160, 160, "CDJ2"). Without a name the first deck's cover is drawn.
Double-click a Graphic node to open a full-size live viewer in place of the Patch (letterboxed at the render resolution, refreshed every engine tick); Close returns to the Patch.
Graphic node settings:
- Render Width / Height: The real output resolution the script draws for (e.g. 1280×720). Coordinates in
g.*are in these pixels. - Node Width / Height: How big the node's preview is on the canvas (or drag the node's bottom-right corner). The render is shown scaled to fit.
- Preview FPS: Caps how often the in-patch preview redraws (the output runs faster).
- Output: Off, Screen (opens a resizable output window, letterboxed at full render resolution, at Output FPS), or NDI (sends an NDI source named NDI Source Name).
Only Keys the Script Names (faster scripts)#
A Script node normally receives the whole incoming frame (hundreds of keys for a deck) and hands a whole frame back, every engine tick, even when the script reads one key. Switch Only Keys the Script Names on (Script section of the node) and the script receives only the keys its text names, and only the keys it writes are changed; everything else passes through untouched. It is off by default.
What counts as "named": every dotted name in the script, bare CDJ1.beat.bar, source.…, output.…, parent.… (the deck the frame belongs to) and bracket keys x["3.inMs"]. A named group (source.CDJ1.beat) brings every key under it.
Leave it off for a script that
- Builds key names while it runs (
get("playback." + x),source[name],for (k in source)) (those keys would silently be missing, or - Deletes keys to filter what goes downstream) deleted keys would stay.
Good candidates: scripts that read a few fixed keys and write value.*, setting.* or a child gate (e.g. an "only during a drop" gate, a jog-ring blink).
One Script for several decks#
An input pin takes one wire, so a second wire into a Script replaces the first. To run one script on several decks, wire the decks into a Merge node and the Merge into the Script. The script then sees every deck's keys side by side and runs once per tick:
// CDJ1 and CDJ2 both wired into a Merge, the Merge into this Script
value.anyOnAir = (CDJ1.playback.onAir || CDJ2.playback.onAir) ? 1 : 0;
value.bpmDiff = CDJ1.beat.currentBpm - CDJ2.beat.currentBpm;
After a Merge, parent means the deck on the winning input (the lowest wired input, or the highest when the Merge says Higher Input Wins). Address the other decks by name. <Merge>.merge.decks lists the decks in input order (In 1 first), for example CDJ1,CDJ2.
system.beep beeps (edge-triggered). A Script fed by a trigger runs once per fire; fed by anything else it runs every tick.
