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
|
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.
|
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),
|
That is a link the pad controller had to make, or one QLC+ made itself: a
|
||||||
which it keeps in COLOURS_FILE so they outlive a restart of the pad controller.
|
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
|
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
|
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"
|
addr: str # "client:port"
|
||||||
client: str
|
client: str
|
||||||
name: str
|
name: str
|
||||||
|
pid: str | None = None # the client's process, for user clients
|
||||||
to: set[str] = field(default_factory=set)
|
to: set[str] = field(default_factory=set)
|
||||||
sources: 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]:
|
def parse_aconnect(text: str) -> list[AlsaPort]:
|
||||||
"""The ports in `aconnect -l` output, with who they connect to and from."""
|
"""The ports in `aconnect -l` output, with who they connect to and from."""
|
||||||
ports: list[AlsaPort] = []
|
ports: list[AlsaPort] = []
|
||||||
client = client_name = None
|
client = client_name = pid = None
|
||||||
for line in text.splitlines():
|
for line in text.splitlines():
|
||||||
m = re.match(r"client (\d+): '([^']+)'", line)
|
m = re.match(r"client (\d+): '([^']+)'(?:.*\bpid=(\d+))?", line)
|
||||||
if m:
|
if m:
|
||||||
client, client_name = m.group(1), m.group(2)
|
client, client_name, pid = m.groups()
|
||||||
continue
|
continue
|
||||||
m = re.match(r"\s+(\d+)\s+'([^']+)'", line)
|
m = re.match(r"\s+(\d+)\s+'([^']+)'", line)
|
||||||
if m and client is not None:
|
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
|
continue
|
||||||
m = re.match(r"\s+(Connecting To|Connected From):(.*)", line)
|
m = re.match(r"\s+(Connecting To|Connected From):(.*)", line)
|
||||||
if m and ports:
|
if m and ports:
|
||||||
@@ -139,20 +144,31 @@ def missing_links(ports: list[AlsaPort], src_name: str | None) -> list[tuple[str
|
|||||||
return links
|
return links
|
||||||
|
|
||||||
|
|
||||||
def ensure_links(src_name: str | None) -> bool:
|
def qlc_feeds(ports: list[AlsaPort]) -> set[tuple[str | None, str]]:
|
||||||
"""Make the missing links. True when one of them is to QLC+."""
|
"""(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:
|
try:
|
||||||
out = subprocess.check_output(["aconnect", "-l"], text=True)
|
out = subprocess.check_output(["aconnect", "-l"], text=True)
|
||||||
except (FileNotFoundError, subprocess.CalledProcessError):
|
except (FileNotFoundError, subprocess.CalledProcessError):
|
||||||
return False
|
return False, set()
|
||||||
ports = parse_aconnect(out)
|
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
|
to_qlc = False
|
||||||
for src, dst in missing_links(ports, src_name):
|
for src, dst in missing_links(ports, src_name):
|
||||||
if subprocess.run(["aconnect", src, dst], capture_output=True).returncode == 0:
|
if subprocess.run(["aconnect", src, dst], capture_output=True).returncode == 0:
|
||||||
print(f"Linked {src} -> {dst}", flush=True)
|
print(f"Linked {src} -> {dst}", flush=True)
|
||||||
to_qlc = to_qlc or dst in qlc
|
if dst in qlc:
|
||||||
return to_qlc
|
to_qlc = True
|
||||||
|
fed.add((qlc[dst], dst))
|
||||||
|
return to_qlc, fed
|
||||||
|
|
||||||
|
|
||||||
def load_colours(layer: PlayLayer) -> None:
|
def load_colours(layer: PlayLayer) -> None:
|
||||||
@@ -208,7 +224,7 @@ def main() -> None:
|
|||||||
print(f"Source: {src_name}", flush=True)
|
print(f"Source: {src_name}", flush=True)
|
||||||
print(f"Virtual: {VIRTUAL_NAME} (tau={args.tau}s @ {args.rate} Hz)", 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)
|
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:
|
if not args.no_lamps:
|
||||||
set_lamps()
|
set_lamps()
|
||||||
|
|
||||||
@@ -232,8 +248,10 @@ def main() -> None:
|
|||||||
else:
|
else:
|
||||||
print("Source: (pad gone, waiting)", flush=True)
|
print("Source: (pad gone, waiting)", flush=True)
|
||||||
src_name = best_name
|
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
|
reopen_at = now + REOPEN_DELAY
|
||||||
|
fed = now_fed
|
||||||
next_link_check = now + 2.0
|
next_link_check = now + 2.0
|
||||||
|
|
||||||
if reopen_at is not None and now >= reopen_at:
|
if reopen_at is not None and now >= reopen_at:
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from pathlib import Path
|
|||||||
ROOT = Path(__file__).resolve().parents[1]
|
ROOT = Path(__file__).resolve().parents[1]
|
||||||
sys.path.insert(0, str(ROOT))
|
sys.path.insert(0, str(ROOT))
|
||||||
|
|
||||||
from padcontroller.midi import missing_links, parse_aconnect, pick_source # noqa: E402
|
from padcontroller.midi import missing_links, parse_aconnect, pick_source, qlc_feeds # noqa: E402
|
||||||
|
|
||||||
BOTH = [
|
BOTH = [
|
||||||
"Midi Through:Midi Through Port-0 14:0",
|
"Midi Through:Midi Through Port-0 14:0",
|
||||||
@@ -71,3 +71,23 @@ def test_nothing_missing_when_linked():
|
|||||||
text = ACONNECT.replace(" 0 'padcontroller '\n", " 0 'padcontroller '\n\tConnecting To: 131:0\n")
|
text = ACONNECT.replace(" 0 'padcontroller '\n", " 0 'padcontroller '\n\tConnecting To: 131:0\n")
|
||||||
assert missing_links(parse_aconnect(text), "SINCO:SINCO SMC-PAD-Master 20:1") == []
|
assert missing_links(parse_aconnect(text), "SINCO:SINCO SMC-PAD-Master 20:1") == []
|
||||||
assert missing_links(parse_aconnect(text), None) == []
|
assert missing_links(parse_aconnect(text), None) == []
|
||||||
|
|
||||||
|
|
||||||
|
LINKED = ACONNECT.replace(" 0 'padcontroller '\n", " 0 'padcontroller '\n\tConnecting To: 131:0\n")
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_aconnect_reads_pids():
|
||||||
|
ports = {p.addr: p for p in parse_aconnect(ACONNECT)}
|
||||||
|
assert ports["131:0"].pid == "57635"
|
||||||
|
assert ports["20:0"].pid is None # a kernel client
|
||||||
|
|
||||||
|
|
||||||
|
def test_qlc_feeds_names_the_qlc_process():
|
||||||
|
assert qlc_feeds(parse_aconnect(LINKED)) == {("57635", "131:0")}
|
||||||
|
assert qlc_feeds(parse_aconnect(ACONNECT)) == set()
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_restarted_qlc_that_linked_itself_is_a_new_feed():
|
||||||
|
before = qlc_feeds(parse_aconnect(LINKED))
|
||||||
|
after = qlc_feeds(parse_aconnect(LINKED.replace("pid=57635", "pid=60001")))
|
||||||
|
assert after - before == {("60001", "131:0")}
|
||||||
Reference in new issue
Block a user