Files
jimmyandClaude Opus 5.5 c7546e5ea9 Show in the test show whether the pads are on the cans or the movers.
A Pads layer frame under the movers pads has Cans pads and Movers pads
buttons (scripts/shows/layer_indicator.py). The pad controller holds channel
16 note 0 (cans) or 1 (movers) down and the other up whenever Pause changes,
QLC+ reloads or it starts, and the Flash buttons light while their note is
held, so the lit one is the layer and a missed message can't leave them the
wrong way round. Each flashes an empty scene of its own: with one between
them, QLC+ lit both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 15:09:49 +13:00

154 lines
7.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Hold Play to move the bank 2 pads up a layer.
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
second set of buttons from the first. Play itself is not passed on.
Pause (CC 28) does the same for bank 1, but latches: the SMC-PAD sends one
message a press, 127 and 0 on alternate presses and nothing on release, and
bank 1 follows it. At 0, bank 1 pads 36–51 go out as they are, for the cans.
At 127, they go out as 84–99, for the movers. Pause itself is not passed on;
instead layer_lamp() tells QLC+ which layer is on, holding channel 16 note 0
(cans) or 1 (movers) down and the other up, for the test show's Pads layer
buttons.
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.
The movers' movement pads (pads 13–16, 9–12 and 5 on the movers layer: notes
96–99, 92–95 and 88) each toggle a relative EFX around the Pan and Tilt knobs (9
and 10, CC 38 and 39). They share a solo frame in QLC+, so starting one stops the others.
QLC+ 4.12 leaves an EFX's last offset on the movers when it stops, until those
sliders change, so when the one that is on goes off, settle asks for the two
knobs one step off and then back (nudge() and positions()). Swapping needs
none: the new EFX writes over the old one's offset. moving holds the note whose
EFX is on, from the presses: only a guess, as QLC+ sends no feedback for it.
The cans' pattern pads (pads 1–8 on the cans layer: notes 36–43) each toggle a
pattern, in a solo frame like the movement pads; pattern holds the note of the
one that is on. A Colour 1 pad starts a colour scene on the cans, and the
newest function wins their colour, so the scene would cover the pattern. While
a pattern is on, a Colour 1 press sets restart_pattern, and the caller sends
pattern_tap() twice a moment later, off and on again, so the pattern restarts on
top in the new colour. Taps sent with the colour itself land in the same QLC+
tick and change nothing.
"""
from __future__ import annotations
PLAY_CC = 27
FIRST_NOTE = 52
LAST_NOTE = 67
SHIFT = 16
PAUSE_CC = 28
BANK_1_FIRST = 36
BANK_1_LAST = 51
MOVERS_SHIFT = 48 # bank 1 goes out as 84–99 while Pause is on, above bank 2's held layer
LAMP_CHANNEL = 15 # channel 16: the Pads layer buttons in QLC+, clear of the pads and knobs
CANS_LAMP, MOVERS_LAMP = 0, 1 # their notes
KNOB_CHANNEL = 0
# Wander, Ballyhoo, Circle, Sweep; Diamond, Square, Corners, Leaf; Tilt: pads 13–16, 9–12, 5
RELATIVE_NOTES = (96, 97, 98, 99, 92, 93, 94, 95, 88)
POSITION_CCS = (38, 39) # knobs 9 and 10: the movers' Pan and Tilt
PATTERN_NOTES = range(36, 44) # the can patterns: pads 1–8 on the cans layer
class PlayLayer:
def __init__(self) -> None:
self.held = False
self.movers = False # Pause latched on puts bank 1 on the movers
# (channel, note as pressed) -> note sent, so a release matches its press
self.sent: dict[tuple[int, int], int] = {}
# Pan and Tilt as last sent; QLC+ starts them at 0.
self.position = {cc: 0 for cc in POSITION_CCS}
self.moving: int | None = None
self.settle = False # a relative EFX just went off: the caller sends nudge(), then positions()
self.pattern: int | None = None
self.pattern_channel = 0
self.restart_pattern = False # a Colour 1 press covered the pattern: the caller sends pattern_tap() twice
# 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]]:
"""The messages to send on. Empty when the message is swallowed."""
status = data[0]
kind = status & 0xF0
channel = status & 0x0F
if kind == 0xB0 and len(data) >= 3 and data[1] == PLAY_CC:
self.held = data[2] > 0
return []
if kind == 0xB0 and len(data) >= 3 and data[1] == PAUSE_CC:
self.movers = data[2] > 0
return self.layer_lamp()
if kind == 0xB0 and len(data) >= 3 and channel == KNOB_CHANNEL and data[1] in self.position:
self.position[data[1]] = data[2]
return [list(data)]
if kind not in (0x80, 0x90) or len(data) < 3:
return [list(data)]
key = (channel, data[1])
is_on = kind == 0x90 and data[2] > 0
if is_on:
out = self.shifted(data[1])
self.sent[key] = out
else:
out = self.sent.pop(key, data[1])
note = out
if note in RELATIVE_NOTES and is_on:
if note == self.moving:
self.moving = None
self.settle = True
else:
self.moving = note
elif note in PATTERN_NOTES and is_on:
self.pattern = None if note == self.pattern else note
self.pattern_channel = channel
elif FIRST_NOTE <= note <= LAST_NOTE and is_on and self.pattern is not None:
self.restart_pattern = True
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 [[status, out, *data[2:]]]
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."""
self.moving = None
self.pattern = None
out = self.layer_lamp()
for colour in self.colours.values():
if colour is not None:
out += tap(*colour)
return out
def layer_lamp(self) -> list[list[int]]:
"""The active layer's lamp note held down and the other's let go."""
on, off = (MOVERS_LAMP, CANS_LAMP) if self.movers else (CANS_LAMP, MOVERS_LAMP)
return [[0x80 | LAMP_CHANNEL, off, 0], [0x90 | LAMP_CHANNEL, on, 127]]
def pattern_tap(self) -> list[list[int]]:
"""A tap of the can pattern that is on, to toggle it; nothing once none is."""
return [] if self.pattern is None else tap(self.pattern_channel, self.pattern)
def nudge(self) -> list[list[int]]:
"""Pan and Tilt one step off their knobs, so QLC+ writes them again."""
return [[0xB0 | KNOB_CHANNEL, cc, v - 1 if v else 1] for cc, v in self.position.items()]
def positions(self) -> list[list[int]]:
"""Pan and Tilt back at their knobs."""
return [[0xB0 | KNOB_CHANNEL, cc, v] for cc, v in self.position.items()]
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]]