diff --git a/CLAUDE.md b/CLAUDE.md index f1ac226..a199b0e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -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. diff --git a/README.md b/README.md index 3dc40dd..fee2218 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/padcontroller/layer.py b/padcontroller/layer.py index fbf1f93..8481ffa 100644 --- a/padcontroller/layer.py +++ b/padcontroller/layer.py @@ -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()] diff --git a/padcontroller/midi.py b/padcontroller/midi.py index 7691edc..452dad7 100644 --- a/padcontroller/midi.py +++ b/padcontroller/midi.py @@ -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](): diff --git a/rgbscripts/steps.js b/rgbscripts/steps.js new file mode 100644 index 0000000..a840528 --- /dev/null +++ b/rgbscripts/steps.js @@ -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; + } +)(); diff --git a/rgbscripts/swap.js b/rgbscripts/swap.js new file mode 100644 index 0000000..895cd98 --- /dev/null +++ b/rgbscripts/swap.js @@ -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; + } +)(); diff --git a/scripts/shows/can_patterns.py b/scripts/shows/can_patterns.py new file mode 100644 index 0000000..4f81790 --- /dev/null +++ b/scripts/shows/can_patterns.py @@ -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''' + + Forward + {run_order} + Steps + {CYAN} + {mode} + {GROUP_RING} + + +''' + + +def group(gid: int, name: str, cans: list[str]) -> str: + heads = "\n".join(f' 0' for x, n in enumerate(cans)) + return f''' + {name} + +{heads} + +''' + + +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''' + + Forward + Loop + Swap + {start} + {end} + RGB + {gid} + +''' + + +def collection(fid: int, name: str, steps: list[int]) -> str: + rows = "\n".join(f' {s}' for i, s in enumerate(steps)) + return f' \n{rows}\n \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}\n' + + appearance(indent + " ") + + f'{indent} \n' + f'{indent} True\n{indent} True\n' + f'{indent} False\n{indent} False\n' + f'{indent} False\n{indent} False\n{indent} False\n' + f'{buttons}{indent}\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' .*? \n', xml, re.S).group(0) + head = m[:m.index(" (#[0-9a-f]{6})', m) + end_note = COLOUR_1_NOTE if start_note == COLOUR_2_NOTE else COLOUR_2_NOTE + controls = "".join( + f' \n {kind}\n {c}\n' + f' \n \n' + for k, (kind, note) in enumerate((("StartColor", start_note), ("EndColor", end_note))) + for i, c in enumerate(colours)) + return head + controls + " \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'\n', + xml, re.S) + if empty is None or "\n ")[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' \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 = '' + 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"( {CANS[name]}\n {name}\n(?: .*\n)*? 1\n)(?! )", + r"\1 2,3,4,5\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' .*? \n', xml, re.S) + if dial is None or f"" not in dial.group(0): + raise SystemExit(f"Couldn't find the Speed dial at {SPEED_MS} ms") + rows = "".join(f' {fid}\n' + for fid, fade, step in speeds) + xml = xml.replace(dial.group(0), dial.group(0).replace(" \n", rows + " \n"), 1) + xml = xml.replace(' ", functions + " ", 1) + SHOW.write_text(xml) + link_scripts() + print(f"Added the can patterns to {SHOW.relative_to(ROOT)}") + + +if __name__ == "__main__": + main() diff --git a/shows/test.qxw b/shows/test.qxw index b0a1fb1..a8aa0d3 100644 --- a/shows/test.qxw +++ b/shows/test.qxw @@ -203,6 +203,7 @@
191
8 1 + 2,3,4,5 beamZ @@ -322,6 +323,59 @@ 0 0 + + Cans odd + + 0 + 0 + 0 + 0 + 0 + 0 + + + Cans even + + 0 + 0 + 0 + 0 + 0 + + + Cans left + + 0 + 0 + 0 + 0 + 0 + 0 + + + Cans right + + 0 + 0 + 0 + 0 + 0 + + + Cans ring + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2,255,3,0,4,0,5,0 @@ -1303,6 +1357,200 @@ 75 78 + + + Forward + Loop + Steps + 4278255615 + White + 13 + + + + + Forward + Loop + Steps + 4278255615 + RGB + 13 + + + + 81 + 80 + + + + Forward + Loop + Swap + 4278255615 + 4278190335 + RGB + 9 + + + + Forward + Loop + Swap + 4278190335 + 4278255615 + RGB + 10 + + + 83 + 84 + 80 + + + + Forward + Loop + Swap + 4278255615 + 4278190335 + RGB + 11 + + + + Forward + Loop + Swap + 4278190335 + 4278255615 + RGB + 12 + + + 86 + 87 + 80 + + + + Forward + Loop + Steps + 4278255615 + RGB + 13 + + + + + Forward + Loop + Steps + 4278255615 + White + 13 + + + + 89 + 90 + + + + Forward + PingPong + Steps + 4278255615 + RGB + 13 + + + + + Forward + PingPong + Steps + 4278255615 + White + 13 + + + + 92 + 93 + + + + Forward + PingPong + Steps + 4278255615 + RGB + 13 + + + + + Forward + PingPong + Steps + 4278255615 + White + 13 + + + + 95 + 96 + + + + Forward + PingPong + Steps + 4278255615 + RGB + 13 + + + + + Forward + PingPong + Steps + 4278255615 + White + 13 + + + + 98 + 99 + + + + Forward + Loop + Steps + 4278255615 + RGB + 13 + + + + + Forward + Loop + Steps + 4278255615 + White + 13 + + + + 101 + 102 + @@ -1920,8 +2168,7 @@ Toggle 100 - - - - - - - - + + True + True + False + False + False + False + False + + + + + + + + + @@ -2219,7 +2492,7 @@ None Default - + True True True @@ -2702,6 +2975,694 @@ 68 + + + + Sunken + Default + Default + None + Default + + + 6 + + StartColor + #ff0000 + + + + StartColor + #ff7f00 + + + + StartColor + #ffbf00 + + + + StartColor + #ffff00 + + + + StartColor + #7fff00 + + + + StartColor + #00ff00 + + + + StartColor + #00ff7f + + + + StartColor + #00ffff + + + + StartColor + #007fff + + + + StartColor + #0000ff + + + + StartColor + #7f00ff + + + + StartColor + #ff00ff + + + + StartColor + #ff2878 + + + + StartColor + #ff7828 + + + + StartColor + #ffffff + + + + StartColor + #5078ff + + + + EndColor + #ff0000 + + + + EndColor + #ff7f00 + + + + EndColor + #ffbf00 + + + + EndColor + #ffff00 + + + + EndColor + #7fff00 + + + + EndColor + #00ff00 + + + + EndColor + #00ff7f + + + + EndColor + #00ffff + + + + EndColor + #007fff + + + + EndColor + #0000ff + + + + EndColor + #7f00ff + + + + EndColor + #ff00ff + + + + EndColor + #ff2878 + + + + EndColor + #ff7828 + + + + EndColor + #ffffff + + + + EndColor + #5078ff + + + + + + + Sunken + Default + Default + None + Default + + + 6 + + StartColor + #ff0000 + + + + StartColor + #ff7f00 + + + + StartColor + #ffbf00 + + + + StartColor + #ffff00 + + + + StartColor + #7fff00 + + + + StartColor + #00ff00 + + + + StartColor + #00ff7f + + + + StartColor + #00ffff + + + + StartColor + #007fff + + + + StartColor + #0000ff + + + + StartColor + #7f00ff + + + + StartColor + #ff00ff + + + + StartColor + #ff2878 + + + + StartColor + #ff7828 + + + + StartColor + #ffffff + + + + StartColor + #5078ff + + + + EndColor + #ff0000 + + + + EndColor + #ff7f00 + + + + EndColor + #ffbf00 + + + + EndColor + #ffff00 + + + + EndColor + #7fff00 + + + + EndColor + #00ff00 + + + + EndColor + #00ff7f + + + + EndColor + #00ffff + + + + EndColor + #007fff + + + + EndColor + #0000ff + + + + EndColor + #7f00ff + + + + EndColor + #ff00ff + + + + EndColor + #ff2878 + + + + EndColor + #ff7828 + + + + EndColor + #ffffff + + + + EndColor + #5078ff + + + + + + + Sunken + Default + Default + None + Default + + + 6 + + StartColor + #ff0000 + + + + StartColor + #ff7f00 + + + + StartColor + #ffbf00 + + + + StartColor + #ffff00 + + + + StartColor + #7fff00 + + + + StartColor + #00ff00 + + + + StartColor + #00ff7f + + + + StartColor + #00ffff + + + + StartColor + #007fff + + + + StartColor + #0000ff + + + + StartColor + #7f00ff + + + + StartColor + #ff00ff + + + + StartColor + #ff2878 + + + + StartColor + #ff7828 + + + + StartColor + #ffffff + + + + StartColor + #5078ff + + + + EndColor + #ff0000 + + + + EndColor + #ff7f00 + + + + EndColor + #ffbf00 + + + + EndColor + #ffff00 + + + + EndColor + #7fff00 + + + + EndColor + #00ff00 + + + + EndColor + #00ff7f + + + + EndColor + #00ffff + + + + EndColor + #007fff + + + + EndColor + #0000ff + + + + EndColor + #7f00ff + + + + EndColor + #ff00ff + + + + EndColor + #ff2878 + + + + EndColor + #ff7828 + + + + EndColor + #ffffff + + + + EndColor + #5078ff + + + + + + + Sunken + Default + Default + None + Default + + + 6 + + StartColor + #ff0000 + + + + StartColor + #ff7f00 + + + + StartColor + #ffbf00 + + + + StartColor + #ffff00 + + + + StartColor + #7fff00 + + + + StartColor + #00ff00 + + + + StartColor + #00ff7f + + + + StartColor + #00ffff + + + + StartColor + #007fff + + + + StartColor + #0000ff + + + + StartColor + #7f00ff + + + + StartColor + #ff00ff + + + + StartColor + #ff2878 + + + + StartColor + #ff7828 + + + + StartColor + #ffffff + + + + StartColor + #5078ff + + + + EndColor + #ff0000 + + + + EndColor + #ff7f00 + + + + EndColor + #ffbf00 + + + + EndColor + #ffff00 + + + + EndColor + #7fff00 + + + + EndColor + #00ff00 + + + + EndColor + #00ff7f + + + + EndColor + #00ffff + + + + EndColor + #007fff + + + + EndColor + #0000ff + + + + EndColor + #7f00ff + + + + EndColor + #ff00ff + + + + EndColor + #ff2878 + + + + EndColor + #ff7828 + + + + EndColor + #ffffff + + + + EndColor + #5078ff + + + @@ -3035,6 +3996,21 @@ 52 45 50 + 81 + 83 + 84 + 86 + 87 + 89 + 90 + 92 + 93 + 95 + 96 + 98 + 99 + 101 + 102 diff --git a/tests/test_pad_layer.py b/tests/test_pad_layer.py index f2d9604..c4f5a58 100644 --- a/tests/test_pad_layer.py +++ b/tests/test_pad_layer.py @@ -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()