Files
jimmyandClaude Opus 5.5 4fd11445e8 Add cabaret's can patterns to the test show.
Eight of make_cabaret_vc.py's Can Patterns on the cans pads 1-8, in a Can
patterns solo frame in place of the pads frame's empty Buttons 53-60:
Theater, Rainbow, Odd Even, Left Right, Scanner (with a fading tail), Fill,
Center and Pairs, laid out for the test show's cans and walking the ring round
the room (scripts/shows/can_patterns.py). Collapse and Chase Out are left out.

The masks show the Colour 1 colour; Odd Even (a checkerboard) and Left Right
swap between Colour 1 and Colour 2 through four Matrix widgets in the Chase
colours frame. All of them follow the cans' Speed dial (knob 1). Each pattern is
RGB matrices running from start to stop (rgbscripts/steps.js and swap.js, linked
into ~/.qlcplus/rgbscripts), so a chase started over one lands on top, and the
pad controller restarts the pattern that is on just after a Colour 1 press so
the new colour scene doesn't cover it.

The row of 4 (#3-#6) never animates; CLAUDE.md now says so for whatever comes
next.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 13:57:13 +13:00

364 lines
19 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""Add cabaret's can patterns to shows/test.qxw, on the cans pads 1–8.
Eight of make_cabaret_vc.py's Can Patterns, laid out for the test show's
test show's cans instead of cabaret's 8. The row of 4 (#3–#6) is always
static (see CLAUDE.md): the patterns leave it out, so it keeps the Colour 1
colour whatever runs. Where cabaret walks its U (#1, #2, the row of 4, #7, #8),
these walk the other 11 cans round the room: #1, #2, #9, #11, #13, #14, #15,
#12, #10, #7, #8.
Most are masks over the Colour 1 colour (the cans' own), so they show whatever
colour is on:
40 Scanner pad 5 one can at a time round the ring, two fading behind it
41 Fill pad 6 the ring fills up and empties again
42 Center pad 7 out from the middle of the room to the back wall, and back in
43 Pairs pad 8 mirrored pairs, outside in and back out
36 Theater pad 1 every third can round the ring
Rainbow brings its own colours, as in cabaret:
37 Rainbow pad 2 a rainbow turning slowly round the ring
Where cabaret's Odd Even and Left Right trade blue and red, these trade the
Colour 1 and Colour 2 colours:
38 Odd Even pad 3 a checkerboard: alternate cans front to back down each
side, and opposite across the room, every can swapping
39 Left Right pad 4 Colour 1 on the left and Colour 2 on the right, swapping
Each is two RGB matrices with the rgbscripts/swap.js script, one per half of
the cans, swapping between the two colours the other way round. Four Matrix
widgets in the collapsed Chase colours frame give them their start and end
colours from the Colour 1 and Colour 2 pads, as the chases get theirs from
Colour 2.
The rest are RGB matrices too, with the rgbscripts/steps.js script playing
their steps, so each pattern runs as the same few functions from start to stop
and a chase started while it runs lands on top of it. (A chaser of scenes would
start a newer scene every step: newer than the chase, so a mask step would
blank the chase and a colour step cover it.) A mask pattern is a pair of Mask
matrices, one on red, green and blue and one on white, so the white in Warm,
White and Cool is masked too; Rainbow and the swaps run Can no white beside
them to take the Colour 1 white off the animated cans. For the same reason a
Colour 1 scene started after a pattern would cover it, so padcontroller/layer.py
restarts the pattern that is on just after a Colour 1 press. Both scripts are
linked into ~/.qlcplus/rgbscripts, where QLC+ looks.
All of them follow the cans' Speed dial (knob 1, CC 30) like the chases. The
dial scales its time by powers of 2, so their fades and step times are its
200 ms default times 1, 2, 4, 8 or 16, the nearest to cabaret's:
Scanner, Theater 0.4 s a step (cabaret 0.4 s)
Fill, Center 0.2 s fade + 0.2 s (0.2 s + 0.3 s)
Pairs 0.2 s fade + 0.6 s (0.2 s + 0.4 s)
Rainbow 1.6 s fade + 1.6 s (2 s + 0.5 s)
Odd Even, Left 1.6 s fade + 1.6 s (3 s + 1 s)
Right
Cabaret's Collapse and Chase Out, which only replay Center's and Scanner's
steps with a dark one after, are left out.
They only set the cans' red, green, blue and white, so the Front, Back and
Middle knobs still set how bright they are. They take the empty buttons of the
pads frame (Buttons 53–60), beside the chases, in a Can patterns solo frame
so only one runs at a time. Like the chases they sit under the pads frame's
Peak (CC 35). #14 gets its colour forced LTP, as the other animated cans
already have, so the colour patterns cover the Colour 1 scene there too.
python3 scripts/shows/can_patterns.py
Run it once; it stops if the patterns are already there. QLC+ has to reopen the
show to see them.
"""
from __future__ import annotations
import json
import math
import re
from pathlib import Path
from mover_bank import NO_FUNCTION, NOTE_BASE, ROOT, appearance, button
SHOW = ROOT / "shows" / "test.qxw"
STAGE = ROOT / "stage" / "map.json"
# Can name -> fixture ID in test.qxw
CANS = {f"#{n}": n - 1 for n in range(1, 9)} | {f"#{n}": n + 1 for n in range(9, 16)}
STATIC = ("#3", "#4", "#5", "#6") # the row of 4 never animates
ANIMATED = {n: fid for n, fid in CANS.items() if n not in STATIC}
RING = ("#1", "#2", "#9", "#11", "#13", "#14", "#15", "#12", "#10", "#7", "#8")
HTP_COLOUR = ("#14",)
F_FIRST = 80
SIZE = 90
# Note -> the empty pads frame button on that pad
EMPTY_BUTTONS = {36: 57, 37: 58, 38: 59, 39: 60, 40: 53, 41: 54, 42: 55, 43: 56}
# make_cabaret_vc.py's colours
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)]
GROUP_ODD, GROUP_EVEN, GROUP_LEFT, GROUP_RIGHT, GROUP_RING = 9, 10, 11, 12, 13
SCRIPTS = (ROOT / "rgbscripts" / "swap.js", ROOT / "rgbscripts" / "steps.js")
USER_SCRIPTS = Path.home() / ".qlcplus" / "rgbscripts"
CYAN, BLUE = 4278255615, 4278190335 # the chases' starting colour; Colour 2 Blue
COLOUR_2_NOTE, COLOUR_1_NOTE = 68, 52 # first pad of each colour set
SPEED_DIAL = 111 # the cans' Speed dial, knob 1
SPEED_MS = 200 # its starting time
# Index into QLC+'s speed dial factors: (Not Sent), 0, 1/16, 1/8, 1/4, 1/2, 1, 2, 4, 8, 16
FACTORS = {SPEED_MS * 2 ** k: 6 + k for k in range(5)} # 1x to 16x
NOT_SENT = 0
SWAP_FADE_MS, SWAP_STEP_MS = 1600, 3200
SCANNER_TAIL = (110, 35) # mask levels of the cans one and two behind the lit one
def positions() -> dict[str, tuple[float, float]]:
fixtures = json.loads(STAGE.read_text())["fixtures"]
return {name: (f["x"], f["y"]) for name, f in fixtures.items() if name in ANIMATED}
def hex_rgb(rgb: tuple[int, int, int]) -> str:
return "%02x%02x%02x" % rgb
def steps_matrix(fid: int, name: str, steps: list[list[tuple[int, int, int]]], fade_in: int, step_ms: int,
run_order: str = "Loop", mode: str = "RGB", blend: str = "Normal") -> str:
"""An RGB matrix on the ring group playing steps (each the ring's colours) with rgbscripts/steps.js."""
text = ";".join(",".join(hex_rgb(c) for c in step) for step in steps)
blend_attr = f' BlendMode="{blend}"' if blend != "Normal" else ""
return f''' <Function ID="{fid}" Type="RGBMatrix" Name="{name}"{blend_attr}>
<Speed FadeIn="{fade_in}" FadeOut="0" Duration="{step_ms}"/>
<Direction>Forward</Direction>
<RunOrder>{run_order}</RunOrder>
<Algorithm Type="Script">Steps</Algorithm>
<MonoColor>{CYAN}</MonoColor>
<ControlMode>{mode}</ControlMode>
<FixtureGroup>{GROUP_RING}</FixtureGroup>
<Property Name="steps" Value="{text}"/>
</Function>
'''
def group(gid: int, name: str, cans: list[str]) -> str:
heads = "\n".join(f' <Head X="{x}" Y="0" Fixture="{ANIMATED[n]}">0</Head>' for x, n in enumerate(cans))
return f''' <FixtureGroup ID="{gid}">
<Name>{name}</Name>
<Size X="{len(cans)}" Y="1"/>
{heads}
</FixtureGroup>
'''
def swap_matrix(fid: int, name: str, gid: int, start: int, end: int) -> str:
"""Every can in its group in the start colour, then the end colour, crossfading."""
return f''' <Function ID="{fid}" Type="RGBMatrix" Name="{name}">
<Speed FadeIn="{SWAP_FADE_MS}" FadeOut="1000" Duration="{SWAP_STEP_MS}"/>
<Direction>Forward</Direction>
<RunOrder>Loop</RunOrder>
<Algorithm Type="Script">Swap</Algorithm>
<MonoColor>{start}</MonoColor>
<EndColor>{end}</EndColor>
<ControlMode>RGB</ControlMode>
<FixtureGroup>{gid}</FixtureGroup>
</Function>
'''
def collection(fid: int, name: str, steps: list[int]) -> str:
rows = "\n".join(f' <Step Number="{i}">{s}</Step>' for i, s in enumerate(steps))
return f' <Function ID="{fid}" Type="Collection" Name="{name}">\n{rows}\n </Function>\n'
def rainbow_at(t: float) -> tuple[int, int, int]:
"""RAINBOW_RGB as a wheel, t from 0 to 8, blending between neighbours."""
i = math.floor(t) % 8
a, b = RAINBOW_RGB[i], RAINBOW_RGB[(i + 1) % 8]
w = t - math.floor(t)
return tuple(round(x + (y - x) * w) for x, y in zip(a, b))
def factor(ms: int) -> int:
"""The speed dial factor that gives ms at its starting time; 0 ms is left alone."""
if ms == 0:
return NOT_SENT
if ms not in FACTORS:
raise SystemExit(f"{ms} ms is not the Speed dial's {SPEED_MS} ms times 1, 2, 4, 8 or 16")
return FACTORS[ms]
def build() -> tuple[str, str, list[tuple[str, int, int]], list[tuple[str, int, int]], list[tuple[int, int, int]]]:
"""The groups, the functions, (caption, function ID, note) for each button in pad order,
(name, matrix ID, first note of its start colour's pads) for each swap matrix, and
(function ID, fade in, step time) for each function on the Speed dial."""
pos = positions()
fid = F_FIRST
blocks: list[str] = []
patterns: dict[str, int] = {}
speeds: list[tuple[int, int, int]] = []
def add(xml_for) -> int:
nonlocal fid
blocks.append(xml_for(fid))
fid += 1
return fid - 1
def add_pattern(caption: str, matrices: list[int], fade_in: int, step_ms: int) -> None:
speeds.extend((m, fade_in, step_ms) for m in matrices if m != no_white)
patterns[caption] = add(lambda f: collection(f, f"Can {caption}", matrices))
def add_mask(caption: str, levels: list[dict[str, int]], fade_in: int, hold: int, run_order: str = "Loop") -> None:
"""A mask pattern: each step the ring's levels, 255 keeping the colour under it and 0 a hole."""
steps = [[(lv.get(n, 0),) * 3 for n in RING] for lv in levels]
rgb = add(lambda f: steps_matrix(f, f"Can {caption}", steps, fade_in, fade_in + hold, run_order, "RGB", "Mask"))
white = add(lambda f: steps_matrix(f, f"Can {caption} white", steps, fade_in, fade_in + hold, run_order,
"White", "Mask"))
add_pattern(caption, [rgb, white], fade_in, fade_in + hold)
no_white = add(lambda f: steps_matrix(f, "Can no white", [[(0, 0, 0)] * len(RING)], 0, 1000, mode="White"))
rainbow = [[rainbow_at(i * 8 / len(RING) + s) for i in range(len(RING))] for s in range(8)]
add_pattern("Rainbow", [add(lambda f: steps_matrix(f, "Can Rainbow", rainbow, 1600, 3200)), no_white], 1600, 3200)
# Odd Even and Left Right: one swap matrix per half, Colour 1 first on one and Colour 2 first on the other.
left = {n for n in ANIMATED if pos[n][0] <= 0} # #14, in the middle of the back wall, goes left
rows = sorted({y for _, y in pos.values()}, reverse=True) # front first
odd = [n for n in ANIMATED if (rows.index(pos[n][1]) + (n not in left)) % 2 == 0]
halves = {"Odd Even": ((GROUP_ODD, "Cans odd", odd), (GROUP_EVEN, "Cans even", [n for n in ANIMATED if n not in odd])),
"Left Right": ((GROUP_LEFT, "Cans left", sorted(left, key=RING.index)),
(GROUP_RIGHT, "Cans right", [n for n in RING if n not in left]))}
groups = "".join(group(gid, name, cans) for pair in halves.values() for gid, name, cans in pair)
swaps = []
for caption, ((gid_a, name_a, _), (gid_b, name_b, _)) in halves.items():
a = add(lambda f: swap_matrix(f, f"Can {caption} {name_a[5:]}", gid_a, CYAN, BLUE))
b = add(lambda f: swap_matrix(f, f"Can {caption} {name_b[5:]}", gid_b, BLUE, CYAN))
swaps += [(f"{caption} {name_a[5:]}", a, COLOUR_1_NOTE), (f"{caption} {name_b[5:]}", b, COLOUR_2_NOTE)]
add_pattern(caption, [a, b, no_white], SWAP_FADE_MS, SWAP_STEP_MS)
groups += group(GROUP_RING, "Cans ring", list(RING))
def scanner_step(i: int) -> dict[str, int]:
"""The can at i lit, and the tail behind it round the ring."""
return {RING[(i - k) % len(RING)]: level for k, level in enumerate((255, *SCANNER_TAIL))}
add_mask("Scanner", [scanner_step(i) for i in range(len(RING))], 0, 400)
add_mask("Fill", [dict.fromkeys(RING[:k], 255) for k in range(1, len(RING) + 1)], 200, 200, "PingPong")
# Rings out from the middle of the room, nearest first; the back wall comes in last.
rings = [{"#2", "#7", "#9", "#10"}, {"#1", "#8"}, set(ANIMATED)]
assert set().union(*rings) == set(ANIMATED)
center, lit = [], set()
for ring in rings:
lit |= ring
center.append(dict.fromkeys(lit, 255))
add_mask("Center", center, 200, 200, "PingPong")
# Mirrored pairs, furthest from the middle first; #14 goes with the back corners.
pairs = sorted(({n, m} for n in ANIMATED for m in ANIMATED
if pos[n][0] < 0 and pos[m][0] == -pos[n][0] and pos[m][1] == pos[n][1]),
key=lambda p: -math.hypot(*pos[min(p)]))
pairs[0] |= {"#14"}
add_mask("Pairs", [dict.fromkeys(p, 255) for p in pairs], 200, 600, "PingPong")
add_mask("Theater", [{n: 255 for i, n in enumerate(RING) if i % 3 == s} for s in range(3)], 0, 400)
order = [("Theater", 36), ("Rainbow", 37), ("Odd Even", 38), ("Left Right", 39),
("Scanner", 40), ("Fill", 41), ("Center", 42), ("Pairs", 43)]
return groups, "".join(blocks), [(caption, patterns[caption], note) for caption, note in order], swaps, speeds
def solo_frame(wid: int, x: int, y: int, buttons: str) -> str:
indent = " "
return (f'{indent}<SoloFrame Caption="Can patterns" ID="{wid}">\n'
+ appearance(indent + " ")
+ f'{indent} <WindowState Visible="True" X="{x}" Y="{y}" Width="{4 * SIZE}" Height="{2 * SIZE}"/>\n'
f'{indent} <AllowChildren>True</AllowChildren>\n{indent} <AllowResize>True</AllowResize>\n'
f'{indent} <ShowHeader>False</ShowHeader>\n{indent} <ShowEnableButton>False</ShowEnableButton>\n'
f'{indent} <Mixing>False</Mixing>\n{indent} <Collapsed>False</Collapsed>\n{indent} <Disabled>False</Disabled>\n'
f'{buttons}{indent}</SoloFrame>\n')
def colour_matrix(xml: str, wid: int, caption: str, fid: int, start_note: int, x: int, y: int) -> str:
"""A copy of the chases' Forward colour widget for a swap matrix: its start colour from the pads
from start_note, its end colour from the other colour set's."""
m = re.search(r' <Matrix Caption="Forward colour" ID="61">.*? </Matrix>\n', xml, re.S).group(0)
head = m[:m.index(" <Control ")]
head = head.replace('Caption="Forward colour" ID="61"', f'Caption="{caption}" ID="{wid}"')
head = head.replace('<Function ID="43" InstantApply', f'<Function ID="{fid}" InstantApply')
head = re.sub(r'X="\d+" Y="\d+" Width', f'X="{x}" Y="{y}" Width', head, count=1)
colours = re.findall(r'<Color>(#[0-9a-f]{6})</Color>', m)
end_note = COLOUR_1_NOTE if start_note == COLOUR_2_NOTE else COLOUR_2_NOTE
controls = "".join(
f' <Control ID="{k * 16 + i + 1}">\n <Type>{kind}</Type>\n <Color>{c}</Color>\n'
f' <Input Universe="1" Channel="{NOTE_BASE + note + i}"/>\n </Control>\n'
for k, (kind, note) in enumerate((("StartColor", start_note), ("EndColor", end_note)))
for i, c in enumerate(colours))
return head + controls + " </Matrix>\n"
def link_scripts() -> None:
USER_SCRIPTS.mkdir(parents=True, exist_ok=True)
for script in SCRIPTS:
link = USER_SCRIPTS / script.name
if not link.is_symlink() or link.resolve() != script:
link.unlink(missing_ok=True)
link.symlink_to(script)
def main() -> None:
xml = SHOW.read_text()
if "Can Scanner" in xml or "Can Rainbow" in xml:
raise SystemExit(f"{SHOW.relative_to(ROOT)} already has the can patterns")
groups, functions, specs, swaps, speeds = build()
used = {int(i) for i in re.findall(r'<Function ID="(\d+)" Type', xml)}
if used & set(range(F_FIRST, F_FIRST + functions.count("<Function "))):
raise SystemExit(f"Function IDs from {F_FIRST} are taken")
taken = {int(i) for i in re.findall(r'<Input Universe="1" Channel="(\d+)"', xml)}
if taken & {NOTE_BASE + n for _, _, n in specs}:
raise SystemExit("Some of the free cans pads are taken")
# Buttons 53–60 are the bottom two rows of the pads frame; a solo frame takes their place.
empty = re.search(r' <Button Caption="Button 53" ID="53".*? <Button Caption="Button 60" ID="60".*? </Button>\n',
xml, re.S)
if empty is None or "<Input" in empty.group(0) or empty.group(0).count("<Button ") != 8:
raise SystemExit("Buttons 53–60 are not the empty rows they were")
spots = {int(w): (int(x), int(y)) for w, x, y in re.findall(
r'<Button Caption="Button (\d+)" ID="\d+" Icon="">\n <WindowState Visible="True" X="(\d+)" Y="(\d+)"',
empty.group(0))}
left, top = min(x for x, _ in spots.values()), min(y for _, y in spots.values())
buttons = "".join(button(EMPTY_BUTTONS[note], caption, spots[EMPTY_BUTTONS[note]][0] - left,
spots[EMPTY_BUTTONS[note]][1] - top, SIZE, fid, NOTE_BASE + note, indent=" ")
for caption, fid, note in specs)
next_id = max(int(i) for i in re.findall(r' ID="(\d+)"', xml.split("<VirtualConsole>")[1])
if int(i) != NO_FUNCTION) + 1
xml = xml.replace(empty.group(0), solo_frame(next_id, left, top, buttons), 1)
# The swap matrices' colour widgets go under the Strobe 2 colour slider in the collapsed Chase colours frame.
strobe_slider = re.search(r' <Slider Caption="Strobe 2 colour" ID="105".*? </Slider>\n', xml, re.S).group(0)
widgets = "".join(colour_matrix(xml, next_id + 1 + k, f"{name} colour", fid, note, 10 + (k % 2) * 310, 735 + (k // 2) * 230)
for k, (name, fid, note) in enumerate(swaps))
xml = xml.replace(strobe_slider, strobe_slider + widgets, 1)
old = '<WindowState Visible="True" X="330" Y="910" Width="640" Height="740"/>'
if old not in xml:
raise SystemExit("Couldn't find the Chase colours frame at 740 high")
xml = xml.replace(old, old.replace('Height="740"', f'Height="{740 + 230 * ((len(swaps) + 1) // 2)}"'), 1)
for name in HTP_COLOUR:
xml, n = re.subn(rf"( <ID>{CANS[name]}</ID>\n <Name>{name}</Name>\n(?: .*\n)*? <ForcedHTP>1</ForcedHTP>\n)(?! <ForcedLTP>)",
r"\1 <ForcedLTP>2,3,4,5</ForcedLTP>\n", xml, count=1)
if n != 1:
raise SystemExit(f"Couldn't find {name}'s forced HTP strobe to put its colour LTP beside")
dial = re.search(rf' <SpeedDial Caption="Speed" ID="{SPEED_DIAL}">.*? </SpeedDial>\n', xml, re.S)
if dial is None or f"<Time>{SPEED_MS}</Time>" not in dial.group(0):
raise SystemExit(f"Couldn't find the Speed dial at {SPEED_MS} ms")
rows = "".join(f' <Function FadeIn="{factor(fade)}" FadeOut="{NOT_SENT}" Duration="{factor(step)}">{fid}</Function>\n'
for fid, fade, step in speeds)
xml = xml.replace(dial.group(0), dial.group(0).replace(" </SpeedDial>\n", rows + " </SpeedDial>\n"), 1)
xml = xml.replace(' <Function ID="0" Type="Scene"', groups + ' <Function ID="0" Type="Scene"', 1)
xml = xml.replace(" </Engine>", functions + " </Engine>", 1)
SHOW.write_text(xml)
link_scripts()
print(f"Added the can patterns to {SHOW.relative_to(ROOT)}")
if __name__ == "__main__":
main()