Generate a Chataigne project from a show spec.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Sonnet 5.5 committed 2026-10-22 11:44:19 +13:00
1 parent e413530658
commit 729a315c7a
8 files changed
+4549

No files matched your search

+1
View File
@@ -3,3 +3,4 @@ __pycache__/
*.qxw~ *.qxw~
.DS_Store .DS_Store
.venv/ .venv/
chataigne/*/*_autosave/
+22
View File
@@ -47,3 +47,25 @@ python3 scripts/figure8_small_eye.py --write-qxw shows/small_eye.qxw
Copy `.qxf` files from `fixtures/` into QLC+’s fixture library if the Copy `.qxf` files from `fixtures/` into QLC+’s fixture library if the
manufacturer/model is missing. manufacturer/model is missing.
## Chataigne
`scripts/make_chataigne.py` turns a show spec into a Chataigne project, so the
SMC-PAD can drive the same colour pads and sliders without QLC+.
```bash
python3 scripts/make_chataigne.py shows/test.show.json chataigne/test
```
Open `chataigne/test/test.noisette`. The **Pad** (MIDI) module reads the SMC-PAD
directly (`--pad` picks the port: USB `SINCO SMC-PAD-Master` by default, or
`SMC-PAD Bluetooth`). The script does the Play-layer shift that `pad_layer.py` does for
QLC+, with no knob smoothing, so `smooth_smc_pad.py` is not needed. Set the lamps with
`scripts/pad_lamps.py`. The **Lights** (DMX) module sends Art-Net to the
node in the spec. The **Preview** module sends a copy to 127.0.0.1 for the simulator (`--preview ''` leaves it out). If it comes up on the wrong output, set DMX Type to Art-Net,
the remote host, and an output universe of net 0, subnet 0, universe 0.
The project also has a dashboard with the same buttons and sliders as the
virtual console, coloured like it. Chataigne serves it on port 9999 for a
phone or browser. Pads, knobs and dashboard stay in step.
Edit `chataigne/show.template.js` for behaviour; the generated `test.js` is
overwritten.
+210
View File
@@ -0,0 +1,210 @@
// Pads pick colours, sliders mix a custom colour, like the QLC+ virtual console.
// It reads the pad directly: Play shifts bank 2 here, as scripts/pad_layer.py does
// when QLC+ is used.
// Generated by scripts/make_chataigne.py: edit this template, not the output.
//
// Runs as a script on the MIDI module "Pad" so it gets the pad and knob events.
// DMX goes out through the DMX module "Lights", and a copy through "Preview" if it exists.
/*__DATA__*/
var LAMP = "Lamp";
var LAMP_OFF = 0.3; // brightness of a pad's tile when it is not playing
var FADE_RATE = 100; // script updates per second
var PLAY_CC = 27; // hold Play to move bank 2 (notes 52-67) up 16, like pad_layer.py
var BANK_FIRST = 52;
var BANK_LAST = 67;
var BANK_SHIFT = 16;
var DMX_SIZE = 513; // channels are 1-based
var states = [];
var sent = [];
var lookup = {};
var lampParams = [];
var sliderParams = [];
var nowParams = [];
var busy = false;
var primed = false;
var playHeld = false;
function init()
{
script.setUpdateRate(FADE_RATE);
for (var i = 0; i < DMX_SIZE; i++) sent[i] = -1;
states = [];
for (var g = 0; g < GROUPS.length; g++)
{
var level = [], from = [], to = [], touched = [];
for (var c = 0; c < DMX_SIZE; c++) { level[c] = 0; from[c] = 0; to[c] = 0; touched[c] = 0; }
var group = GROUPS[g];
for (var p = 0; p < group.pads.length; p++) mark(touched, group.pads[p].levels);
for (var s = 0; s < group.sliders.length; s++) mark(touched, group.sliders[s].levels);
var mix = [];
for (var m = 0; m < group.sliders.length; m++) mix[m] = 0;
states[g] = {active: -1, elapsed: 0, duration: 0, level: level, from: from, to: to, touched: touched, mix: mix};
// Controls on the script's Params, for the dashboard to show.
sliderParams[g] = [];
lampParams[g] = [];
for (var q = 0; q < group.pads.length; q++)
{
script.addTrigger(group.pads[q].id, group.name + " " + group.pads[q].name);
lampParams[g][q] = script.addColorParameter(group.pads[q].id + LAMP, group.name + " " + group.pads[q].name + " lamp", shade(group.pads[q].rgb, LAMP_OFF));
lookup[group.pads[q].id] = {g: g, p: q, s: -1};
}
for (var r = 0; r < group.sliders.length; r++)
{
sliderParams[g][r] = script.addFloatParameter(group.sliders[r].id, group.name + " " + group.sliders[r].name, 0, 0, 1);
lookup[group.sliders[r].id] = {g: g, p: -1, s: r};
}
nowParams[g] = script.addStringParameter(group.now, group.name + " scene", "");
}
script.log("show script ready: " + GROUPS.length + " groups");
}
function mark(touched, levels)
{
for (var i = 0; i < levels.length; i += 2) touched[levels[i]] = 1;
}
// A pad press starts its scene and fades the others out. A second press stops it.
function noteOnEvent(channel, pitch, velocity)
{
if (velocity == 0) return;
if (playHeld && pitch >= BANK_FIRST && pitch <= BANK_LAST) pitch += BANK_SHIFT;
for (var g = 0; g < GROUPS.length; g++)
{
var pads = GROUPS[g].pads;
for (var p = 0; p < pads.length; p++)
{
if (pads[p].note == pitch) { press(g, p); return; }
}
}
}
// A control on the dashboard changed.
function scriptParameterChanged(param)
{
if (busy) return;
var hit = lookup[param.name];
if (!hit) return;
if (hit.p >= 0) press(hit.g, hit.p);
else states[hit.g].mix[hit.s] = param.get();
}
function shade(rgb, level)
{
return [rgb[0] * level, rgb[1] * level, rgb[2] * level, 1];
}
// Light the playing pad's strip on the board and show its name.
function show(g, name)
{
busy = true;
nowParams[g].set(name);
var pads = GROUPS[g].pads;
for (var p = 0; p < pads.length; p++) lampParams[g][p].set(shade(pads[p].rgb, states[g].active == p ? 1 : LAMP_OFF));
busy = false;
}
function press(g, p)
{
var st = states[g];
var pad = GROUPS[g].pads[p];
for (var c = 0; c < DMX_SIZE; c++) { st.from[c] = st.level[c]; st.to[c] = 0; }
if (st.active == p)
{
st.active = -1;
st.duration = pad.fadeOut;
show(g, "");
}
else
{
for (var i = 0; i < pad.levels.length; i += 2) st.to[pad.levels[i]] = pad.levels[i + 1];
st.active = p;
st.duration = pad.fadeIn;
show(g, pad.name);
}
st.elapsed = 0;
}
function ccEvent(channel, number, value)
{
if (number == PLAY_CC) { playHeld = value > 0; return; }
for (var g = 0; g < GROUPS.length; g++)
{
var sliders = GROUPS[g].sliders;
for (var s = 0; s < sliders.length; s++)
{
if (sliders[s].cc == number)
{
states[g].mix[s] = value / 127;
busy = true;
sliderParams[g][s].set(value / 127);
busy = false;
}
}
}
}
// The dashboard web server does not always start when a project loads with it enabled, so switch
// it off and on once the script is running.
function startWeb()
{
var settings = root.projectSettings;
if (!settings || !settings.dashboardSettings) return;
var web = settings.dashboardSettings.enableDashboardServer;
if (!web) return;
web.set(false);
web.set(true);
script.log("dashboard web server restarted");
}
function update(deltaTime)
{
// A colour control's starting value is read in a different colour model and saved values load
// after init, so paint every tile once the script is running.
if (!primed)
{
primed = true;
startWeb();
for (var g = 0; g < GROUPS.length; g++) show(g, states[g].active >= 0 ? GROUPS[g].pads[states[g].active].name : "");
}
var out = [];
for (var c = 0; c < DMX_SIZE; c++) out[c] = 0;
for (var g = 0; g < GROUPS.length; g++) render(g, deltaTime, out);
var first = -1, last = -1;
for (var i = 1; i < DMX_SIZE; i++)
{
if (out[i] != sent[i]) { if (first < 0) first = i; last = i; }
}
if (first < 0) return;
var values = [];
for (var j = first; j <= last; j++) { values.push(out[j]); sent[j] = out[j]; }
root.modules.lights.send(first, values);
if (root.modules.preview) root.modules.preview.send(first, values);
}
function render(g, deltaTime, out)
{
var st = states[g];
st.elapsed += deltaTime * 1000;
var t = st.duration > 0 ? Math.min(1, st.elapsed / st.duration) : 1;
for (var c = 1; c < DMX_SIZE; c++)
{
if (!st.touched[c]) continue;
st.level[c] = st.from[c] + (st.to[c] - st.from[c]) * t;
out[c] = Math.max(out[c], st.level[c]);
}
var sliders = GROUPS[g].sliders;
for (var s = 0; s < sliders.length; s++)
{
var levels = sliders[s].levels;
for (var i = 0; i < levels.length; i += 2)
{
out[levels[i]] = Math.max(out[levels[i]], levels[i + 1] * st.mix[s]);
}
}
for (var k = 1; k < DMX_SIZE; k++) out[k] = Math.round(out[k]);
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 69 B

+269
View File
@@ -0,0 +1,269 @@
// Pads pick colours, sliders mix a custom colour, like the QLC+ virtual console.
// It reads the pad directly: Play shifts bank 2 here, as scripts/pad_layer.py does
// when QLC+ is used.
// Generated by scripts/make_chataigne.py: edit this template, not the output.
//
// Runs as a script on the MIDI module "Pad" so it gets the pad and knob events.
// DMX goes out through the DMX module "Lights", and a copy through "Preview" if it exists.
var GROUPS = [
{
name: "Colour 1",
now: "now1",
pads: [
{id: "c1Red", rgb: [1.0, 0.0, 0.0], note: 52, name: "Red", fadeIn: 1000, fadeOut: 1000, levels: [88,255,90,255,91,0,92,0,93,0,96,255,98,255,99,0,100,0,101,0,104,255,106,255,107,0,108,0,109,0,112,255,114,255,115,0,116,0,117,0,120,255,122,255,123,0,124,0,125,0,128,255,130,255,131,0,132,0,133,0,136,255,138,255,139,0,140,0,141,0,144,255,146,255,147,0,148,0,149,0,152,255,154,255,155,0,156,0,157,0,160,255,162,255,163,0,164,0,165,0,168,255,170,255,171,0,172,0,173,0,176,255,178,255,179,0,180,0,181,0,184,255,186,255,187,0,188,0,189,0,192,255,194,255,195,0,196,0,197,0,200,255,202,255,203,0,204,0,205,0]},
{id: "c1Orange", rgb: [1.0, 0.498, 0.0], note: 53, name: "Orange", fadeIn: 1000, fadeOut: 1000, levels: [88,255,90,255,91,127,92,0,93,0,96,255,98,255,99,127,100,0,101,0,104,255,106,255,107,127,108,0,109,0,112,255,114,255,115,127,116,0,117,0,120,255,122,255,123,127,124,0,125,0,128,255,130,255,131,127,132,0,133,0,136,255,138,255,139,127,140,0,141,0,144,255,146,255,147,127,148,0,149,0,152,255,154,255,155,127,156,0,157,0,160,255,162,255,163,127,164,0,165,0,168,255,170,255,171,127,172,0,173,0,176,255,178,255,179,127,180,0,181,0,184,255,186,255,187,127,188,0,189,0,192,255,194,255,195,127,196,0,197,0,200,255,202,255,203,127,204,0,205,0]},
{id: "c1Yellow", rgb: [1.0, 1.0, 0.0], note: 54, name: "Yellow", fadeIn: 1000, fadeOut: 1000, levels: [88,255,90,255,91,255,92,0,93,0,96,255,98,255,99,255,100,0,101,0,104,255,106,255,107,255,108,0,109,0,112,255,114,255,115,255,116,0,117,0,120,255,122,255,123,255,124,0,125,0,128,255,130,255,131,255,132,0,133,0,136,255,138,255,139,255,140,0,141,0,144,255,146,255,147,255,148,0,149,0,152,255,154,255,155,255,156,0,157,0,160,255,162,255,163,255,164,0,165,0,168,255,170,255,171,255,172,0,173,0,176,255,178,255,179,255,180,0,181,0,184,255,186,255,187,255,188,0,189,0,192,255,194,255,195,255,196,0,197,0,200,255,202,255,203,255,204,0,205,0]},
{id: "c1Lime", rgb: [0.498, 1.0, 0.0], note: 55, name: "Lime", fadeIn: 1000, fadeOut: 1000, levels: [88,255,90,127,91,255,92,0,93,0,96,255,98,127,99,255,100,0,101,0,104,255,106,127,107,255,108,0,109,0,112,255,114,127,115,255,116,0,117,0,120,255,122,127,123,255,124,0,125,0,128,255,130,127,131,255,132,0,133,0,136,255,138,127,139,255,140,0,141,0,144,255,146,127,147,255,148,0,149,0,152,255,154,127,155,255,156,0,157,0,160,255,162,127,163,255,164,0,165,0,168,255,170,127,171,255,172,0,173,0,176,255,178,127,179,255,180,0,181,0,184,255,186,127,187,255,188,0,189,0,192,255,194,127,195,255,196,0,197,0,200,255,202,127,203,255,204,0,205,0]},
{id: "c1Green", rgb: [0.0, 1.0, 0.0], note: 56, name: "Green", fadeIn: 1000, fadeOut: 1000, levels: [88,255,90,0,91,255,92,0,93,0,96,255,98,0,99,255,100,0,101,0,104,255,106,0,107,255,108,0,109,0,112,255,114,0,115,255,116,0,117,0,120,255,122,0,123,255,124,0,125,0,128,255,130,0,131,255,132,0,133,0,136,255,138,0,139,255,140,0,141,0,144,255,146,0,147,255,148,0,149,0,152,255,154,0,155,255,156,0,157,0,160,255,162,0,163,255,164,0,165,0,168,255,170,0,171,255,172,0,173,0,176,255,178,0,179,255,180,0,181,0,184,255,186,0,187,255,188,0,189,0,192,255,194,0,195,255,196,0,197,0,200,255,202,0,203,255,204,0,205,0]},
{id: "c1Spring", rgb: [0.0, 1.0, 0.498], note: 57, name: "Spring", fadeIn: 1000, fadeOut: 1000, levels: [88,255,90,0,91,255,92,127,93,0,96,255,98,0,99,255,100,127,101,0,104,255,106,0,107,255,108,127,109,0,112,255,114,0,115,255,116,127,117,0,120,255,122,0,123,255,124,127,125,0,128,255,130,0,131,255,132,127,133,0,136,255,138,0,139,255,140,127,141,0,144,255,146,0,147,255,148,127,149,0,152,255,154,0,155,255,156,127,157,0,160,255,162,0,163,255,164,127,165,0,168,255,170,0,171,255,172,127,173,0,176,255,178,0,179,255,180,127,181,0,184,255,186,0,187,255,188,127,189,0,192,255,194,0,195,255,196,127,197,0,200,255,202,0,203,255,204,127,205,0]},
{id: "c1Cyan", rgb: [0.0, 1.0, 1.0], note: 58, name: "Cyan", fadeIn: 1000, fadeOut: 1000, levels: [88,255,90,0,91,255,92,255,93,0,96,255,98,0,99,255,100,255,101,0,104,255,106,0,107,255,108,255,109,0,112,255,114,0,115,255,116,255,117,0,120,255,122,0,123,255,124,255,125,0,128,255,130,0,131,255,132,255,133,0,136,255,138,0,139,255,140,255,141,0,144,255,146,0,147,255,148,255,149,0,152,255,154,0,155,255,156,255,157,0,160,255,162,0,163,255,164,255,165,0,168,255,170,0,171,255,172,255,173,0,176,255,178,0,179,255,180,255,181,0,184,255,186,0,187,255,188,255,189,0,192,255,194,0,195,255,196,255,197,0,200,255,202,0,203,255,204,255,205,0]},
{id: "c1Azure", rgb: [0.0, 0.498, 1.0], note: 59, name: "Azure", fadeIn: 1000, fadeOut: 1000, levels: [88,255,90,0,91,127,92,255,93,0,96,255,98,0,99,127,100,255,101,0,104,255,106,0,107,127,108,255,109,0,112,255,114,0,115,127,116,255,117,0,120,255,122,0,123,127,124,255,125,0,128,255,130,0,131,127,132,255,133,0,136,255,138,0,139,127,140,255,141,0,144,255,146,0,147,127,148,255,149,0,152,255,154,0,155,127,156,255,157,0,160,255,162,0,163,127,164,255,165,0,168,255,170,0,171,127,172,255,173,0,176,255,178,0,179,127,180,255,181,0,184,255,186,0,187,127,188,255,189,0,192,255,194,0,195,127,196,255,197,0,200,255,202,0,203,127,204,255,205,0]},
{id: "c1Blue", rgb: [0.0, 0.0, 1.0], note: 60, name: "Blue", fadeIn: 1000, fadeOut: 1000, levels: [88,255,90,0,91,0,92,255,93,0,96,255,98,0,99,0,100,255,101,0,104,255,106,0,107,0,108,255,109,0,112,255,114,0,115,0,116,255,117,0,120,255,122,0,123,0,124,255,125,0,128,255,130,0,131,0,132,255,133,0,136,255,138,0,139,0,140,255,141,0,144,255,146,0,147,0,148,255,149,0,152,255,154,0,155,0,156,255,157,0,160,255,162,0,163,0,164,255,165,0,168,255,170,0,171,0,172,255,173,0,176,255,178,0,179,0,180,255,181,0,184,255,186,0,187,0,188,255,189,0,192,255,194,0,195,0,196,255,197,0,200,255,202,0,203,0,204,255,205,0]},
{id: "c1Violet", rgb: [0.498, 0.0, 1.0], note: 61, name: "Violet", fadeIn: 1000, fadeOut: 1000, levels: [88,255,90,127,91,0,92,255,93,0,96,255,98,127,99,0,100,255,101,0,104,255,106,127,107,0,108,255,109,0,112,255,114,127,115,0,116,255,117,0,120,255,122,127,123,0,124,255,125,0,128,255,130,127,131,0,132,255,133,0,136,255,138,127,139,0,140,255,141,0,144,255,146,127,147,0,148,255,149,0,152,255,154,127,155,0,156,255,157,0,160,255,162,127,163,0,164,255,165,0,168,255,170,127,171,0,172,255,173,0,176,255,178,127,179,0,180,255,181,0,184,255,186,127,187,0,188,255,189,0,192,255,194,127,195,0,196,255,197,0,200,255,202,127,203,0,204,255,205,0]},
{id: "c1Magenta", rgb: [1.0, 0.0, 1.0], note: 62, name: "Magenta", fadeIn: 1000, fadeOut: 1000, levels: [88,255,90,255,91,0,92,255,93,0,96,255,98,255,99,0,100,255,101,0,104,255,106,255,107,0,108,255,109,0,112,255,114,255,115,0,116,255,117,0,120,255,122,255,123,0,124,255,125,0,128,255,130,255,131,0,132,255,133,0,136,255,138,255,139,0,140,255,141,0,144,255,146,255,147,0,148,255,149,0,152,255,154,255,155,0,156,255,157,0,160,255,162,255,163,0,164,255,165,0,168,255,170,255,171,0,172,255,173,0,176,255,178,255,179,0,180,255,181,0,184,255,186,255,187,0,188,255,189,0,192,255,194,255,195,0,196,255,197,0,200,255,202,255,203,0,204,255,205,0]},
{id: "c1Pink", rgb: [1.0, 0.157, 0.471], note: 63, name: "Pink", fadeIn: 1000, fadeOut: 1000, levels: [88,255,90,255,91,40,92,120,93,0,96,255,98,255,99,40,100,120,101,0,104,255,106,255,107,40,108,120,109,0,112,255,114,255,115,40,116,120,117,0,120,255,122,255,123,40,124,120,125,0,128,255,130,255,131,40,132,120,133,0,136,255,138,255,139,40,140,120,141,0,144,255,146,255,147,40,148,120,149,0,152,255,154,255,155,40,156,120,157,0,160,255,162,255,163,40,164,120,165,0,168,255,170,255,171,40,172,120,173,0,176,255,178,255,179,40,180,120,181,0,184,255,186,255,187,40,188,120,189,0,192,255,194,255,195,40,196,120,197,0,200,255,202,255,203,40,204,120,205,0]},
{id: "c1Warm", rgb: [1.0, 0.941, 0.627], note: 64, name: "Warm", fadeIn: 1000, fadeOut: 1000, levels: [88,255,90,255,91,120,92,40,93,120,96,255,98,255,99,120,100,40,101,120,104,255,106,255,107,120,108,40,109,120,112,255,114,255,115,120,116,40,117,120,120,255,122,255,123,120,124,40,125,120,128,255,130,255,131,120,132,40,133,120,136,255,138,255,139,120,140,40,141,120,144,255,146,255,147,120,148,40,149,120,152,255,154,255,155,120,156,40,157,120,160,255,162,255,163,120,164,40,165,120,168,255,170,255,171,120,172,40,173,120,176,255,178,255,179,120,180,40,181,120,184,255,186,255,187,120,188,40,189,120,192,255,194,255,195,120,196,40,197,120,200,255,202,255,203,120,204,40,205,120]},
{id: "c1White", rgb: [1.0, 1.0, 1.0], note: 65, name: "White", fadeIn: 1000, fadeOut: 1000, levels: [88,255,90,0,91,0,92,0,93,255,96,255,98,0,99,0,100,0,101,255,104,255,106,0,107,0,108,0,109,255,112,255,114,0,115,0,116,0,117,255,120,255,122,0,123,0,124,0,125,255,128,255,130,0,131,0,132,0,133,255,136,255,138,0,139,0,140,0,141,255,144,255,146,0,147,0,148,0,149,255,152,255,154,0,155,0,156,0,157,255,160,255,162,0,163,0,164,0,165,255,168,255,170,0,171,0,172,0,173,255,176,255,178,0,179,0,180,0,181,255,184,255,186,0,187,0,188,0,189,255,192,255,194,0,195,0,196,0,197,255,200,255,202,0,203,0,204,0,205,255]},
{id: "c1Cool", rgb: [0.784, 0.941, 1.0], note: 66, name: "Cool", fadeIn: 1000, fadeOut: 1000, levels: [88,255,90,80,91,120,92,255,93,120,96,255,98,80,99,120,100,255,101,120,104,255,106,80,107,120,108,255,109,120,112,255,114,80,115,120,116,255,117,120,120,255,122,80,123,120,124,255,125,120,128,255,130,80,131,120,132,255,133,120,136,255,138,80,139,120,140,255,141,120,144,255,146,80,147,120,148,255,149,120,152,255,154,80,155,120,156,255,157,120,160,255,162,80,163,120,164,255,165,120,168,255,170,80,171,120,172,255,173,120,176,255,178,80,179,120,180,255,181,120,184,255,186,80,187,120,188,255,189,120,192,255,194,80,195,120,196,255,197,120,200,255,202,80,203,120,204,255,205,120]},
{id: "c1Custom", rgb: [1.0, 0.235, 0.0], note: 67, name: "Custom", fadeIn: 1000, fadeOut: 1000, levels: [88,0,96,0,104,0,112,0,120,0,128,0,136,0,144,0,152,0,160,0,168,0,176,0,184,0,192,0,200,0]},
],
sliders: [
{id: "s1Dim", cc: 30, name: "Dim", levels: [88,255,96,255,104,255,112,255,120,255,128,255,136,255,144,255,152,255,160,255,168,255,176,255,184,255,192,255,200,255]},
{id: "s1R", cc: 31, name: "R", levels: [90,255,98,255,106,255,114,255,122,255,130,255,138,255,146,255,154,255,162,255,170,255,178,255,186,255,194,255,202,255]},
{id: "s1G", cc: 32, name: "G", levels: [91,255,99,255,107,255,115,255,123,255,131,255,139,255,147,255,155,255,163,255,171,255,179,255,187,255,195,255,203,255]},
{id: "s1B", cc: 33, name: "B", levels: [92,255,100,255,108,255,116,255,124,255,132,255,140,255,148,255,156,255,164,255,172,255,180,255,188,255,196,255,204,255]},
{id: "s1W", cc: 34, name: "W", levels: [93,255,101,255,109,255,117,255,125,255,133,255,141,255,149,255,157,255,165,255,173,255,181,255,189,255,197,255,205,255]},
]
},
{
name: "Colour 2",
now: "now2",
pads: [
{id: "c2Red", rgb: [1.0, 0.0, 0.0], note: 68, name: "Red", fadeIn: 1000, fadeOut: 1000, levels: [9,255,10,0,11,255,12,0,13,0,14,0,15,255,16,0,17,0,18,0,19,255,20,0,21,0,22,0,23,255,24,0,25,0,26,0,27,255,28,0,29,0,30,0,31,255,32,0,33,0,34,0,35,255,36,0,37,0,38,0,53,255,54,0,55,255,56,0,57,0,58,0,59,255,60,0,61,0,62,0,63,255,64,0,65,0,66,0,67,255,68,0,69,0,70,0,71,255,72,0,73,0,74,0,75,255,76,0,77,0,78,0,79,255,80,0,81,0,82,0,266,255,267,0,268,255,269,0,270,0,271,0,272,255,273,0,274,0,275,0,276,255,277,0,278,0,279,0,280,255,281,0,282,0,283,0,284,255,285,0,286,0,287,0,288,255,289,0,290,0,291,0,292,255,293,0,294,0,295,0,309,255,310,0,311,255,312,0,313,0,314,0,315,255,316,0,317,0,318,0,319,255,320,0,321,0,322,0,323,255,324,0,325,0,326,0,327,255,328,0,329,0,330,0,331,255,332,0,333,0,334,0,335,255,336,0,337,0,338,0]},
{id: "c2Orange", rgb: [1.0, 0.498, 0.0], note: 69, name: "Orange", fadeIn: 1000, fadeOut: 1000, levels: [9,255,10,0,11,255,12,127,13,0,14,0,15,255,16,127,17,0,18,0,19,255,20,127,21,0,22,0,23,255,24,127,25,0,26,0,27,255,28,127,29,0,30,0,31,255,32,127,33,0,34,0,35,255,36,127,37,0,38,0,53,255,54,0,55,255,56,127,57,0,58,0,59,255,60,127,61,0,62,0,63,255,64,127,65,0,66,0,67,255,68,127,69,0,70,0,71,255,72,127,73,0,74,0,75,255,76,127,77,0,78,0,79,255,80,127,81,0,82,0,266,255,267,0,268,255,269,127,270,0,271,0,272,255,273,127,274,0,275,0,276,255,277,127,278,0,279,0,280,255,281,127,282,0,283,0,284,255,285,127,286,0,287,0,288,255,289,127,290,0,291,0,292,255,293,127,294,0,295,0,309,255,310,0,311,255,312,127,313,0,314,0,315,255,316,127,317,0,318,0,319,255,320,127,321,0,322,0,323,255,324,127,325,0,326,0,327,255,328,127,329,0,330,0,331,255,332,127,333,0,334,0,335,255,336,127,337,0,338,0]},
{id: "c2Yellow", rgb: [1.0, 1.0, 0.0], note: 70, name: "Yellow", fadeIn: 1000, fadeOut: 1000, levels: [9,255,10,0,11,255,12,255,13,0,14,0,15,255,16,255,17,0,18,0,19,255,20,255,21,0,22,0,23,255,24,255,25,0,26,0,27,255,28,255,29,0,30,0,31,255,32,255,33,0,34,0,35,255,36,255,37,0,38,0,53,255,54,0,55,255,56,255,57,0,58,0,59,255,60,255,61,0,62,0,63,255,64,255,65,0,66,0,67,255,68,255,69,0,70,0,71,255,72,255,73,0,74,0,75,255,76,255,77,0,78,0,79,255,80,255,81,0,82,0,266,255,267,0,268,255,269,255,270,0,271,0,272,255,273,255,274,0,275,0,276,255,277,255,278,0,279,0,280,255,281,255,282,0,283,0,284,255,285,255,286,0,287,0,288,255,289,255,290,0,291,0,292,255,293,255,294,0,295,0,309,255,310,0,311,255,312,255,313,0,314,0,315,255,316,255,317,0,318,0,319,255,320,255,321,0,322,0,323,255,324,255,325,0,326,0,327,255,328,255,329,0,330,0,331,255,332,255,333,0,334,0,335,255,336,255,337,0,338,0]},
{id: "c2Lime", rgb: [0.498, 1.0, 0.0], note: 71, name: "Lime", fadeIn: 1000, fadeOut: 1000, levels: [9,255,10,0,11,127,12,255,13,0,14,0,15,127,16,255,17,0,18,0,19,127,20,255,21,0,22,0,23,127,24,255,25,0,26,0,27,127,28,255,29,0,30,0,31,127,32,255,33,0,34,0,35,127,36,255,37,0,38,0,53,255,54,0,55,127,56,255,57,0,58,0,59,127,60,255,61,0,62,0,63,127,64,255,65,0,66,0,67,127,68,255,69,0,70,0,71,127,72,255,73,0,74,0,75,127,76,255,77,0,78,0,79,127,80,255,81,0,82,0,266,255,267,0,268,127,269,255,270,0,271,0,272,127,273,255,274,0,275,0,276,127,277,255,278,0,279,0,280,127,281,255,282,0,283,0,284,127,285,255,286,0,287,0,288,127,289,255,290,0,291,0,292,127,293,255,294,0,295,0,309,255,310,0,311,127,312,255,313,0,314,0,315,127,316,255,317,0,318,0,319,127,320,255,321,0,322,0,323,127,324,255,325,0,326,0,327,127,328,255,329,0,330,0,331,127,332,255,333,0,334,0,335,127,336,255,337,0,338,0]},
{id: "c2Green", rgb: [0.0, 1.0, 0.0], note: 72, name: "Green", fadeIn: 1000, fadeOut: 1000, levels: [9,255,10,0,11,0,12,255,13,0,14,0,15,0,16,255,17,0,18,0,19,0,20,255,21,0,22,0,23,0,24,255,25,0,26,0,27,0,28,255,29,0,30,0,31,0,32,255,33,0,34,0,35,0,36,255,37,0,38,0,53,255,54,0,55,0,56,255,57,0,58,0,59,0,60,255,61,0,62,0,63,0,64,255,65,0,66,0,67,0,68,255,69,0,70,0,71,0,72,255,73,0,74,0,75,0,76,255,77,0,78,0,79,0,80,255,81,0,82,0,266,255,267,0,268,0,269,255,270,0,271,0,272,0,273,255,274,0,275,0,276,0,277,255,278,0,279,0,280,0,281,255,282,0,283,0,284,0,285,255,286,0,287,0,288,0,289,255,290,0,291,0,292,0,293,255,294,0,295,0,309,255,310,0,311,0,312,255,313,0,314,0,315,0,316,255,317,0,318,0,319,0,320,255,321,0,322,0,323,0,324,255,325,0,326,0,327,0,328,255,329,0,330,0,331,0,332,255,333,0,334,0,335,0,336,255,337,0,338,0]},
{id: "c2Spring", rgb: [0.0, 1.0, 0.498], note: 73, name: "Spring", fadeIn: 1000, fadeOut: 1000, levels: [9,255,10,0,11,0,12,255,13,127,14,0,15,0,16,255,17,127,18,0,19,0,20,255,21,127,22,0,23,0,24,255,25,127,26,0,27,0,28,255,29,127,30,0,31,0,32,255,33,127,34,0,35,0,36,255,37,127,38,0,53,255,54,0,55,0,56,255,57,127,58,0,59,0,60,255,61,127,62,0,63,0,64,255,65,127,66,0,67,0,68,255,69,127,70,0,71,0,72,255,73,127,74,0,75,0,76,255,77,127,78,0,79,0,80,255,81,127,82,0,266,255,267,0,268,0,269,255,270,127,271,0,272,0,273,255,274,127,275,0,276,0,277,255,278,127,279,0,280,0,281,255,282,127,283,0,284,0,285,255,286,127,287,0,288,0,289,255,290,127,291,0,292,0,293,255,294,127,295,0,309,255,310,0,311,0,312,255,313,127,314,0,315,0,316,255,317,127,318,0,319,0,320,255,321,127,322,0,323,0,324,255,325,127,326,0,327,0,328,255,329,127,330,0,331,0,332,255,333,127,334,0,335,0,336,255,337,127,338,0]},
{id: "c2Cyan", rgb: [0.0, 1.0, 1.0], note: 74, name: "Cyan", fadeIn: 1000, fadeOut: 1000, levels: [9,255,10,0,11,0,12,255,13,255,14,0,15,0,16,255,17,255,18,0,19,0,20,255,21,255,22,0,23,0,24,255,25,255,26,0,27,0,28,255,29,255,30,0,31,0,32,255,33,255,34,0,35,0,36,255,37,255,38,0,53,255,54,0,55,0,56,255,57,255,58,0,59,0,60,255,61,255,62,0,63,0,64,255,65,255,66,0,67,0,68,255,69,255,70,0,71,0,72,255,73,255,74,0,75,0,76,255,77,255,78,0,79,0,80,255,81,255,82,0,266,255,267,0,268,0,269,255,270,255,271,0,272,0,273,255,274,255,275,0,276,0,277,255,278,255,279,0,280,0,281,255,282,255,283,0,284,0,285,255,286,255,287,0,288,0,289,255,290,255,291,0,292,0,293,255,294,255,295,0,309,255,310,0,311,0,312,255,313,255,314,0,315,0,316,255,317,255,318,0,319,0,320,255,321,255,322,0,323,0,324,255,325,255,326,0,327,0,328,255,329,255,330,0,331,0,332,255,333,255,334,0,335,0,336,255,337,255,338,0]},
{id: "c2Azure", rgb: [0.0, 0.498, 1.0], note: 75, name: "Azure", fadeIn: 1000, fadeOut: 1000, levels: [9,255,10,0,11,0,12,127,13,255,14,0,15,0,16,127,17,255,18,0,19,0,20,127,21,255,22,0,23,0,24,127,25,255,26,0,27,0,28,127,29,255,30,0,31,0,32,127,33,255,34,0,35,0,36,127,37,255,38,0,53,255,54,0,55,0,56,127,57,255,58,0,59,0,60,127,61,255,62,0,63,0,64,127,65,255,66,0,67,0,68,127,69,255,70,0,71,0,72,127,73,255,74,0,75,0,76,127,77,255,78,0,79,0,80,127,81,255,82,0,266,255,267,0,268,0,269,127,270,255,271,0,272,0,273,127,274,255,275,0,276,0,277,127,278,255,279,0,280,0,281,127,282,255,283,0,284,0,285,127,286,255,287,0,288,0,289,127,290,255,291,0,292,0,293,127,294,255,295,0,309,255,310,0,311,0,312,127,313,255,314,0,315,0,316,127,317,255,318,0,319,0,320,127,321,255,322,0,323,0,324,127,325,255,326,0,327,0,328,127,329,255,330,0,331,0,332,127,333,255,334,0,335,0,336,127,337,255,338,0]},
{id: "c2Blue", rgb: [0.0, 0.0, 1.0], note: 76, name: "Blue", fadeIn: 1000, fadeOut: 1000, levels: [9,255,10,0,11,0,12,0,13,255,14,0,15,0,16,0,17,255,18,0,19,0,20,0,21,255,22,0,23,0,24,0,25,255,26,0,27,0,28,0,29,255,30,0,31,0,32,0,33,255,34,0,35,0,36,0,37,255,38,0,53,255,54,0,55,0,56,0,57,255,58,0,59,0,60,0,61,255,62,0,63,0,64,0,65,255,66,0,67,0,68,0,69,255,70,0,71,0,72,0,73,255,74,0,75,0,76,0,77,255,78,0,79,0,80,0,81,255,82,0,266,255,267,0,268,0,269,0,270,255,271,0,272,0,273,0,274,255,275,0,276,0,277,0,278,255,279,0,280,0,281,0,282,255,283,0,284,0,285,0,286,255,287,0,288,0,289,0,290,255,291,0,292,0,293,0,294,255,295,0,309,255,310,0,311,0,312,0,313,255,314,0,315,0,316,0,317,255,318,0,319,0,320,0,321,255,322,0,323,0,324,0,325,255,326,0,327,0,328,0,329,255,330,0,331,0,332,0,333,255,334,0,335,0,336,0,337,255,338,0]},
{id: "c2Violet", rgb: [0.498, 0.0, 1.0], note: 77, name: "Violet", fadeIn: 1000, fadeOut: 1000, levels: [9,255,10,0,11,127,12,0,13,255,14,0,15,127,16,0,17,255,18,0,19,127,20,0,21,255,22,0,23,127,24,0,25,255,26,0,27,127,28,0,29,255,30,0,31,127,32,0,33,255,34,0,35,127,36,0,37,255,38,0,53,255,54,0,55,127,56,0,57,255,58,0,59,127,60,0,61,255,62,0,63,127,64,0,65,255,66,0,67,127,68,0,69,255,70,0,71,127,72,0,73,255,74,0,75,127,76,0,77,255,78,0,79,127,80,0,81,255,82,0,266,255,267,0,268,127,269,0,270,255,271,0,272,127,273,0,274,255,275,0,276,127,277,0,278,255,279,0,280,127,281,0,282,255,283,0,284,127,285,0,286,255,287,0,288,127,289,0,290,255,291,0,292,127,293,0,294,255,295,0,309,255,310,0,311,127,312,0,313,255,314,0,315,127,316,0,317,255,318,0,319,127,320,0,321,255,322,0,323,127,324,0,325,255,326,0,327,127,328,0,329,255,330,0,331,127,332,0,333,255,334,0,335,127,336,0,337,255,338,0]},
{id: "c2Magenta", rgb: [1.0, 0.0, 1.0], note: 78, name: "Magenta", fadeIn: 1000, fadeOut: 1000, levels: [9,255,10,0,11,255,12,0,13,255,14,0,15,255,16,0,17,255,18,0,19,255,20,0,21,255,22,0,23,255,24,0,25,255,26,0,27,255,28,0,29,255,30,0,31,255,32,0,33,255,34,0,35,255,36,0,37,255,38,0,53,255,54,0,55,255,56,0,57,255,58,0,59,255,60,0,61,255,62,0,63,255,64,0,65,255,66,0,67,255,68,0,69,255,70,0,71,255,72,0,73,255,74,0,75,255,76,0,77,255,78,0,79,255,80,0,81,255,82,0,266,255,267,0,268,255,269,0,270,255,271,0,272,255,273,0,274,255,275,0,276,255,277,0,278,255,279,0,280,255,281,0,282,255,283,0,284,255,285,0,286,255,287,0,288,255,289,0,290,255,291,0,292,255,293,0,294,255,295,0,309,255,310,0,311,255,312,0,313,255,314,0,315,255,316,0,317,255,318,0,319,255,320,0,321,255,322,0,323,255,324,0,325,255,326,0,327,255,328,0,329,255,330,0,331,255,332,0,333,255,334,0,335,255,336,0,337,255,338,0]},
{id: "c2Pink", rgb: [1.0, 0.157, 0.471], note: 79, name: "Pink", fadeIn: 1000, fadeOut: 1000, levels: [9,255,10,0,11,255,12,40,13,120,14,0,15,255,16,40,17,120,18,0,19,255,20,40,21,120,22,0,23,255,24,40,25,120,26,0,27,255,28,40,29,120,30,0,31,255,32,40,33,120,34,0,35,255,36,40,37,120,38,0,53,255,54,0,55,255,56,40,57,120,58,0,59,255,60,40,61,120,62,0,63,255,64,40,65,120,66,0,67,255,68,40,69,120,70,0,71,255,72,40,73,120,74,0,75,255,76,40,77,120,78,0,79,255,80,40,81,120,82,0,266,255,267,0,268,255,269,40,270,120,271,0,272,255,273,40,274,120,275,0,276,255,277,40,278,120,279,0,280,255,281,40,282,120,283,0,284,255,285,40,286,120,287,0,288,255,289,40,290,120,291,0,292,255,293,40,294,120,295,0,309,255,310,0,311,255,312,40,313,120,314,0,315,255,316,40,317,120,318,0,319,255,320,40,321,120,322,0,323,255,324,40,325,120,326,0,327,255,328,40,329,120,330,0,331,255,332,40,333,120,334,0,335,255,336,40,337,120,338,0]},
{id: "c2Warm", rgb: [1.0, 0.941, 0.627], note: 80, name: "Warm", fadeIn: 1000, fadeOut: 1000, levels: [9,255,10,0,11,255,12,120,13,40,14,120,15,255,16,120,17,40,18,120,19,255,20,120,21,40,22,120,23,255,24,120,25,40,26,120,27,255,28,120,29,40,30,120,31,255,32,120,33,40,34,120,35,255,36,120,37,40,38,120,53,255,54,0,55,255,56,120,57,40,58,120,59,255,60,120,61,40,62,120,63,255,64,120,65,40,66,120,67,255,68,120,69,40,70,120,71,255,72,120,73,40,74,120,75,255,76,120,77,40,78,120,79,255,80,120,81,40,82,120,266,255,267,0,268,255,269,120,270,40,271,120,272,255,273,120,274,40,275,120,276,255,277,120,278,40,279,120,280,255,281,120,282,40,283,120,284,255,285,120,286,40,287,120,288,255,289,120,290,40,291,120,292,255,293,120,294,40,295,120,309,255,310,0,311,255,312,120,313,40,314,120,315,255,316,120,317,40,318,120,319,255,320,120,321,40,322,120,323,255,324,120,325,40,326,120,327,255,328,120,329,40,330,120,331,255,332,120,333,40,334,120,335,255,336,120,337,40,338,120]},
{id: "c2White", rgb: [1.0, 1.0, 1.0], note: 81, name: "White", fadeIn: 1000, fadeOut: 1000, levels: [9,255,10,0,11,0,12,0,13,0,14,255,15,0,16,0,17,0,18,255,19,0,20,0,21,0,22,255,23,0,24,0,25,0,26,255,27,0,28,0,29,0,30,255,31,0,32,0,33,0,34,255,35,0,36,0,37,0,38,255,53,255,54,0,55,0,56,0,57,0,58,255,59,0,60,0,61,0,62,255,63,0,64,0,65,0,66,255,67,0,68,0,69,0,70,255,71,0,72,0,73,0,74,255,75,0,76,0,77,0,78,255,79,0,80,0,81,0,82,255,266,255,267,0,268,0,269,0,270,0,271,255,272,0,273,0,274,0,275,255,276,0,277,0,278,0,279,255,280,0,281,0,282,0,283,255,284,0,285,0,286,0,287,255,288,0,289,0,290,0,291,255,292,0,293,0,294,0,295,255,309,255,310,0,311,0,312,0,313,0,314,255,315,0,316,0,317,0,318,255,319,0,320,0,321,0,322,255,323,0,324,0,325,0,326,255,327,0,328,0,329,0,330,255,331,0,332,0,333,0,334,255,335,0,336,0,337,0,338,255]},
{id: "c2Cool", rgb: [0.784, 0.941, 1.0], note: 82, name: "Cool", fadeIn: 1000, fadeOut: 1000, levels: [9,255,10,0,11,80,12,120,13,255,14,120,15,80,16,120,17,255,18,120,19,80,20,120,21,255,22,120,23,80,24,120,25,255,26,120,27,80,28,120,29,255,30,120,31,80,32,120,33,255,34,120,35,80,36,120,37,255,38,120,53,255,54,0,55,80,56,120,57,255,58,120,59,80,60,120,61,255,62,120,63,80,64,120,65,255,66,120,67,80,68,120,69,255,70,120,71,80,72,120,73,255,74,120,75,80,76,120,77,255,78,120,79,80,80,120,81,255,82,120,266,255,267,0,268,80,269,120,270,255,271,120,272,80,273,120,274,255,275,120,276,80,277,120,278,255,279,120,280,80,281,120,282,255,283,120,284,80,285,120,286,255,287,120,288,80,289,120,290,255,291,120,292,80,293,120,294,255,295,120,309,255,310,0,311,80,312,120,313,255,314,120,315,80,316,120,317,255,318,120,319,80,320,120,321,255,322,120,323,80,324,120,325,255,326,120,327,80,328,120,329,255,330,120,331,80,332,120,333,255,334,120,335,80,336,120,337,255,338,120]},
{id: "c2Custom", rgb: [1.0, 0.235, 0.0], note: 83, name: "Custom", fadeIn: 1000, fadeOut: 1000, levels: [9,0,53,0,266,0,309,0]},
],
sliders: [
{id: "s2Dim", cc: 35, name: "Dim", levels: [9,255,53,255,266,255,309,255]},
{id: "s2R", cc: 36, name: "R", levels: [11,255,15,255,19,255,23,255,27,255,31,255,35,255,55,255,59,255,63,255,67,255,71,255,75,255,79,255,268,255,272,255,276,255,280,255,284,255,288,255,292,255,311,255,315,255,319,255,323,255,327,255,331,255,335,255]},
{id: "s2G", cc: 37, name: "G", levels: [12,255,16,255,20,255,24,255,28,255,32,255,36,255,56,255,60,255,64,255,68,255,72,255,76,255,80,255,269,255,273,255,277,255,281,255,285,255,289,255,293,255,312,255,316,255,320,255,324,255,328,255,332,255,336,255]},
{id: "s2B", cc: 38, name: "B", levels: [13,255,17,255,21,255,25,255,29,255,33,255,37,255,57,255,61,255,65,255,69,255,73,255,77,255,81,255,270,255,274,255,278,255,282,255,286,255,290,255,294,255,313,255,317,255,321,255,325,255,329,255,333,255,337,255]},
{id: "s2W", cc: 39, name: "W", levels: [14,255,18,255,22,255,26,255,30,255,34,255,38,255,58,255,62,255,66,255,70,255,74,255,78,255,82,255,271,255,275,255,279,255,283,255,287,255,291,255,295,255,314,255,318,255,322,255,326,255,330,255,334,255,338,255]},
]
},
];
var LAMP = "Lamp";
var LAMP_OFF = 0.3; // brightness of a pad's tile when it is not playing
var FADE_RATE = 100; // script updates per second
var PLAY_CC = 27; // hold Play to move bank 2 (notes 52-67) up 16, like pad_layer.py
var BANK_FIRST = 52;
var BANK_LAST = 67;
var BANK_SHIFT = 16;
var DMX_SIZE = 513; // channels are 1-based
var states = [];
var sent = [];
var lookup = {};
var lampParams = [];
var sliderParams = [];
var nowParams = [];
var busy = false;
var primed = false;
var playHeld = false;
function init()
{
script.setUpdateRate(FADE_RATE);
for (var i = 0; i < DMX_SIZE; i++) sent[i] = -1;
states = [];
for (var g = 0; g < GROUPS.length; g++)
{
var level = [], from = [], to = [], touched = [];
for (var c = 0; c < DMX_SIZE; c++) { level[c] = 0; from[c] = 0; to[c] = 0; touched[c] = 0; }
var group = GROUPS[g];
for (var p = 0; p < group.pads.length; p++) mark(touched, group.pads[p].levels);
for (var s = 0; s < group.sliders.length; s++) mark(touched, group.sliders[s].levels);
var mix = [];
for (var m = 0; m < group.sliders.length; m++) mix[m] = 0;
states[g] = {active: -1, elapsed: 0, duration: 0, level: level, from: from, to: to, touched: touched, mix: mix};
// Controls on the script's Params, for the dashboard to show.
sliderParams[g] = [];
lampParams[g] = [];
for (var q = 0; q < group.pads.length; q++)
{
script.addTrigger(group.pads[q].id, group.name + " " + group.pads[q].name);
lampParams[g][q] = script.addColorParameter(group.pads[q].id + LAMP, group.name + " " + group.pads[q].name + " lamp", shade(group.pads[q].rgb, LAMP_OFF));
lookup[group.pads[q].id] = {g: g, p: q, s: -1};
}
for (var r = 0; r < group.sliders.length; r++)
{
sliderParams[g][r] = script.addFloatParameter(group.sliders[r].id, group.name + " " + group.sliders[r].name, 0, 0, 1);
lookup[group.sliders[r].id] = {g: g, p: -1, s: r};
}
nowParams[g] = script.addStringParameter(group.now, group.name + " scene", "");
}
script.log("show script ready: " + GROUPS.length + " groups");
}
function mark(touched, levels)
{
for (var i = 0; i < levels.length; i += 2) touched[levels[i]] = 1;
}
// A pad press starts its scene and fades the others out. A second press stops it.
function noteOnEvent(channel, pitch, velocity)
{
if (velocity == 0) return;
if (playHeld && pitch >= BANK_FIRST && pitch <= BANK_LAST) pitch += BANK_SHIFT;
for (var g = 0; g < GROUPS.length; g++)
{
var pads = GROUPS[g].pads;
for (var p = 0; p < pads.length; p++)
{
if (pads[p].note == pitch) { press(g, p); return; }
}
}
}
// A control on the dashboard changed.
function scriptParameterChanged(param)
{
if (busy) return;
var hit = lookup[param.name];
if (!hit) return;
if (hit.p >= 0) press(hit.g, hit.p);
else states[hit.g].mix[hit.s] = param.get();
}
function shade(rgb, level)
{
return [rgb[0] * level, rgb[1] * level, rgb[2] * level, 1];
}
// Light the playing pad's strip on the board and show its name.
function show(g, name)
{
busy = true;
nowParams[g].set(name);
var pads = GROUPS[g].pads;
for (var p = 0; p < pads.length; p++) lampParams[g][p].set(shade(pads[p].rgb, states[g].active == p ? 1 : LAMP_OFF));
busy = false;
}
function press(g, p)
{
var st = states[g];
var pad = GROUPS[g].pads[p];
for (var c = 0; c < DMX_SIZE; c++) { st.from[c] = st.level[c]; st.to[c] = 0; }
if (st.active == p)
{
st.active = -1;
st.duration = pad.fadeOut;
show(g, "");
}
else
{
for (var i = 0; i < pad.levels.length; i += 2) st.to[pad.levels[i]] = pad.levels[i + 1];
st.active = p;
st.duration = pad.fadeIn;
show(g, pad.name);
}
st.elapsed = 0;
}
function ccEvent(channel, number, value)
{
if (number == PLAY_CC) { playHeld = value > 0; return; }
for (var g = 0; g < GROUPS.length; g++)
{
var sliders = GROUPS[g].sliders;
for (var s = 0; s < sliders.length; s++)
{
if (sliders[s].cc == number)
{
states[g].mix[s] = value / 127;
busy = true;
sliderParams[g][s].set(value / 127);
busy = false;
}
}
}
}
// The dashboard web server does not always start when a project loads with it enabled, so switch
// it off and on once the script is running.
function startWeb()
{
var settings = root.projectSettings;
if (!settings || !settings.dashboardSettings) return;
var web = settings.dashboardSettings.enableDashboardServer;
if (!web) return;
web.set(false);
web.set(true);
script.log("dashboard web server restarted");
}
function update(deltaTime)
{
// A colour control's starting value is read in a different colour model and saved values load
// after init, so paint every tile once the script is running.
if (!primed)
{
primed = true;
startWeb();
for (var g = 0; g < GROUPS.length; g++) show(g, states[g].active >= 0 ? GROUPS[g].pads[states[g].active].name : "");
}
var out = [];
for (var c = 0; c < DMX_SIZE; c++) out[c] = 0;
for (var g = 0; g < GROUPS.length; g++) render(g, deltaTime, out);
var first = -1, last = -1;
for (var i = 1; i < DMX_SIZE; i++)
{
if (out[i] != sent[i]) { if (first < 0) first = i; last = i; }
}
if (first < 0) return;
var values = [];
for (var j = first; j <= last; j++) { values.push(out[j]); sent[j] = out[j]; }
root.modules.lights.send(first, values);
if (root.modules.preview) root.modules.preview.send(first, values);
}
function render(g, deltaTime, out)
{
var st = states[g];
st.elapsed += deltaTime * 1000;
var t = st.duration > 0 ? Math.min(1, st.elapsed / st.duration) : 1;
for (var c = 1; c < DMX_SIZE; c++)
{
if (!st.touched[c]) continue;
st.level[c] = st.from[c] + (st.to[c] - st.from[c]) * t;
out[c] = Math.max(out[c], st.level[c]);
}
var sliders = GROUPS[g].sliders;
for (var s = 0; s < sliders.length; s++)
{
var levels = sliders[s].levels;
for (var i = 0; i < levels.length; i += 2)
{
out[levels[i]] = Math.max(out[levels[i]], levels[i + 1] * st.mix[s]);
}
}
for (var k = 1; k < DMX_SIZE; k++) out[k] = Math.round(out[k]);
}
File diff suppressed because it is too large. Load diff
+325
View File
@@ -0,0 +1,325 @@
#!/usr/bin/env python3
"""Write a Chataigne project from a show spec.
python3 scripts/make_chataigne.py shows/test.show.json chataigne/test
Writes <out>/<name>.noisette and <out>/<name>.js. The script holds the scenes and
the pad and slider mapping, and sends DMX through the project's DMX module, named Lights, and a copy to Preview. Solo
frames and scene fades follow what QLC+ does with the same spec.
"""
from __future__ import annotations
import argparse
import json
import struct
import zlib
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
TEMPLATE = ROOT / "chataigne" / "show.template.js"
def absolute_levels(show: dict, stage: dict, values: dict[str, dict[str, int]]) -> dict[int, int]:
"""Map a scene's fixture channels to 1-based DMX channels in the output universe."""
levels: dict[int, int] = {}
for key, channels in values.items():
fixture = stage["fixtures"][key]
for offset, level in channels.items():
levels[int(fixture["address"]) + int(offset) + 1] = int(level)
return levels
SCALE = 1.25
MARGIN = 10
BUTTON = 28
def clear_png() -> bytes:
"""A 4x4 fully transparent PNG, for a trigger that should show what is behind it."""
def chunk(kind: bytes, data: bytes) -> bytes:
body = kind + data
return struct.pack(">I", len(data)) + body + struct.pack(">I", zlib.crc32(body))
rows = b"".join(b"\x00" + b"\x00" * 16 for _ in range(4))
return (
b"\x89PNG\r\n\x1a\n"
+ chunk(b"IHDR", struct.pack(">IIBBBBB", 4, 4, 8, 6, 0, 0, 0))
+ chunk(b"IDAT", zlib.compress(rows))
+ chunk(b"IEND", b"")
)
def script_path(name: str) -> str:
"""Chataigne names the script after its file and the module after its title."""
return f"/modules/pad/scripts/{name}/params/"
def ident(prefix: str, number: int, name: str) -> str:
"""A control name Chataigne keeps as written: letters and digits, lower-case first."""
return f"{prefix}{number}" + "".join(c for c in name if c.isalnum())
def collect(show: dict, stage: dict) -> dict:
functions = {f["key"]: f for f in show["functions"]}
groups: dict[str, dict] = {}
for number, frame in enumerate(show["vc"], 1):
pads, sliders = [], []
for widget in frame.get("children", []):
kind = widget["type"]
function = functions[widget["function"]]
binding = widget.get("input") or {}
levels = absolute_levels(show, stage, function["values"])
if kind == "button" and "note" in binding:
pads.append({
"id": ident("c", number, widget["caption"]),
"box": box(frame, widget),
"bg": widget.get("bg", [60, 60, 60]),
"fg": widget.get("fg", [255, 255, 255]),
"note": binding["note"][1],
"name": widget["caption"],
"fade": [function.get("fade_in") or 0, function.get("fade_out") or 0],
"levels": levels,
})
elif kind == "slider" and "cc" in binding:
sliders.append({
"id": ident("s", number, widget["caption"]),
"box": box(frame, widget),
"fg": widget.get("fg", [255, 255, 255]),
"cc": binding["cc"][1],
"name": widget["caption"],
"levels": levels,
})
if pads or sliders:
groups[frame["caption"]] = {
"name": frame["caption"],
"now": f"now{number}",
"box": box(frame, {"x": 0, "y": -30, "w": frame["w"], "h": 26}),
"pads": pads,
"sliders": sliders,
}
return groups
def box(frame: dict, widget: dict) -> list[int]:
"""x, y, w, h of a widget on the dashboard. Frames sit side by side, as on the virtual console."""
return [round((frame["x"] + widget["x"]) * SCALE), round((frame["y"] + widget["y"]) * SCALE + 40),
round(widget["w"] * SCALE), round(widget["h"] * SCALE)]
def colour(rgb: list[int]) -> int:
"""A Chataigne colour value: ARGB as a signed 32-bit int."""
argb = (255 << 24) | (rgb[0] << 16) | (rgb[1] << 8) | rgb[2]
return argb - (1 << 32) if argb >= 1 << 31 else argb
def js_levels(levels: dict[int, int]) -> str:
return "[" + ",".join(f"{ch},{level}" for ch, level in sorted(levels.items())) + "]"
def render_data(groups: dict) -> str:
lines = ["var GROUPS = ["]
for caption, group in groups.items():
lines.append(" {")
lines.append(f" name: {json.dumps(caption)},")
lines.append(f" now: {json.dumps(group['now'])},")
lines.append(" pads: [")
for pad in group["pads"]:
lines.append(
f" {{id: {json.dumps(pad['id'])}, rgb: {json.dumps([round(c / 255, 3) for c in pad['bg']])}, note: {pad['note']}, name: {json.dumps(pad['name'])}, "
f"fadeIn: {pad['fade'][0]}, fadeOut: {pad['fade'][1]}, levels: {js_levels(pad['levels'])}}},"
)
lines.append(" ],")
lines.append(" sliders: [")
for slider in group["sliders"]:
lines.append(
f" {{id: {json.dumps(slider['id'])}, cc: {slider['cc']}, name: {json.dumps(slider['name'])}, levels: {js_levels(slider['levels'])}}},"
)
lines.append(" ]")
lines.append(" },")
lines.append("];")
return "\n".join(lines)
def dashboard_item(index: int, kind: str, target: str, box: list[int], label: str, colours: dict[str, list[int]]) -> dict:
parameters = [
{"value": [float(box[0]), float(box[1])], "controlAddress": "/viewUIPosition"},
{"value": [float(box[2]), float(box[3])], "controlAddress": "/viewUISize"},
{"value": target, "controlAddress": "/target"},
{"value": label, "controlAddress": "/customText", "enabled": True},
]
for address, rgb in colours.items():
parameters.append({"value": colour(rgb), "controlAddress": address, "enabled": True})
return {
"parameters": parameters,
"niceName": f"Item {index}",
"type": kind,
"ghostAddress": target,
"controllable": target,
}
def dashboard(groups: dict, name: str, view: tuple[int, int], overlay: str | None) -> dict:
"""A dashboard with a tile and button per pad, a slider per knob, and what each group is showing."""
items = []
for group in groups.values():
items.append(dashboard_item(
len(items) + 1, "DashboardParameterItem", script_path(name) + group["now"],
group["box"], group["name"], {},
))
for pad in group["pads"]:
x, y, w, h = pad["box"]
# Triggers draw grey whatever colour they are given, but a colour control always paints.
# The tile carries the colour and name; the trigger on it is a transparent image that takes the press.
small = overlay is None
tile = dashboard_item(
len(items) + 1, "DashboardParameterItem", script_path(name) + pad["id"] + "Lamp",
[x, y, w, h - BUTTON - 2 if small else h], pad["name"], {"/textColor": [255, 255, 255]},
)
tile["parameters"] += [
{"value": True, "controlAddress": "/readOnly"},
{"value": False, "controlAddress": "/showValue"},
]
items.append(tile)
press = dashboard_item(
len(items) + 1, "DashboardTriggerItem", script_path(name) + pad["id"],
[x, y + h - BUTTON, w, BUTTON] if small else [x, y, w, h], "Select" if small else "",
{"/backgroundColor": pad["bg"], "/textColor": pad["fg"]},
)
if overlay:
# A custom label that is a single space: with none, the trigger draws its own name.
press["parameters"][3].update({"value": " ", "enabled": True})
press["parameters"].append({"value": False, "controlAddress": "/showLabel"})
press["parameters"].append({"value": overlay, "controlAddress": "/customImage", "enabled": True})
items.append(press)
for slider in group["sliders"]:
items.append(dashboard_item(
len(items) + 1, "DashboardParameterItem", script_path(name) + slider["id"], slider["box"], slider["name"],
{"/foregroundColor": slider["fg"]},
))
# Dashboard coordinates start at the middle of the view, so move the board to its top left.
left = min(i["parameters"][0]["value"][0] for i in items)
top = min(i["parameters"][0]["value"][1] for i in items)
for i in items:
position = i["parameters"][0]["value"]
position[0] += MARGIN - view[0] / 2 - left
position[1] += MARGIN - view[1] / 2 - top
return {
"parameters": [{"value": False, "controlAddress": "/editMode"}],
"items": [
{
"niceName": "Board",
"type": "BaseItem",
"itemManager": {
# The web page puts the middle of the canvas at 0, 0, so the canvas has to be the view's size
# for the board to start at its top left.
"parameters": [{"value": [float(view[0]), float(view[1])], "controlAddress": "/canvasSize", "enabled": True}],
"items": items,
"viewOffset": [0, 0],
"viewZoom": 1.0,
},
}
],
"viewOffset": [0, 0],
"viewZoom": 1.0,
}
def dmx_module(name: str, host: str, universe: int, interface: str | None) -> dict:
device: dict = {"containers": {"output": {"parameters": [{"value": host, "controlAddress": "/remoteHost"}]}}}
if interface:
device["parameters"] = [{"value": interface, "controlAddress": "/networkInterface"}]
return {
"niceName": name,
"type": "DMX",
"params": {
"parameters": [
{"value": "Art-Net", "controlAddress": "/dmxType"},
{"value": 40, "controlAddress": "/sendRate"},
],
"containers": {
"artNet": {"containers": {"output": {"parameters": [{"value": host, "controlAddress": "/remoteHost"}]}}},
"outputUniverses": {
"items": [
{
"niceName": "Universe",
"parameters": [
{"value": 0, "controlAddress": "/net"},
{"value": 0, "controlAddress": "/subnet"},
{"value": universe, "controlAddress": "/universe"},
],
}
]
}
},
},
"device": device,
}
def project(
script: str, host: str, universe: int, interface: str, groups: dict, preview: str | None, pad: str, view: tuple[int, int], overlay: str | None
) -> dict:
"""A Chataigne project: a DMX module on Art-Net and a MIDI module that runs the show script."""
dmx = [dmx_module("Lights", host, universe, interface)]
if preview:
dmx.append(dmx_module("Preview", preview, universe, None))
midi = {
"niceName": "Pad",
"type": "MIDI",
"params": {"parameters": [{"value": [pad, ""], "inputName": pad, "controlAddress": "/devices"}]},
"scripts": {
"items": [{"niceName": "Show", "parameters": [{"value": script, "controlAddress": "/filePath"}]}]
},
}
return {
"metaData": {"version": "1.10.4"},
"projectSettings": {
"containers": {
"dashboardSettings": {
"parameters": [
{"value": True, "controlAddress": "/enableDashboardServer"},
{"value": 9999, "hexMode": False, "controlAddress": "/serverPort"},
]
}
}
},
"dashboardManager": dashboard(groups, Path(script).stem, view, overlay),
"modules": {"viewOffset": [0, 0], "viewZoom": 1.0, "items": [*dmx, midi]},
}
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("show", type=Path)
parser.add_argument("out", type=Path, help="directory to write into")
parser.add_argument("--host", help="Art-Net destination (default: from the show's output universe)")
parser.add_argument("--pad", default="SINCO SMC-PAD-Master", help="MIDI input the pad arrives on (Bluetooth: SMC-PAD Bluetooth)")
parser.add_argument("--view", default="1574x953", help="dashboard panel size in pixels, for the top-left placement")
parser.add_argument("--small-buttons", action="store_true", help="a grey Select button under each tile, instead of the whole tile pressing")
parser.add_argument("--preview", default="127.0.0.1", help="second Art-Net destination for the simulator; empty for none")
args = parser.parse_args()
show = json.loads(args.show.read_text())
stage = json.loads((ROOT / show["stage"]).read_text())
output = next(u["output"] for u in show["universes"] if u.get("output", {}).get("plugin") == "ArtNet")
name = args.show.name.removesuffix(".show.json")
groups = collect(show, stage)
source = TEMPLATE.read_text().replace("/*__DATA__*/", render_data(groups))
args.out.mkdir(parents=True, exist_ok=True)
(args.out / f"{name}.js").write_text(source)
overlay = None if args.small_buttons else str((args.out / "clear.png").resolve())
if overlay:
(args.out / "clear.png").write_bytes(clear_png())
doc = project(f"{name}.js", args.host or output["ip"], int(output["universe"]), output["uid"], groups, args.preview or None, args.pad, tuple(int(n) for n in args.view.split("x")), overlay)
(args.out / f"{name}.noisette").write_text(json.dumps(doc, indent=2) + "\n")
print(f"{args.out / (name + '.noisette')}: {len(groups)} groups, {sum(len(g['pads']) for g in groups.values())} pads")
if __name__ == "__main__":
main()
+62
View File
@@ -0,0 +1,62 @@
"""Chataigne export: channel mapping and the project file."""
from __future__ import annotations
import json
import subprocess
import sys
import tempfile
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "scripts"))
import make_chataigne # noqa: E402
class ChataigneExportTest(unittest.TestCase):
def setUp(self) -> None:
self.show = json.loads((ROOT / "shows" / "test.show.json").read_text())
self.stage = json.loads((ROOT / self.show["stage"]).read_text())
def test_channels_are_one_based_dmx(self) -> None:
levels = make_chataigne.absolute_levels(self.show, self.stage, {"#1": {"0": 255, "2": 10}, "M1": {"8": 7}})
self.assertEqual(levels, {88: 255, 90: 10, 9: 7})
def test_groups_hold_pads_and_sliders(self) -> None:
groups = make_chataigne.collect(self.show, self.stage)
self.assertEqual(list(groups), ["Colour 1", "Colour 2"])
cans = groups["Colour 1"]
self.assertEqual([p["note"] for p in cans["pads"]][:2], [52, 53])
self.assertEqual([s["cc"] for s in cans["sliders"]], [30, 31, 32, 33, 34])
self.assertEqual(cans["pads"][0]["fade"], [1000, 1000])
def test_writes_project_and_script(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
subprocess.run(
[sys.executable, str(ROOT / "scripts" / "make_chataigne.py"), str(ROOT / "shows" / "test.show.json"), tmp],
check=True,
capture_output=True,
)
project = json.loads((Path(tmp) / "test.noisette").read_text())
script = (Path(tmp) / "test.js").read_text()
settings = project["projectSettings"]["containers"]["dashboardSettings"]["parameters"]
self.assertIn({"value": True, "controlAddress": "/enableDashboardServer"}, settings)
board = project["dashboardManager"]["items"][0]["itemManager"]["items"]
targets = [item["controllable"] for item in board]
self.assertEqual(len(board), 32 * 2 + 10 + 2)
self.assertEqual(len(set(targets)), len(targets))
for item in board:
self.assertIn(item["controllable"].rsplit("/", 1)[1].removesuffix("Lamp"), script)
canvas = project["dashboardManager"]["items"][0]["itemManager"]["parameters"][0]
self.assertEqual((canvas["value"], canvas["enabled"]), ([1574.0, 953.0], True))
names = [m["niceName"] for m in project["modules"]["items"]]
self.assertEqual(names, ["Lights", "Preview", "Pad"])
self.assertEqual(project["modules"]["items"][1]["device"]["containers"]["output"]["parameters"][0]["value"], "127.0.0.1")
self.assertIn("var GROUPS", script)
self.assertNotIn("__DATA__", script)
if __name__ == "__main__":
unittest.main()