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
@@ -62,7 +62,7 @@ it as a systemd user service that starts at login and waits for the pad:
|
|||||||
padcontroller/systemd/install.sh
|
padcontroller/systemd/install.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
Options after the command go to the pad controller (for example `--lock-knobs`).
|
Options after the command go to the pad controller (for example `--no-lamps`).
|
||||||
`--no-enable` installs it without starting it at login (start it with
|
`--no-enable` installs it without starting it at login (start it with
|
||||||
`systemctl --user start padcontroller`). `--uninstall` removes the service. Logs: `journalctl --user -u padcontroller -f`.
|
`systemctl --user start padcontroller`). `--uninstall` removes the service. Logs: `journalctl --user -u padcontroller -f`.
|
||||||
|
|
||||||
|
|||||||
+113
-32
@@ -4,16 +4,37 @@ The SMC-PAD sends CC 27 as 127 when Play goes down and 0 when it comes up.
|
|||||||
While it is down, pad notes 52–67 go out as 68–83, so QLC+ can tell a
|
While it is down, pad notes 52–67 go out as 68–83, so QLC+ can tell a
|
||||||
second set of buttons from the first. Play itself is not passed on.
|
second set of buttons from the first. Play itself is not passed on.
|
||||||
|
|
||||||
With lock_knobs, knobs 1–5 (CC 30–34) drive colour 1's sliders and knobs 6–10
|
Pause (CC 28) does the same for bank 1, but toggles: each press flips it.
|
||||||
(CC 35–39) drive colour 2's, but only after the Custom pad (note 67, or 83
|
Off, bank 1 pads 36–51 go out as they are, for the cans. On, they go out as
|
||||||
with Play held) has been pressed. Pressing any other bank 2 pad locks them
|
84–99, for the movers. Pause itself is not passed on. The movers are not
|
||||||
again, and its sliders are sent back to zero so their scenes stop.
|
sound reactive, so Sound and Threshold (84 and 85) do nothing on their layer.
|
||||||
Locked knob turns are dropped.
|
|
||||||
|
|
||||||
The Sound pad (note 36) toggles QLC+'s audio triggers, which pump the cans'
|
The Sound pad (note 36) toggles QLC+'s audio triggers, which pump the cans'
|
||||||
Sound submaster in the Dimmers frame. Every press and release also sends CC 100
|
Sound submaster in the Dimmers frame. Every press and release also sends CC 100
|
||||||
at full, so switching sound off leaves the cans at full rather than wherever
|
at full, so switching sound off leaves the cans at full rather than wherever
|
||||||
the music left them.
|
the music left them.
|
||||||
|
|
||||||
|
The Threshold pad (note 37) toggles a second audio trigger, which flashes the
|
||||||
|
cans to full on bass hits. While it is on, CC 100 is held at 0 so the cans sit
|
||||||
|
dark between hits; switching it off puts the submaster back to full.
|
||||||
|
|
||||||
|
The two are exclusive: turning one on taps the other's note first when it is
|
||||||
|
on, so QLC+ switches it off.
|
||||||
|
|
||||||
|
Knob 6 (CC 35) is the sides' peak. It goes on to the Peak submasters, which
|
||||||
|
set how bright the Threshold hits, the chases and the strobe flash. While Sound is on,
|
||||||
|
it also holds both side sliders (knobs 5 and 8, CC 34 and 37) at its value, so
|
||||||
|
the bass pumps the sides up to it; turns of knobs 5 and 8 meanwhile are kept
|
||||||
|
and put back when Sound goes off.
|
||||||
|
|
||||||
|
pump and threshold follow the two pads' presses, so the pad controller can
|
||||||
|
light whichever is on. QLC+ sends no feedback for its audio triggers, so they
|
||||||
|
are only a guess; reopen() clears them, as QLC+ starts with both off.
|
||||||
|
|
||||||
|
colours holds the last colour pad pressed in each set, as sent (52–67 for the
|
||||||
|
cans, 68–83 for the movers), or None once it is pressed again: the colour
|
||||||
|
buttons toggle in a solo frame. QLC+ does not save which buttons are on, so
|
||||||
|
reopen() presses them again when QLC+ loads the show.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
@@ -22,20 +43,30 @@ PLAY_CC = 27
|
|||||||
FIRST_NOTE = 52
|
FIRST_NOTE = 52
|
||||||
LAST_NOTE = 67
|
LAST_NOTE = 67
|
||||||
SHIFT = 16
|
SHIFT = 16
|
||||||
CUSTOM_NOTE = 67
|
PAUSE_CC = 28
|
||||||
KNOB_FIRST_CC = 30
|
BANK_1_FIRST = 36
|
||||||
KNOBS_PER_LAYER = 5
|
BANK_1_LAST = 51
|
||||||
|
MOVERS_SHIFT = 48 # bank 1 goes out as 84–99 while Pause is on, above bank 2's held layer
|
||||||
SOUND_NOTE = 36
|
SOUND_NOTE = 36
|
||||||
|
THRESHOLD_NOTE = 37
|
||||||
SUBMASTER_CC = 100
|
SUBMASTER_CC = 100
|
||||||
|
KNOB_CHANNEL = 0
|
||||||
|
PEAK_CC = 35 # knob 6
|
||||||
|
SIDE_CCS = (34, 37) # knobs 5 and 8: Cans 9–15 and Cans 1, 2, 7, 8
|
||||||
|
|
||||||
|
|
||||||
class PlayLayer:
|
class PlayLayer:
|
||||||
def __init__(self, lock_knobs: bool = False) -> None:
|
def __init__(self) -> None:
|
||||||
self.lock_knobs = lock_knobs
|
|
||||||
self.unlocked: set[int] = set() # layers 0 and 1
|
|
||||||
self.held = False
|
self.held = False
|
||||||
|
self.movers = False # Pause toggles bank 1 between the cans and the movers
|
||||||
# (channel, note as pressed) -> note sent, so a release matches its press
|
# (channel, note as pressed) -> note sent, so a release matches its press
|
||||||
self.sent: dict[tuple[int, int], int] = {}
|
self.sent: dict[tuple[int, int], int] = {}
|
||||||
|
self.pump = False
|
||||||
|
self.threshold = False
|
||||||
|
# Last value of each knob below, from the pad; QLC+ starts them at full.
|
||||||
|
self.knobs = {cc: 127 for cc in (PEAK_CC, *SIDE_CCS)}
|
||||||
|
# set -> (channel, note sent) of the colour that is on
|
||||||
|
self.colours: dict[int, tuple[int, int] | None] = {1: None, 2: None}
|
||||||
|
|
||||||
def handle(self, data: list[int]) -> list[list[int]]:
|
def handle(self, data: list[int]) -> list[list[int]]:
|
||||||
"""The messages to send on. Empty when the message is swallowed."""
|
"""The messages to send on. Empty when the message is swallowed."""
|
||||||
@@ -45,30 +76,80 @@ class PlayLayer:
|
|||||||
if kind == 0xB0 and len(data) >= 3 and data[1] == PLAY_CC:
|
if kind == 0xB0 and len(data) >= 3 and data[1] == PLAY_CC:
|
||||||
self.held = data[2] > 0
|
self.held = data[2] > 0
|
||||||
return []
|
return []
|
||||||
if kind == 0xB0 and len(data) >= 3 and self.lock_knobs:
|
if kind == 0xB0 and len(data) >= 3 and data[1] == PAUSE_CC:
|
||||||
index = data[1] - KNOB_FIRST_CC
|
if data[2] > 0:
|
||||||
if 0 <= index < 2 * KNOBS_PER_LAYER and index // KNOBS_PER_LAYER not in self.unlocked:
|
self.movers = not self.movers
|
||||||
return []
|
return []
|
||||||
|
if kind == 0xB0 and len(data) >= 3 and channel == KNOB_CHANNEL and data[1] in self.knobs:
|
||||||
|
self.knobs[data[1]] = data[2]
|
||||||
|
if data[1] == PEAK_CC:
|
||||||
|
return [list(data), *self.sides()]
|
||||||
|
return [] if self.pump else [list(data)]
|
||||||
if kind not in (0x80, 0x90) or len(data) < 3:
|
if kind not in (0x80, 0x90) or len(data) < 3:
|
||||||
return [list(data)]
|
return [list(data)]
|
||||||
note = data[1]
|
key = (channel, data[1])
|
||||||
key = (channel, note)
|
|
||||||
is_on = kind == 0x90 and data[2] > 0
|
is_on = kind == 0x90 and data[2] > 0
|
||||||
extra: list[list[int]] = []
|
|
||||||
if is_on and FIRST_NOTE <= note <= LAST_NOTE:
|
|
||||||
layer = 1 if self.held else 0
|
|
||||||
if note == CUSTOM_NOTE:
|
|
||||||
self.unlocked.add(layer)
|
|
||||||
elif layer in self.unlocked:
|
|
||||||
self.unlocked.discard(layer)
|
|
||||||
first = KNOB_FIRST_CC + layer * KNOBS_PER_LAYER
|
|
||||||
extra = [[0xB0, first + n, 0] for n in range(KNOBS_PER_LAYER)]
|
|
||||||
if note == SOUND_NOTE:
|
|
||||||
# Again on release, after any spectrum frame QLC+ still had queued
|
|
||||||
extra = [[0xB0, SUBMASTER_CC, 127]]
|
|
||||||
if is_on:
|
if is_on:
|
||||||
out = note + SHIFT if self.held and FIRST_NOTE <= note <= LAST_NOTE else note
|
out = self.shifted(data[1])
|
||||||
self.sent[key] = out
|
self.sent[key] = out
|
||||||
else:
|
else:
|
||||||
out = self.sent.pop(key, note)
|
out = self.sent.pop(key, data[1])
|
||||||
return [[status, out, *data[2:]], *extra]
|
note = out
|
||||||
|
before: list[list[int]] = []
|
||||||
|
extra: list[list[int]] = []
|
||||||
|
if note == SOUND_NOTE:
|
||||||
|
if is_on:
|
||||||
|
if self.threshold:
|
||||||
|
before = tap(channel, THRESHOLD_NOTE)
|
||||||
|
self.threshold = False
|
||||||
|
self.pump = not self.pump
|
||||||
|
extra = self.sides(restore=not self.pump)
|
||||||
|
# Again on release, after any spectrum frame QLC+ still had queued
|
||||||
|
extra = [*extra, [0xB0, SUBMASTER_CC, 127]]
|
||||||
|
elif note == THRESHOLD_NOTE:
|
||||||
|
if is_on:
|
||||||
|
if self.pump:
|
||||||
|
before = tap(channel, SOUND_NOTE)
|
||||||
|
self.pump = False
|
||||||
|
extra = self.sides(restore=True)
|
||||||
|
self.threshold = not self.threshold
|
||||||
|
extra = [*extra, [0xB0, SUBMASTER_CC, 0 if self.threshold else 127]]
|
||||||
|
if is_on and FIRST_NOTE <= out <= LAST_NOTE + SHIFT:
|
||||||
|
colour_set = 1 if out <= LAST_NOTE else 2
|
||||||
|
pressed = (channel, out)
|
||||||
|
self.colours[colour_set] = None if self.colours[colour_set] == pressed else pressed
|
||||||
|
return [*before, [status, out, *data[2:]], *extra]
|
||||||
|
|
||||||
|
def shifted(self, note: int) -> int:
|
||||||
|
"""The note a press goes out as: bank 2 up while Play is held, bank 1 up while Pause is on."""
|
||||||
|
if self.held and FIRST_NOTE <= note <= LAST_NOTE:
|
||||||
|
return note + SHIFT
|
||||||
|
if self.movers and BANK_1_FIRST <= note <= BANK_1_LAST:
|
||||||
|
return note + MOVERS_SHIFT
|
||||||
|
return note
|
||||||
|
|
||||||
|
def reopen(self) -> list[list[int]]:
|
||||||
|
"""QLC+ has loaded the show: everything is off. Press the colours that were on.
|
||||||
|
|
||||||
|
The Sound submaster goes back to full too, as sound is off.
|
||||||
|
"""
|
||||||
|
self.pump = False
|
||||||
|
self.threshold = False
|
||||||
|
out = []
|
||||||
|
for colour in self.colours.values():
|
||||||
|
if colour is not None:
|
||||||
|
out += tap(*colour)
|
||||||
|
return out + [[0xB0, SUBMASTER_CC, 127]]
|
||||||
|
|
||||||
|
def sides(self, restore: bool = False) -> list[list[int]]:
|
||||||
|
"""The side sliders at the peak while Sound is on, or back at their own knobs."""
|
||||||
|
if restore:
|
||||||
|
return [[0xB0 | KNOB_CHANNEL, cc, self.knobs[cc]] for cc in SIDE_CCS]
|
||||||
|
if not self.pump:
|
||||||
|
return []
|
||||||
|
return [[0xB0 | KNOB_CHANNEL, cc, self.knobs[PEAK_CC]] for cc in SIDE_CCS]
|
||||||
|
|
||||||
|
|
||||||
|
def tap(channel: int, note: int) -> list[list[int]]:
|
||||||
|
"""A press and release of note, to toggle a QLC+ button off."""
|
||||||
|
return [[0x90 | channel, note, 127], [0x80 | channel, note, 0]]
|
||||||
+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
|
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.
|
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).
|
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
|
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
|
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.
|
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:
|
Usage:
|
||||||
.venv/bin/python -m padcontroller.midi
|
.venv/bin/python -m padcontroller.midi
|
||||||
# optional: --tau 0.05 (seconds; lower = snappier, higher = silkier)
|
# 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
|
from __future__ import annotations
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import json
|
||||||
import math
|
import math
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import threading
|
||||||
import time
|
import time
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from pathlib import Path
|
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.
|
# The lamp colours come from the show scripts, which are not part of this package.
|
||||||
sys.path.insert(0, str(ROOT / "scripts" / "pad"))
|
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"
|
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.
|
# USB first when the pad is plugged in, Bluetooth otherwise.
|
||||||
SOURCE_HINTS = (
|
SOURCE_HINTS = (
|
||||||
"SINCO SMC-PAD-Master",
|
"SINCO SMC-PAD-Master",
|
||||||
@@ -123,14 +134,63 @@ def missing_links(ports: list[AlsaPort], src_name: str | None) -> list[tuple[str
|
|||||||
return links
|
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:
|
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
|
return False
|
||||||
for src, dst in missing_links(parse_aconnect(out), src_name):
|
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:
|
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
|
||||||
|
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:
|
def main() -> None:
|
||||||
@@ -142,11 +202,6 @@ def main() -> None:
|
|||||||
help="smoothing time constant in seconds (default 0.055)",
|
help="smoothing time constant in seconds (default 0.055)",
|
||||||
)
|
)
|
||||||
ap.add_argument("--rate", type=float, default=120.0, help="update Hz")
|
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")
|
ap.add_argument("--no-lamps", action="store_true", help="leave the pad lamp colours alone")
|
||||||
args = ap.parse_args()
|
args = ap.parse_args()
|
||||||
|
|
||||||
@@ -163,14 +218,21 @@ def main() -> None:
|
|||||||
current: dict[tuple[int, int], float] = {}
|
current: dict[tuple[int, int], float] = {}
|
||||||
target: dict[tuple[int, int], float] = {}
|
target: dict[tuple[int, int], float] = {}
|
||||||
last_sent: dict[tuple[int, int], int] = {}
|
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"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)
|
ensure_links(src_name)
|
||||||
|
sound_lamps = None
|
||||||
if not args.no_lamps:
|
if not args.no_lamps:
|
||||||
set_lamps()
|
set_lamps()
|
||||||
|
sound_lamps = SoundLamps()
|
||||||
|
|
||||||
dt = 1.0 / args.rate
|
dt = 1.0 / args.rate
|
||||||
alpha = 1.0 - math.exp(-dt / max(args.tau, 1e-4))
|
alpha = 1.0 - math.exp(-dt / max(args.tau, 1e-4))
|
||||||
@@ -192,9 +254,19 @@ 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
|
||||||
ensure_links(src_name)
|
if ensure_links(src_name) and now >= reopen_from:
|
||||||
|
reopen_at = now + REOPEN_DELAY
|
||||||
next_link_check = now + 2.0
|
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
|
# Drain inbound
|
||||||
while True:
|
while True:
|
||||||
msg = midiin.get_message()
|
msg = midiin.get_message()
|
||||||
@@ -215,6 +287,11 @@ def main() -> None:
|
|||||||
else:
|
else:
|
||||||
# Notes, aftertouch, PC, the Sound reset (always resent), etc. → immediate
|
# Notes, aftertouch, PC, the Sound reset (always resent), etc. → immediate
|
||||||
midiout.send_message(out)
|
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
|
# Ease CC toward targets and emit when quantized value moves
|
||||||
for key, tgt in list(target.items()):
|
for key, tgt in list(target.items()):
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
# Install the SMC-PAD pad controller as a systemd user service and start it.
|
# Install the SMC-PAD pad controller as a systemd user service and start it.
|
||||||
#
|
#
|
||||||
# padcontroller/systemd/install.sh # install, enable, start
|
# padcontroller/systemd/install.sh # install, enable, start
|
||||||
# padcontroller/systemd/install.sh --lock-knobs # pass options to the pad controller
|
# padcontroller/systemd/install.sh --no-lamps # pass options to the pad controller
|
||||||
# padcontroller/systemd/install.sh --no-enable # install only; start it with
|
# padcontroller/systemd/install.sh --no-enable # install only; start it with
|
||||||
# # systemctl --user start padcontroller
|
# # systemctl --user start padcontroller
|
||||||
# padcontroller/systemd/install.sh --uninstall
|
# padcontroller/systemd/install.sh --uninstall
|
||||||
|
|||||||
@@ -28,5 +28,42 @@ def set_lamps() -> None:
|
|||||||
print(f"Lamps not set: {exc}", flush=True)
|
print(f"Lamps not set: {exc}", flush=True)
|
||||||
|
|
||||||
|
|
||||||
|
# Bank 1 pads 1 and 2 (notes 36 and 37), lit while their sound mode is on.
|
||||||
|
PUMP_RGB = (0, 255, 0)
|
||||||
|
THRESHOLD_RGB = (255, 120, 0)
|
||||||
|
|
||||||
|
|
||||||
|
def set_sound_lamps(pump: bool, threshold: bool) -> None:
|
||||||
|
"""Light the Pump and Threshold pads while their mode is on, without saving.
|
||||||
|
|
||||||
|
Writes only the pad's running copy, so the stored preset (bank 1 off) comes
|
||||||
|
back on a power cycle. Needs the USB Private port; raises when it is missing.
|
||||||
|
"""
|
||||||
|
sys.path.insert(0, str(ROOT))
|
||||||
|
sys.path.insert(0, str(ROOT / "scripts" / "pad"))
|
||||||
|
import pad_colours
|
||||||
|
import rtmidi
|
||||||
|
from padcontroller.device import transact
|
||||||
|
from padcontroller.preset import scale
|
||||||
|
from padcontroller.sysex import RAM, write_request
|
||||||
|
|
||||||
|
lamps = {0: PUMP_RGB if pump else (0, 0, 0), 1: THRESHOLD_RGB if threshold else (0, 0, 0)}
|
||||||
|
midiout = rtmidi.MidiOut(rtapi=rtmidi.API_LINUX_ALSA)
|
||||||
|
midiin = rtmidi.MidiIn(rtapi=rtmidi.API_LINUX_ALSA)
|
||||||
|
index = midiout.get_ports().index(pad_colours.private_port(midiout.get_ports()))
|
||||||
|
midiin.open_port(index)
|
||||||
|
midiin.ignore_types(sysex=False, timing=True, active_sense=True)
|
||||||
|
midiout.open_port(index)
|
||||||
|
try:
|
||||||
|
for base in pad_colours.bank_bases(1):
|
||||||
|
for pad, rgb in lamps.items():
|
||||||
|
address = RAM + base + pad * pad_colours.RECORD + pad_colours.RGB_AT
|
||||||
|
transact(midiout, midiin, write_request(address, bytes(scale(c) for c in rgb)))
|
||||||
|
finally:
|
||||||
|
for port in (midiout, midiin):
|
||||||
|
port.close_port()
|
||||||
|
port.delete()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
set_lamps()
|
set_lamps()
|
||||||
+138
-36
@@ -8,6 +8,9 @@ from padcontroller.layer import PlayLayer # noqa: E402
|
|||||||
|
|
||||||
PLAY_DOWN = [0xB0, 27, 127]
|
PLAY_DOWN = [0xB0, 27, 127]
|
||||||
PLAY_UP = [0xB0, 27, 0]
|
PLAY_UP = [0xB0, 27, 0]
|
||||||
|
PAUSE_DOWN = [0xB0, 28, 127]
|
||||||
|
PAUSE_UP = [0xB0, 28, 0]
|
||||||
|
SIDES_FULL = [[0xB0, 34, 127], [0xB0, 37, 127]]
|
||||||
|
|
||||||
|
|
||||||
class PlayLayerTest(unittest.TestCase):
|
class PlayLayerTest(unittest.TestCase):
|
||||||
@@ -46,44 +49,143 @@ class PlayLayerTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_sound_pad_puts_the_submaster_back_to_full(self):
|
def test_sound_pad_puts_the_submaster_back_to_full(self):
|
||||||
layer = PlayLayer()
|
layer = PlayLayer()
|
||||||
self.assertEqual(layer.handle([0x99, 36, 100]), [[0x99, 36, 100], [0xB0, 100, 127]])
|
self.assertEqual(layer.handle([0x99, 36, 100]), [[0x99, 36, 100], *SIDES_FULL, [0xB0, 100, 127]])
|
||||||
self.assertEqual(layer.handle([0x89, 36, 0]), [[0x89, 36, 0], [0xB0, 100, 127]])
|
self.assertEqual(layer.handle([0x89, 36, 0]), [[0x89, 36, 0], [0xB0, 100, 127]])
|
||||||
self.assertEqual(layer.handle([0x99, 37, 100]), [[0x99, 37, 100]])
|
|
||||||
|
def test_threshold_pad_holds_the_submaster_at_zero_while_on(self):
|
||||||
|
layer = PlayLayer()
|
||||||
|
self.assertEqual(layer.handle([0x99, 37, 100]), [[0x99, 37, 100], [0xB0, 100, 0]])
|
||||||
|
self.assertEqual(layer.handle([0x89, 37, 0]), [[0x89, 37, 0], [0xB0, 100, 0]])
|
||||||
|
self.assertEqual(layer.handle([0x99, 37, 100]), [[0x99, 37, 100], [0xB0, 100, 127]])
|
||||||
|
self.assertEqual(layer.handle([0x89, 37, 0]), [[0x89, 37, 0], [0xB0, 100, 127]])
|
||||||
|
|
||||||
|
def test_sound_pads_track_which_mode_is_on(self):
|
||||||
|
layer = PlayLayer()
|
||||||
|
layer.handle([0x99, 36, 100])
|
||||||
|
layer.handle([0x89, 36, 0])
|
||||||
|
self.assertEqual((layer.pump, layer.threshold), (True, False))
|
||||||
|
layer.handle([0x99, 36, 100])
|
||||||
|
layer.handle([0x99, 36, 0]) # note on at velocity 0 is a release
|
||||||
|
self.assertEqual((layer.pump, layer.threshold), (False, False))
|
||||||
|
|
||||||
|
def test_turning_threshold_on_switches_pump_off_first(self):
|
||||||
|
layer = PlayLayer()
|
||||||
|
layer.handle([0x99, 36, 100])
|
||||||
|
self.assertEqual(
|
||||||
|
layer.handle([0x99, 37, 100]),
|
||||||
|
[[0x99, 36, 127], [0x89, 36, 0], [0x99, 37, 100], *SIDES_FULL, [0xB0, 100, 0]],
|
||||||
|
)
|
||||||
|
self.assertEqual((layer.pump, layer.threshold), (False, True))
|
||||||
|
|
||||||
|
def test_turning_pump_on_switches_threshold_off_first(self):
|
||||||
|
layer = PlayLayer()
|
||||||
|
layer.handle([0x99, 37, 100])
|
||||||
|
self.assertEqual(
|
||||||
|
layer.handle([0x99, 36, 100]),
|
||||||
|
[[0x99, 37, 127], [0x89, 37, 0], [0x99, 36, 100], *SIDES_FULL, [0xB0, 100, 127]],
|
||||||
|
)
|
||||||
|
self.assertEqual((layer.pump, layer.threshold), (True, False))
|
||||||
|
|
||||||
|
def test_turning_a_mode_off_leaves_the_other_alone(self):
|
||||||
|
layer = PlayLayer()
|
||||||
|
layer.handle([0x99, 37, 100])
|
||||||
|
self.assertEqual(layer.handle([0x99, 37, 100]), [[0x99, 37, 100], [0xB0, 100, 127]])
|
||||||
|
self.assertEqual((layer.pump, layer.threshold), (False, False))
|
||||||
|
|
||||||
|
def test_peak_knob_goes_on_to_the_hits_submaster(self):
|
||||||
|
layer = PlayLayer()
|
||||||
|
self.assertEqual(layer.handle([0xB0, 35, 60]), [[0xB0, 35, 60]])
|
||||||
|
|
||||||
|
def test_side_knobs_pass_through_while_sound_is_off(self):
|
||||||
|
layer = PlayLayer()
|
||||||
|
self.assertEqual(layer.handle([0xB0, 34, 90]), [[0xB0, 34, 90]])
|
||||||
|
layer.handle([0x99, 37, 100]) # Threshold keeps them: the submaster holds the sides dark
|
||||||
|
self.assertEqual(layer.handle([0xB0, 37, 80]), [[0xB0, 37, 80]])
|
||||||
|
|
||||||
|
def test_pump_holds_the_sides_at_the_peak(self):
|
||||||
|
layer = PlayLayer()
|
||||||
|
layer.handle([0xB0, 34, 90])
|
||||||
|
layer.handle([0xB0, 35, 60])
|
||||||
|
self.assertEqual(layer.handle([0x99, 36, 100]),
|
||||||
|
[[0x99, 36, 100], [0xB0, 34, 60], [0xB0, 37, 60], [0xB0, 100, 127]])
|
||||||
|
self.assertEqual(layer.handle([0xB0, 35, 40]), [[0xB0, 35, 40], [0xB0, 34, 40], [0xB0, 37, 40]])
|
||||||
|
self.assertEqual(layer.handle([0xB0, 37, 100]), []) # kept for later
|
||||||
|
|
||||||
|
def test_pump_off_puts_the_side_knobs_back(self):
|
||||||
|
layer = PlayLayer()
|
||||||
|
layer.handle([0xB0, 34, 90])
|
||||||
|
layer.handle([0xB0, 35, 60])
|
||||||
|
layer.handle([0x99, 36, 100])
|
||||||
|
layer.handle([0xB0, 37, 100])
|
||||||
|
self.assertEqual(layer.handle([0x99, 36, 100]),
|
||||||
|
[[0x99, 36, 100], [0xB0, 34, 90], [0xB0, 37, 100], [0xB0, 100, 127]])
|
||||||
|
|
||||||
|
def test_threshold_taking_over_from_pump_puts_the_side_knobs_back(self):
|
||||||
|
layer = PlayLayer()
|
||||||
|
layer.handle([0xB0, 34, 90])
|
||||||
|
layer.handle([0xB0, 35, 60])
|
||||||
|
layer.handle([0x99, 36, 100])
|
||||||
|
self.assertEqual(layer.handle([0x99, 37, 100]),
|
||||||
|
[[0x99, 36, 127], [0x89, 36, 0], [0x99, 37, 100],
|
||||||
|
[0xB0, 34, 90], [0xB0, 37, 127], [0xB0, 100, 0]])
|
||||||
|
|
||||||
|
def test_colours_remember_the_last_pad_in_each_set(self):
|
||||||
|
layer = PlayLayer()
|
||||||
|
layer.handle([0x99, 52, 100])
|
||||||
|
layer.handle([0x99, 55, 100])
|
||||||
|
layer.handle(PLAY_DOWN)
|
||||||
|
layer.handle([0x99, 61, 100]) # Colour 2 Blue, sent as 77
|
||||||
|
self.assertEqual(layer.colours, {1: (9, 55), 2: (9, 77)})
|
||||||
|
|
||||||
|
def test_pressing_the_lit_colour_again_turns_it_off(self):
|
||||||
|
layer = PlayLayer()
|
||||||
|
layer.handle([0x99, 52, 100])
|
||||||
|
layer.handle([0x89, 52, 0])
|
||||||
|
layer.handle([0x99, 52, 100])
|
||||||
|
self.assertEqual(layer.colours[1], None)
|
||||||
|
|
||||||
|
def test_reopen_presses_the_colours_again_and_clears_sound(self):
|
||||||
|
layer = PlayLayer()
|
||||||
|
layer.handle([0x99, 54, 100])
|
||||||
|
layer.handle(PLAY_DOWN)
|
||||||
|
layer.handle([0x99, 66, 100])
|
||||||
|
layer.handle(PLAY_UP)
|
||||||
|
layer.handle([0x99, 36, 100])
|
||||||
|
self.assertEqual(layer.reopen(), [[0x99, 54, 127], [0x89, 54, 0], [0x99, 82, 127], [0x89, 82, 0],
|
||||||
|
[0xB0, 100, 127]])
|
||||||
|
self.assertEqual((layer.pump, layer.threshold), (False, False))
|
||||||
|
self.assertEqual(layer.colours, {1: (9, 54), 2: (9, 82)}) # still on, for the next reopen
|
||||||
|
|
||||||
|
def test_pause_toggles_bank_1_to_the_movers(self):
|
||||||
|
layer = PlayLayer()
|
||||||
|
self.assertEqual(layer.handle(PAUSE_DOWN), [])
|
||||||
|
self.assertEqual(layer.handle(PAUSE_UP), [])
|
||||||
|
self.assertEqual(layer.handle([0x99, 40, 100]), [[0x99, 88, 100]])
|
||||||
|
self.assertEqual(layer.handle([0x99, 51, 100]), [[0x99, 99, 100]])
|
||||||
|
self.assertEqual(layer.handle([0x99, 52, 100]), [[0x99, 52, 100]])
|
||||||
|
layer.handle(PAUSE_DOWN)
|
||||||
|
layer.handle(PAUSE_UP)
|
||||||
|
self.assertEqual(layer.handle([0x99, 44, 100]), [[0x99, 44, 100]])
|
||||||
|
|
||||||
|
def test_sound_pads_do_nothing_on_the_movers_layer(self):
|
||||||
|
layer = PlayLayer()
|
||||||
|
layer.handle(PAUSE_DOWN)
|
||||||
|
self.assertEqual(layer.handle([0x99, 36, 100]), [[0x99, 84, 100]])
|
||||||
|
self.assertEqual(layer.handle([0x89, 36, 0]), [[0x89, 84, 0]])
|
||||||
|
self.assertEqual(layer.handle([0x99, 37, 100]), [[0x99, 85, 100]])
|
||||||
|
self.assertEqual(layer.handle([0x89, 37, 0]), [[0x89, 85, 0]])
|
||||||
|
self.assertEqual((layer.pump, layer.threshold), (False, False))
|
||||||
|
|
||||||
|
def test_bank_1_release_matches_its_press_across_pause(self):
|
||||||
|
layer = PlayLayer()
|
||||||
|
layer.handle(PAUSE_DOWN)
|
||||||
|
layer.handle([0x99, 48, 100])
|
||||||
|
layer.handle(PAUSE_DOWN)
|
||||||
|
self.assertEqual(layer.handle([0x89, 48, 0]), [[0x89, 96, 0]])
|
||||||
|
|
||||||
|
def test_reopen_with_no_colours_only_resets_the_submaster(self):
|
||||||
|
self.assertEqual(PlayLayer().reopen(), [[0xB0, 100, 127]])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
||||||
class LockedKnobsTest(unittest.TestCase):
|
|
||||||
def test_knobs_are_dropped_until_custom_is_pressed(self):
|
|
||||||
layer = PlayLayer(lock_knobs=True)
|
|
||||||
self.assertEqual(layer.handle([0xB0, 31, 64]), [])
|
|
||||||
layer.handle([0x99, 67, 100])
|
|
||||||
self.assertEqual(layer.handle([0xB0, 31, 64]), [[0xB0, 31, 64]])
|
|
||||||
self.assertEqual(layer.handle([0xB0, 36, 64]), [])
|
|
||||||
|
|
||||||
def test_another_pad_locks_them_again(self):
|
|
||||||
layer = PlayLayer(lock_knobs=True)
|
|
||||||
layer.handle([0x99, 67, 100])
|
|
||||||
layer.handle([0x99, 60, 100])
|
|
||||||
self.assertEqual(layer.handle([0xB0, 31, 64]), [])
|
|
||||||
|
|
||||||
def test_locking_sends_the_sliders_back_to_zero(self):
|
|
||||||
layer = PlayLayer(lock_knobs=True)
|
|
||||||
layer.handle([0x99, 67, 100])
|
|
||||||
sent = layer.handle([0x99, 60, 100])
|
|
||||||
self.assertEqual(sent[0], [0x99, 60, 100])
|
|
||||||
self.assertEqual(sent[1:], [[0xB0, 30 + n, 0] for n in range(5)])
|
|
||||||
self.assertEqual(layer.handle([0x99, 61, 100]), [[0x99, 61, 100]])
|
|
||||||
|
|
||||||
def test_play_layer_unlocks_the_second_set(self):
|
|
||||||
layer = PlayLayer(lock_knobs=True)
|
|
||||||
layer.handle(PLAY_DOWN)
|
|
||||||
layer.handle([0x99, 67, 100])
|
|
||||||
self.assertEqual(layer.handle([0xB0, 36, 64]), [[0xB0, 36, 64]])
|
|
||||||
self.assertEqual(layer.handle([0xB0, 31, 64]), [])
|
|
||||||
|
|
||||||
def test_other_knobs_and_unlocked_mode_are_untouched(self):
|
|
||||||
self.assertEqual(PlayLayer(lock_knobs=True).handle([0xB0, 40, 64]), [[0xB0, 40, 64]])
|
|
||||||
self.assertEqual(PlayLayer().handle([0xB0, 31, 64]), [[0xB0, 31, 64]])
|
|
||||||
Reference in new issue
Block a user