Files
qlcplus/tests/test_pad_layer.py
T

84 lines
3.1 KiB
Python

import sys
import unittest
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from padeditor.layer import PlayLayer # noqa: E402
PLAY_DOWN = [0xB0, 27, 127]
PLAY_UP = [0xB0, 27, 0]
class PlayLayerTest(unittest.TestCase):
def test_notes_pass_through_when_play_is_up(self):
layer = PlayLayer()
self.assertEqual(layer.handle([0x99, 52, 100]), [[0x99, 52, 100]])
def test_play_is_not_passed_on(self):
layer = PlayLayer()
self.assertEqual(layer.handle(PLAY_DOWN), [])
self.assertEqual(layer.handle(PLAY_UP), [])
def test_bank_2_moves_up_while_play_is_held(self):
layer = PlayLayer()
layer.handle(PLAY_DOWN)
self.assertEqual(layer.handle([0x99, 52, 100]), [[0x99, 68, 100]])
self.assertEqual(layer.handle([0x99, 67, 100]), [[0x99, 83, 100]])
layer.handle(PLAY_UP)
self.assertEqual(layer.handle([0x99, 52, 100]), [[0x99, 52, 100]])
def test_other_notes_and_ccs_are_left_alone(self):
layer = PlayLayer()
layer.handle(PLAY_DOWN)
self.assertEqual(layer.handle([0x99, 40, 100]), [[0x99, 40, 100]])
self.assertEqual(layer.handle([0xB0, 30, 64]), [[0xB0, 30, 64]])
def test_release_matches_its_press(self):
layer = PlayLayer()
layer.handle(PLAY_DOWN)
layer.handle([0x99, 55, 100])
layer.handle(PLAY_UP)
self.assertEqual(layer.handle([0x89, 55, 0]), [[0x89, 71, 0]])
layer.handle([0x99, 55, 100])
layer.handle(PLAY_DOWN)
self.assertEqual(layer.handle([0x99, 55, 0]), [[0x99, 55, 0]])
if __name__ == "__main__":
unittest.main()
class LockedKnobsTest(unittest.TestCase):
def test_knobs_are_dropped_until_custom_is_pressed(self):
layer = PlayLayer(lock_knobs=True)
self.assertEqual(layer.handle([0xB0, 31, 64]), [])
layer.handle([0x99, 67, 100])
self.assertEqual(layer.handle([0xB0, 31, 64]), [[0xB0, 31, 64]])
self.assertEqual(layer.handle([0xB0, 36, 64]), [])
def test_another_pad_locks_them_again(self):
layer = PlayLayer(lock_knobs=True)
layer.handle([0x99, 67, 100])
layer.handle([0x99, 60, 100])
self.assertEqual(layer.handle([0xB0, 31, 64]), [])
def test_locking_sends_the_sliders_back_to_zero(self):
layer = PlayLayer(lock_knobs=True)
layer.handle([0x99, 67, 100])
sent = layer.handle([0x99, 60, 100])
self.assertEqual(sent[0], [0x99, 60, 100])
self.assertEqual(sent[1:], [[0xB0, 30 + n, 0] for n in range(5)])
self.assertEqual(layer.handle([0x99, 61, 100]), [[0x99, 61, 100]])
def test_play_layer_unlocks_the_second_set(self):
layer = PlayLayer(lock_knobs=True)
layer.handle(PLAY_DOWN)
layer.handle([0x99, 67, 100])
self.assertEqual(layer.handle([0xB0, 36, 64]), [[0xB0, 36, 64]])
self.assertEqual(layer.handle([0xB0, 31, 64]), [])
def test_other_knobs_and_unlocked_mode_are_untouched(self):
self.assertEqual(PlayLayer(lock_knobs=True).handle([0xB0, 40, 64]), [[0xB0, 40, 64]])
self.assertEqual(PlayLayer().handle([0xB0, 31, 64]), [[0xB0, 31, 64]])