diff --git a/padcontroller/layer.py b/padcontroller/layer.py
index c3f55b0..a1456fb 100644
--- a/padcontroller/layer.py
+++ b/padcontroller/layer.py
@@ -7,7 +7,10 @@ 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.
+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
@@ -43,6 +46,8 @@ 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)
@@ -76,7 +81,7 @@ class PlayLayer:
return []
if kind == 0xB0 and len(data) >= 3 and data[1] == PAUSE_CC:
self.movers = data[2] > 0
- return []
+ 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)]
@@ -119,12 +124,17 @@ class PlayLayer:
"""QLC+ has loaded the show: everything is off. Press the colours that were on."""
self.moving = None
self.pattern = None
- out = []
+ 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)
diff --git a/padcontroller/midi.py b/padcontroller/midi.py
index 2d4dabf..1abd846 100644
--- a/padcontroller/midi.py
+++ b/padcontroller/midi.py
@@ -54,7 +54,7 @@ for p in glob.glob(str(ROOT / ".venv" / "lib" / "python*" / "site-packages")):
sys.path.insert(0, p)
import rtmidi
-from padcontroller.layer import PlayLayer # noqa: E402
+from padcontroller.layer import LAMP_CHANNEL, 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"))
@@ -225,6 +225,8 @@ def main() -> None:
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)
_, fed = ensure_links(src_name)
+ for out in layer.layer_lamp():
+ midiout.send_message(out)
if not args.no_lamps:
set_lamps()
@@ -259,7 +261,8 @@ def main() -> 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)
+ pressed = sum(out[0] & 0xF0 == 0x90 and out[0] & 0x0F != LAMP_CHANNEL for out in taps)
+ print(f"QLC+ reopened: pressed {pressed} colour pad(s) again", flush=True)
# Drain inbound
while True:
diff --git a/scripts/shows/layer_indicator.py b/scripts/shows/layer_indicator.py
new file mode 100644
index 0000000..bf46179
--- /dev/null
+++ b/scripts/shows/layer_indicator.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python3
+"""Show in shows/test.qxw whether the pad's bank 1 is on the cans or the movers.
+
+Pause on the pad latches bank 1 onto the cans or the movers, but only
+padcontroller knows which is on (padcontroller/layer.py). It now says so on
+MIDI channel 16: note 0 held down for the cans and note 1 for the movers, the
+other released. Two Flash buttons in a Pads layer frame, under the movers
+pads frame, light while their note is held, so whichever is lit is the layer
+the pads are on. Flash rather than Toggle, so each message sets the state outright and a
+missed one can't leave them the wrong way round. Each flashes an empty scene
+of its own: QLC+ lights every button whose function is flashing, so with one
+scene between them both would light.
+
+ python3 scripts/shows/layer_indicator.py
+
+Run it once; it stops if the frame is already there. QLC+ has to reopen the
+show to see it.
+"""
+
+from __future__ import annotations
+
+import re
+
+from mover_bank import NO_FUNCTION, ROOT, button, frame
+
+SHOW = ROOT / "shows" / "test.qxw"
+LAYER_NOTE_BASE = 15 * 4096 + 128 # QLC+ input channel of a channel-16 note: this plus the note
+CANS_NOTE, MOVERS_NOTE = 0, 1 # padcontroller/layer.py
+SIZE = 90
+
+
+def main() -> None:
+ xml = SHOW.read_text()
+ if 'Caption="Pads layer"' in xml:
+ raise SystemExit(f"{SHOW.relative_to(ROOT)} already has the pads layer indicator")
+ fid = max(int(i) for i in re.findall(r'")[1]) if int(i) != NO_FUNCTION) + 1
+
+ layers = (("Cans pads", CANS_NOTE), ("Movers pads", MOVERS_NOTE))
+ scenes = "".join(f' \n'
+ ' \n \n'
+ for k, (caption, _) in enumerate(layers))
+ buttons = "".join(button(wid + 1 + k, caption, 10 + k * SIZE, 10, SIZE, fid + k, LAYER_NOTE_BASE + note, "Flash")
+ for k, (caption, note) in enumerate(layers))
+ widget = frame(wid, "Pads layer", 470, 700, 2 * SIZE + 20, SIZE + 20, buttons, header=False)
+
+ anchor = ' ' # after the movers pads in the console
+ if anchor not in xml:
+ raise SystemExit("Couldn't find the Movers position frame")
+ xml = xml.replace(anchor, widget + anchor, 1)
+ xml = xml.replace(" ", scenes + " ", 1)
+ SHOW.write_text(xml)
+ print(f"Added the pads layer indicator to {SHOW.relative_to(ROOT)} (widgets from ID {wid})")
+
+
+if __name__ == "__main__":
+ main()
diff --git a/shows/test.qxw b/shows/test.qxw
index 928e97d..9c929e9 100644
--- a/shows/test.qxw
+++ b/shows/test.qxw
@@ -1607,6 +1607,12 @@
53
+
+
+
+
+
+
@@ -3891,6 +3897,50 @@
+
+
+ Sunken
+ Default
+ Default
+ None
+ Default
+
+
+ True
+ True
+ False
+ False
+ False
+ False
+
+
+
Sunken
diff --git a/tests/test_pad_layer.py b/tests/test_pad_layer.py
index 62378b9..1586fb0 100644
--- a/tests/test_pad_layer.py
+++ b/tests/test_pad_layer.py
@@ -11,6 +11,8 @@ PLAY_UP = [0xB0, 27, 0]
# The pad latches Pause: one message a press, 127 and 0 on alternate presses.
PAUSE_ON = [0xB0, 28, 127]
PAUSE_OFF = [0xB0, 28, 0]
+CANS_LIT = [[0x8F, 1, 0], [0x9F, 0, 127]] # channel 16: note 0 down, 1 up
+MOVERS_LIT = [[0x8F, 0, 0], [0x9F, 1, 127]]
class PlayLayerTest(unittest.TestCase):
@@ -80,16 +82,16 @@ class PlayLayerTest(unittest.TestCase):
layer.handle(PLAY_DOWN)
layer.handle([0x99, 66, 100])
layer.handle(PLAY_UP)
- self.assertEqual(layer.reopen(), [[0x99, 54, 127], [0x89, 54, 0], [0x99, 82, 127], [0x89, 82, 0]])
+ self.assertEqual(layer.reopen(), CANS_LIT + [[0x99, 54, 127], [0x89, 54, 0], [0x99, 82, 127], [0x89, 82, 0]])
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_ON), [])
+ self.assertEqual(layer.handle(PAUSE_ON), MOVERS_LIT)
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]])
- self.assertEqual(layer.handle(PAUSE_OFF), [])
+ self.assertEqual(layer.handle(PAUSE_OFF), CANS_LIT)
self.assertEqual(layer.handle([0x99, 44, 100]), [[0x99, 44, 100]])
def test_pads_1_and_2_move_up_on_the_movers_layer(self):
@@ -107,15 +109,22 @@ class PlayLayerTest(unittest.TestCase):
layer.handle(PAUSE_OFF)
self.assertEqual(layer.handle([0x89, 48, 0]), [[0x89, 96, 0]])
- def test_reopen_with_no_colours_sends_nothing(self):
- self.assertEqual(PlayLayer().reopen(), [])
+ def test_reopen_with_no_colours_only_lights_the_layer(self):
+ self.assertEqual(PlayLayer().reopen(), CANS_LIT)
+
+ def test_pause_lights_the_layer_it_moves_to(self):
+ layer = PlayLayer()
+ self.assertEqual(layer.layer_lamp(), CANS_LIT)
+ self.assertEqual(layer.handle(PAUSE_ON), MOVERS_LIT)
+ self.assertEqual(layer.handle(PAUSE_OFF), CANS_LIT)
+ self.assertEqual(layer.reopen(), CANS_LIT)
def test_pause_follows_the_pads_latch(self):
layer = PlayLayer()
- layer.handle(PAUSE_OFF) # already on the cans: stays there
+ self.assertEqual(layer.handle(PAUSE_OFF), CANS_LIT) # already on the cans: stays there
self.assertFalse(layer.movers)
- layer.handle(PAUSE_ON)
- layer.handle(PAUSE_ON) # a repeat changes nothing
+ self.assertEqual(layer.handle(PAUSE_ON), MOVERS_LIT)
+ self.assertEqual(layer.handle(PAUSE_ON), MOVERS_LIT) # a repeat changes nothing
self.assertTrue(layer.movers)
def test_wander_off_settles_pan_and_tilt(self):