diff --git a/.claude/launch.json b/.claude/launch.json
index 23842aa..346639f 100644
--- a/.claude/launch.json
+++ b/.claude/launch.json
@@ -12,6 +12,12 @@
"runtimeExecutable": ".venv/bin/python",
"runtimeArgs": ["-m", "simulator", "--http", "127.0.0.1:8766", "--artnet", "127.0.0.1:6455", "--demo"],
"port": 8766
+ },
+ {
+ "name": "simulator-artnet",
+ "runtimeExecutable": ".venv/bin/python",
+ "runtimeArgs": ["-m", "simulator", "--http", "127.0.0.1:8767", "--artnet", "127.0.0.1:6456"],
+ "port": 8767
}
]
}
diff --git a/shows/test.qxw b/shows/test.qxw
index ab737e4..fb6c582 100644
--- a/shows/test.qxw
+++ b/shows/test.qxw
@@ -118,7 +118,7 @@
8
M1
0
-
0
+ 44
43
9
@@ -129,7 +129,7 @@
9
M2
0
- 44
+ 0
43
9
diff --git a/simulator/__main__.py b/simulator/__main__.py
index 4c55fad..e5ef6fc 100644
--- a/simulator/__main__.py
+++ b/simulator/__main__.py
@@ -83,7 +83,7 @@ def _demo_frame(fixtures: list[Fixture], elapsed: float) -> bytearray:
for index, fixture in enumerate(movers):
pan = int(32768 + math.sin(elapsed * 0.6 + index * math.pi) * 9000)
pan = max(0, min(65535, pan))
- tilt = 42000
+ tilt = 20000
_put(frame, fixture, "Pan", (pan >> 8) & 0xFF)
_put(frame, fixture, "Pan Fine", pan & 0xFF)
_put(frame, fixture, "Tilt", (tilt >> 8) & 0xFF)
diff --git a/simulator/decode.py b/simulator/decode.py
index e0237a3..d40817b 100644
--- a/simulator/decode.py
+++ b/simulator/decode.py
@@ -6,6 +6,7 @@ such as Dimmer, Red, Pan, and Zoom select the slots.
from __future__ import annotations
+import math
import re
from simulator.stage import Fixture, Stage
@@ -13,6 +14,10 @@ from simulator.stage import Fixture, Stage
_PIXEL = re.compile(r"^(red|green|blue|white) (\d+)$", re.IGNORECASE)
PAN_DEGREES = 540.0
+# Tilt 127 is straight down. 0 leans along the pan heading, 255 away from it.
+TILT_DEGREES = 270.0
+# Plan reach of a beam at or above horizontal.
+BEAM_MAX_M = 4.7
ZOOM_MIN = 5.0
ZOOM_MAX = 45.0
@@ -378,8 +383,10 @@ def _decode_mover_named(channels: list[int], names: list[str]) -> dict:
pan_speed = _value(channels, names, "Pan/Tilt Speed")
pan_deg = (pan - 32768) / 65536.0 * PAN_DEGREES
zoom_deg = ZOOM_MIN + (zoom / 255.0) * (ZOOM_MAX - ZOOM_MIN)
- # Long enough to read on the plan at tilt zero. Tilt stretches the throw.
- beam_m = 2.2 + (tilt / 65535.0) * 2.5
+ tilt_deg = (tilt - 32768) / 65536.0 * TILT_DEGREES
+ # Reach along the pan heading on the plan. Negative points behind it.
+ lean = max(-90.0, min(90.0, -tilt_deg))
+ beam_m = BEAM_MAX_M * math.sin(math.radians(lean))
return {
"r": red,
"g": green,
@@ -393,6 +400,7 @@ def _decode_mover_named(channels: list[int], names: list[str]) -> dict:
"speed_hz": speed,
"dynamic": dynamic_name,
"pan_deg": round(pan_deg, 2),
+ "tilt_deg": round(tilt_deg, 2),
"zoom_deg": round(zoom_deg, 2),
"beam_m": round(beam_m, 3),
"pixels": tinted,
@@ -422,6 +430,8 @@ def view_fixture(fixture: Fixture, universes: dict[int, bytes]) -> dict:
viewed = decode_mover(channels)
else:
viewed = decode_can(channels)
+ if fixture.pan_reverse and "pan_deg" in viewed:
+ viewed["pan_deg"] = -viewed["pan_deg"]
viewed["patched"] = True
return viewed
diff --git a/simulator/stage.py b/simulator/stage.py
index 93ba306..4f87ea3 100644
--- a/simulator/stage.py
+++ b/simulator/stage.py
@@ -36,6 +36,7 @@ class Fixture:
channel_names: list[str] = field(default_factory=list)
direction: float = 0.0 # cans: beam heading, degrees clockwise from +Y
zero: float = 0.0 # movers: heading at pan centre, same degrees
+ pan_reverse: bool = False # movers: rising pan turns the head anticlockwise
@property
def dmx(self) -> int | None:
@@ -61,6 +62,7 @@ class Fixture:
"channel_names": self.channel_names,
"direction": self.direction,
"zero": self.zero,
+ "pan_reverse": self.pan_reverse,
}
@@ -144,6 +146,7 @@ def load_stage(path: Path) -> Stage:
channel_names=channel_names,
direction=float(raw.get("direction") or 0),
zero=float(raw.get("zero") or 0),
+ pan_reverse=bool(raw.get("pan_reverse", False)),
)
)
return Stage(
diff --git a/simulator/static/app.js b/simulator/static/app.js
index 6e42d2b..e201d27 100644
--- a/simulator/static/app.js
+++ b/simulator/static/app.js
@@ -293,17 +293,24 @@ function drawGlow(sx, sy, fixture, color) {
function drawBeam(sx, sy, fixture, live, color, fixed) {
const level = (color.r + color.g + color.b) / 255;
- const length = fixed ? fixed.beam : Math.max(live.beam_m || 0, fixture.kind === "mover" ? 2.2 : 0);
- if (live.patched === false || level <= 0.02 || !length) return;
+ if (live.patched === false || level <= 0.02) return;
const aim = fixed || aimed(fixture.id, live, fixture.zero);
+ // Mover reach is signed: below zero the head has tilted past straight down.
+ const reach = fixed ? fixed.beam : fixture.kind === "mover" ? aim.beam : live.beam_m || 0;
// DMX focus 0 is a wide wash. Focus 255 holds the zoom angle.
// Fixed beams pass spread directly, 0 tight and 1 wide.
const spread = fixed ? fixed.focus : 1 - (live.focus || 0);
const zoom = fixed ? fixed.zoom : live.zoom_deg || 8;
const tight = zoom / 2;
const wide = Math.max(tight, 40);
- const rad = aim.pan * Math.PI / 180;
const half = (tight + (wide - tight) * spread) * Math.PI / 180;
+ if (fixture.kind === "mover" && Math.abs(reach) < SPOT_M) {
+ drawSpot(sx, sy, fixture, aim.pan, reach, half, color, spread);
+ return;
+ }
+ const length = Math.abs(reach);
+ if (!length) return;
+ const rad = (aim.pan + (reach < 0 ? 180 : 0)) * Math.PI / 180;
const tip = [fixture.x + Math.sin(rad) * length, fixture.y + Math.cos(rad) * length];
const left = [fixture.x + Math.sin(rad - half) * length, fixture.y + Math.cos(rad - half) * length];
const right = [fixture.x + Math.sin(rad + half) * length, fixture.y + Math.cos(rad + half) * length];
@@ -320,6 +327,27 @@ function drawBeam(sx, sy, fixture, live, color, fixed) {
ctx.fill();
}
+// Below this plan reach a mover is pointing near straight down.
+const SPOT_M = 0.5;
+// Throw to the floor for the spot under a mover.
+const DROP_M = 2.5;
+
+function drawSpot(sx, sy, fixture, pan, reach, half, color, spread) {
+ const rad = pan * Math.PI / 180;
+ const cx = sx(fixture.x + Math.sin(rad) * reach);
+ const cy = sy(fixture.y + Math.cos(rad) * reach);
+ const radius = Math.max(4, Math.abs(sx(DROP_M * Math.tan(half)) - sx(0)));
+ const gradient = ctx.createRadialGradient(cx, cy, 0, cx, cy, radius);
+ const alpha = 0.85 * (1 - spread * 0.35);
+ gradient.addColorStop(0, `rgba(${color.r},${color.g},${color.b},${alpha})`);
+ gradient.addColorStop(0.7, `rgba(${color.r},${color.g},${color.b},${alpha * 0.6})`);
+ gradient.addColorStop(1, `rgba(${color.r},${color.g},${color.b},0)`);
+ ctx.fillStyle = gradient;
+ ctx.beginPath();
+ ctx.arc(cx, cy, radius, 0, Math.PI * 2);
+ ctx.fill();
+}
+
function lensRotation(live) {
if (live.spin_dps) return ((performance.now() / 1000) * live.spin_dps * Math.PI) / 180;
return ((live.lens_deg || 0) * Math.PI) / 180;
@@ -443,6 +471,7 @@ function updateDetail() {
if (live.reset) bits.push("reset");
if (fixture.kind === "mover" && live.pan_deg != null) {
bits.push(`pan ${live.pan_deg.toFixed(0)}°`);
+ if (live.tilt_deg != null) bits.push(`tilt ${live.tilt_deg.toFixed(0)}°`);
bits.push(`zoom ${(live.zoom_deg || 0).toFixed(0)}°`);
if (live.spin_dps) bits.push(`lens ${live.spin_dps > 0 ? "CW" : "CCW"}`);
else if (live.lens_deg) bits.push(`lens ${live.lens_deg.toFixed(0)}°`);
diff --git a/stage/map.json b/stage/map.json
index 86aba55..3524a0f 100644
--- a/stage/map.json
+++ b/stage/map.json
@@ -113,9 +113,10 @@
"kind": "mover",
"def": "Small Eye 7 Mover",
"universe": 0,
- "address": 0,
+ "address": 44,
"channels": 43,
- "zero": 0
+ "zero": 90,
+ "pan_reverse": true
},
"M2": {
"x": 0.3,
@@ -124,9 +125,9 @@
"kind": "mover",
"def": "Small Eye 7 Mover",
"universe": 0,
- "address": 44,
+ "address": 0,
"channels": 43,
- "zero": 0
+ "zero": -90
},
"#9": {
"x": -3.5,
@@ -234,7 +235,8 @@
"address": 300,
"channels": 43,
"note": "Back right, between #14 and #15",
- "zero": 0
+ "zero": 0,
+ "pan_reverse": true
}
}
}
diff --git a/tests/test_chataigne.py b/tests/test_chataigne.py
index 4637fea..47eed66 100644
--- a/tests/test_chataigne.py
+++ b/tests/test_chataigne.py
@@ -21,7 +21,7 @@ class ChataigneExportTest(unittest.TestCase):
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}})
+ levels = make_chataigne.absolute_levels(self.show, self.stage, {"#1": {"0": 255, "2": 10}, "M2": {"8": 7}})
self.assertEqual(levels, {88: 255, 90: 10, 9: 7})
def test_groups_hold_pads_and_sliders(self) -> None:
diff --git a/tests/test_simulator.py b/tests/test_simulator.py
index be37ff5..921bab7 100644
--- a/tests/test_simulator.py
+++ b/tests/test_simulator.py
@@ -42,9 +42,9 @@ def test_xchc_patch_matches_the_stage_map():
assert by_id["#1"].address == 87
assert by_id["#1"].dmx == 88
assert by_id["#8"].address == 143
- assert by_id["M1"].address == 0
- assert by_id["M1"].dmx == 1
- assert by_id["M2"].address == 44
+ assert by_id["M1"].address == 44
+ assert by_id["M1"].dmx == 45
+ assert by_id["M2"].address == 0
assert by_id["M1"].channels == 43
assert by_id["#3"].kind == "can"
assert stage.output_ip == "192.168.1.228"
@@ -54,14 +54,16 @@ def test_xchc_patch_matches_the_stage_map():
assert by_id["#13"].x == -3.5 and by_id["#15"].x == 3.5
assert by_id["#14"].x == 0.0 and by_id["#14"].y == -7.65
assert by_id["#1"].address == 87 and by_id["#9"].address == 151
- assert by_id["#15"].address == 199 and by_id["M1"].address == 0
- assert by_id["M2"].address == 44 and by_id["#15"].channels == 8
+ assert by_id["#15"].address == 199 and by_id["M2"].address == 0
+ assert by_id["M1"].address == 44 and by_id["#15"].channels == 8
assert by_id["M3"].address == 257 and by_id["M3"].channels == 43
assert by_id["M3"].x == -1.75 and by_id["M3"].y == -7.65
assert by_id["M4"].address == 300 and by_id["M4"].x == 1.75
assert by_id["#1"].direction == 71 and by_id["#8"].direction == -72
assert by_id["#3"].direction == 0 and by_id["#14"].direction == -179
- assert by_id["M1"].zero == 0 and by_id["M4"].zero == 0
+ assert by_id["M2"].zero == -90 and by_id["M4"].zero == 0
+ assert by_id["M1"].zero == 90 and by_id["M1"].pan_reverse and not by_id["M2"].pan_reverse
+ assert by_id["M4"].pan_reverse and not by_id["M3"].pan_reverse
assert stage.warnings == []
@@ -94,16 +96,25 @@ def test_can_macro_functions():
def test_mover_home_points_at_the_audience():
channels = [0] * 43
channels[0] = 128 # pan coarse, fine 0 → 32768, the centre of 540°
- channels[2] = 160
+ channels[2] = 64
channels[8] = 255
channels[10] = 255 # red on the first pixel
viewed = decode_mover(channels)
assert viewed["pan_deg"] == 0
assert viewed["r"] == 255
assert viewed["beam_m"] > 2
- parked = [0] * 43
- parked[8] = 255
- assert decode_mover(parked)["beam_m"] >= 2.2
+
+
+def test_mover_tilt_goes_through_straight_down():
+ def reach(tilt):
+ channels = [0] * 43
+ channels[2] = tilt
+ return decode_mover(channels)["beam_m"]
+
+ assert reach(0) == 4.7 # forward and up
+ assert abs(reach(127)) < 0.2 # a spot under the head
+ assert reach(255) < -4.6 # behind the pan heading
+ assert reach(64) > 0 > reach(192)
assert lens_spin(0) == 0
assert lens_spin(160) < 0
assert lens_spin(230) > 0
@@ -173,6 +184,43 @@ def test_map_definition_selects_the_channels():
assert live["pan_deg"] == 0
+def test_front_movers_face_forward_at_pan_zero_and_back_at_85():
+ stage = load_stage(ROOT / "stage" / "map.json")
+ by_id = {fixture.id: fixture for fixture in stage.fixtures}
+
+ def heading(pan):
+ frame = bytearray(512)
+ for mover in (by_id["M1"], by_id["M2"]):
+ frame[mover.address + mover.channel_names.index("Pan")] = pan
+ live = view_stage(stage, {0: bytes(frame)})
+ return {key: wrap_degrees(by_id[key].zero + live[key]["pan_deg"]) for key in ("M1", "M2")}
+
+ assert heading(0) == {"M1": 0, "M2": 0}
+ back = heading(85)
+ assert abs(abs(back["M1"]) - 180) <= 2 and abs(abs(back["M2"]) - 180) <= 2
+ # M2 turns clockwise and M1 anticlockwise.
+ assert heading(20)["M2"] > 0 > heading(20)["M1"]
+
+
+def test_back_movers_face_the_middle_at_pan_zero():
+ stage = load_stage(ROOT / "stage" / "map.json")
+ by_id = {fixture.id: fixture for fixture in stage.fixtures}
+
+ def heading(pan):
+ frame = bytearray(512)
+ for mover in (by_id["M3"], by_id["M4"]):
+ frame[mover.address + mover.channel_names.index("Pan")] = pan
+ live = view_stage(stage, {0: bytes(frame)})
+ return {key: wrap_degrees(by_id[key].zero + live[key]["pan_deg"]) for key in ("M3", "M4")}
+
+ # M3 is on the left (-X) so the middle is +X, 90°. M4 mirrors it.
+ assert heading(0) == {"M3": 90, "M4": -90}
+ back = heading(85)
+ assert abs(back["M3"] + 90) <= 2 and abs(back["M4"] - 90) <= 2
+ # M3 turns clockwise and M4 anticlockwise, so both swing toward the back wall first.
+ assert heading(20)["M3"] > 90 and heading(20)["M4"] < -90
+
+
def test_view_reads_universe_bytes():
stage = load_stage(ROOT / "stage" / "map.json")
apply_show(stage, ROOT / "shows" / "xchc.qxw")
@@ -203,7 +251,7 @@ def test_http_state_follows_artnet():
with urlopen(f"http://127.0.0.1:{port}/api/state") as response:
payload = json.load(response)
assert payload["packets"] == 1
- assert payload["fixtures"]["M1"]["r"] == 255
+ assert payload["fixtures"]["M2"]["r"] == 255
with urlopen(f"http://127.0.0.1:{port}/api/stage") as response:
described = json.load(response)
assert described["fixtures"][0]["x"] == -3.5
@@ -224,7 +272,7 @@ def test_heading_is_stored_in_the_map(tmp_path):
assert saved["fixtures"]["#1"]["direction"] == 45
assert saved["fixtures"]["#2"]["direction"] == before["#2"]["direction"]
assert saved["fixtures"]["M1"]["zero"] == -30
- assert saved["fixtures"]["M2"]["zero"] == 0
+ assert saved["fixtures"]["M2"]["zero"] == -90
again = load_stage(target)
by_id = {fixture.id: fixture for fixture in again.fixtures}
assert by_id["#1"].direction == 45