Files
qlcplus/scripts/colour_sets.py
T

153 lines
6.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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()