Bank 2's lamp colours come from preset page 7, not page 3, so pad_colours.py writes there and the editor labels it Bank 2. The factory reset loads the image MidiSuite uploads for its own reset, and the bank toggle writes the global-block byte MidiSuite uses to switch banks. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
122 lines
4.0 KiB
Python
122 lines
4.0 KiB
Python
"""Scene colours become preset RGB writes, and the codec matches a known message."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
spec = importlib.util.spec_from_file_location("pad_colours", ROOT / "scripts" / "pad_colours.py")
|
|
colours = importlib.util.module_from_spec(spec)
|
|
assert spec.loader is not None
|
|
sys.modules["pad_colours"] = colours
|
|
spec.loader.exec_module(colours)
|
|
|
|
|
|
def test_codec_matches_the_published_write():
|
|
inner = bytes.fromhex("00592209000005000000800100000178")
|
|
wire = bytes([0xF0, *colours.encode(inner), 0xF7])
|
|
assert wire == bytes.fromhex("f000320949000040020000000018000000017001f7")
|
|
assert colours.decode(wire[1:-1]) == inner
|
|
|
|
|
|
def test_scene_colours_are_stored_on_the_note_36_pads():
|
|
writes = colours.colour_writes()
|
|
first = writes[:16]
|
|
assert [name for name, _addr, _rgb in first] == [
|
|
"Red",
|
|
"Green",
|
|
"Blue",
|
|
"White",
|
|
"Yellow",
|
|
"Cyan",
|
|
"Magenta",
|
|
"Orange",
|
|
"Warm",
|
|
"Cool",
|
|
"Pink",
|
|
"Lime",
|
|
"Full",
|
|
"Half",
|
|
"Dim50",
|
|
"Black",
|
|
]
|
|
assert first[0][1:] == (1048, bytes.fromhex("f00000"))
|
|
assert first[1][1:] == (1074, bytes.fromhex("00f000"))
|
|
assert first[2][1:] == (1100, bytes.fromhex("0000f0"))
|
|
assert first[3][1:] == (1126, bytes.fromhex("f0f0f0"))
|
|
assert first[15][1:] == (1048 + 15 * 26, b"\x00\x00\x00")
|
|
assert len(writes) == 16 * len(colours.BANKS)
|
|
assert {address for _name, address, _rgb in writes if _name == "Red"} == {
|
|
bank + 4 for bank in colours.BANKS
|
|
}
|
|
|
|
|
|
def test_xchc_colours_are_stored_on_page_7_for_pad_bank_2():
|
|
writes = colours.colour_writes(bank=2, colours=colours.xchc_colours())
|
|
first = [item for item in writes if item[1] < colours.BANKS[1]]
|
|
assert [name for name, _addr, _rgb in first] == [
|
|
"Red",
|
|
"Orange",
|
|
"Yellow",
|
|
"Green",
|
|
"Cyan",
|
|
"Blue",
|
|
"Violet",
|
|
"Magenta",
|
|
"White",
|
|
"",
|
|
"",
|
|
"",
|
|
"",
|
|
"",
|
|
"",
|
|
"",
|
|
]
|
|
assert first[0][1:] == (3128, bytes.fromhex("f00000"))
|
|
assert first[1][1:] == (3154, bytes.fromhex("f07800"))
|
|
assert first[6][1:] == (3128 + 6 * 26, bytes.fromhex("7800f0"))
|
|
assert first[8][1:] == (3128 + 8 * 26, bytes.fromhex("f0f0f0"))
|
|
assert first[9][1:] == (3128 + 9 * 26, b"\x00\x00\x00")
|
|
assert {address for name, address, _rgb in writes if name == "Red"} == {
|
|
base + 5 * 16 * 26 + 4 for base in colours.BANKS
|
|
}
|
|
|
|
|
|
def test_save_is_the_empty_write_midi_suite_sends():
|
|
inner = colours.decode(bytes(colours.save_request()[1:-1]))
|
|
assert inner[:3] == b"\x00\x59\x22"
|
|
length = int.from_bytes(inner[3:6], "little")
|
|
assert inner[6:6 + length] == bytes([5, 0, 0, 0, 0, 0, 0, 0])
|
|
assert len(colours.save_request()) == 20
|
|
|
|
|
|
def test_private_port_is_not_the_master_or_qlc():
|
|
names = [
|
|
"SINCO:SINCO SMC-PAD-Master 20:1",
|
|
"SINCO:SINCO SMC-PAD-Private 20:0",
|
|
"qlcplus:__QLC__ 128:0",
|
|
]
|
|
assert colours.private_port(names) == "SINCO:SINCO SMC-PAD-Private 20:0"
|
|
|
|
|
|
def test_identify_lights_each_page_in_its_own_colour():
|
|
factory = (ROOT / "tests" / "data" / "smc_pad_factory.bin").read_bytes()
|
|
image = colours.identify_image(factory)
|
|
preset = colours.preset
|
|
assert len(image) == len(factory)
|
|
for number in range(preset.PRESET_COUNT):
|
|
for index in range(preset.PAD_COUNT):
|
|
at = preset.colour_offset(number, index)
|
|
_name, red, green, blue = colours.PAGE_COLOURS[index // preset.PAGE_LEN]
|
|
assert image[at:at + 3] == bytes(map(colours.scale, (red, green, blue)))
|
|
changed = {at for at in range(len(image)) if image[at] != factory[at]}
|
|
lamps = {
|
|
preset.colour_offset(number, index) + step
|
|
for number in range(preset.PRESET_COUNT)
|
|
for index in range(preset.PAD_COUNT)
|
|
for step in range(3)
|
|
}
|
|
assert changed <= lamps
|