Add two sets of colour scenes to the test show and light the pads from them.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b8e6b5f24b
commit
6c060720ee
5 files changed
+7049
-3
No files matched your search
@@ -0,0 +1,152 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Add two sets of 16 colour scenes and their buttons to shows/test.show.json.
|
||||
|
||||
Colour 1 paints all 15 cans and colour 2 the four movers, so one colour
|
||||
for each can be on at once. Each set is a solo frame and every scene
|
||||
fades in and out over FADE_MS. Bank 2 (notes 52–67) picks colour 1.
|
||||
Holding Play picks set B: the smoother turns those notes into 68–83 while
|
||||
Play is down. Bank 1 is kept for animations.
|
||||
|
||||
python3 scripts/colour_sets.py && python3 -m showfile write shows/test.show.json -o shows/test.qxw
|
||||
The sliders are Playback sliders over five scenes per set (Dim, R, G, B, W),
|
||||
so they never override a channel. Knobs 1–5 move colour 1's sliders and knobs
|
||||
6–10 colour 2's. Run the smoother with --lock-knobs to make them work only
|
||||
after the Custom pad is pressed; any other pad sends them back to zero (see
|
||||
pad_layer.py).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
SPEC = ROOT / "shows" / "test.show.json"
|
||||
|
||||
FADE_MS = 1000
|
||||
DIMMER, RED, GREEN, BLUE, WHITE = 0, 2, 3, 4, 5
|
||||
PAD_BANK_2_FIRST_NOTE = 52
|
||||
HELD_FIRST_NOTE = 68 # scripts/pad_layer.py sends bank 2 here while Play is held
|
||||
PROFILE = "M-VAVE SMC-PAD"
|
||||
OMNI = 16 # QLC+ MIDI plugin channel that accepts every MIDI channel
|
||||
PAD_MIDI_CH = 9 # the pads send notes on channel 10
|
||||
KNOB_FIRST_CC = 30 # pad knob 1; colour 2's sliders follow colour 1's
|
||||
PAD_PORT = "SMC-PAD Smooth" # scripts/smooth_smc_pad.py; it applies the Play layer
|
||||
|
||||
# name, r, g, b, w. Bottom row first, four to a row. The cans have a white emitter, so the whites use it.
|
||||
COLOURS = (
|
||||
("Red", 255, 0, 0, 0),
|
||||
("Orange", 255, 127, 0, 0),
|
||||
("Yellow", 255, 255, 0, 0),
|
||||
("Lime", 127, 255, 0, 0),
|
||||
("Green", 0, 255, 0, 0),
|
||||
("Spring", 0, 255, 127, 0),
|
||||
("Cyan", 0, 255, 255, 0),
|
||||
("Azure", 0, 127, 255, 0),
|
||||
("Blue", 0, 0, 255, 0),
|
||||
("Violet", 127, 0, 255, 0),
|
||||
("Magenta", 255, 0, 255, 0),
|
||||
("Pink", 255, 40, 120, 0),
|
||||
("Warm", 255, 120, 40, 120),
|
||||
("White", 0, 0, 0, 255),
|
||||
("Cool", 80, 120, 255, 120),
|
||||
)
|
||||
# The top-right pad is the custom colour. Its button shows this swatch, but
|
||||
# its scene is dark: the sliders next to it mix the colour from five scenes.
|
||||
# Its pad lamp stays off.
|
||||
CUSTOM = (("Custom", 255, 60, 0, 0),)
|
||||
CANS = [f"#{n}" for n in range(1, 16)]
|
||||
MOVERS = ["M1", "M2", "M3", "M4"]
|
||||
# Mover channels: 8 is centre brightness, 9 centre strobe, then seven R G B W groups from 10.
|
||||
MOVER_BRIGHTNESS, MOVER_STROBE, MOVER_GROUPS, MOVER_FIRST_COLOUR = 8, 9, 7, 10
|
||||
|
||||
|
||||
def swatch(r: int, g: int, b: int, w: int) -> list[int]:
|
||||
return [min(255, r + w), min(255, g + w), min(255, b + w)]
|
||||
|
||||
|
||||
# Mixer beside each grid: caption, can channel, offset in a mover colour group (None is brightness).
|
||||
SLIDERS = (
|
||||
("Dim", DIMMER, None, [255, 255, 255]),
|
||||
("R", RED, 0, [255, 0, 0]),
|
||||
("G", GREEN, 1, [0, 255, 0]),
|
||||
("B", BLUE, 2, [0, 0, 255]),
|
||||
("W", WHITE, 3, [255, 255, 255]),
|
||||
)
|
||||
|
||||
|
||||
def component(cans: list[str], movers: list[str], can_channel: int, offset: int | None) -> dict:
|
||||
"""One channel kind of this set at full, for a Playback slider to scale."""
|
||||
values = {can: {can_channel: 255} for can in cans}
|
||||
for mover in movers:
|
||||
if offset is None:
|
||||
values[mover] = {MOVER_BRIGHTNESS: 255}
|
||||
else:
|
||||
values[mover] = {MOVER_FIRST_COLOUR + group * 4 + offset: 255 for group in range(MOVER_GROUPS)}
|
||||
return values
|
||||
|
||||
|
||||
def custom_off(cans: list[str], movers: list[str]) -> dict:
|
||||
"""The Custom pad's own scene: dark, so the sliders' scenes set the colour."""
|
||||
values = {can: {DIMMER: 0} for can in cans}
|
||||
values.update({mover: {MOVER_BRIGHTNESS: 0} for mover in movers})
|
||||
return values
|
||||
|
||||
|
||||
def sliders(label: str, first_cc: int) -> list[dict]:
|
||||
"""Playback sliders. Each scales its own scene, so nothing is overridden."""
|
||||
return [{
|
||||
"type": "slider", "caption": caption, "function": f"custom_{label}_{caption}",
|
||||
"x": 400 + index * 52, "y": 10, "w": 48, "h": 200, "fg": fg,
|
||||
"input": {"universe": 1, "cc": [0, first_cc + index]},
|
||||
} for index, (caption, _can, _offset, fg) in enumerate(SLIDERS)]
|
||||
|
||||
|
||||
def main() -> None:
|
||||
spec = json.loads(SPEC.read_text())
|
||||
spec["universes"][1]["input"] = {"plugin": "MIDI", "uid": PAD_PORT, "profile": PROFILE, "channel": OMNI, "line": 0}
|
||||
functions, frames = [], []
|
||||
for si, (label, cans, movers) in enumerate((("1", CANS, []), ("2", [], MOVERS))):
|
||||
buttons = []
|
||||
for i, (name, r, g, b, w) in enumerate(COLOURS + CUSTOM):
|
||||
key = f"colour_{label}_{i + 1}"
|
||||
on = 255
|
||||
values = {can: {DIMMER: on, RED: r, GREEN: g, BLUE: b, WHITE: w} for can in cans}
|
||||
for mover in movers:
|
||||
values[mover] = {MOVER_BRIGHTNESS: on, MOVER_STROBE: 0}
|
||||
for group in range(MOVER_GROUPS):
|
||||
first = MOVER_FIRST_COLOUR + group * 4
|
||||
values[mover].update({first: r, first + 1: g, first + 2: b, first + 3: w})
|
||||
if name == CUSTOM[0][0]:
|
||||
values = custom_off(cans, movers)
|
||||
functions.append({
|
||||
"key": key, "type": "scene", "name": f"{label} {name}",
|
||||
"fade_in": FADE_MS, "fade_out": FADE_MS, "values": values,
|
||||
})
|
||||
sw = swatch(r, g, b, w)
|
||||
dark = sum(sw) > 380
|
||||
button = {
|
||||
"type": "button", "caption": name, "function": key,
|
||||
# 4 wide like the pads: the first four colours are the bottom row.
|
||||
"x": 10 + (i % 4) * 96, "y": 10 + (3 - i // 4) * 66, "w": 90, "h": 60,
|
||||
"bg": sw,
|
||||
"fg": [0, 0, 0] if dark else [255, 255, 255],
|
||||
}
|
||||
button["input"] = {"universe": 1, "note": [PAD_MIDI_CH, (HELD_FIRST_NOTE if si else PAD_BANK_2_FIRST_NOTE) + i]}
|
||||
buttons.append(button)
|
||||
for caption, can_channel, offset, _fg in SLIDERS:
|
||||
functions.append({
|
||||
"key": f"custom_{label}_{caption}", "type": "scene", "name": f"{label} Custom {caption}",
|
||||
"values": component(cans, movers, can_channel, offset),
|
||||
})
|
||||
frames.append({
|
||||
"type": "solo", "caption": f"Colour {label}", "x": 10, "y": 10 + si * 310,
|
||||
"w": 400 + len(SLIDERS) * 52, "h": 300, "children": buttons + sliders(label, KNOB_FIRST_CC + si * len(SLIDERS)),
|
||||
})
|
||||
spec["functions"] = functions
|
||||
spec["vc"] = frames
|
||||
SPEC.write_text(json.dumps(spec, indent=2) + "\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
+18
-3
@@ -6,6 +6,7 @@ first. Note messages do not change these lamps. The colour is three
|
||||
bytes in the preset, written over the Private USB port.
|
||||
|
||||
.venv/bin/python scripts/pad_colours.py --xchc --bank 2
|
||||
.venv/bin/python scripts/pad_colours.py --colour-set --bank 2
|
||||
.venv/bin/python scripts/pad_colours.py --dry-run
|
||||
.venv/bin/python scripts/pad_colours.py --clear
|
||||
.venv/bin/python scripts/pad_colours.py --identify
|
||||
@@ -117,6 +118,18 @@ def xchc_colours(clear: bool = False) -> list[tuple[str, bytes]]:
|
||||
return colours
|
||||
|
||||
|
||||
def colour_set(clear: bool = False) -> list[tuple[str, bytes]]:
|
||||
"""The colours of shows/test.qxw in pad order, then the rest of the bank off."""
|
||||
from colour_sets import COLOURS
|
||||
|
||||
colours = []
|
||||
for name, r, g, b, w in COLOURS:
|
||||
rgb = b"\x00\x00\x00" if clear else bytes(scale(c) for c in led_rgb(r, g, b, w))
|
||||
colours.append((name, rgb))
|
||||
colours.extend(("", b"\x00\x00\x00") for _ in range(16 - len(colours)))
|
||||
return colours
|
||||
|
||||
|
||||
# Preset page whose records light each pad bank. Page 3 also sends notes
|
||||
# 52–67 but its colours are not shown; bank 2 takes them from page 7.
|
||||
BANK_PAGE = {1: 2, 2: 7}
|
||||
@@ -208,8 +221,9 @@ def apply(
|
||||
raise SystemExit(f"the pad did not accept the save ({reply.hex()})")
|
||||
print("Saved on the pad.", flush=True)
|
||||
finally:
|
||||
midiout.close_port()
|
||||
midiin.close_port()
|
||||
for port in (midiout, midiin):
|
||||
port.close_port()
|
||||
port.delete()
|
||||
|
||||
|
||||
def main(argv: list[str] | None = None) -> int:
|
||||
@@ -217,6 +231,7 @@ def main(argv: list[str] | None = None) -> int:
|
||||
parser.add_argument("--bank", type=int, default=1, help="pad bank to write (2 is notes 52–67)")
|
||||
parser.add_argument("--page", type=int, help="write preset page 0–7 instead (page 2 is bank 1, 3 is bank 2; 7 repeats 52–67)")
|
||||
parser.add_argument("--xchc", action="store_true", help="use the solid colour scenes from shows/xchc.qxw")
|
||||
parser.add_argument("--colour-set", action="store_true", help="use the 16 colours from shows/test.qxw")
|
||||
parser.add_argument("--clear", action="store_true", help="store black on every scene pad")
|
||||
parser.add_argument("--identify", action="store_true", help="light each pad page in its own colour")
|
||||
parser.add_argument("--dry-run", action="store_true", help="print the colours and do not open a port")
|
||||
@@ -235,7 +250,7 @@ def main(argv: list[str] | None = None) -> int:
|
||||
raise SystemExit(str(exc)) from exc
|
||||
print(f"Saved on the pad ({written} bytes changed).")
|
||||
return 0
|
||||
palette = xchc_colours(args.clear) if args.xchc else None
|
||||
palette = xchc_colours(args.clear) if args.xchc else colour_set(args.clear) if args.colour_set else None
|
||||
if args.dry_run:
|
||||
seen = set()
|
||||
for name, address, rgb in colour_writes(args.clear, args.bank, palette):
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Set the SMC-PAD lamps: bank 1 off, bank 2 in the colours of shows/test.qxw.
|
||||
|
||||
.venv/bin/python scripts/pad_lamps.py
|
||||
|
||||
Needs the USB Private port. smooth_smc_pad.py does this on start; run this
|
||||
when the pad is read by Chataigne instead.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def set_lamps() -> None:
|
||||
"""Bank 1 lamps off, bank 2 lamps from shows/test.qxw. Needs the USB Private port."""
|
||||
sys.path.insert(0, str(ROOT))
|
||||
sys.path.insert(0, str(ROOT / "scripts"))
|
||||
import pad_colours
|
||||
|
||||
try:
|
||||
pad_colours.apply(True, bank=1)
|
||||
pad_colours.apply(False, bank=2, colours=pad_colours.colour_set())
|
||||
except (SystemExit, Exception) as exc: # the Bluetooth link has no Private port
|
||||
print(f"Lamps not set: {exc}", flush=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
set_lamps()
|
||||
+1453
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user