Read the pad over USB when it's plugged in, and keep its links to the pad and QLC+ up.
padcontroller.midi now follows the pad every 2 s: it reopens it after a replug, moves to USB when that turns up, and re-links QLC+ to the virtual port after a restart, so QLC+ can stay open. Only the chosen source is subscribed, so a USB pad no longer gets Bluetooth input as well. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a295fefac0
commit
8f8c69898a
2 files changed
+162
-46
No files matched your search
@@ -0,0 +1,73 @@
|
||||
"""padcontroller.midi: picking the pad's port and keeping the ALSA links up."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
from padcontroller.midi import missing_links, parse_aconnect, pick_source # noqa: E402
|
||||
|
||||
BOTH = [
|
||||
"Midi Through:Midi Through Port-0 14:0",
|
||||
"SINCO:SINCO SMC-PAD-Private 20:0",
|
||||
"SINCO:SINCO SMC-PAD-Master 20:1",
|
||||
"SMC-PAD:SMC-PAD Bluetooth 128:0",
|
||||
"padcontroller-out:padcontroller 130:0",
|
||||
]
|
||||
|
||||
ACONNECT = """\
|
||||
client 20: 'SINCO' [type=kernel,card=1]
|
||||
0 'SINCO SMC-PAD-Private'
|
||||
1 'SINCO SMC-PAD-Master'
|
||||
\tConnecting To: 129:0
|
||||
client 128: 'SMC-PAD' [type=user,pid=1153]
|
||||
0 'SMC-PAD Bluetooth'
|
||||
client 129: 'padcontroller-in' [type=user,pid=57888]
|
||||
0 'RtMidi input '
|
||||
\tConnected From: 20:1
|
||||
client 130: 'padcontroller-out' [type=user,pid=57888]
|
||||
0 'padcontroller '
|
||||
client 131: 'qlcplus' [type=user,pid=57635]
|
||||
0 '__QLC__ '
|
||||
"""
|
||||
|
||||
|
||||
def test_usb_wins_over_bluetooth():
|
||||
assert BOTH[pick_source(BOTH)] == "SINCO:SINCO SMC-PAD-Master 20:1"
|
||||
|
||||
|
||||
def test_bluetooth_when_unplugged():
|
||||
names = [n for n in BOTH if "SINCO" not in n]
|
||||
assert names[pick_source(names)] == "SMC-PAD:SMC-PAD Bluetooth 128:0"
|
||||
|
||||
|
||||
def test_no_pad_and_never_our_own_port():
|
||||
assert pick_source(["padcontroller-out:padcontroller 130:0"]) is None
|
||||
|
||||
|
||||
def test_parse_aconnect_reads_links():
|
||||
ports = {p.addr: p for p in parse_aconnect(ACONNECT)}
|
||||
assert ports["20:1"].to == {"129:0"}
|
||||
assert ports["129:0"].sources == {"20:1"}
|
||||
assert ports["131:0"].client == "qlcplus"
|
||||
|
||||
|
||||
def test_relinks_qlc_after_a_restart():
|
||||
ports = parse_aconnect(ACONNECT)
|
||||
assert missing_links(ports, "SINCO:SINCO SMC-PAD-Master 20:1") == [("130:0", "131:0")]
|
||||
|
||||
|
||||
def test_relinks_a_replugged_pad_and_only_that_one():
|
||||
ports = parse_aconnect(ACONNECT.replace("\tConnected From: 20:1\n", ""))
|
||||
links = missing_links(ports, "SINCO:SINCO SMC-PAD-Master 20:1")
|
||||
assert ("20:1", "129:0") in links
|
||||
assert not any(src == "128:0" for src, _ in links)
|
||||
|
||||
|
||||
def test_nothing_missing_when_linked():
|
||||
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), None) == []
|
||||
Reference in new issue
Block a user