#!/usr/bin/env python3
"""Add a Ballyhoo pad for the movers to shows/test.qxw, on note 94.
On the movers layer (Pause on), pad 11 toggles a fast, wide figure of eight
around wherever the Pan and Tilt knobs (9 and 10, CC 38 and 39) put the movers,
as Wander does:
94 Ballyhoo an Eight about ±85° of pan and ±26° of tilt, 2.5 s round
All four start together. M1 and M4 turn the other way to M2 and M3, so the
same move mirrors left to right and front to back, and the beams sweep out
and cross in the middle together. It fades in over 0.5 s, which QLC+ counts inside each 3 s round. When it goes off,
the pad controller nudges the two knobs so QLC+ drops its last offset
(padcontroller/layer.py).
python3 scripts/shows/mover_ballyhoo.py
Run it once on a show with Wander and without Ballyhoo; it stops if Ballyhoo
is already there. QLC+ has to reopen the show to see it.
"""
from __future__ import annotations
import re
from mover_bank import LEFT_TO_RIGHT, NO_FUNCTION, ROOT, button, note
SHOW = ROOT / "shows" / "test.qxw"
WIDTH, HEIGHT = 40, 24 # of 255 each way: 540° of pan, 270° of tilt
ROUND_MS = 3000
FADE_IN_MS = 500
def efx(fid: int) -> str:
fixtures = "".join(f""" {f}
0
0Forward0
""" for f in LEFT_TO_RIGHT)
# Relative: the EFX adds its offset from 127 to the Pan and Tilt sliders' levels.
return f"""
{fixtures} ParallelForwardLoopEight{WIDTH}{HEIGHT}0011271012710
"""
def main() -> None:
xml = SHOW.read_text()
if 'Name="Movers ballyhoo"' in xml:
raise SystemExit(f"{SHOW.relative_to(ROOT)} already has the movers ballyhoo")
engine, console = xml.split("")
fid = max(int(i) for i in re.findall(r'", efx(fid) + " ", 1)
# Beside Wander, on the pad after it.
wander = re.search(r' \n', xml, re.S).group(0)
xml = xml.replace(wander, wander + button(wid, "Ballyhoo", 190, 100, 90, fid, note(46)), 1)
SHOW.write_text(xml)
print(f"Added the movers ballyhoo to {SHOW.relative_to(ROOT)} (function {fid}, widget {wid})")
if __name__ == "__main__":
main()