#!/usr/bin/env python3 """Draw the SMC-PAD layout for shows/test.qxw as shows/test-pads.png. Every label and colour comes from the show's virtual console: a pad shows the caption of the button on its note, and a colour pad that button's colour, so running this again after changing the show brings the picture up to date. Bank 1, Pause off notes 36–51 the cans layer Bank 1, Pause on notes 84–99 the movers layer (padcontroller adds 48) Bank 2 notes 52–67 Colour 1, the cans Bank 2, Play held notes 68–83 Colour 2, the movers and the chases (adds 16) Pad 1 is bottom left, as on the pad; knobs are laid out as in shows/openmic-knobs.png. A knob shows the sliders and speed dials on its CC. python3 scripts/shows/draw_test_pads.py It needs Inkscape to turn the drawing into a PNG. """ from __future__ import annotations import html import re import subprocess import tempfile from pathlib import Path from mover_bank import NOTE_BASE, ROOT SHOW = ROOT / "shows" / "test.qxw" OUT = ROOT / "shows" / "test-pads.png" BG, PANEL, TEXT, MUTED, EDGE = "#1a1a1c", "#232327", "#f2f2f2", "#9a9aa4", "#3a3a42" PAD_W, PAD_H, GAP = 150, 90, 10 KNOB_R, KNOB_DX, KNOB_DY = 40, 150, 130 KNOB_BANK_H = 70 + 2 * KNOB_R + 3 * KNOB_DY + 100 # with room for the bottom labels # Function pads, by the frame their button is in: (fill, edge) GROUPS = {"Can patterns": ("#3b2a55", "#b79cff"), "Movement": ("#14423f", "#6fe0d2")} CHASE, STROBE = ("#1d3557", "#8fb8ff"), ("#4a4a50", "#ffffff") LAYERS = ( ("Bank 1 · cans", "Pause off · pads 1–16", 36), ("Bank 1 · movers", "Pause on", 84), ("Bank 2 · Colour 1", "the cans · pads 17–32", 52), ("Bank 2 · Colour 2", "Play held · the movers and the chases", 68), ) def argb(value: str) -> str | None: """#rrggbb from a QLC+ colour, or None for Default.""" return None if value == "Default" else "#%06x" % (int(value) & 0xFFFFFF) def text_colour(fill: str) -> str: r, g, b = (int(fill[i:i + 2], 16) for i in (1, 3, 5)) return "#111111" if 0.299 * r + 0.587 * g + 0.114 * b > 150 else TEXT def buttons(vc: str) -> dict[int, tuple[str, str | None, str]]: """note -> (caption, background colour, the solo frame or frame it's in) for each button on a channel-10 note.""" out = {} frames: list[tuple[int, str]] = [] # (position, caption) of each frame opening for m in re.finditer(r'<(?:Solo)?Frame Caption="([^"]*)"', vc): frames.append((m.start(), m.group(1))) for m in re.finditer(r'', vc, re.S): inp = re.search(r'', m.group(2)) if inp is None or not 0 <= int(inp.group(1)) - NOTE_BASE < 128: continue frame = max((f for f in frames if f[0] < m.start()), default=(0, ""))[1] bg = re.search(r"([^<]*)", m.group(2)) out[int(inp.group(1)) - NOTE_BASE] = (html.unescape(m.group(1)), argb(bg.group(1)) if bg else None, frame) return out def knobs(vc: str) -> dict[int, list[str]]: """CC -> captions of the sliders and speed dials on it.""" out: dict[int, list[str]] = {} for m in re.finditer(r'<(Slider|SpeedDial) Caption="([^"]*)" ID="\d+"(.*?)', vc, re.S): inp = re.search(r'', m.group(3)) if inp and int(inp.group(1)) < 128: out.setdefault(int(inp.group(1)), []).append(html.unescape(m.group(2))) return out def wrap(caption: str) -> list[str]: words, lines = caption.split(), [""] for w in words: if lines[-1] and len(lines[-1]) + 1 + len(w) > 11: lines.append(w) else: lines[-1] = f"{lines[-1]} {w}".strip() return lines def pad(x: int, y: int, number: int, info: tuple[str, str | None, str] | None) -> str: if info is None or info[0].startswith("Button "): return (f'' f'{number}') caption, colour, frame = info if colour: fill, edge = colour, "#ffffff" elif frame in GROUPS: fill, edge = GROUPS[frame] elif "Strobe" in caption: fill, edge = STROBE else: fill, edge = CHASE ink = text_colour(fill) lines = wrap(caption) first = y + PAD_H / 2 + 8 - (len(lines) - 1) * 12 label = "".join(f'{html.escape(t)}' for i, t in enumerate(lines)) return (f'{number}' + label) def grid(x: int, y: int, title: str, sub: str, base: int, info: dict, first_pad: int) -> str: out = [f'{html.escape(title)}', f'{html.escape(sub)}'] top = y + 55 for i in range(16): col, row = i % 4, 3 - i // 4 # pad 1 bottom left out.append(pad(x + col * (PAD_W + GAP), top + row * (PAD_H + GAP), first_pad + i, info.get(base + i))) return "".join(out) def knob_bank(x: int, y: int, bank: int, info: dict[int, list[str]]) -> str: out = [f'Knobs · bank {bank}'] for i in range(8): number = (bank - 1) * 8 + i + 1 cx, cy = x + KNOB_R + 20 + (i % 2) * KNOB_DX, y + 70 + KNOB_R + (3 - i // 2) * KNOB_DY names = info.get(29 + number, []) stroke = TEXT if names else EDGE out.append(f'' f'{number}') label = " / ".join(dict.fromkeys(names)) # Peak and Brightness share knob 15 if label: out.append(f'' f'{html.escape(label)}') return "".join(out) def main() -> None: vc = SHOW.read_text().split("")[1] info, knob_info = buttons(vc), knobs(vc) panel_w = 4 * PAD_W + 3 * GAP col2, col3 = 60 + panel_w + 70, 60 + 2 * (panel_w + 70) row_h = 55 + 4 * PAD_H + 3 * GAP + 80 width, height = col3 + 2 * KNOB_DX + 60, max(60 + 2 * row_h, 70 + 2 * KNOB_BANK_H) body = [] for k, (title, sub, base) in enumerate(LAYERS): x, y = (60, col2)[k % 2], 70 + (k // 2) * row_h body.append(grid(x, y, title, sub, base, info, 1 if base in (36, 84) else 17)) body += [knob_bank(col3, 70, 1, knob_info), knob_bank(col3, 70 + KNOB_BANK_H, 2, knob_info)] svg = f''' {"".join(body)} ''' with tempfile.TemporaryDirectory() as tmp: src = Path(tmp) / "test-pads.svg" src.write_text(svg) subprocess.run(["inkscape", str(src), "--export-type=png", f"--export-filename={OUT}", "--export-dpi=96"], check=True, capture_output=True) print(f"Drew {OUT.relative_to(ROOT)} ({width}x{height})") if __name__ == "__main__": main()