74 lines
2.3 KiB
Python
74 lines
2.3 KiB
Python
"""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_bluetooth_wins_over_usb():
|
|
assert BOTH[pick_source(BOTH)] == "SMC-PAD:SMC-PAD Bluetooth 128:0"
|
|
|
|
|
|
def test_usb_when_not_paired():
|
|
names = [n for n in BOTH if "Bluetooth" not in n]
|
|
assert names[pick_source(names)] == "SINCO:SINCO SMC-PAD-Master 20:1"
|
|
|
|
|
|
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) == []
|