Draw the test show's pad layout.
shows/test-pads.png shows both banks of pads on every layer (bank 1 on the cans and, with Pause, the movers; bank 2 as Colour 1 and, with Play held, Colour 2) and what each knob does. scripts/shows/draw_test_pads.py reads the labels and colours from the show's virtual console, so running it again brings the picture up to date. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c71b6da9d9
commit
9ebe3a5af1
2 files changed
+181
No files matched your search
@@ -0,0 +1,181 @@
|
||||
#!/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'<Button Caption="([^"]*)" ID="\d+" Icon="">(.*?)</Button>', vc, re.S):
|
||||
inp = re.search(r'<Input Universe="1" Channel="(\d+)"/>', 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"<BackgroundColor>([^<]*)</BackgroundColor>", 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+"(.*?)</\1>', vc, re.S):
|
||||
inp = re.search(r'<Input Universe="1" Channel="(\d+)"/>', 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'<rect x="{x}" y="{y}" width="{PAD_W}" height="{PAD_H}" rx="10" fill="none" stroke="{EDGE}" '
|
||||
f'stroke-width="2" stroke-dasharray="6 6"/>'
|
||||
f'<text x="{x + 10}" y="{y + 22}" class="num" style="fill:{MUTED}">{number}</text>')
|
||||
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'<text x="{x + PAD_W / 2}" y="{first + i * 24}" class="label" style="fill:{ink}" '
|
||||
f'text-anchor="middle">{html.escape(t)}</text>' for i, t in enumerate(lines))
|
||||
return (f'<rect x="{x}" y="{y}" width="{PAD_W}" height="{PAD_H}" rx="10" fill="{fill}" stroke="{edge}" '
|
||||
f'stroke-width="3"/><text x="{x + 10}" y="{y + 22}" class="num" style="fill:{ink}" opacity="0.7">{number}</text>'
|
||||
+ label)
|
||||
|
||||
|
||||
def grid(x: int, y: int, title: str, sub: str, base: int, info: dict, first_pad: int) -> str:
|
||||
out = [f'<text x="{x}" y="{y}" class="title">{html.escape(title)}</text>',
|
||||
f'<text x="{x}" y="{y + 30}" class="sub">{html.escape(sub)}</text>']
|
||||
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'<text x="{x}" y="{y}" class="title">Knobs · bank {bank}</text>']
|
||||
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'<circle cx="{cx}" cy="{cy}" r="{KNOB_R}" fill="{PANEL}" stroke="{stroke}" stroke-width="3"/>'
|
||||
f'<text x="{cx}" y="{cy + 9}" class="knob" style="fill:{stroke}" text-anchor="middle">{number}</text>')
|
||||
label = " / ".join(dict.fromkeys(names)) # Peak and Brightness share knob 15
|
||||
if label:
|
||||
out.append(f'<text x="{cx}" y="{cy + KNOB_R + 24}" class="small" text-anchor="middle">'
|
||||
f'{html.escape(label)}</text>')
|
||||
return "".join(out)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
vc = SHOW.read_text().split("<VirtualConsole>")[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'''<svg xmlns="http://www.w3.org/2000/svg" width="{width}" height="{height}" viewBox="0 0 {width} {height}">
|
||||
<style>
|
||||
text {{ font-family: "DejaVu Sans", sans-serif; fill: {TEXT}; }}
|
||||
.title {{ font-size: 30px; font-weight: bold; }}
|
||||
.sub {{ font-size: 20px; fill: {MUTED}; }}
|
||||
.num {{ font-size: 15px; font-weight: bold; }}
|
||||
.label {{ font-size: 19px; }}
|
||||
.knob {{ font-size: 26px; font-weight: bold; }}
|
||||
.small {{ font-size: 18px; }}
|
||||
</style>
|
||||
<rect width="100%" height="100%" fill="{BG}"/>
|
||||
{"".join(body)}
|
||||
</svg>
|
||||
'''
|
||||
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()
|
||||
Reference in new issue
Block a user