Add audio test tab with test generator, test fader and output mutes

- switch the DSP's test generator (pink/white noise, sine 20 Hz-20 kHz, command 0x39)
- entering lowers all outputs to -50 dB before the generator starts; one test fader
  raises them together; mute buttons for every output
- presets cannot be stored, recalled, imported or exported while the test runs
- leaving switches the generator off first, then restores every output gain
- a DSP found playing a test signal on connect goes straight into the audio test;
  saved gains survive an app restart (config.json)
- simulator and memory-image support for the test signal

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
GivouandClaude Opus 5.5 committed 2026-11-01 21:33:01 +01:00
1 parent 61400df667
commit 66f988cf08
12 files changed
+280 -12

No files matched your search

+29 -2
View File
@@ -21,7 +21,7 @@ LINK_RESYNC_DELAY = 1.5 # re-read the config this long after the last change on
class Device:
def __init__(self, dev_id: str, name: str, host: str, port: int = P.PORT, model: str = "auto",
addr: int = 1, autoconnect: bool = True, on_event=None, transport: str = "tcp", usb: str = "",
lock_code: str = "", auto_unlock: bool = False):
lock_code: str = "", auto_unlock: bool = False, test_saved: list | None = None):
self.id = dev_id
self.name = name
self.host = host
@@ -36,6 +36,10 @@ class Device:
self.lock_code = lock_code if P.LOCK_CODE.fullmatch(lock_code or "") else ""
self.auto_unlock = auto_unlock
self.demo = False # in-process simulator of the demo mode, never saved
# audio test: output gains from before the test (restored when it ends) and the test fader level
self.test_saved: list[int] | None = test_saved if isinstance(test_saved, list) else None
self.test_level = -50.0
self.on_online = None # async callback(device) once a connection is fully loaded
self.status = "disconnected" # disconnected | connecting | loading | locked | online | error
self.error = ""
@@ -66,11 +70,12 @@ class Device:
return {"id": self.id, "name": self.name, "host": self.host, "port": self.port,
"model": self.model_key, "addr": self.addr, "autoconnect": self.autoconnect,
"transport": self.transport, "usb": self.usb,
"lock_code": self.lock_code, "auto_unlock": self.auto_unlock}
"lock_code": self.lock_code, "auto_unlock": self.auto_unlock, "test_saved": self.test_saved}
def snapshot(self) -> dict:
cfg = self.config()
cfg["lock_code"] = bool(self.lock_code) # clients only learn whether a code is remembered
cfg["test_level"] = self.test_level
return {**cfg, "demo": self.demo, "status": self.status, "error": self.error, "info": self.info,
"detected_model": self.model_name or None,
"n_in": self.model.n_in if self.model else 0,
@@ -128,6 +133,26 @@ class Device:
await asyncio.sleep(0.3)
await self.refresh()
@property
def test_active(self) -> bool:
return bool(self.state and self.state.get("test", {}).get("source"))
async def set_test_signal(self, source: int, freq: int):
"""Switch the inputs to a test generator (1 pink, 2 white, 3 sine) or back to the analog inputs (0)."""
if self.status != "online" or not self.state:
raise RuntimeError("DSP is not connected")
await self.flush() # queued changes (e.g. lowered faders) reach the DSP first
await self._request(P.CMD_TEST_SIGNAL, bytes([source, freq]))
self.state["test"] = {"source": source, "freq": freq}
self.on_event({"type": "test", "device": self.id, "test": self.state["test"]})
async def flush(self):
"""Wait until every queued parameter change has been sent."""
while self._pending:
await asyncio.sleep(0.01)
async with self._lock: # the last one may still wait for its answer
pass
async def unlock(self, code: str) -> bool:
"""Try a lock code while the DSP waits for it. True if the DSP accepted it."""
code = str(code or "").strip().upper()
@@ -255,6 +280,8 @@ class Device:
self._set_status("online")
self._emit_state()
self._tasks += [asyncio.create_task(self._write_loop()), asyncio.create_task(self._meter_loop())]
if self.on_online:
asyncio.create_task(self.on_online(self))
done, _ = await asyncio.wait(self._tasks, return_when=asyncio.FIRST_COMPLETED)
for t in done:
if t.exception():
+16 -1
View File
@@ -25,6 +25,7 @@ CMD_PRESET_NAME = 0x29
CMD_PRESET_COUNT = 0x2C # answer: [time lock][4 bytes time lock data][device lock] (see device_locked)
CMD_UNLOCK = 0x2D # [0][code 4] -> answer [0][1 = unlocked, 0 = wrong code]
CMD_SET_LOCK_CODE = 0x2F # [code 4]
CMD_TEST_SIGNAL = 0x39 # [source][freq index]: 0 = analog input, 1 = pink noise, 2 = white noise, 3 = sine
CMD_METER = 0x40
# Parameter commands
@@ -45,6 +46,7 @@ CMD_GEQ = 0x48
CMD_LINK = 0x3B # [ch][u16 link mask], see link_masks()
CHUNK_SIZE = 50
TEST_SOURCES = ("analog", "pink", "white", "sine")
LOCK_CODE = re.compile(r"[A-Z0-9]{4}") # device lock code: 4 characters, digits and upper-case letters
@@ -222,6 +224,11 @@ class Model:
def globals_base(self) -> int:
return self.out_base + self.n_out * self.out_size
@property
def test_base(self) -> int:
"""Test signal (source, sine frequency index), after the mute masks and one word per channel."""
return self.globals_base + 4 + 2 * self.n_in + 2 * self.n_out
@property
def size(self) -> int:
return self.globals_base + 4 + 2 * self.n_in + 2 * self.n_out + 12
@@ -315,7 +322,9 @@ def parse_state(model: Model, buf: bytes) -> dict:
"link": u16(p + 84),
"mute": bool(out_mute >> i & 1),
})
return {"preset_name": _name(buf[2:16]), "inputs": inputs, "outputs": outputs}
source, freq = struct.unpack_from("<HH", buf, model.test_base)
test = {"source": source if source < len(TEST_SOURCES) else 0, "freq": freq if freq < 31 else 0}
return {"preset_name": _name(buf[2:16]), "inputs": inputs, "outputs": outputs, "test": test}
def build_state_buffer(model: Model, state: dict) -> bytearray:
@@ -359,6 +368,8 @@ def build_state_buffer(model: Model, state: dict) -> bytearray:
struct.pack_into("<4H", buf, p + 78, ch["gain"], int(ch["polarity"]), ch["delay"], ch.get("link", 1 << i))
out_mute |= int(ch["mute"]) << i
struct.pack_into("<HH", buf, model.globals_base, in_mute, out_mute)
test = state.get("test") or {}
struct.pack_into("<HH", buf, model.test_base, test.get("source", 0), test.get("freq", 0))
return buf
@@ -380,6 +391,7 @@ def default_state(model: Model) -> dict:
"limit": {"attack": 49, "release": 499, "knee": 0, "threshold": 220},
"gain": 280, "polarity": False, "delay": 0, "mute": False, "link": 1 << i,
} for i in range(model.n_out)],
"test": {"source": 0, "freq": 17},
}
@@ -500,6 +512,9 @@ def apply_command(model: Model, state: dict, cmd: int, p: bytes):
"""Update state from an incoming set command (used by the simulator)."""
if not p:
return
if cmd == CMD_TEST_SIGNAL:
state["test"] = {"source": p[0], "freq": p[1] if len(p) > 1 else 0}
return
c = p[0]
kind, idx = ("in", c) if c < model.n_in else ("out", c - model.n_in)
chans = state["inputs" if kind == "in" else "outputs"]