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():