Network search, device ID, max level lock and the Channel settings tab

- network search: probes the local networks for DSPs (TCP 9761, asks for the device info)
  and adds them with one click
- device ID (address byte, 1-250) under the device's advanced settings
- the Link tab became "Channel settings": links, max level per channel and channel colours
  (colours moved here from the device settings); linked channels can't be selected again
- max level: software lock for the gain faders, enforced by the server (API, test fader,
  copy) and the UI; a DSP turned up on the device can only be pulled down until it snaps in
- global mute button only turns red (no text)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
GivouandClaude Opus 5.5 committed 2026-11-01 23:29:41 +01:00
1 parent 9473fc9eca
commit 52ecff85ce
8 files changed
+264 -49

No files matched your search

+78 -7
View File
@@ -154,6 +154,17 @@ def clean_colors(v) -> dict:
return out
def clean_maxgain(v) -> dict:
"""Software gain limits per channel: {"in0": raw 0..399} (400 = +12 dB would be no limit)."""
out = {}
for k, g in (v.items() if isinstance(v, dict) else []):
if re.fullmatch(r"(in|out)\d{1,2}", str(k)):
g = int(_num(g, 0, 400, 400))
if g < 400:
out[str(k)] = g
return out
def clean_gains(v) -> list[int] | None:
"""Saved output gains of an interrupted audio test (from config.json)."""
if not isinstance(v, list) or not v or len(v) > 8:
@@ -315,7 +326,8 @@ class App:
bool(d.get("autoconnect", True)), on_event=self.broadcast,
transport="usb" if usb else "tcp", usb=str(d.get("usb") or ""),
lock_code=str(d.get("lock_code") or ""), auto_unlock=bool(d.get("auto_unlock")),
test_saved=clean_gains(d.get("test_saved")), colors=clean_colors(d.get("colors")))
test_saved=clean_gains(d.get("test_saved")), colors=clean_colors(d.get("colors")),
maxgain=clean_maxgain(d.get("maxgain")))
dev.on_online = self.device_online
self.devices[dev_id] = dev
if dev.autoconnect:
@@ -334,7 +346,7 @@ class App:
dev.test_level = _num(db, -60, TEST_MAX, TEST_LEVEL)
raw = P.db_to_gain(dev.test_level)
for i in range(len(dev.state["outputs"])):
dev.set_param("out", i, "gain", raw)
dev.set_param("out", i, "gain", dev.gain_cap("out", i, raw))
def restore_gains(self, dev: Device):
for i, g in enumerate((dev.test_saved or [])[: len(dev.state["outputs"])]):
@@ -436,6 +448,8 @@ class App:
params += [f"mix.{k}" for k in range(min(len(sch["mix"]), len(tch["mix"])))]
for p in params:
v = copy.deepcopy(self._get(sch, p))
if p == "gain":
v = dev.gain_cap(kind, idx, v)
if self._get(tch, p) != v:
dev.set_param(kind, idx, p, v)
changed += 1
@@ -472,6 +486,52 @@ class App:
except Exception as e: # noqa: BLE001 - connection lost meanwhile: checked again on the next connect
log.warning("%s: audio test check failed: %s", dev.name, e)
# ------------------------------------------------------------ network search
async def scan_network(self) -> list[dict]:
"""Look for DSPs (TCP 9761) in the local /24 networks and ask them who they are.
DSPs this app is connected to are skipped: a DSP takes only one connection."""
busy = {d.host for d in self.real_devices() if d.transport == "tcp" and d.status in ("connecting", "loading", "locked", "online")}
known = {d.host: d for d in self.real_devices() if d.transport == "tcp"}
nets = []
for ip in local_ips():
net = ip.rsplit(".", 1)[0]
if not ip.startswith("127.") and net not in nets:
nets.append(net)
sem = asyncio.Semaphore(96)
async def probe(ip: str):
if ip in busy:
d = known[ip]
return {"host": ip, "port": P.PORT, "info": d.info, "model": d.model_name or None, "known": d.name, "busy": True}
async with sem:
try:
r, w = await asyncio.wait_for(asyncio.open_connection(ip, P.PORT), 0.7)
except (OSError, asyncio.TimeoutError):
return None
info = ""
try:
w.write(P.build_frame(P.CMD_HANDSHAKE) + P.build_frame(P.CMD_DEVICE_INFO))
await w.drain()
parser, end = P.FrameParser(), time.monotonic() + 1.2
while not info and time.monotonic() < end:
data = await asyncio.wait_for(r.read(512), max(0.05, end - time.monotonic()))
if not data:
break
for f in parser.feed(data):
if f.cmd == P.CMD_DEVICE_INFO:
info = f.payload.split(b"\x00")[0].decode("latin1", "replace").strip()
except (OSError, asyncio.TimeoutError):
pass
finally:
w.close()
d = known.get(ip)
return {"host": ip, "port": P.PORT, "info": info, "model": P.detect_model(info), "known": d.name if d else "", "busy": False}
hosts = [f"{net}.{i}" for net in nets[:2] for i in range(1, 255)]
found = [x for x in await asyncio.gather(*(probe(h) for h in hosts)) if x]
return sorted(found, key=lambda x: tuple(int(p) for p in x["host"].split(".")))
def real_devices(self) -> list[Device]:
return [d for d in self.devices.values() if not d.demo]
@@ -702,6 +762,8 @@ class App:
return self.copy_settings(body)
if path == "/api/demo":
return await self.set_demo(body) if method == "PUT" else self.demo_info()
if path == "/api/scan" and method == "POST":
return await self.scan_network()
if path == "/api/usb" and method == "GET":
return await asyncio.to_thread(usbhid.list_devices)
if path == "/api/limiter" and method == "GET":
@@ -738,9 +800,10 @@ class App:
setattr(dev, "model_key" if k == "model" else k, str(body[k]))
if "transport" in body:
dev.transport = "usb" if body["transport"] == "usb" else "tcp"
for k in ("port", "addr"):
if k in body:
setattr(dev, k, int(body[k]))
if "port" in body:
dev.port = int(_num(body["port"], 1, 65535, P.PORT))
if "addr" in body: # device ID of the DSP (address byte of every frame)
dev.addr = int(_num(body["addr"], 1, 250, 1))
if "autoconnect" in body:
dev.autoconnect = bool(body["autoconnect"])
if "auto_unlock" in body:
@@ -761,8 +824,16 @@ class App:
await dev.stop()
return {"ok": True}
if action == "set":
dev.set_param(body["kind"], int(body["idx"]), body["param"], body["value"])
return {"ok": True}
kind, idx, value = body["kind"], int(body["idx"]), body["value"]
if body["param"] == "gain":
value = dev.gain_cap(kind, idx, int(value)) # software max level
dev.set_param(kind, idx, body["param"], value)
return {"ok": True, "value": value}
if action == "maxgain": # app-side setting, the DSP doesn't know it
dev.maxgain = clean_maxgain(body.get("maxgain"))
self.save()
self.broadcast({"type": "device", "device": dev.id, "data": dev.snapshot()})
return {"ok": True, "maxgain": dev.maxgain}
if action == "preset/recall":
await dev.recall_preset(int(body["index"]))
return {"ok": True}