On Bluetooth there is no Private port, so every Sound or Threshold press opened two sequencer clients to light the lamps and left them open when the port lookup raised. After 29 presses the sequencer was full and aconnect could no longer open it. set_sound_lamps and Link now close both clients on that path too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
72 lines
2.5 KiB
Python
72 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Set the SMC-PAD lamps: bank 1 off, bank 2 in the colours of shows/test.qxw.
|
|
|
|
.venv/bin/python scripts/pad/pad_lamps.py
|
|
|
|
Needs the USB Private port. padcontroller.midi does this on start; run this
|
|
when the pad is read by Chataigne instead.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
|
|
|
|
def set_lamps() -> None:
|
|
"""Bank 1 lamps off, bank 2 lamps from shows/test.qxw. Needs the USB Private port."""
|
|
sys.path.insert(0, str(ROOT))
|
|
sys.path.insert(0, str(ROOT / "scripts" / "pad"))
|
|
import pad_colours
|
|
|
|
try:
|
|
pad_colours.apply(True, bank=1)
|
|
pad_colours.apply(False, bank=2, colours=pad_colours.colour_set())
|
|
except (SystemExit, Exception) as exc: # the Bluetooth link has no Private port
|
|
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)
|
|
try:
|
|
# Free both clients when the Private port is missing too, or every
|
|
# sound pad press on Bluetooth leaks two and fills the sequencer.
|
|
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)
|
|
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__":
|
|
set_lamps()
|