Light pad bank 2 from page 7, and add factory reset and a pad bank toggle to the editor.

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>
This commit is contained in:
jimmyandClaude Sonnet 5.5 committed 2026-10-21 20:34:34 +13:00
1 parent 63b3129cca
commit 3992744a1d
9 files changed
+239 -113

No files matched your search

+24 -1
View File
@@ -10,10 +10,13 @@ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from pathlib import Path
from urllib.parse import urlparse
from padeditor.device import Link, PadError, connected, read_global, read_image, save_image, write_colour
from padeditor.device import Link, PadError, connected, read_global, read_image, save_image, set_bank, write_colour
from padeditor.preset import IMAGE_LEN, PresetError, pack, pack_global, unpack, unpack_global
STATIC_DIR = Path(__file__).parent / "static"
# The image MidiSuite uploads for its factory reset, and its global block.
FACTORY_IMAGE = Path(__file__).parent / "factory.bin"
FACTORY_GLOBAL = bytes.fromhex("780032040000020001010000")
class ApiError(Exception):
@@ -76,12 +79,28 @@ class Editor:
raise ApiError(str(exc), 503) from exc
return {"ok": True, "offset": offset}
def bank(self, body: dict) -> dict:
bank = body.get("bank")
if isinstance(bank, bool) or bank not in (0, 1):
raise ApiError("bank must be 0 or 1")
with self.lock:
try:
set_bank(bank)
except PadError as exc:
raise ApiError(str(exc), 503) from exc
return {"ok": True, "bank": bank}
def imported(self, raw: bytes) -> dict:
try:
return unpack(raw)
except PresetError as exc:
raise ApiError(str(exc)) from exc
def factory(self) -> dict:
document = unpack(FACTORY_IMAGE.read_bytes())
document["global"] = unpack_global(FACTORY_GLOBAL)
return document
def exported(self, document: dict) -> bytes:
try:
return pack(document)
@@ -173,11 +192,15 @@ class Handler(BaseHTTPRequestHandler):
self._json(200, editor.save(self._json_body()))
elif route == ("POST", "/api/colour"):
self._json(200, editor.colour(self._json_body()))
elif route == ("POST", "/api/bank"):
self._json(200, editor.bank(self._json_body()))
elif route == ("POST", "/api/import"):
raw = self._read()
if len(raw) != IMAGE_LEN:
raise ApiError(f"preset file is {len(raw)} bytes, expected {IMAGE_LEN}")
self._json(200, editor.imported(raw))
elif route == ("POST", "/api/factory"):
self._json(200, editor.factory())
elif route == ("POST", "/api/export"):
self._bytes(editor.exported(self._json_body()), "application/octet-stream", "smc-pad-preset.bin")
else: