#!/usr/bin/env python3
"""Add Pan, Tilt, Focus and Rotate sliders for the movers to shows/test.qxw.
As in templeoftechno.qxw, knobs 9–12 (CC 38–41) drive all four movers at once:
Knob 9 CC 38 Pan channel 0
Knob 10 CC 39 Tilt channel 2
Knob 11 CC 40 Focus channel 7
Knob 12 CC 41 Rotate channel 5 (Lens Rotate)
They sit in a Movers position frame beside Sound peak, below the cans' chase runs.
python3 scripts/shows/mover_position.py
Run it once on a show without them; it stops if they are already there.
QLC+ has to reopen the show to see them.
"""
from __future__ import annotations
import re
from pathlib import Path
from mover_bank import LEFT_TO_RIGHT, NO_FUNCTION, ROOT, appearance, frame
SHOW = ROOT / "shows" / "test.qxw"
# Caption, CC, mover channel, starting value: temple techno's.
SLIDERS = (
("Pan", 38, 0, 0),
("Tilt", 39, 2, 0),
("Focus", 40, 7, 70),
("Rotate", 41, 5, 0),
)
def level(wid: int, caption: str, x: int, cc: int, channel: int, value: int, indent: str = " ") -> str:
rows = "".join(f'{indent} {channel}\n' for f in LEFT_TO_RIGHT)
return (f'{indent}\n'
f'{indent} \n'
+ appearance(indent + " ", "Sunken")
+ f'{indent} \n'
f'{indent} Level\n'
f'{indent} \n{rows}{indent} \n'
f'{indent} \n{indent} {NO_FUNCTION}\n{indent} \n{indent}\n')
def main() -> None:
xml = SHOW.read_text()
if 'Caption="Movers position"' in xml:
raise SystemExit(f"{SHOW.relative_to(ROOT)} already has the mover position sliders")
next_id = max(int(i) for i in re.findall(r' ID="(\d+)"', xml.split("")[1])
if int(i) != NO_FUNCTION) + 1
sliders = "".join(level(next_id + 1 + i, caption, 10 + 58 * i, cc, channel, value)
for i, (caption, cc, channel, value) in enumerate(SLIDERS))
widgets = frame(next_id, "Movers position", 420, 630, 10 + 58 * len(SLIDERS), 250, sliders)
xml = xml.replace(" \n ", widgets + " \n ", 1)
SHOW.write_text(xml)
print(f"Added the mover position sliders to {SHOW.relative_to(ROOT)} (widgets from ID {next_id})")
if __name__ == "__main__":
main()