The rig sim receives Art-Net (UDP 6454, answers ArtPoll) and DDP (each port the room's DDP strips use) in sim_net.c and passes changed universes and pixels to the page over /sim/ws, now with a kind byte in front of each binary frame. Rooms gain fixture types: ddp strips, artnet pixel strips, and artnet cans and movers that read named channels from the room's dmx_definitions (the qlcplus stage map's format). Overlapping DMX channels are refused. Cans and movers are decoded and drawn as in the qlcplus stage simulator (dmx.js, dmx-draw.js). In Edit mode: pick a type to add, edit port/offset/universe/address/colour order/definition, see a can's or mover's live channels, make a controller output aimed at the sim and send its test. The room dialog lists DMX definitions, with presets, a channel editor, and .qxf and stage map import. GET /sim/api/dmx shows what the receiver has had. Tests: test/api/test_sim_net.py and test/browser/dmx_decode.test.mjs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
115 lines
4.3 KiB
JavaScript
115 lines
4.3 KiB
JavaScript
// The simulated rig's DMX decoder (led-simulator/web/dmx.js), checked against the qlcplus simulator's rules
|
|
// (technicalkiwi/qlcplus simulator/decode.py): node --test test/browser/dmx_decode.test.mjs
|
|
import assert from 'node:assert/strict';
|
|
import { createRequire } from 'node:module';
|
|
import { test } from 'node:test';
|
|
|
|
createRequire(import.meta.url)('../../led-simulator/web/dmx.js');
|
|
const D = globalThis.RigDmx;
|
|
const CAN = D.PRESET_DEFINITIONS['beamZ BCC145'].channels;
|
|
const MOVER = D.PRESET_DEFINITIONS['Small Eye 7 Mover'].channels;
|
|
|
|
function universe(at, values) {
|
|
const f = new Uint8Array(512);
|
|
f.set(values, at - 1);
|
|
return new Map([[0, f]]);
|
|
}
|
|
|
|
const can = (values, address = 1) =>
|
|
D.viewFixture({ kind: 'can', universe: 0, address, channel_names: CAN }, universe(address, values));
|
|
const mover = (values, extra = {}) =>
|
|
D.viewFixture({ kind: 'mover', universe: 0, address: 1, channel_names: MOVER, ...extra }, universe(1, values));
|
|
|
|
test('a can at full dimmer and red shows red', () => {
|
|
const v = can([255, 0, 255, 0, 0, 0, 0, 0]);
|
|
assert.deepEqual([v.r, v.g, v.b], [255, 0, 0]);
|
|
assert.equal(v.function, 'mix');
|
|
assert.equal(v.strobe_hz, 0);
|
|
assert.equal(v.patched, true);
|
|
});
|
|
|
|
test('the can reads from its own address', () => {
|
|
const v = can([128, 0, 0, 0, 255, 0, 0, 0], 95);
|
|
assert.deepEqual([v.r, v.g, v.b], [0, 0, 128]);
|
|
});
|
|
|
|
test('white adds to every colour and the dimmer scales the mix', () => {
|
|
const v = can([128, 0, 100, 0, 0, 100, 0, 0]);
|
|
// mix_rgbw: min(255, 100 + 100) * 128/255 = 100.39 -> 100; 100 * 128/255 = 50.2 -> 50
|
|
assert.deepEqual([v.r, v.g, v.b], [100, 50, 50]);
|
|
});
|
|
|
|
test('can strobe above 7 flashes, at the qlcplus rate', () => {
|
|
assert.equal(can([255, 7, 255]).strobe_hz, 0);
|
|
const v = can([255, 131, 255]);
|
|
// 1 + (131 - 7) / 248 * 18 = 10
|
|
assert.equal(v.strobe_hz, 10);
|
|
assert.equal(v.strobe_mode, 'strobe');
|
|
});
|
|
|
|
test('can macro bands pick the function', () => {
|
|
assert.equal(can([255, 0, 0, 0, 0, 0, 60]).function, 'fixed');
|
|
assert.equal(can([255, 0, 0, 0, 0, 0, 120]).function, 'jump');
|
|
assert.equal(can([255, 0, 0, 0, 0, 0, 255]).sound, 2);
|
|
// fixed: (60 - 51) * 10 // 50 = 1 -> orange
|
|
const v = can([255, 0, 0, 0, 0, 0, 60]);
|
|
assert.deepEqual([v.r, v.g, v.b], [255, 96, 0]);
|
|
});
|
|
|
|
test('a mover at pan and tilt centre points along its zero, straight down', () => {
|
|
const v = mover([128, 0, 128, 0]);
|
|
assert.equal(v.pan_deg, 0);
|
|
assert.equal(v.tilt_deg, 0);
|
|
assert.equal(v.beam_m, 0);
|
|
});
|
|
|
|
test('mover pan spans 540 degrees and pan_reverse mirrors it', () => {
|
|
// (0xC000 - 0x8000) / 65536 * 540 = 135
|
|
assert.equal(mover([192, 0, 128, 0]).pan_deg, 135);
|
|
assert.equal(mover([192, 0, 128, 0], { pan_reverse: true }).pan_deg, -135);
|
|
});
|
|
|
|
test('mover tilt leans the beam out on the plan', () => {
|
|
const v = mover([128, 0, 0, 0]);
|
|
// tilt (0 - 32768) / 65536 * 270 = -135; lean = min(90, 135) = 90 -> full reach
|
|
assert.equal(v.tilt_deg, -135);
|
|
assert.equal(v.beam_m, D.BEAM_MAX_M);
|
|
});
|
|
|
|
test('mover pixels, dimmer and strobe', () => {
|
|
const ch = new Array(43).fill(0);
|
|
ch[MOVER.indexOf('Center Brightness')] = 255;
|
|
ch[MOVER.indexOf('Green 1')] = 200;
|
|
ch[MOVER.indexOf('Center Strobe')] = 220;
|
|
const v = mover(ch);
|
|
assert.equal(v.pixels.length, 7);
|
|
assert.deepEqual(v.pixels[0], [0, 200, 0]);
|
|
assert.deepEqual([v.r, v.g, v.b], [0, 200, 0]);
|
|
assert.equal(v.strobe_mode, 'random');
|
|
assert.equal(v.strobe_hz, 12);
|
|
});
|
|
|
|
test('mover colour macro fills all seven pixels', () => {
|
|
const ch = new Array(43).fill(0);
|
|
ch[MOVER.indexOf('Center Brightness')] = 255;
|
|
ch[MOVER.indexOf('Colour Macro')] = 10; // first band: red
|
|
const v = mover(ch);
|
|
assert.equal(v.function, 'macro');
|
|
assert.ok(v.pixels.every((p) => p[0] === 255 && p[1] === 0 && p[2] === 0));
|
|
});
|
|
|
|
test('an unpatched fixture is dark', () => {
|
|
const v = D.viewFixture({ kind: 'can', universe: 0, address: 0, channel_names: CAN }, new Map());
|
|
assert.equal(v.patched, false);
|
|
});
|
|
|
|
test('Art-Net pixels run on into the next universe, 170 a universe', () => {
|
|
const u0 = new Uint8Array(512).fill(1);
|
|
const u1 = new Uint8Array(512).fill(2);
|
|
const px = D.artnetPixels(new Map([[0, u0], [1, u1]]), 0, 1, 200);
|
|
assert.equal(px.length, 600);
|
|
assert.equal(px[509], 1);
|
|
assert.equal(px[510], 2);
|
|
assert.deepEqual(D.dmxRuns({ kind: 'pixels', universe: 0, address: 1 }, {}, 200), [[0, 0, 510], [1, 0, 90]]);
|
|
});
|