Press the colours again when a restarted QLC+ links itself to the pad controller.
The pad controller only took a QLC+ reload as one when it had to make the link to QLC+ itself. A restarted QLC+ often subscribes to the virtual port on its own as it opens the show, before the next check, so the colours stayed off. Each check now also notes the QLC+ process and port it feeds (qlc_feeds), and a new one counts as a reload too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4fd11445e8
commit
cf94c7b1ba
2 files changed
+53
-15
No files matched your search
+32
-14
@@ -15,8 +15,12 @@ turns up) and re-links QLC+ to the virtual port after a restart, so QLC+ can sta
|
||||
|
||||
QLC+ reopens its MIDI port when it loads a show, so a new link to QLC+ while
|
||||
the pad controller runs means the show has just loaded with every button off.
|
||||
REOPEN_DELAY later it presses the last colour pads again (see PlayLayer.colours),
|
||||
which it keeps in COLOURS_FILE so they outlive a restart of the pad controller.
|
||||
That is a link the pad controller had to make, or one QLC+ made itself: a
|
||||
restarted QLC+ subscribes to the virtual port on its own as it opens the show,
|
||||
before the next check, so a QLC+ process or port fed that wasn't at the last
|
||||
check counts too (qlc_feeds). REOPEN_DELAY later it presses the last colour pads
|
||||
again (see PlayLayer.colours), which it keeps in COLOURS_FILE so they outlive a
|
||||
restart of the pad controller.
|
||||
|
||||
When one of the movers' movement pads goes off, SETTLE_DELAY later it
|
||||
nudges the Pan and Tilt knobs a step and puts them back, so QLC+ drops
|
||||
@@ -95,6 +99,7 @@ class AlsaPort:
|
||||
addr: str # "client:port"
|
||||
client: str
|
||||
name: str
|
||||
pid: str | None = None # the client's process, for user clients
|
||||
to: set[str] = field(default_factory=set)
|
||||
sources: set[str] = field(default_factory=set)
|
||||
|
||||
@@ -102,15 +107,15 @@ class AlsaPort:
|
||||
def parse_aconnect(text: str) -> list[AlsaPort]:
|
||||
"""The ports in `aconnect -l` output, with who they connect to and from."""
|
||||
ports: list[AlsaPort] = []
|
||||
client = client_name = None
|
||||
client = client_name = pid = None
|
||||
for line in text.splitlines():
|
||||
m = re.match(r"client (\d+): '([^']+)'", line)
|
||||
m = re.match(r"client (\d+): '([^']+)'(?:.*\bpid=(\d+))?", line)
|
||||
if m:
|
||||
client, client_name = m.group(1), m.group(2)
|
||||
client, client_name, pid = m.groups()
|
||||
continue
|
||||
m = re.match(r"\s+(\d+)\s+'([^']+)'", line)
|
||||
if m and client is not None:
|
||||
ports.append(AlsaPort(f"{client}:{m.group(1)}", client_name, m.group(2).strip()))
|
||||
ports.append(AlsaPort(f"{client}:{m.group(1)}", client_name, m.group(2).strip(), pid))
|
||||
continue
|
||||
m = re.match(r"\s+(Connecting To|Connected From):(.*)", line)
|
||||
if m and ports:
|
||||
@@ -139,20 +144,31 @@ def missing_links(ports: list[AlsaPort], src_name: str | None) -> list[tuple[str
|
||||
return links
|
||||
|
||||
|
||||
def ensure_links(src_name: str | None) -> bool:
|
||||
"""Make the missing links. True when one of them is to QLC+."""
|
||||
def qlc_feeds(ports: list[AlsaPort]) -> set[tuple[str | None, str]]:
|
||||
"""(pid, address) of each QLC+ port the pad controller's output is linked to."""
|
||||
ours_out = next((p for p in ports if p.client == "padcontroller-out"), None)
|
||||
if ours_out is None:
|
||||
return set()
|
||||
return {(p.pid, p.addr) for p in ports if p.client == "qlcplus" and p.addr in ours_out.to}
|
||||
|
||||
|
||||
def ensure_links(src_name: str | None) -> tuple[bool, set[tuple[str | None, str]]]:
|
||||
"""Make the missing links. Whether one of them was to QLC+, and the QLC+ ports fed after."""
|
||||
try:
|
||||
out = subprocess.check_output(["aconnect", "-l"], text=True)
|
||||
except (FileNotFoundError, subprocess.CalledProcessError):
|
||||
return False
|
||||
return False, set()
|
||||
ports = parse_aconnect(out)
|
||||
qlc = {p.addr for p in ports if p.client == "qlcplus"}
|
||||
qlc = {p.addr: p.pid for p in ports if p.client == "qlcplus"}
|
||||
fed = qlc_feeds(ports)
|
||||
to_qlc = False
|
||||
for src, dst in missing_links(ports, src_name):
|
||||
if subprocess.run(["aconnect", src, dst], capture_output=True).returncode == 0:
|
||||
print(f"Linked {src} -> {dst}", flush=True)
|
||||
to_qlc = to_qlc or dst in qlc
|
||||
return to_qlc
|
||||
if dst in qlc:
|
||||
to_qlc = True
|
||||
fed.add((qlc[dst], dst))
|
||||
return to_qlc, fed
|
||||
|
||||
|
||||
def load_colours(layer: PlayLayer) -> None:
|
||||
@@ -208,7 +224,7 @@ def main() -> None:
|
||||
print(f"Source: {src_name}", flush=True)
|
||||
print(f"Virtual: {VIRTUAL_NAME} (tau={args.tau}s @ {args.rate} Hz)", flush=True)
|
||||
print("Pass notes through (Play held shifts bank 2 up 16); smooth CC. Ctrl+C to stop.", flush=True)
|
||||
ensure_links(src_name)
|
||||
_, fed = ensure_links(src_name)
|
||||
if not args.no_lamps:
|
||||
set_lamps()
|
||||
|
||||
@@ -232,8 +248,10 @@ def main() -> None:
|
||||
else:
|
||||
print("Source: (pad gone, waiting)", flush=True)
|
||||
src_name = best_name
|
||||
if ensure_links(src_name) and now >= reopen_from:
|
||||
linked, now_fed = ensure_links(src_name)
|
||||
if (linked or now_fed - fed) and now >= reopen_from:
|
||||
reopen_at = now + REOPEN_DELAY
|
||||
fed = now_fed
|
||||
next_link_check = now + 2.0
|
||||
|
||||
if reopen_at is not None and now >= reopen_at:
|
||||
|
||||
Reference in new issue
Block a user