diff --git a/padcontroller/layer.py b/padcontroller/layer.py index 8481ffa..c3f55b0 100644 --- a/padcontroller/layer.py +++ b/padcontroller/layer.py @@ -4,9 +4,10 @@ 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 toggles: each press flips it. -Off, bank 1 pads 36–51 go out as they are, for the cans. On, they go out as -84–99, for the movers. Pause 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. 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 @@ -52,7 +53,7 @@ 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 toggles bank 1 between the cans and the movers + 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. @@ -74,8 +75,7 @@ class PlayLayer: self.held = data[2] > 0 return [] if kind == 0xB0 and len(data) >= 3 and data[1] == PAUSE_CC: - if data[2] > 0: - self.movers = not self.movers + self.movers = data[2] > 0 return [] if kind == 0xB0 and len(data) >= 3 and channel == KNOB_CHANNEL and data[1] in self.position: self.position[data[1]] = data[2] diff --git a/tests/test_pad_layer.py b/tests/test_pad_layer.py index c4f5a58..62378b9 100644 --- a/tests/test_pad_layer.py +++ b/tests/test_pad_layer.py @@ -8,8 +8,9 @@ from padcontroller.layer import PlayLayer # noqa: E402 PLAY_DOWN = [0xB0, 27, 127] PLAY_UP = [0xB0, 27, 0] -PAUSE_DOWN = [0xB0, 28, 127] -PAUSE_UP = [0xB0, 28, 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] class PlayLayerTest(unittest.TestCase): @@ -84,18 +85,16 @@ class PlayLayerTest(unittest.TestCase): 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(PAUSE_ON), []) 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(PAUSE_OFF), []) self.assertEqual(layer.handle([0x99, 44, 100]), [[0x99, 44, 100]]) def test_pads_1_and_2_move_up_on_the_movers_layer(self): layer = PlayLayer() - layer.handle(PAUSE_DOWN) + layer.handle(PAUSE_ON) 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]]) @@ -103,19 +102,27 @@ class PlayLayerTest(unittest.TestCase): def test_bank_1_release_matches_its_press_across_pause(self): layer = PlayLayer() - layer.handle(PAUSE_DOWN) + layer.handle(PAUSE_ON) layer.handle([0x99, 48, 100]) - layer.handle(PAUSE_DOWN) + 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_pause_follows_the_pads_latch(self): + layer = PlayLayer() + layer.handle(PAUSE_OFF) # already on the cans: stays there + self.assertFalse(layer.movers) + layer.handle(PAUSE_ON) + layer.handle(PAUSE_ON) # a repeat changes nothing + self.assertTrue(layer.movers) + def test_wander_off_settles_pan_and_tilt(self): layer = PlayLayer() self.assertEqual(layer.handle([0xB0, 38, 40]), [[0xB0, 38, 40]]) layer.handle([0xB0, 39, 0]) - layer.handle(PAUSE_DOWN) + layer.handle(PAUSE_ON) self.assertEqual(layer.handle([0x99, 48, 100]), [[0x99, 96, 100]]) layer.handle([0x89, 48, 0]) self.assertEqual((layer.moving, layer.settle), (96, False)) @@ -132,7 +139,7 @@ class PlayLayerTest(unittest.TestCase): def test_ballyhoo_takes_over_from_wander_without_a_settle(self): layer = PlayLayer() - layer.handle(PAUSE_DOWN) + layer.handle(PAUSE_ON) layer.handle([0x99, 48, 100]) self.assertEqual(layer.handle([0x99, 49, 100]), [[0x99, 97, 100]]) self.assertEqual((layer.moving, layer.settle), (97, False)) @@ -170,14 +177,14 @@ class PlayLayerTest(unittest.TestCase): def test_pattern_pads_on_the_movers_layer_are_not_can_patterns(self): layer = PlayLayer() - layer.handle(PAUSE_DOWN) + layer.handle(PAUSE_ON) layer.handle([0x99, 42, 127]) self.assertIsNone(layer.pattern) def test_every_movement_pad_settles_when_it_goes_off(self): for pad_note, sent in ((51, 99), (44, 92), (47, 95), (40, 88)): layer = PlayLayer() - layer.handle(PAUSE_DOWN) + layer.handle(PAUSE_ON) self.assertEqual(layer.handle([0x99, pad_note, 100]), [[0x99, sent, 100]]) self.assertEqual((layer.moving, layer.settle), (sent, False)) layer.handle([0x99, pad_note, 100])