Move the SMC-PAD MIDI intercept into padeditor and add a systemd user service with an installer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Opus 5.5 committed 2026-10-22 12:06:31 +13:00
1 parent 647cfa3a75
commit 00de2595b6
13 files changed
+127 -34

No files matched your search

+1
View File
@@ -14,4 +14,5 @@ python_version = "3.12"
[scripts] [scripts]
midi = "python scripts/pad/midi.py" midi = "python scripts/pad/midi.py"
intercept = "python -m padeditor.intercept"
padeditor = "python -m padeditor" padeditor = "python -m padeditor"
+17 -3
View File
@@ -13,7 +13,7 @@ shows/ Workspaces to open in QLC+
small_eye.qxw Movers-only figure-of-8 show small_eye.qxw Movers-only figure-of-8 show
archive/ Older scratch workspaces archive/ Older scratch workspaces
scripts/ Launchers (pattern_studio.sh, flash_luxdmx_xiao.sh) scripts/ Launchers (pattern_studio.sh, flash_luxdmx_xiao.sh)
pad/ SMC-PAD tools: smoother, Play layer, lamps, MIDI patching pad/ SMC-PAD tools: lamps, MIDI patching, capture decoding
shows/ Generators / patchers for the shows and Chataigne shows/ Generators / patchers for the shows and Chataigne
anim/ showfile animations to preview over Art-Net anim/ showfile animations to preview over Art-Net
stage/ Stage map (SVG, JSON, canvas) stage/ Stage map (SVG, JSON, canvas)
@@ -51,6 +51,20 @@ python3 scripts/shows/figure8_small_eye.py --write-qxw shows/small_eye.qxw
Copy `.qxf` files from `fixtures/` into QLC+’s fixture library if the Copy `.qxf` files from `fixtures/` into QLC+’s fixture library if the
manufacturer/model is missing. manufacturer/model is missing.
## SMC-PAD intercept
`padeditor.intercept` reads the SMC-PAD, smooths its knobs, applies the Play
layer, and sends the result on a virtual MIDI port named `SMC-PAD Smooth` for
QLC+. Run it by hand with `.venv/bin/python -m padeditor.intercept`, or install
it as a systemd user service that starts at login and waits for the pad:
```bash
padeditor/systemd/install.sh
```
Options after the command go to the intercept (for example `--lock-knobs`).
`--uninstall` removes the service. Logs: `journalctl --user -u smc-pad-intercept -f`.
## Chataigne ## Chataigne
`scripts/shows/make_chataigne.py` turns a show spec into a Chataigne project, so the `scripts/shows/make_chataigne.py` turns a show spec into a Chataigne project, so the
@@ -62,8 +76,8 @@ python3 scripts/shows/make_chataigne.py shows/test.show.json chataigne/test
Open `chataigne/test/test.noisette`. The **Pad** (MIDI) module reads the SMC-PAD Open `chataigne/test/test.noisette`. The **Pad** (MIDI) module reads the SMC-PAD
directly (`--pad` picks the port: USB `SINCO SMC-PAD-Master` by default, or directly (`--pad` picks the port: USB `SINCO SMC-PAD-Master` by default, or
`SMC-PAD Bluetooth`). The script does the Play-layer shift that `pad_layer.py` does for `SMC-PAD Bluetooth`). The script does the Play-layer shift that `padeditor/layer.py` does for
QLC+, with no knob smoothing, so `smooth_smc_pad.py` is not needed. Set the lamps with QLC+, with no knob smoothing, so the intercept is not needed. Set the lamps with
`scripts/pad/pad_lamps.py`. The **Lights** (DMX) module sends Art-Net to the `scripts/pad/pad_lamps.py`. The **Lights** (DMX) module sends Art-Net to the
node in the spec. The **Preview** module sends a copy to 127.0.0.1 for the simulator (`--preview ''` leaves it out). If it comes up on the wrong output, set DMX Type to Art-Net, node in the spec. The **Preview** module sends a copy to 127.0.0.1 for the simulator (`--preview ''` leaves it out). If it comes up on the wrong output, set DMX Type to Art-Net,
the remote host, and an output universe of net 0, subnet 0, universe 0. the remote host, and an output universe of net 0, subnet 0, universe 0.
+2 -2
View File
@@ -1,5 +1,5 @@
// Pads pick colours, sliders mix a custom colour, like the QLC+ virtual console. // Pads pick colours, sliders mix a custom colour, like the QLC+ virtual console.
// It reads the pad directly: Play shifts bank 2 here, as scripts/pad/pad_layer.py does // It reads the pad directly: Play shifts bank 2 here, as padeditor/layer.py does
// when QLC+ is used. // when QLC+ is used.
// Generated by scripts/shows/make_chataigne.py: edit this template, not the output. // Generated by scripts/shows/make_chataigne.py: edit this template, not the output.
// //
@@ -11,7 +11,7 @@
var LAMP = "Lamp"; var LAMP = "Lamp";
var LAMP_OFF = 0.3; // brightness of a pad's tile when it is not playing var LAMP_OFF = 0.3; // brightness of a pad's tile when it is not playing
var FADE_RATE = 100; // script updates per second var FADE_RATE = 100; // script updates per second
var PLAY_CC = 27; // hold Play to move bank 2 (notes 52-67) up 16, like pad_layer.py var PLAY_CC = 27; // hold Play to move bank 2 (notes 52-67) up 16, like padeditor/layer.py
var BANK_FIRST = 52; var BANK_FIRST = 52;
var BANK_LAST = 67; var BANK_LAST = 67;
var BANK_SHIFT = 16; var BANK_SHIFT = 16;
+2 -2
View File
@@ -1,5 +1,5 @@
// Pads pick colours, sliders mix a custom colour, like the QLC+ virtual console. // Pads pick colours, sliders mix a custom colour, like the QLC+ virtual console.
// It reads the pad directly: Play shifts bank 2 here, as scripts/pad/pad_layer.py does // It reads the pad directly: Play shifts bank 2 here, as padeditor/layer.py does
// when QLC+ is used. // when QLC+ is used.
// Generated by scripts/shows/make_chataigne.py: edit this template, not the output. // Generated by scripts/shows/make_chataigne.py: edit this template, not the output.
// //
@@ -70,7 +70,7 @@ var GROUPS = [
var LAMP = "Lamp"; var LAMP = "Lamp";
var LAMP_OFF = 0.3; // brightness of a pad's tile when it is not playing var LAMP_OFF = 0.3; // brightness of a pad's tile when it is not playing
var FADE_RATE = 100; // script updates per second var FADE_RATE = 100; // script updates per second
var PLAY_CC = 27; // hold Play to move bank 2 (notes 52-67) up 16, like pad_layer.py var PLAY_CC = 27; // hold Play to move bank 2 (notes 52-67) up 16, like padeditor/layer.py
var BANK_FIRST = 52; var BANK_FIRST = 52;
var BANK_LAST = 67; var BANK_LAST = 67;
var BANK_SHIFT = 16; var BANK_SHIFT = 16;
@@ -1,20 +1,21 @@
#!/usr/bin/env python3 """Intercept the SMC-PAD's MIDI and smooth its knob CCs so RGBW fades feel less stepped.
"""Smooth SMC-PAD knob CCs so RGBW fades feel less stepped.
Reads the physical pad (Bluetooth or USB), passes pad notes through Reads the physical pad (Bluetooth or USB), passes pad notes through
immediately, and eases Control Change values toward their targets at immediately, and eases Control Change values toward their targets at
~120 Hz before emitting on a virtual port named "SMC-PAD Smooth". ~120 Hz before emitting on a virtual port named "SMC-PAD Smooth".
On start it also sets the pad lamps over USB (pad_colours.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 Play is held, bank 2 notes 52–67 go out as 68–83 (see pad_layer.py). While Play is held, bank 2 notes 52–67 go out as 68–83 (see padeditor/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
patch_smc_pad.py once the smoother is running). patch_smc_pad.py once the intercept is running).
Usage: Usage:
.venv/bin/python scripts/pad/smooth_smc_pad.py .venv/bin/python -m padeditor.intercept
# optional: --tau 0.05 (seconds; lower = snappier, higher = silkier) # optional: --tau 0.05 (seconds; lower = snappier, higher = silkier)
padeditor/systemd/install.sh runs it as a systemd user service.
""" """
from __future__ import annotations from __future__ import annotations
@@ -27,16 +28,18 @@ import sys
import time import time
from pathlib import Path from pathlib import Path
ROOT = Path(__file__).resolve().parents[2] ROOT = Path(__file__).resolve().parents[1]
import glob import glob
for p in glob.glob(str(ROOT / ".venv" / "lib" / "python*" / "site-packages")): for p in glob.glob(str(ROOT / ".venv" / "lib" / "python*" / "site-packages")):
sys.path.insert(0, p) sys.path.insert(0, p)
import rtmidi import rtmidi
sys.path.insert(0, str(Path(__file__).resolve().parent)) from padeditor.layer import 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 # noqa: E402
from pad_layer import PlayLayer # noqa: E402
VIRTUAL_NAME = "SMC-PAD Smooth" VIRTUAL_NAME = "SMC-PAD Smooth"
SOURCE_HINTS = ( SOURCE_HINTS = (
File renamed without changes.
+40
View File
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
# Install the SMC-PAD MIDI intercept as a systemd user service and start it.
#
# padeditor/systemd/install.sh # install, enable, start
# padeditor/systemd/install.sh --lock-knobs # pass options to the intercept
# padeditor/systemd/install.sh --uninstall
#
# Logs: journalctl --user -u smc-pad-intercept -f
set -euo pipefail
UNIT=smc-pad-intercept.service
HERE="$(cd "$(dirname "$0")" && pwd)"
ROOT="$(cd "$HERE/../.." && pwd)"
DEST="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user"
if [[ "${1:-}" == "--uninstall" ]]; then
systemctl --user disable --now "$UNIT" 2>/dev/null || true
rm -f "$DEST/$UNIT"
systemctl --user daemon-reload
echo "Removed $UNIT."
exit 0
fi
PYTHON="$ROOT/.venv/bin/python"
[[ -x "$PYTHON" ]] || PYTHON="$(command -v python3)"
"$PYTHON" -c "import rtmidi" 2>/dev/null || {
echo "$PYTHON cannot import rtmidi. Run pipenv install (or pip install python-rtmidi) first." >&2
exit 1
}
ARGS="$*"
mkdir -p "$DEST"
sed -e "s|@ROOT@|$ROOT|g" -e "s|@PYTHON@|$PYTHON|g" -e "s|@ARGS@|$ARGS|g" \
"$HERE/$UNIT" >"$DEST/$UNIT"
systemctl --user daemon-reload
systemctl --user enable "$UNIT"
systemctl --user restart "$UNIT"
echo "Installed $DEST/$UNIT and started it."
systemctl --user --no-pager status "$UNIT" | head -5 || true
@@ -0,0 +1,22 @@
# SMC-PAD MIDI intercept (padeditor.intercept) as a systemd user service.
# install.sh fills in @ROOT@, @PYTHON@ and @ARGS@ and copies it to
# ~/.config/systemd/user/.
[Unit]
Description=SMC-PAD MIDI intercept (virtual port "SMC-PAD Smooth")
After=sound.target
# Keep retrying while the pad is switched off or not paired yet.
StartLimitIntervalSec=0
[Service]
Type=simple
WorkingDirectory=@ROOT@
ExecStart=@PYTHON@ -m padeditor.intercept @ARGS@
Environment=PYTHONUNBUFFERED=1
# The intercept closes its ports on Ctrl+C.
KillSignal=SIGINT
Restart=always
RestartSec=3
[Install]
WantedBy=default.target
+1 -1
View File
@@ -3,7 +3,7 @@
.venv/bin/python scripts/pad/pad_lamps.py .venv/bin/python scripts/pad/pad_lamps.py
Needs the USB Private port. smooth_smc_pad.py does this on start; run this Needs the USB Private port. padeditor.intercept does this on start; run this
when the pad is read by Chataigne instead. when the pad is read by Chataigne instead.
""" """
+1 -1
View File
@@ -75,7 +75,7 @@ PAD_COLORS = [
def detect_midi_uid() -> str: def detect_midi_uid() -> str:
"""Prefer smoothed virtual port when the smoother daemon is running.""" """Prefer smoothed virtual port when the intercept (padeditor.intercept) is running."""
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):
+22 -9
View File
@@ -3,7 +3,7 @@
# #
# Order matters: # Order matters:
# 1) pad present (Bluetooth or USB) # 1) pad present (Bluetooth or USB)
# 2) smoother (creates "SMC-PAD Smooth") # 2) intercept (creates "SMC-PAD Smooth")
# 3) patch workspace to that port # 3) patch workspace to that port
# 4) open QLC+ last # 4) open QLC+ last
set -euo pipefail set -euo pipefail
@@ -30,12 +30,21 @@ if ! pad_present; then
exit 1 exit 1
fi fi
# Restart smoother so it re-opens the pad port cleanly (avoid pkill -f; it matches this script) # Restart the intercept so it re-opens the pad port cleanly. Use the systemd
while read -r pid; do # user service when it is installed (padeditor/systemd/install.sh).
[[ -n "$pid" ]] && kill "$pid" 2>/dev/null || true SERVICE=smc-pad-intercept.service
done < <(ps -eo pid,args | awk '/[.]venv\/bin\/python .*smooth_smc_pad[.]py/ {print $1}') LOG=/tmp/smc_pad_intercept.log
sleep 0.4 if systemctl --user is-enabled --quiet "$SERVICE" 2>/dev/null; then
nohup "$PYTHON" scripts/pad/smooth_smc_pad.py --tau 0.055 >>/tmp/smooth_smc_pad.log 2>&1 & systemctl --user restart "$SERVICE"
LOG=
else
# avoid pkill -f; it matches this script
while read -r pid; do
[[ -n "$pid" ]] && kill "$pid" 2>/dev/null || true
done < <(ps -eo pid,args | awk '/python.* -m padeditor[.]intercept/ {print $1}')
sleep 0.4
nohup "$PYTHON" -m padeditor.intercept --tau 0.055 >>"$LOG" 2>&1 &
fi
for _ in $(seq 1 20); do for _ in $(seq 1 20); do
if aconnect -l 2>/dev/null | grep -q 'SMC-PAD Smooth'; then if aconnect -l 2>/dev/null | grep -q 'SMC-PAD Smooth'; then
break break
@@ -43,8 +52,12 @@ for _ in $(seq 1 20); do
sleep 0.25 sleep 0.25
done done
if ! aconnect -l 2>/dev/null | grep -q 'SMC-PAD Smooth'; then if ! aconnect -l 2>/dev/null | grep -q 'SMC-PAD Smooth'; then
echo "Smoother failed to create SMC-PAD Smooth. See /tmp/smooth_smc_pad.log" >&2 echo "The intercept failed to create SMC-PAD Smooth." >&2
tail -20 /tmp/smooth_smc_pad.log >&2 || true if [[ -n "$LOG" ]]; then
tail -20 "$LOG" >&2 || true
else
journalctl --user -u "$SERVICE" -n 20 --no-pager >&2 || true
fi
exit 1 exit 1
fi fi
+5 -5
View File
@@ -4,15 +4,15 @@
Colour 1 paints all 15 cans and colour 2 the four movers, so one colour Colour 1 paints all 15 cans and colour 2 the four movers, so one colour
for each can be on at once. Each set is a solo frame and every scene for each can be on at once. Each set is a solo frame and every scene
fades in and out over FADE_MS. Bank 2 (notes 52–67) picks colour 1. fades in and out over FADE_MS. Bank 2 (notes 52–67) picks colour 1.
Holding Play picks set B: the smoother turns those notes into 68–83 while Holding Play picks set B: the intercept turns those notes into 68–83 while
Play is down. Bank 1 is kept for animations. Play is down. Bank 1 is kept for animations.
python3 scripts/shows/colour_sets.py && python3 -m showfile write shows/test.show.json -o shows/test.qxw python3 scripts/shows/colour_sets.py && python3 -m showfile write shows/test.show.json -o shows/test.qxw
The sliders are Playback sliders over five scenes per set (Dim, R, G, B, W), The sliders are Playback sliders over five scenes per set (Dim, R, G, B, W),
so they never override a channel. Knobs 1–5 move colour 1's sliders and knobs so they never override a channel. Knobs 1–5 move colour 1's sliders and knobs
6–10 colour 2's. Run the smoother with --lock-knobs to make them work only 6–10 colour 2's. Run the intercept with --lock-knobs to make them work only
after the Custom pad is pressed; any other pad sends them back to zero (see after the Custom pad is pressed; any other pad sends them back to zero (see
pad_layer.py). padeditor/layer.py).
""" """
from __future__ import annotations from __future__ import annotations
@@ -26,12 +26,12 @@ SPEC = ROOT / "shows" / "test.show.json"
FADE_MS = 1000 FADE_MS = 1000
DIMMER, RED, GREEN, BLUE, WHITE = 0, 2, 3, 4, 5 DIMMER, RED, GREEN, BLUE, WHITE = 0, 2, 3, 4, 5
PAD_BANK_2_FIRST_NOTE = 52 PAD_BANK_2_FIRST_NOTE = 52
HELD_FIRST_NOTE = 68 # scripts/pad/pad_layer.py sends bank 2 here while Play is held HELD_FIRST_NOTE = 68 # padeditor/layer.py sends bank 2 here while Play is held
PROFILE = "M-VAVE SMC-PAD" PROFILE = "M-VAVE SMC-PAD"
OMNI = 16 # QLC+ MIDI plugin channel that accepts every MIDI channel OMNI = 16 # QLC+ MIDI plugin channel that accepts every MIDI channel
PAD_MIDI_CH = 9 # the pads send notes on channel 10 PAD_MIDI_CH = 9 # the pads send notes on channel 10
KNOB_FIRST_CC = 30 # pad knob 1; colour 2's sliders follow colour 1's KNOB_FIRST_CC = 30 # pad knob 1; colour 2's sliders follow colour 1's
PAD_PORT = "SMC-PAD Smooth" # scripts/pad/smooth_smc_pad.py; it applies the Play layer PAD_PORT = "SMC-PAD Smooth" # padeditor/intercept.py; it applies the Play layer
# name, r, g, b, w. Bottom row first, four to a row. The cans have a white emitter, so the whites use it. # name, r, g, b, w. Bottom row first, four to a row. The cans have a white emitter, so the whites use it.
COLOURS = ( COLOURS = (
+2 -2
View File
@@ -2,9 +2,9 @@ import sys
import unittest import unittest
from pathlib import Path from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts" / "pad")) sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from pad_layer import PlayLayer # noqa: E402 from padeditor.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]