Toggle the pad's bank 1 to the movers with Pause, and add a Threshold sound mode.
Pause flips bank 1 between the cans (36-51) and the movers (84-99). Threshold flashes the cans on bass hits and is exclusive with Sound, and knob 6 is the sides' peak. The Sound and Threshold pads light while on, and the colour pads that were on are pressed again when QLC+ reloads the show. --lock-knobs is gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
72c227b153
commit
11da656ee6
6 files changed
+378
-81
No files matched your search
+88
-11
@@ -6,6 +6,7 @@ immediately, and eases Control Change values toward their targets at
|
||||
|
||||
On start it also sets the pad lamps over USB (scripts/pad/pad_lamps.py): bank 1 off and
|
||||
bank 2 in the colours from shows/test.qxw. On Bluetooth it says so and carries on.
|
||||
While it runs, the Pump and Threshold pads (notes 36 and 37) light while their mode is on.
|
||||
While Play is held, bank 2 notes 52–67 go out as 68–83 (see padcontroller/layer.py).
|
||||
|
||||
Point QLC+ MIDI input at that virtual port (midi.qxw does this via
|
||||
@@ -13,6 +14,11 @@ patch_smc_pad.py once the pad controller is running). Every 2 s it checks the
|
||||
links: it reopens the pad when it is replugged (or moves to USB when that turns
|
||||
up) and re-links QLC+ to the virtual port after a restart, so QLC+ can stay open.
|
||||
|
||||
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.
|
||||
|
||||
Usage:
|
||||
.venv/bin/python -m padcontroller.midi
|
||||
# optional: --tau 0.05 (seconds; lower = snappier, higher = silkier)
|
||||
@@ -23,10 +29,13 @@ padcontroller/systemd/install.sh runs it as a systemd user service.
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import math
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
@@ -42,9 +51,11 @@ from padcontroller.layer import SUBMASTER_CC, PlayLayer # noqa: E402
|
||||
|
||||
# The lamp colours come from the show scripts, which are not part of this package.
|
||||
sys.path.insert(0, str(ROOT / "scripts" / "pad"))
|
||||
from pad_lamps import set_lamps # noqa: E402
|
||||
from pad_lamps import set_lamps, set_sound_lamps # noqa: E402
|
||||
|
||||
VIRTUAL_NAME = "padcontroller"
|
||||
COLOURS_FILE = Path(os.environ.get("XDG_STATE_HOME", Path.home() / ".local" / "state")) / "padcontroller" / "colours.json"
|
||||
REOPEN_DELAY = 1.5 # s for QLC+ to finish loading the virtual console
|
||||
# USB first when the pad is plugged in, Bluetooth otherwise.
|
||||
SOURCE_HINTS = (
|
||||
"SINCO SMC-PAD-Master",
|
||||
@@ -123,14 +134,63 @@ def missing_links(ports: list[AlsaPort], src_name: str | None) -> list[tuple[str
|
||||
return links
|
||||
|
||||
|
||||
def ensure_links(src_name: str | None) -> None:
|
||||
def ensure_links(src_name: str | None) -> bool:
|
||||
"""Make the missing links. True when one of them is to QLC+."""
|
||||
try:
|
||||
out = subprocess.check_output(["aconnect", "-l"], text=True)
|
||||
except (FileNotFoundError, subprocess.CalledProcessError):
|
||||
return
|
||||
for src, dst in missing_links(parse_aconnect(out), src_name):
|
||||
return False
|
||||
ports = parse_aconnect(out)
|
||||
qlc = {p.addr for p in ports if p.client == "qlcplus"}
|
||||
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
|
||||
|
||||
|
||||
def load_colours(layer: PlayLayer) -> None:
|
||||
try:
|
||||
saved = json.loads(COLOURS_FILE.read_text())
|
||||
layer.colours = {int(k): tuple(v) if v else None for k, v in saved.items()}
|
||||
except (OSError, ValueError, TypeError):
|
||||
pass
|
||||
|
||||
|
||||
def save_colours(layer: PlayLayer) -> None:
|
||||
try:
|
||||
COLOURS_FILE.parent.mkdir(parents=True, exist_ok=True)
|
||||
COLOURS_FILE.write_text(json.dumps(layer.colours) + "\n")
|
||||
except OSError as exc:
|
||||
print(f"Colours not saved: {exc}", flush=True)
|
||||
|
||||
|
||||
class SoundLamps:
|
||||
"""Show which sound pad is on, off the MIDI loop: each write takes ~60 ms."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.wanted: tuple[bool, bool] | None = None
|
||||
self.wake = threading.Event()
|
||||
threading.Thread(target=self._run, daemon=True).start()
|
||||
|
||||
def show(self, pump: bool, threshold: bool) -> None:
|
||||
self.wanted = (pump, threshold)
|
||||
self.wake.set()
|
||||
|
||||
def _run(self) -> None:
|
||||
shown = None
|
||||
while True:
|
||||
self.wake.wait()
|
||||
self.wake.clear()
|
||||
wanted = self.wanted
|
||||
if wanted is None or wanted == shown:
|
||||
continue
|
||||
try:
|
||||
set_sound_lamps(*wanted)
|
||||
shown = wanted
|
||||
except (SystemExit, Exception) as exc: # no Private port on Bluetooth
|
||||
print(f"Sound lamps not set: {exc}", flush=True)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
@@ -142,11 +202,6 @@ def main() -> None:
|
||||
help="smoothing time constant in seconds (default 0.055)",
|
||||
)
|
||||
ap.add_argument("--rate", type=float, default=120.0, help="update Hz")
|
||||
ap.add_argument(
|
||||
"--lock-knobs",
|
||||
action="store_true",
|
||||
help="knobs 1-10 move test.qxw's custom sliders only after the Custom pad is pressed",
|
||||
)
|
||||
ap.add_argument("--no-lamps", action="store_true", help="leave the pad lamp colours alone")
|
||||
args = ap.parse_args()
|
||||
|
||||
@@ -163,14 +218,21 @@ def main() -> None:
|
||||
current: dict[tuple[int, int], float] = {}
|
||||
target: dict[tuple[int, int], float] = {}
|
||||
last_sent: dict[tuple[int, int], int] = {}
|
||||
layer = PlayLayer(lock_knobs=args.lock_knobs)
|
||||
layer = PlayLayer()
|
||||
load_colours(layer)
|
||||
saved_colours = dict(layer.colours)
|
||||
reopen_at: float | None = None
|
||||
# Links made this soon after start are ours being restored, with QLC+'s buttons as they were.
|
||||
reopen_from = time.monotonic() + 5.0
|
||||
|
||||
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)
|
||||
sound_lamps = None
|
||||
if not args.no_lamps:
|
||||
set_lamps()
|
||||
sound_lamps = SoundLamps()
|
||||
|
||||
dt = 1.0 / args.rate
|
||||
alpha = 1.0 - math.exp(-dt / max(args.tau, 1e-4))
|
||||
@@ -192,9 +254,19 @@ def main() -> None:
|
||||
else:
|
||||
print("Source: (pad gone, waiting)", flush=True)
|
||||
src_name = best_name
|
||||
ensure_links(src_name)
|
||||
if ensure_links(src_name) and now >= reopen_from:
|
||||
reopen_at = now + REOPEN_DELAY
|
||||
next_link_check = now + 2.0
|
||||
|
||||
if reopen_at is not None and now >= reopen_at:
|
||||
reopen_at = None
|
||||
taps = layer.reopen()
|
||||
for out in taps:
|
||||
midiout.send_message(out)
|
||||
print(f"QLC+ reopened: pressed {sum(out[0] & 0xF0 == 0x90 for out in taps)} colour pad(s) again", flush=True)
|
||||
if sound_lamps:
|
||||
sound_lamps.show(layer.pump, layer.threshold)
|
||||
|
||||
# Drain inbound
|
||||
while True:
|
||||
msg = midiin.get_message()
|
||||
@@ -215,6 +287,11 @@ def main() -> None:
|
||||
else:
|
||||
# Notes, aftertouch, PC, the Sound reset (always resent), etc. → immediate
|
||||
midiout.send_message(out)
|
||||
if sound_lamps:
|
||||
sound_lamps.show(layer.pump, layer.threshold)
|
||||
if layer.colours != saved_colours:
|
||||
save_colours(layer)
|
||||
saved_colours = dict(layer.colours)
|
||||
|
||||
# Ease CC toward targets and emit when quantized value moves
|
||||
for key, tgt in list(target.items()):
|
||||
|
||||
Reference in new issue
Block a user