#!/usr/bin/env python3
"""Generate shows/cabaret.qxw — grouped can RGB + per-mover position and RGB."""
from __future__ import annotations
import math
import socket
import subprocess
import time
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
OUT = ROOT / "shows" / "cabaret.qxw"
ARTNET_NODE_FALLBACK = "192.168.1.227"
ARTNET_PORT = 6454
def local_ipv4s() -> list[str]:
"""IPv4 addresses QLC+ will enumerate as Art-Net lines (string-sorted)."""
addrs: set[str] = set()
try:
out = subprocess.check_output(
["ip", "-4", "-o", "addr", "show"], text=True
)
except (OSError, subprocess.CalledProcessError):
out = ""
for line in out.splitlines():
parts = line.split()
if "inet" in parts:
addrs.add(parts[parts.index("inet") + 1].split("/")[0])
if not addrs:
addrs.add("127.0.0.1")
return sorted(addrs)
def artnet_bind_uid_line() -> tuple[str, int]:
addrs = local_ipv4s()
lan = [a for a in addrs if a.startswith("192.168.1.")]
uid = lan[0] if lan else next(
(a for a in addrs if not a.startswith("127.")), addrs[0]
)
return uid, addrs.index(uid)
def discover_artnet_node(local_ip: str, fallback: str = ARTNET_NODE_FALLBACK) -> str:
"""ArtPoll for a dmx-gateway; keep the last known node if none reply."""
poll = bytearray(14)
poll[0:8] = b"Art-Net\x00"
poll[8:10] = bytes((0x00, 0x20))
poll[11] = 14
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.settimeout(0.25)
try:
sock.bind(("", 0))
for dest in ("192.168.1.255", fallback):
try:
sock.sendto(poll, (dest, ARTNET_PORT))
except OSError:
pass
found: list[tuple[str, str]] = []
deadline = time.monotonic() + 1.2
while time.monotonic() < deadline:
try:
data, addr = sock.recvfrom(1024)
except TimeoutError:
continue
except socket.timeout:
continue
if not data.startswith(b"Art-Net") or len(data) < 45:
continue
opcode = data[8] | (data[9] << 8)
if opcode != 0x2100:
continue
ip = addr[0]
if ip in {local_ip, "127.0.0.1"}:
continue
name = data[26:44].split(b"\x00", 1)[0].decode("latin1", "replace")
found.append((ip, name))
for ip, name in found:
if "gateway" in name.lower() or "dmx" in name.lower():
return ip
if found:
return found[0][0]
except OSError:
pass
finally:
sock.close()
return fallback
M1, M2 = 8, 9
# Can groups: 1-2 | 3-4-5-6 | 7-8
GROUP_L = [0, 1]
GROUP_C = [2, 3, 4, 5]
GROUP_R = [6, 7]
# Can 8ch: Dim=0, Strobe=1, R=2, G=3, B=4
# Mover 43ch: Pan/Tilt Speed=4, Focus=7, Center Bright=8, Center Strobe=9; RGB heads 1–7
MOVER_SPEED = 4
MOVER_FOCUS = 7
MOVER_DIM = 8
MOVER_R = [10, 14, 18, 22, 26, 30, 34]
MOVER_G = [11, 15, 19, 23, 27, 31, 35]
MOVER_B = [12, 16, 20, 24, 28, 32, 36]
FOCUS_DEFAULT = 70
CANS = list(range(8))
PALETTE: dict[str, tuple[int, int, int]] = {
"Amber": (255, 90, 0),
"Pink": (255, 50, 160),
"HotBlue": (round(0.30 * 255), 0, 255), # 30% red, 100% blue
"Red": (255, 0, 0),
"Green": (0, 255, 0),
"Blue": (0, 0, 255),
"Orange": (255, 127, 0),
"Yellow": (255, 255, 0),
"Purple": (127, 0, 255),
}
CAN_ODD = [0, 2, 4, 6] # #1,3,5,7
CAN_EVEN = [1, 3, 5, 7] # #2,4,6,8
MOVER_SOLIDS = [
"Amber",
"Pink",
"Red",
"Green",
"Blue",
"Orange",
"Yellow",
"Purple",
]
POSITION_FADE_MS = 2000
# name, M1 (pan, tilt), M2 (pan, tilt), button colour
# Same DMX pan = split (180° hang). Cross left was mirrored (108) = 180° out.
# Down = floor aim (M2 hung 180°: pad 181/145 → DMX 74/145, M1 80/161).
POSITIONS: list[tuple[str, tuple[int, int], tuple[int, int], str]] = [
("Down", (80, 161), (74, 145), "4278236360"),
("Roof", (179, 0), (179, 0), "4282664004"),
("Wall", (179, 36), (179, 36), "4284900966"),
("Mid", (164, 18), (164, 18), "4286611584"),
("Cross", (140, 26), (140, 26), "4281545523"),
("Out", (200, 22), (200, 22), "4279900698"),
]
POSITION_FUNC0 = 100
FIGURE8_MS = 3000
# Absolute EFX per Position (QLC+ 4.12 relative does not hold the look
# when Move is a separate VC button). Collections 140–157, EFX 300+.
MOVE_COL0 = 140
MOVE_EFX0 = 300
MOVE_EIGHT_BG = "4282664004"
MOVE_ZIGZAG_BG = "4281545523"
MOVE_SWIRL_BG = "4286611584"
MOVE_PATTERNS: list[tuple[str, str, int, int, str, dict]] = [
("Figure 8", "Eight", 56, 56, MOVE_EIGHT_BG, {}),
("Zigzag", "Lissajous", 80, 40, MOVE_ZIGZAG_BG, {"x_freq": 3, "cross": True}),
("Swirl", "Circle", 50, 50, MOVE_SWIRL_BG, {}),
]
# Wander is a four-corner pan/tilt chase, not an EFX. M2's pan offsets are
# mirrored so the 180° hang walks the same box on the opposite corner.
WANDER_BG = "4278236360"
WANDER_FUNC0 = 800
WANDER_STEPS: tuple[tuple[tuple[int, int], tuple[int, int]], ...] = (
((10, -8), (-10, 8)),
((10, 8), (-10, -8)),
((-10, 8), (10, -8)),
((-10, -8), (10, 8)),
)
PATTERN_SPEED_MS = 500 # one can-chase step
MOVER_PATTERN_MS = FIGURE8_MS # one mover EFX loop
TAP_MS = 500 # 120 BPM default
SPEED_DURATION_ONE = 6
# Speed Dial visibility: PlusMinus=1 Dial=2 Tap=4 Hours=8 Minutes=16 Seconds=32 Milliseconds=64
SPEED_VIS_FADER = 2 | 32 | 64 # rotary + sec/ms, sized like a slider
SPEED_VIS_TAP = 4 | 32 | 64 # tap button + sec/ms
# Spatial can patterns from shows/xchc.qxw (RGB only; dimmer stays on C Bright).
# Solids 190–198; spatial chasers from 200. Colour is a separate SoloFrame so
# Scanner/Fill/… can run on top (they only black out idle cans).
PATTERN_COLOR_FUNC0 = 190
PATTERN_COLOR_NAMES = [
"Amber",
"Pink",
"Red",
"Green",
"Blue",
"Orange",
"Yellow",
"Purple",
"White",
]
PATTERN_FUNC0 = 200
# Moods: slow colour chases from 400, one palette for cans and one for the
# mover heads (colour only, no pan/tilt). Fade fills the whole step and every
# fixture stays at or above MOOD_FLOOR, so the stage never drops to black.
MOOD_FUNC0 = 400
MOOD_STEP_MS = 6000
MOOD_FLOOR = 0.35
MOOD_PAIRS: list[tuple[str, str, str]] = [
("Citrus", "Orange", "Green"),
("Harbour", "Orange", "Blue"),
("Absinthe", "Green", "Purple"),
("Flamingo", "Pink", "Orange"),
("Velvet", "Purple", "Orange"),
]
# Move Lab: trial mover movements from 700, aimed along the line from Down
# (t=0) toward Wall (t=1). Chasers fade between pan/tilt scenes; EFX loops
# take MOVE_LAB_EFX_MULT steps.
MOVE_LAB_FUNC0 = 700
MOVE_LAB_STEP_MS = 3000
MOVE_LAB_EFX_MULT = 8 # Speed Dial "4" multiplier: one EFX loop = 4 steps
MOVE_LAB_SPOTS: list[tuple[str, float]] = [
("Down", 0.0),
("15%", 0.15),
("30%", 0.3),
("45%", 0.45),
("60%", 0.6),
]
# caption, button colour, kind, args
MOVE_LAB_STYLES: list[tuple[str, str, str, dict]] = [
("Circle", "4282664004", "efx", {"algo": "Circle", "w": 22, "h": 22}),
("Eight", "4281545523", "efx", {"algo": "Eight", "w": 36, "h": 20}),
("Sway", "4286611584", "chase", {"m1": [(14, 0), (-14, 0)], "m2": [(14, 0), (-14, 0)]}),
("Cross Sway", "4284900966", "chase", {"m1": [(14, 0), (-14, 0)], "m2": [(-14, 0), (14, 0)]}),
("Nod", "4279900698", "chase", {"m1": [(0, -12), (0, 12)], "m2": [(0, -12), (0, 12)]}),
(
"Wander",
"4278236360",
"chase",
{
"m1": [(10, -8), (10, 8), (-10, 8), (-10, -8)],
"m2": [(-10, 8), (-10, -8), (10, -8), (10, 8)],
},
),
]
MOVER_STROBE = 9 # Center Strobe: 0–3 open, 4–200 slow→fast, 201+ random
CAN_STROBE = 1 # 0–7 off, 8–255 slow→fast
U_WALK = list(range(8)) # #1 → #2 → row of 4 L→R → #7 → #8
LEFT_CANS = {0, 1, 2, 3}
RIGHT_CANS = {4, 5, 6, 7}
PAIR_SETS = [{0, 7}, {1, 6}, {2, 5}, {3, 4}]
CENTER_RINGS = [{3, 4}, {2, 3, 4, 5}, set(range(8))]
RAINBOW_RGB = [
(255, 0, 0),
(255, 127, 0),
(255, 255, 0),
(0, 255, 0),
(0, 255, 255),
(0, 0, 255),
(127, 0, 255),
(255, 0, 255),
]
LOOK_PAIRS: list[tuple[str, str | None]] = [
("Amber", None),
("Pink", "Amber"),
("Pink", "HotBlue"),
("Red", "Green"),
("Blue", "Green"),
("Blue", "Red"),
("Orange", "Blue"),
("Yellow", "Purple"),
]
def color_label(name: str) -> str:
return "Blue" if name == "HotBlue" else name
def qlc_color(r: int, g: int, b: int) -> str:
return str((0xFF << 24) | (r << 16) | (g << 8) | b)
def mix_color(
a: tuple[int, int, int], b: tuple[int, int, int]
) -> tuple[int, int, int]:
return ((a[0] + b[0]) // 2, (a[1] + b[1]) // 2, (a[2] + b[2]) // 2)
RGB = [
("R", 2, MOVER_R, "4294901760", "Red"),
("G", 3, MOVER_G, "4278255360", "Green"),
("B", 4, MOVER_B, "4278190335", "Blue"),
]
def appearance(
fg: str = "Default",
bg: str = "Default",
frame: str = "Sunken",
) -> str:
return f"""
{frame}
{fg}
{bg}
None
Default
"""
def slider(
wid: int,
caption: str,
x: int,
y: int,
w: int,
h: int,
channels: list[tuple[int, int]],
*,
value: int = 0,
fg: str = "Default",
cng: str = "None",
inverted: bool = False,
high: int = 255,
) -> str:
ch_xml = "\n".join(
f' {ch}' for fid, ch in channels
)
inv = "true" if inverted else "false"
return f"""
{appearance(fg=fg)}
Level
{ch_xml}
4294967295
"""
def speed_dial(
wid: int,
caption: str,
x: int,
y: int,
w: int,
h: int,
time_ms: int,
functions: list[tuple[int, int, int]],
*,
min_ms: int = 40,
max_ms: int = 2000,
visibility: int = SPEED_VIS_FADER,
) -> str:
"""Speed Dial. functions are (func_id, duration_mult, fade_in_mult); 0 = not sent."""
fn_xml = "\n".join(
f' {fid}'
for fid, dur, fade in functions
)
return f"""
{appearance()}
{visibility}
{fn_xml}
"""
def button(
wid: int,
caption: str,
func_id: int,
x: int,
y: int,
w: int,
h: int,
bg: str,
fg: str = "4294967295",
*,
indent: str = " ",
) -> str:
inner = indent + " "
return f"""{indent}"""
def solo_frame(
wid: int,
caption: str,
x: int,
y: int,
w: int,
h: int,
children: str,
*,
show_header: bool = True,
) -> str:
header = "True" if show_header else "False"
return f"""
Sunken
Default
Default
None
Default
True
True
{header}
False
False
{children}
"""
def can_fixture_val(fid: int, r: int, g: int, b: int) -> str:
# Dimmer is owned by the C Bright slider (HTP).
return (
f' '
f"2,{r},3,{g},4,{b},5,0,6,0,7,0"
f""
)
def mover_fixture_val(fid: int, r: int, g: int, b: int) -> str:
# Dimmer is owned by the Mover Bright slider (HTP).
parts: list[int] = []
for i in range(7):
base = 10 + i * 4
parts.extend([base, r, base + 1, g, base + 2, b, base + 3, 0])
return f' {",".join(str(x) for x in parts)}'
def look_scene_xml(
func_id: int,
name: str,
can_colors: dict[int, tuple[int, int, int]] | None = None,
mover_colors: dict[int, tuple[int, int, int]] | None = None,
) -> str:
vals: list[str] = []
if can_colors:
vals += [can_fixture_val(fid, *rgb) for fid, rgb in can_colors.items()]
if mover_colors:
vals += [mover_fixture_val(fid, *rgb) for fid, rgb in mover_colors.items()]
return f"""
{chr(10).join(vals)}
"""
def look_caption(kind: str, left_n: str, right_n: str | None) -> str:
ll, rl = color_label(left_n), color_label(right_n or left_n)
if right_n is None:
return ll
if kind == "cans":
return f"1-4 {ll} 5-8 {rl}"
return f"Odd {ll} Even {rl}"
def look_values(
kind: str, left: tuple[int, int, int], right: tuple[int, int, int]
) -> tuple[dict[int, tuple[int, int, int]] | None, dict[int, tuple[int, int, int]] | None]:
if kind == "cans":
return {**{i: left for i in range(4)}, **{i: right for i in range(4, 8)}}, None
if kind == "cans_oe":
return {**{i: left for i in CAN_ODD}, **{i: right for i in CAN_EVEN}}, None
raise ValueError(kind)
def build_looks() -> tuple[str, dict[str, list[tuple[str, int, str]]]]:
specs: dict[str, list[tuple[str, int, str]]] = {
"cans": [],
"movers": [],
"cans_oe": [],
}
scenes: list[str] = []
func_id = 0
for kind in ("cans", "cans_oe"):
for left_n, right_n in LOOK_PAIRS:
if kind == "cans_oe" and right_n is None:
continue
left = PALETTE[left_n]
right = PALETTE[right_n] if right_n else left
cans, movers = look_values(kind, left, right)
if right_n is None:
cans = {fid: left for fid in CANS}
movers = None
ll, rl = color_label(left_n), color_label(right_n or left_n)
name = f"{kind} {ll}" if right_n is None else f"{kind} {ll} {rl}"
scenes.append(look_scene_xml(func_id, name, cans, movers))
bg = qlc_color(*left) if right_n is None else qlc_color(*mix_color(left, right))
specs[kind].append((look_caption(kind, left_n, right_n), func_id, bg))
func_id += 1
for color_n in MOVER_SOLIDS:
rgb = PALETTE[color_n]
label = color_label(color_n)
scenes.append(
look_scene_xml(
func_id,
f"movers {label}",
mover_colors={M1: rgb, M2: rgb},
)
)
specs["movers"].append((label, func_id, qlc_color(*rgb)))
func_id += 1
return "\n".join(scenes), specs
def look_scenes_xml() -> str:
xml, _ = build_looks()
return xml
def position_scene_xml() -> str:
blocks = []
for i, (name, m1, m2, _bg) in enumerate(POSITIONS):
poses = {M1: m1, M2: m2}
vals = []
for fid in (M1, M2):
pan, tilt = poses[fid]
vals.append(
f' 0,{pan},1,0,2,{tilt},3,0'
)
# Duration 0: keep writing while the button is on so Move EFX
# (absolute, offset to this look) has a live base.
blocks.append(
f"""
{chr(10).join(vals)}
"""
)
return "\n".join(blocks)
def position_button_specs() -> list[tuple[str, int, str]]:
return [
(name, POSITION_FUNC0 + i, bg)
for i, (name, _m1, _m2, bg) in enumerate(POSITIONS)
]
def move_pattern_specs() -> dict[str, list[tuple[str, int, str]]]:
_, specs, _ = build_move_functions()
return specs
def efx_block(
func_id: int,
name: str,
algorithm: str,
width: int,
height: int,
fixtures: list[tuple[int, str, int]],
pan: int,
tilt: int,
*,
rotation: int = 0,
x_freq: int = 1,
y_freq: int = 1,
x_phase: int = 0,
y_phase: int = 0,
duration: int = FIGURE8_MS,
) -> str:
# Absolute, like the working XCHC figure-8: Offset is the Position look.
fixture_xml = "\n".join(
f"""
{fid}
0
0
{direction}
{offset}
255
"""
for fid, direction, offset in fixtures
)
return f"""
{fixture_xml}
Parallel
Forward
Loop
{algorithm}
{width}
{height}
{rotation}
0
{pan}
{x_freq}
{x_phase}
{tilt}
{y_freq}
{y_phase}
"""
def collection_xml(func_id: int, name: str, steps: list[int]) -> str:
step_xml = "\n".join(
f" {sid}" for i, sid in enumerate(steps)
)
return f"""
{step_xml}
"""
def efx_fit(tilt: int, height: int) -> tuple[int, int]:
"""Keep the Position aim. Shrink height to fit; only nudge off a hard stop."""
height = min(int(height), 127)
if tilt <= 0:
h = min(height, 24)
return h, h
if tilt >= 255:
h = min(height, 24)
return 255 - h, h
h = min(height, tilt, 255 - tilt)
if h < 8:
h = min(height, 16)
return max(h, min(255 - h, tilt)), h
return tilt, h
def build_move_functions() -> tuple[str, dict[str, list[tuple[str, int, str]]], list[int]]:
blocks: list[str] = []
specs: dict[str, list[tuple[str, int, str]]] = {}
all_efx: list[int] = []
efx_id = MOVE_EFX0
col_id = MOVE_COL0
for pname, algo, width, height, bg, kw in MOVE_PATTERNS:
specs[pname] = []
cross = bool(kw.get("cross"))
extra = {k: v for k, v in kw.items() if k != "cross"}
for pos_name, m1, m2, _pbg in POSITIONS:
efx_ids: list[int] = []
if m1 == m2:
fixture_specs = (
((M1, "Forward", 0), (M2, "Backward", 180))
if cross
else ((M1, "Forward", 0), (M2, "Forward", 0))
)
y, h = efx_fit(m1[1], height)
blocks.append(
efx_block(
efx_id,
f"{pname} {pos_name}",
algo,
width,
h,
list(fixture_specs),
m1[0],
y,
**extra,
)
)
efx_ids.append(efx_id)
efx_id += 1
else:
for fid, (pan, tilt) in ((M1, m1), (M2, m2)):
direction, start = (
("Backward", 180) if cross and fid == M2 else ("Forward", 0)
)
y, h = efx_fit(tilt, height)
blocks.append(
efx_block(
efx_id,
f"{pname} {pos_name} M{fid - 7}",
algo,
width,
h,
[(fid, direction, start)],
pan,
y,
**extra,
)
)
efx_ids.append(efx_id)
efx_id += 1
blocks.append(collection_xml(col_id, f"{pname} {pos_name}", efx_ids))
specs[pname].append((pos_name, col_id, bg))
all_efx.extend(efx_ids)
col_id += 1
return "\n".join(blocks), specs, all_efx
def move_efx_xml() -> str:
xml, _, _ = build_move_functions()
return xml
def can_pattern_speed_functions() -> list[tuple[int, int, int]]:
# Colour chases fade across the whole step; a dial that only shortens the
# step would cut their fades off and each step would jump.
_, colour, spatial = build_can_patterns()
return [(fid, SPEED_DURATION_ONE, SPEED_DURATION_ONE) for _c, fid, _b in colour] + [
(fid, SPEED_DURATION_ONE, 0) for _c, fid, _b in spatial
]
def mover_pattern_speed_functions() -> list[tuple[int, int, int]]:
_, _, efx_ids = build_move_functions()
_, _, wander_speed = build_wander_functions()
return [(eid, SPEED_DURATION_ONE, 0) for eid in efx_ids] + wander_speed
def tap_tempo_functions() -> list[tuple[int, int, int]]:
return can_pattern_speed_functions() + mover_pattern_speed_functions()
def chaser_xml(
func_id: int,
name: str,
steps: list[int],
*,
fade_in: int,
hold: int,
fade_out: int = 0,
run_order: str = "Loop",
) -> str:
duration = fade_in + hold + fade_out
step_xml = "\n".join(
f' {sid}'
for i, sid in enumerate(steps)
)
return f"""
Forward
{run_order}
{step_xml}
"""
def cans_lit_scene(
func_id: int, name: str, lit: dict[int, tuple[int, int, int]]
) -> str:
return look_scene_xml(
func_id, name, can_colors={fid: lit.get(fid, (0, 0, 0)) for fid in CANS}
)
def cans_mask_scene(func_id: int, name: str, lit_ids: set[int]) -> str:
"""Mask blend: 255 keeps Pattern Colour, 0 punches a hole. No LTP fight."""
vals = []
for fid in CANS:
if fid in lit_ids:
vals.append(f' 2,255,3,255,4,255')
else:
vals.append(can_fixture_val(fid, 0, 0, 0))
return f"""
{chr(10).join(vals)}
"""
def pattern_colour_scenes_xml() -> tuple[str, list[tuple[str, int, str]]]:
blocks: list[str] = []
specs: list[tuple[str, int, str]] = []
for i, name in enumerate(PATTERN_COLOR_NAMES):
rgb = (255, 255, 255) if name == "White" else PALETTE[name]
fid = PATTERN_COLOR_FUNC0 + i
blocks.append(
look_scene_xml(
fid,
f"Can Pattern {name}",
can_colors={cid: rgb for cid in CANS},
)
)
specs.append((color_label(name), fid, qlc_color(*rgb)))
return "\n".join(blocks), specs
def build_can_patterns() -> tuple[str, list[tuple[str, int, str]], list[tuple[str, int, str]]]:
"""Spatial masks vs colour chases — colour lives in Pattern Colour so they don't LTP-fight."""
fid = PATTERN_FUNC0
blocks: list[str] = []
colour_specs: list[tuple[str, int, str]] = []
spatial_specs: list[tuple[str, int, str]] = []
def add_scene(name: str, lit: dict[int, tuple[int, int, int]]) -> int:
nonlocal fid
blocks.append(cans_lit_scene(fid, name, lit))
sid = fid
fid += 1
return sid
def add_chaser(
caption: str,
bg: str,
steps: list[int],
dest: list[tuple[str, int, str]],
*,
fade_in: int,
hold: int,
run_order: str = "Loop",
) -> None:
nonlocal fid
blocks.append(
chaser_xml(
fid,
f"Can {caption}",
steps,
fade_in=fade_in,
hold=hold,
run_order=run_order,
)
)
dest.append((caption, fid, bg))
fid += 1
def add_mask(name: str, lit_ids: set[int]) -> int:
nonlocal fid
blocks.append(cans_mask_scene(fid, name, lit_ids))
sid = fid
fid += 1
return sid
off = add_mask("Can Pattern Off", set())
rainbow_steps = []
for step in range(8):
lit = {can: RAINBOW_RGB[(ci + step) % 8] for ci, can in enumerate(U_WALK)}
rainbow_steps.append(add_scene(f"Can Rainbow {step + 1}", lit))
add_chaser("Rainbow", "4280427042", rainbow_steps, colour_specs, fade_in=2000, hold=500)
blue, red = (0, 0, 255), (255, 0, 0)
odd_blue = {i: (blue if i % 2 == 0 else red) for i in CANS}
odd_red = {i: (red if i % 2 == 0 else blue) for i in CANS}
oe_a = add_scene("Can Odd Blue Even Red", odd_blue)
oe_b = add_scene("Can Odd Red Even Blue", odd_red)
add_chaser("Odd Even", "4284752486", [oe_a, oe_b], colour_specs, fade_in=3000, hold=1000)
scanner_steps = []
for i, can in enumerate(U_WALK):
scanner_steps.append(add_mask(f"Can Scanner {i + 1}", {can}))
add_chaser("Scanner", "4292033564", scanner_steps, spatial_specs, fade_in=0, hold=400)
fill_steps = []
for n in range(1, 9):
fill_steps.append(add_mask(f"Can Fill {n}", set(U_WALK[:n])))
add_chaser(
"Fill", "4278218076", fill_steps, spatial_specs, fade_in=200, hold=300, run_order="PingPong"
)
center_steps = []
for i, ring in enumerate(CENTER_RINGS):
center_steps.append(add_mask(f"Can Center {i + 1}", set(ring)))
add_chaser(
"Center",
"4280817043",
center_steps,
spatial_specs,
fade_in=200,
hold=300,
run_order="PingPong",
)
pair_steps = []
for i, ids in enumerate(PAIR_SETS):
pair_steps.append(add_mask(f"Can Pairs {i + 1}", set(ids)))
add_chaser(
"Pairs", "4294946560", pair_steps, spatial_specs, fade_in=200, hold=400, run_order="PingPong"
)
lr_a = add_scene(
"Can Left Blue Right Red",
{**{i: (0, 0, 255) for i in LEFT_CANS}, **{i: (255, 0, 0) for i in RIGHT_CANS}},
)
lr_b = add_scene(
"Can Left Red Right Blue",
{**{i: (255, 0, 0) for i in LEFT_CANS}, **{i: (0, 0, 255) for i in RIGHT_CANS}},
)
add_chaser("Left Right", "4279648704", [lr_a, lr_b], colour_specs, fade_in=3000, hold=1000)
theater_steps = []
for step in range(3):
theater_steps.append(
add_mask(f"Can Theater {step + 1}", {can for can in CANS if can % 3 == step})
)
add_chaser("Theater", "4285143962", theater_steps, spatial_specs, fade_in=0, hold=400)
add_chaser(
"Collapse",
"4281545523",
[*reversed(center_steps), off],
spatial_specs,
fade_in=200,
hold=300,
run_order="Loop",
)
add_chaser(
"Chase Out",
"4284900966",
[*scanner_steps, off],
spatial_specs,
fade_in=0,
hold=300,
run_order="Loop",
)
return "\n".join(blocks), colour_specs, spatial_specs
def can_pattern_xml() -> str:
colours, _ = pattern_colour_scenes_xml()
patterns, _, _ = build_can_patterns()
return colours + "\n" + patterns
def can_pattern_colour_button_specs() -> list[tuple[str, int, str]]:
_, solids = pattern_colour_scenes_xml()
_, colour_chasers, _ = build_can_patterns()
return solids + colour_chasers
def can_pattern_button_specs() -> list[tuple[str, int, str]]:
_, _, spatial = build_can_patterns()
return spatial
def scale_rgb(rgb: tuple[int, int, int], level: float) -> tuple[int, int, int]:
return (round(rgb[0] * level), round(rgb[1] * level), round(rgb[2] * level))
def blend_rgb(
a: tuple[int, int, int], b: tuple[int, int, int], w: float
) -> tuple[int, int, int]:
"""w=1 is all a, w=0 is all b."""
return (
round(a[0] * w + b[0] * (1 - w)),
round(a[1] * w + b[1] * (1 - w)),
round(a[2] * w + b[2] * (1 - w)),
)
RGB3 = tuple[int, int, int]
def mood_scene_xml(
func_id: int,
name: str,
cans: dict[int, RGB3] | None = None,
movers: dict[int, list[RGB3]] | None = None,
) -> str:
"""Every step of a mood carries the same channels so the chaser crossfades them."""
vals = [can_fixture_val(fid, *rgb) for fid, rgb in (cans or {}).items()]
for fid, heads in (movers or {}).items():
parts: list[int] = []
for i, (r, g, b) in enumerate(heads):
base = 10 + i * 4
parts += [base, r, base + 1, g, base + 2, b, base + 3, 0]
vals.append(
f' {",".join(str(x) for x in parts)}'
)
return f"""
{chr(10).join(vals)}
"""
def build_moods() -> tuple[str, list[tuple[str, int, str]], list[tuple[str, int, str]]]:
"""Returns xml, can mood buttons, mover mood buttons."""
blocks: list[str] = []
can_specs: list[tuple[str, int, str]] = []
mover_specs: list[tuple[str, int, str]] = []
fid = MOOD_FUNC0
heads = range(7)
def add_chase(prefix: str, caption: str, bg: str, steps: list[tuple[dict, dict]], dest) -> None:
nonlocal fid
step_ids = []
for k, (cans, movers) in enumerate(steps):
blocks.append(mood_scene_xml(fid, f"{prefix} {caption} {k + 1}", cans, movers))
step_ids.append(fid)
fid += 1
blocks.append(
chaser_xml(fid, f"{prefix} {caption}", step_ids, fade_in=MOOD_STEP_MS, hold=0)
)
dest.append((caption, fid, bg))
fid += 1
def wave(i: float, s: int, n: int) -> tuple[float, float]:
phase = 2 * math.pi * (i / n - s / 8)
w = 0.5 + 0.5 * math.cos(phase)
lvl = MOOD_FLOOR + (1 - MOOD_FLOOR) * (0.5 + 0.5 * math.cos(2 * phase))
return w, lvl
for theme, a_name, b_name in MOOD_PAIRS:
a, b = PALETTE[a_name], PALETTE[b_name]
bg = qlc_color(*mix_color(a, b))
pulse = [(a, 1.0), (a, MOOD_FLOOR), (b, 1.0), (b, MOOD_FLOOR)]
# Cans. Breathe: all cans swell and sink in one colour, then the other.
add_chase(
"Can Mood",
f"{theme} Breathe",
bg,
[({c: scale_rgb(rgb, lvl) for c in CANS}, {}) for rgb, lvl in pulse],
can_specs,
)
# Tide: odd/even, then left/right, each trading colours.
add_chase(
"Can Mood",
f"{theme} Tide",
bg,
[
({c: (a if c % 2 == 0 else b) for c in CANS}, {}),
({c: (a if c in LEFT_CANS else b) for c in CANS}, {}),
({c: (b if c % 2 == 0 else a) for c in CANS}, {}),
({c: (b if c in LEFT_CANS else a) for c in CANS}, {}),
],
can_specs,
)
# Drift: a colour wave rolls along the U with two soft bright crests.
drift = []
for s in range(8):
cans = {}
for i, c in enumerate(U_WALK):
w, lvl = wave(i, s, 8)
cans[c] = scale_rgb(blend_rgb(a, b, w), lvl)
drift.append((cans, {}))
add_chase("Can Mood", f"{theme} Drift", bg, drift, can_specs)
# Movers, colour only. Breathe: the two heads counter-pulse.
steps = []
for k, (rgb, lvl) in enumerate(pulse):
other_rgb, other_lvl = pulse[(k + 3) % 4]
steps.append(
(
{},
{
M1: [scale_rgb(rgb, lvl)] * 7,
M2: [scale_rgb(other_rgb, other_lvl)] * 7,
},
)
)
add_chase("Mover Mood", f"{theme} Breathe", bg, steps, mover_specs)
# Tide: one mover each colour, then the rings split, then swap.
alt_ab = [a if h % 2 == 0 else b for h in heads]
alt_ba = [b if h % 2 == 0 else a for h in heads]
add_chase(
"Mover Mood",
f"{theme} Tide",
bg,
[
({}, {M1: [a] * 7, M2: [b] * 7}),
({}, {M1: alt_ab, M2: alt_ba}),
({}, {M1: [b] * 7, M2: [a] * 7}),
({}, {M1: alt_ba, M2: alt_ab}),
],
mover_specs,
)
# Drift: a colour wave spins round each mover's seven heads.
drift = []
for s in range(8):
m1, m2 = [], []
for h in heads:
w, lvl = wave(h, s, 7)
m1.append(scale_rgb(blend_rgb(a, b, w), lvl))
w, lvl = wave(h + 3.5, s, 7)
m2.append(scale_rgb(blend_rgb(a, b, w), lvl))
drift.append(({}, {M1: m1, M2: m2}))
add_chase("Mover Mood", f"{theme} Drift", bg, drift, mover_specs)
return "\n".join(blocks), can_specs, mover_specs
def can_mood_speed_functions() -> list[tuple[int, int, int]]:
_, specs, _ = build_moods()
return [(fid, SPEED_DURATION_ONE, SPEED_DURATION_ONE) for _c, fid, _b in specs]
def mover_mood_speed_functions() -> list[tuple[int, int, int]]:
_, _, specs = build_moods()
return [(fid, SPEED_DURATION_ONE, SPEED_DURATION_ONE) for _c, fid, _b in specs]
def move_lab_aim(fid: int, t: float, dx: int = 0, dy: int = 0) -> tuple[int, int]:
"""DMX pan/tilt t of the way from Down to Wall, nudged by dx/dy."""
down = POSITIONS[0][1] if fid == M1 else POSITIONS[0][2]
wall = POSITIONS[2][1] if fid == M1 else POSITIONS[2][2]
pan = down[0] + (wall[0] - down[0]) * t + dx
tilt = down[1] + (wall[1] - down[1]) * t + dy
return max(0, min(255, round(pan))), max(0, min(255, round(tilt)))
def build_wander_functions() -> tuple[str, list[tuple[str, int, str]], list[tuple[int, int, int]]]:
"""Per-position Wander chasers. Returns xml, position buttons, speed-dial funcs."""
blocks: list[str] = []
specs: list[tuple[str, int, str]] = []
speed: list[tuple[int, int, int]] = []
fid = WANDER_FUNC0
for pos_name, m1, m2, _bg in POSITIONS:
step_ids: list[int] = []
for k, (d1, d2) in enumerate(WANDER_STEPS):
vals = []
for mover, base, (dx, dy) in ((M1, m1, d1), (M2, m2, d2)):
pan = max(0, min(255, base[0] + dx))
tilt = max(0, min(255, base[1] + dy))
vals.append(
f' 0,{pan},1,0,2,{tilt},3,0'
)
blocks.append(
f"""
{chr(10).join(vals)}
"""
)
step_ids.append(fid)
fid += 1
blocks.append(
chaser_xml(
fid, f"Wander {pos_name}", step_ids, fade_in=MOVER_PATTERN_MS, hold=0
)
)
specs.append((pos_name, fid, WANDER_BG))
speed.append((fid, SPEED_DURATION_ONE, SPEED_DURATION_ONE))
fid += 1
return "\n".join(blocks), specs, speed
def build_move_lab() -> tuple[str, list[tuple[str, int, str]], list[tuple[int, int, int]]]:
"""Returns xml, buttons (row per spot, column per style), speed dial functions."""
blocks: list[str] = []
specs: list[tuple[str, int, str]] = []
speed: list[tuple[int, int, int]] = []
fid = MOVE_LAB_FUNC0
for spot, t in MOVE_LAB_SPOTS:
for style, bg, kind, args in MOVE_LAB_STYLES:
name = f"Move Lab {style} {spot}"
if kind == "efx":
efx_ids = []
for mover in (M1, M2):
pan, tilt = move_lab_aim(mover, t)
y, h = efx_fit(tilt, args["h"])
blocks.append(
efx_block(
fid,
f"{name} M{mover - 7}",
args["algo"],
args["w"],
h,
[(mover, "Forward", 0)],
pan,
y,
duration=MOVE_LAB_STEP_MS * 4,
)
)
efx_ids.append(fid)
speed.append((fid, MOVE_LAB_EFX_MULT, 0))
fid += 1
blocks.append(collection_xml(fid, name, efx_ids))
else:
step_ids = []
for k, (d1, d2) in enumerate(zip(args["m1"], args["m2"])):
vals = []
for mover, (dx, dy) in ((M1, d1), (M2, d2)):
pan, tilt = move_lab_aim(mover, t, dx, dy)
vals.append(
f' 0,{pan},1,0,2,{tilt},3,0'
)
blocks.append(
f"""
{chr(10).join(vals)}
"""
)
step_ids.append(fid)
fid += 1
blocks.append(
chaser_xml(fid, name, step_ids, fade_in=MOVE_LAB_STEP_MS, hold=0)
)
speed.append((fid, SPEED_DURATION_ONE, SPEED_DURATION_ONE))
specs.append((f"{style} {spot}", fid, bg))
fid += 1
return "\n".join(blocks), specs, speed
def fixture_xml() -> str:
parts = []
for i in range(8):
parts.append(
f"""
beamZ
BCC145
8 Channel
{i}
BCC145 #{i + 1}
0
{87 + i * 8}
8
"""
)
for i, addr in enumerate((0, 44)):
parts.append(
f"""
Small Eye 7
Mover
43 Channel
{8 + i}
Small Eye 7 #{i + 1}
0
{addr}
43
"""
)
return "\n".join(parts)
def fixture_groups_xml() -> str:
def heads(fids: list[int]) -> str:
return "\n".join(
f'
0'
for i, fid in enumerate(fids)
)
return f"""
Cans 1-2
{heads(GROUP_L)}
Cans 3-6
{heads(GROUP_C)}
Cans 7-8
{heads(GROUP_R)}
Small Eye Movers
0
0
"""
def main() -> None:
sl_w, sl_h = 44, 240
block_gap = 28
row_gap = 36
header_h = 28
widgets: list[str] = []
wid = 0
max_x = 0
max_y = 0
def place_slider(
caption,
x,
y,
w,
h,
channels,
value=0,
fg="Default",
cng="None",
inverted=False,
high=255,
):
nonlocal wid, max_x, max_y
widgets.append(
slider(
wid,
caption,
x,
y,
w,
h,
channels,
value=value,
fg=fg,
cng=cng,
inverted=inverted,
high=high,
)
)
wid += 1
max_x = max(max_x, x + w)
max_y = max(max_y, y + h)
def place_speed_slider(
caption,
x,
y,
time_ms,
functions,
*,
min_ms=50,
max_ms=8000,
w=64,
h=sl_h,
visibility=SPEED_VIS_FADER,
):
nonlocal wid, max_x, max_y
widgets.append(
speed_dial(
wid,
caption,
x,
y,
w,
h,
time_ms,
functions,
min_ms=min_ms,
max_ms=max_ms,
visibility=visibility,
)
)
wid += 1
max_x = max(max_x, x + w)
max_y = max(max_y, y + h)
return x + w
def place_looks(
title: str,
looks: list[tuple[str, int, str]],
x: int,
y: int,
*,
cols: int = 2,
btn_w: int = 156,
sink: list[str] | None = None,
frame_y: int | None = None,
) -> int:
nonlocal wid, max_x, max_y
pad = 4
gap_x, gap_y = 6, 6
n = len(looks)
cols = max(1, min(cols, n))
rows = max(1, (n + cols - 1) // cols)
frame_w = pad * 2 + cols * btn_w + (cols - 1) * gap_x
frame_h = header_h + sl_h
inner_h = sl_h - pad
btn_h = (inner_h - gap_y * (rows - 1)) // rows
look_btns = []
frame_id = wid
wid += 1
for i, (caption, func_id, bg) in enumerate(looks):
col, row = i % cols, i // cols
look_btns.append(
button(
wid,
caption,
func_id,
pad + col * (btn_w + gap_x),
header_h + pad + row * (btn_h + gap_y),
btn_w,
btn_h,
bg,
indent=" ",
)
)
wid += 1
fy = y - header_h if frame_y is None else frame_y
xml = solo_frame(
frame_id,
title,
x,
fy,
frame_w,
frame_h,
"\n".join(look_btns),
)
if sink is None:
widgets.append(xml)
max_x = max(max_x, x + frame_w)
max_y = max(max_y, fy + frame_h)
return x + frame_w
sink.append(xml)
return frame_w
_, look_specs = build_looks()
y0 = header_h
x = 10
x = place_speed_slider(
"Tap",
x,
y0,
TAP_MS,
tap_tempo_functions(),
min_ms=100,
max_ms=4000,
w=110,
visibility=SPEED_VIS_TAP,
)
x += block_gap
place_slider(
"M Bright",
x,
y0,
sl_w,
sl_h,
[(M1, MOVER_DIM), (M2, MOVER_DIM)],
255,
"4294967295",
)
x += sl_w + 2
place_slider(
"M Focus",
x,
y0,
sl_w,
sl_h,
[(M1, MOVER_FOCUS), (M2, MOVER_FOCUS)],
FOCUS_DEFAULT,
"4294902015",
)
x += sl_w + 2
place_slider(
"Speed",
x,
y0,
sl_w,
sl_h,
[(M1, MOVER_SPEED), (M2, MOVER_SPEED)],
0,
"4294967295",
inverted=True,
)
x += sl_w + 2
place_slider(
"M Strobe",
x,
y0,
sl_w,
sl_h,
[(M1, MOVER_STROBE), (M2, MOVER_STROBE)],
0,
"4294967040",
high=200,
)
x += sl_w + 2
x = place_speed_slider(
"M Pat",
x,
y0,
MOVER_PATTERN_MS,
mover_pattern_speed_functions(),
min_ms=200,
max_ms=12000,
)
x += 2
for name, _can_ch, mover_chs, fg, cng in RGB:
place_slider(
f"M {name}",
x,
y0,
sl_w,
sl_h,
[(fid, c) for fid in (M1, M2) for c in mover_chs],
fg=fg,
cng=cng,
)
x += sl_w + 2
x += block_gap - 2
move_pad = 4
looks_x0 = x
looks_chunks: list[str] = []
inner_x = move_pad
inner_w = place_looks(
"Position",
position_button_specs(),
inner_x,
y0,
cols=2,
btn_w=72,
sink=looks_chunks,
frame_y=move_pad,
)
inner_x += inner_w + block_gap
move_specs = move_pattern_specs()
for title in ("Figure 8", "Zigzag", "Swirl"):
inner_w = place_looks(
title,
move_specs[title],
inner_x,
y0,
cols=2,
btn_w=72,
sink=looks_chunks,
frame_y=move_pad,
)
inner_x += inner_w + block_gap
_, wander_specs, _ = build_wander_functions()
inner_w = place_looks(
"Wander",
wander_specs,
inner_x,
y0,
cols=2,
btn_w=72,
sink=looks_chunks,
frame_y=move_pad,
)
inner_x += inner_w + block_gap
parent_w = inner_x + move_pad
parent_h = header_h + sl_h + move_pad
widgets.append(
solo_frame(
wid,
"",
looks_x0,
y0 - header_h,
parent_w,
parent_h,
"\n".join(looks_chunks),
show_header=False,
)
)
max_x = max(max_x, looks_x0 + parent_w)
max_y = max(max_y, y0 - header_h + parent_h)
wid += 1
x = looks_x0 + parent_w + block_gap
x = place_looks("Movers", look_specs["movers"], x, y0)
y1 = y0 + sl_h + row_gap
x = 10
place_slider(
"C Bright",
x,
y1,
sl_w,
sl_h,
[(f, 0) for f in CANS],
255,
"4294967295",
)
x += sl_w + 2
place_slider(
"C Strobe",
x,
y1,
sl_w,
sl_h,
[(f, CAN_STROBE) for f in CANS],
0,
"4294967040",
)
x += sl_w + block_gap
x = place_looks("Cans", look_specs["cans"], x, y1)
x += block_gap
x = place_looks("Cans Odd/Even", look_specs["cans_oe"], x, y1)
x += block_gap
x = place_looks(
"Pattern Colour",
can_pattern_colour_button_specs(),
x,
y1,
cols=3,
btn_w=72,
)
x += block_gap
x = place_looks(
"Can Patterns",
can_pattern_button_specs(),
x,
y1,
cols=3,
btn_w=72,
)
x += 8
place_speed_slider(
"C Pat",
x,
y1,
PATTERN_SPEED_MS,
can_pattern_speed_functions(),
min_ms=50,
max_ms=4000,
)
y2 = y1 + sl_h + row_gap
x = 10
_, can_mood_specs, mover_mood_specs = build_moods()
x = place_looks("Can Moods", can_mood_specs, x, y2, cols=3, btn_w=120)
x += 8
x = place_speed_slider(
"C Mood",
x,
y2,
MOOD_STEP_MS,
can_mood_speed_functions(),
min_ms=1000,
max_ms=30000,
)
x += block_gap
x = place_looks("Mover Moods · colour", mover_mood_specs, x, y2, cols=3, btn_w=120)
x += 8
place_speed_slider(
"M Mood",
x,
y2,
MOOD_STEP_MS,
mover_mood_speed_functions(),
min_ms=1000,
max_ms=30000,
)
y3 = y2 + sl_h + row_gap
x = 10
_, lab_specs, lab_speed = build_move_lab()
x = place_looks(
"Move Lab · Down → Wall", lab_specs, x, y3, cols=len(MOVE_LAB_STYLES), btn_w=100
)
x += 8
place_speed_slider(
"Move",
x,
y3,
MOVE_LAB_STEP_MS,
lab_speed,
min_ms=500,
max_ms=20000,
)
total_w = max_x + 16
total_h = max_y + 16
artnet_uid, artnet_line = artnet_bind_uid_line()
artnet_node = discover_artnet_node(artnet_uid)
print(
f"Art-Net bind {artnet_uid} line {artnet_line} → {artnet_node} universe 0"
)
qxw = f"""
Q Light Controller Plus
4.12.7
Jimmy
{fixture_xml()}
{fixture_groups_xml()}
{look_scenes_xml()}
{position_scene_xml()}
{move_efx_xml()}
{build_wander_functions()[0]}
{can_pattern_xml()}
{build_moods()[0]}
{build_move_lab()[0]}
None
Default
Default
None
Default
{"\n".join(widgets)}
"""
OUT.parent.mkdir(parents=True, exist_ok=True)
OUT.write_text(qxw)
print(f"Wrote {OUT} ({total_w}x{total_h}, {wid} widgets)")
if __name__ == "__main__":
main()