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>
This commit is contained in:
jimmyandClaude Opus 5.5 committed 2026-10-23 13:57:13 +13:00
1 parent e7e1cf656b
commit 4fd11445e8
9 files changed
+1622 -98

No files matched your search

+9
View File
@@ -37,6 +37,15 @@ the stage view, make sure the MIDI controller is working and the simulator is on
to 127.0.0.1 only, so testing drives the simulator and never the real rig. Keep
it that way; don't point it at a 192.168.1.x node.
## Cans 3–6 are always static
The row of 4 (#3–#6, fixture IDs 2–5) never animates. Chases, patterns, loops,
strobes and side dimmer holds leave them out, so they keep the Colour 1 scene
and their own dimmer knob whatever else runs. Their colour stays HTP, unlike the
other cans. When adding an animation for the cans, build it on the other 11
(the groups `Sides` and `Strobe cans` in test.qxw already skip them) and don't
write any FixtureVal for IDs 2–5.
Tell the user what was down and what you did about it. The preview
configurations in `.claude/launch.json` run separate copies on other ports
(8770, 8766) and don't count as the services being up.
+1
View File
@@ -7,6 +7,7 @@ QLC+ show files, fixture definitions, and generators for the XCHC stage
```
fixtures/ Fixture definitions (.qxf) — install into QLC+ if needed
rgbscripts/ RGB matrix scripts; scripts/shows/can_patterns.py links them into ~/.qlcplus/rgbscripts
shows/ Workspaces to open in QLC+
xchc.qxw Main show (patterns + movers, unified VC)
simple.qxw Manual board: M1/M2 pads, shared + individual RGBW
+23
View File
@@ -21,6 +21,15 @@ sliders change, so when the one that is on goes off, settle asks for the two
knobs one step off and then back (nudge() and positions()). Swapping needs
none: the new EFX writes over the old one's offset. moving holds the note whose
EFX is on, from the presses: only a guess, as QLC+ sends no feedback for it.
The cans' pattern pads (pads 1–8 on the cans layer: notes 36–43) each toggle a
pattern, in a solo frame like the movement pads; pattern holds the note of the
one that is on. A Colour 1 pad starts a colour scene on the cans, and the
newest function wins their colour, so the scene would cover the pattern. While
a pattern is on, a Colour 1 press sets restart_pattern, and the caller sends
pattern_tap() twice a moment later, off and on again, so the pattern restarts on
top in the new colour. Taps sent with the colour itself land in the same QLC+
tick and change nothing.
"""
from __future__ import annotations
@@ -37,6 +46,7 @@ KNOB_CHANNEL = 0
# Wander, Ballyhoo, Circle, Sweep; Diamond, Square, Corners, Leaf; Tilt: pads 13–16, 9–12, 5
RELATIVE_NOTES = (96, 97, 98, 99, 92, 93, 94, 95, 88)
POSITION_CCS = (38, 39) # knobs 9 and 10: the movers' Pan and Tilt
PATTERN_NOTES = range(36, 44) # the can patterns: pads 1–8 on the cans layer
class PlayLayer:
@@ -49,6 +59,9 @@ class PlayLayer:
self.position = {cc: 0 for cc in POSITION_CCS}
self.moving: int | None = None
self.settle = False # a relative EFX just went off: the caller sends nudge(), then positions()
self.pattern: int | None = None
self.pattern_channel = 0
self.restart_pattern = False # a Colour 1 press covered the pattern: the caller sends pattern_tap() twice
# set -> (channel, note sent) of the colour that is on
self.colours: dict[int, tuple[int, int] | None] = {1: None, 2: None}
@@ -83,6 +96,11 @@ class PlayLayer:
self.settle = True
else:
self.moving = note
elif note in PATTERN_NOTES and is_on:
self.pattern = None if note == self.pattern else note
self.pattern_channel = channel
elif FIRST_NOTE <= note <= LAST_NOTE and is_on and self.pattern is not None:
self.restart_pattern = True
if is_on and FIRST_NOTE <= out <= LAST_NOTE + SHIFT:
colour_set = 1 if out <= LAST_NOTE else 2
pressed = (channel, out)
@@ -100,12 +118,17 @@ class PlayLayer:
def reopen(self) -> list[list[int]]:
"""QLC+ has loaded the show: everything is off. Press the colours that were on."""
self.moving = None
self.pattern = None
out = []
for colour in self.colours.values():
if colour is not None:
out += tap(*colour)
return out
def pattern_tap(self) -> list[list[int]]:
"""A tap of the can pattern that is on, to toggle it; nothing once none is."""
return [] if self.pattern is None else tap(self.pattern_channel, self.pattern)
def nudge(self) -> list[list[int]]:
"""Pan and Tilt one step off their knobs, so QLC+ writes them again."""
return [[0xB0 | KNOB_CHANNEL, cc, v - 1 if v else 1] for cc, v in self.position.items()]
+4
View File
@@ -60,6 +60,7 @@ VIRTUAL_NAME = "padcontroller"
COLOURS_FILE = Path(os.environ.get("XDG_STATE_HOME", Path.home() / ".local" / "state")) / "padcontroller" / "colours.json"
REOPEN_DELAY = 1.5 # s for QLC+ to finish loading the virtual console
SETTLE_DELAY = 0.1 # s for QLC+ to stop a relative EFX before the knob nudge, and between its two steps
RESTART_DELAY = 0.1 # s after a Colour 1 press before the can pattern's off tap, and between it and the on tap
# Bluetooth first when the pad is paired, USB otherwise.
SOURCE_HINTS = (
"SMC-PAD Bluetooth",
@@ -265,6 +266,9 @@ def main() -> None:
if layer.settle:
layer.settle = False
later += [(now + SETTLE_DELAY, layer.nudge), (now + 2 * SETTLE_DELAY, layer.positions)]
if layer.restart_pattern:
layer.restart_pattern = False
later += [(now + RESTART_DELAY, layer.pattern_tap), (now + 2 * RESTART_DELAY, layer.pattern_tap)]
for due in [item for item in later if now >= item[0]]:
later.remove(due)
for out in due[1]():
+68
View File
@@ -0,0 +1,68 @@
/*
Steps: play the steps written in the "steps" property, one after another.
steps is the steps separated by ";", each the pixels' colours as rrggbb hex
separated by ",", left to right and then top to bottom. Missing pixels are
off. The matrix's own colour is not used.
shows/test.qxw's can patterns use it (scripts/shows/can_patterns.py): each is
one RGB matrix running for as long as the pattern does, so a chase started
after it lands on top, where a chaser of scenes would start a newer scene
every step. With a Mask blend, grey levels dim the colour under it.
QLC+ loads it from ~/.qlcplus/rgbscripts, where can_patterns.py links it.
*/
var testAlgo;
(
function()
{
var algo = new Object;
algo.apiVersion = 2;
algo.name = "Steps";
algo.author = "qlcplus shows";
algo.acceptColors = 0;
algo.properties = new Array();
algo.steps = [[0]];
algo.text = "000000";
algo.properties.push("name:steps|type:string|display:Steps|write:setSteps|read:getSteps");
algo.setSteps = function(_steps)
{
algo.text = _steps;
algo.steps = String(_steps).split(";").map(function(step) {
return step.split(",").map(function(hex) { return parseInt(hex, 16) || 0; });
});
};
algo.getSteps = function()
{
return algo.text;
};
algo.rgbMap = function(width, height, rgb, step)
{
var pixels = algo.steps[step % algo.steps.length];
var map = new Array(height);
for (var y = 0; y < height; y++)
{
map[y] = new Array(width);
for (var x = 0; x < width; x++)
{
var i = y * width + x;
map[y][x] = i < pixels.length ? pixels[i] : 0;
}
}
return map;
};
algo.rgbMapStepCount = function(width, height)
{
return algo.steps.length;
};
testAlgo = algo;
return algo;
}
)();
+45
View File
@@ -0,0 +1,45 @@
/*
Swap: every pixel in one colour, then every pixel in the other.
Two steps, all pixels lit with the step's colour. Give the RGB matrix a start
and an end colour and QLC+ hands step 0 the start colour and step 1 the end
colour, so the matrix swaps between them; with a fade in it crossfades.
shows/test.qxw's Odd Even and Left Right cans patterns use it, two matrices
at once with their colours the other way round (scripts/shows/can_patterns.py).
QLC+ loads it from ~/.qlcplus/rgbscripts, where can_patterns.py links it.
*/
var testAlgo;
(
function()
{
var algo = new Object;
algo.apiVersion = 2;
algo.name = "Swap";
algo.author = "qlcplus shows";
algo.acceptColors = 2;
algo.properties = new Array();
algo.rgbMap = function(width, height, rgb, step)
{
var map = new Array(height);
for (var y = 0; y < height; y++)
{
map[y] = new Array(width);
for (var x = 0; x < width; x++)
map[y][x] = rgb;
}
return map;
};
algo.rgbMapStepCount = function(width, height)
{
return 2;
};
testAlgo = algo;
return algo;
}
)();
+363
View File
@@ -0,0 +1,363 @@
#!/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()
+1074 -98
View File
File diff suppressed because it is too large. Load diff
+35
View File
@@ -139,6 +139,41 @@ class PlayLayerTest(unittest.TestCase):
layer.handle([0x99, 49, 100])
self.assertEqual((layer.moving, layer.settle), (None, True))
def test_colour_1_restarts_the_can_pattern_on_top(self):
layer = PlayLayer()
layer.handle([0x99, 40, 127])
self.assertEqual(layer.handle([0x99, 57, 127]), [[0x99, 57, 127]])
self.assertTrue(layer.restart_pattern)
self.assertEqual(layer.pattern_tap(), [[0x99, 40, 127], [0x89, 40, 0]])
self.assertEqual(layer.pattern, 40)
def test_colour_1_leaves_the_cans_alone_with_no_pattern(self):
layer = PlayLayer()
layer.handle([0x99, 36, 127])
layer.handle([0x99, 36, 127])
self.assertEqual(layer.handle([0x99, 57, 127]), [[0x99, 57, 127]])
self.assertFalse(layer.restart_pattern)
self.assertEqual(layer.pattern_tap(), [])
def test_a_new_pattern_takes_over_in_the_solo_frame(self):
layer = PlayLayer()
layer.handle([0x99, 40, 127])
layer.handle([0x99, 37, 127])
self.assertEqual(layer.pattern, 37)
def test_colour_2_does_not_restart_the_can_pattern(self):
layer = PlayLayer()
layer.handle([0x99, 43, 127])
layer.handle(PLAY_DOWN)
self.assertEqual(layer.handle([0x99, 57, 127]), [[0x99, 73, 127]])
self.assertFalse(layer.restart_pattern)
def test_pattern_pads_on_the_movers_layer_are_not_can_patterns(self):
layer = PlayLayer()
layer.handle(PAUSE_DOWN)
layer.handle([0x99, 42, 127])
self.assertIsNone(layer.pattern)
def test_every_movement_pad_settles_when_it_goes_off(self):
for pad_note, sent in ((51, 99), (44, 92), (47, 95), (40, 88)):
layer = PlayLayer()