Add SoundField room planner, copy channel settings and global mute
SoundField (new tab, static/soundfield.js): - top view of the room with stage, speakers placed by dragging and aimed with a handle, type presets, height, coverage, max SPL and DSP output assignment - level map (tops by energy), sub map with phase at a chosen frequency, timing map for delay/fill speakers, audience statistics - suggestions with one-click apply: aiming, main height, delay line, sub centre cluster (power alley), front fills, quick start layout - delays from the speed of sound and temperature, written to the assigned DSP outputs - plan stored by the server (shared, part of the settings backup) Copy channel settings: level/filters/EQ/dynamics/routing to any channels of all connected DSPs. Mute all: mutes every channel of every connected DSP and unmutes only what was open before, also on DSPs that reconnect later; works while the app window is locked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ffb6c05d47
commit
a7ee66d761
8 files changed
+998
-12
No files matched your search
@@ -7,6 +7,7 @@ Then open http://<this-computer>:8080 on your phone.
|
||||
import argparse
|
||||
import asyncio
|
||||
import base64
|
||||
import copy
|
||||
import errno
|
||||
import hashlib
|
||||
import json
|
||||
@@ -89,6 +90,42 @@ def clean_limiter(data: dict) -> dict:
|
||||
return {"amps": amps, "assign": assign, "ref": ref}
|
||||
|
||||
|
||||
SF_ROLES = ("main", "sub", "delay", "fill")
|
||||
|
||||
|
||||
def clean_soundfield(data) -> dict:
|
||||
"""SoundField room plan: room, stage, reference position and speakers (positions in metres)."""
|
||||
data = data if isinstance(data, dict) else {}
|
||||
room = data.get("room") if isinstance(data.get("room"), dict) else {}
|
||||
w, d = _num(room.get("w"), 4, 200, 20), _num(room.get("d"), 4, 300, 30)
|
||||
stage = data.get("stage") if isinstance(data.get("stage"), dict) else {}
|
||||
ref = data.get("ref") if isinstance(data.get("ref"), dict) else {}
|
||||
speakers = []
|
||||
for s in (data.get("speakers") or [])[:48]:
|
||||
if not isinstance(s, dict):
|
||||
continue
|
||||
sid = re.sub(r"[^\w-]", "", str(s.get("id") or ""))[:16] or uuid.uuid4().hex[:8]
|
||||
speakers.append({
|
||||
"id": sid, "name": str(s.get("name") or "Speaker")[:24],
|
||||
"role": s.get("role") if s.get("role") in SF_ROLES else "main",
|
||||
"type": re.sub(r"[^\w-]", "", str(s.get("type") or "custom"))[:16],
|
||||
"x": _num(s.get("x"), 0, w, w / 2), "y": _num(s.get("y"), 0, d, 1), "h": _num(s.get("h"), 0, 30, 2),
|
||||
"aim": _num(s.get("aim"), -180, 180, 0), "cov": _num(s.get("cov"), 20, 360, 90),
|
||||
"spl": _num(s.get("spl"), 80, 160, 128),
|
||||
"tx": _num(s.get("tx"), 0, w, w / 2), "ty": _num(s.get("ty"), 0, d, d / 2),
|
||||
"outs": [o for o in (s.get("outs") or [])[:8] if re.fullmatch(r"[\w-]+:\d{1,2}", str(o))],
|
||||
})
|
||||
return {
|
||||
"room": {"w": w, "d": d},
|
||||
"stage": {"w": _num(stage.get("w"), 0, w, min(8, w)), "d": _num(stage.get("d"), 0, d / 2, 4)},
|
||||
"temp": _num(data.get("temp"), -10, 45, 20),
|
||||
"precedence": _num(data.get("precedence"), 0, 30, 5),
|
||||
"ear": _num(data.get("ear"), 0.5, 3, 1.7),
|
||||
"ref": {"x": _num(ref.get("x"), 0, w, w / 2), "y": _num(ref.get("y"), 0, d, d * 0.6)},
|
||||
"speakers": speakers,
|
||||
}
|
||||
|
||||
|
||||
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:
|
||||
@@ -114,6 +151,7 @@ class App:
|
||||
self.sessions: dict[str, float] = {} # token hash -> expiry
|
||||
self.failures: dict[str, tuple[int, float]] = {} # ip -> (failed attempts, locked until)
|
||||
self.limiter: dict = clean_limiter({})
|
||||
self.soundfield: dict = clean_soundfield({})
|
||||
# desktop app: its own window logs in with a one-time token, other devices need the PIN
|
||||
self.app_token: str | None = None
|
||||
self.app_sessions: set[str] = set()
|
||||
@@ -127,6 +165,8 @@ class App:
|
||||
self.demo = {"enabled": False, "model": "408"}
|
||||
self.demo_server: asyncio.Server | None = None
|
||||
self.demo_resume: set[str] = set() # real devices to reconnect when the demo ends
|
||||
# global mute: per device the channels that were open before, unmuted again on release
|
||||
self.mute_all = {"active": False, "restore": {}}
|
||||
|
||||
# ------------------------------------------------------------ config
|
||||
|
||||
@@ -142,6 +182,10 @@ class App:
|
||||
self.sessions = {k: v for k, v in cfg.get("sessions", {}).items() if v > now}
|
||||
self.locked = bool(cfg.get("locked"))
|
||||
self.lang = cfg.get("lang") if cfg.get("lang") in ("en", "de") else ""
|
||||
m = cfg.get("mute_all") or {}
|
||||
self.mute_all = {"active": bool(m.get("active")), "restore": {
|
||||
str(k): [[c[0], int(c[1])] for c in v if isinstance(c, list) and len(c) == 2 and c[0] in ("in", "out")]
|
||||
for k, v in (m.get("restore") or {}).items() if isinstance(v, list)}}
|
||||
self.apply_config(cfg)
|
||||
|
||||
def apply_config(self, cfg: dict):
|
||||
@@ -152,6 +196,8 @@ class App:
|
||||
elif not self.auth: # first start (a backup without PIN keeps the current one)
|
||||
self.set_pin(DEFAULT_PIN, save=False)
|
||||
self.limiter = clean_limiter(cfg.get("limiter") or {})
|
||||
if "soundfield" in cfg:
|
||||
self.soundfield = clean_soundfield(cfg.get("soundfield"))
|
||||
r = cfg.get("remote") or {}
|
||||
self.remote = {"enabled": bool(r.get("enabled")), "port": int(_num(r.get("port"), 1, 65535, 8080))}
|
||||
for d in cfg.get("devices", [])[:20]:
|
||||
@@ -165,7 +211,7 @@ class App:
|
||||
"""App backup: devices, PIN (hashed), amplifiers/limiter data, remote access - no logins."""
|
||||
return {"format": CONFIG_FORMAT, "version": 1, "exported": time.strftime("%Y-%m-%dT%H:%M:%S"),
|
||||
"devices": [d.config() for d in self.real_devices()], "auth": self.auth,
|
||||
"limiter": self.limiter, "remote": self.remote}
|
||||
"limiter": self.limiter, "remote": self.remote, "soundfield": self.soundfield}
|
||||
|
||||
async def restore_config(self, doc: dict, session: str):
|
||||
if not isinstance(doc, dict) or doc.get("format") != CONFIG_FORMAT:
|
||||
@@ -182,6 +228,7 @@ class App:
|
||||
for dev in self.devices.values():
|
||||
self.broadcast({"type": "device", "device": dev.id, "data": dev.snapshot()})
|
||||
self.broadcast({"type": "limiter", "data": self.limiter})
|
||||
self.broadcast({"type": "soundfield", "data": self.soundfield})
|
||||
if self.app_token: # desktop app: (re)start or stop the LAN listener as restored
|
||||
await self.start_remote()
|
||||
|
||||
@@ -220,7 +267,10 @@ class App:
|
||||
def save(self):
|
||||
sessions = {k: v for k, v in self.sessions.items() if k not in self.app_sessions}
|
||||
cfg = {"devices": [d.config() for d in self.real_devices()], "auth": self.auth,
|
||||
"sessions": sessions, "limiter": self.limiter, "remote": self.remote, "locked": self.locked}
|
||||
"sessions": sessions, "limiter": self.limiter, "remote": self.remote, "locked": self.locked,
|
||||
"soundfield": self.soundfield,
|
||||
"mute_all": {"active": self.mute_all["active"],
|
||||
"restore": {k: v for k, v in self.mute_all["restore"].items() if k != "demo"}}}
|
||||
if self.lang:
|
||||
cfg["lang"] = self.lang
|
||||
self.config_path.write_text(json.dumps(cfg, indent=2), encoding="utf-8")
|
||||
@@ -234,7 +284,7 @@ class App:
|
||||
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")))
|
||||
dev.on_online = self.check_audio_test
|
||||
dev.on_online = self.device_online
|
||||
self.devices[dev_id] = dev
|
||||
if dev.autoconnect:
|
||||
if self.demo["enabled"]:
|
||||
@@ -280,6 +330,97 @@ class App:
|
||||
self.broadcast({"type": "device", "device": dev.id, "data": dev.snapshot()})
|
||||
return {"ok": True}
|
||||
|
||||
async def device_online(self, dev: Device):
|
||||
await self.check_audio_test(dev)
|
||||
if not self.mute_all["active"] and self.mute_all["restore"].get(dev.id):
|
||||
self.unmute_device(dev) # released while this DSP was offline
|
||||
self.save()
|
||||
|
||||
# ------------------------------------------------------------ global mute
|
||||
|
||||
def mute_all_info(self) -> dict:
|
||||
return {"active": self.mute_all["active"]}
|
||||
|
||||
def unmute_device(self, dev: Device):
|
||||
for kind, i in self.mute_all["restore"].pop(dev.id, []):
|
||||
chans = dev.state["inputs" if kind == "in" else "outputs"]
|
||||
if i < len(chans) and chans[i]["mute"]:
|
||||
dev.set_param(kind, i, "mute", False)
|
||||
|
||||
def set_mute_all(self, mute: bool) -> dict:
|
||||
"""Mute every channel of every connected DSP; releasing unmutes only what was open before."""
|
||||
online = [d for d in self.devices.values() if d.status == "online" and d.state]
|
||||
if mute and not self.mute_all["active"]:
|
||||
self.mute_all["restore"] = {}
|
||||
for dev in online:
|
||||
opened = [[kind, i] for kind, key in (("in", "inputs"), ("out", "outputs"))
|
||||
for i, ch in enumerate(dev.state[key]) if not ch["mute"]]
|
||||
for kind, i in opened:
|
||||
dev.set_param(kind, i, "mute", True)
|
||||
self.mute_all["restore"][dev.id] = opened
|
||||
self.mute_all["active"] = True
|
||||
elif not mute and self.mute_all["active"]:
|
||||
self.mute_all["active"] = False
|
||||
for dev in online:
|
||||
self.unmute_device(dev) # offline ones follow when they connect again
|
||||
self.save()
|
||||
self.broadcast({"type": "muteall", "data": self.mute_all_info()})
|
||||
return self.mute_all_info()
|
||||
|
||||
# ------------------------------------------------------------ copy channel settings
|
||||
|
||||
def copy_settings(self, body: dict) -> dict:
|
||||
"""Copy groups of settings from one channel to channels of the same kind (any connected DSP)."""
|
||||
src = self.devices.get(str(body.get("device")))
|
||||
kind = "in" if body.get("kind") == "in" else "out"
|
||||
key = "inputs" if kind == "in" else "outputs"
|
||||
if not src or not src.state:
|
||||
raise RuntimeError("DSP is not connected")
|
||||
sch = src.state[key][int(body.get("idx", 0))]
|
||||
groups = set(body.get("groups") or [])
|
||||
changed = 0
|
||||
for t in body.get("targets") or []:
|
||||
dev = self.devices.get(str(t.get("device")))
|
||||
if not dev or dev.status != "online" or not dev.state:
|
||||
continue
|
||||
if dev.test_active:
|
||||
raise RuntimeError("Audio test is on – switch it off first")
|
||||
idx = int(t.get("idx", -1))
|
||||
if not 0 <= idx < len(dev.state[key]) or (dev is src and idx == int(body.get("idx", 0))):
|
||||
continue
|
||||
tch = dev.state[key][idx]
|
||||
params = []
|
||||
if "level" in groups:
|
||||
params += ["gain", "delay", "polarity"]
|
||||
if "filters" in groups:
|
||||
params += ["hp", "lp"]
|
||||
if "eq" in groups:
|
||||
params += ["peq_bypass"] + [f"peq.{b}" for b in range(min(len(sch["peq"]), len(tch["peq"])))]
|
||||
if kind == "in":
|
||||
params += ["geq_bypass"] + [f"geq.{b}" for b in range(31)]
|
||||
if "dynamics" in groups:
|
||||
params += ["gate"] if kind == "in" else ["comp", "limit"]
|
||||
if "routing" in groups and kind == "out":
|
||||
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 self._get(tch, p) != v:
|
||||
dev.set_param(kind, idx, p, v)
|
||||
changed += 1
|
||||
if "routing" in groups and kind == "out":
|
||||
m = sch["matrix"] & ((1 << len(tch["mix"])) - 1)
|
||||
if tch["matrix"] != m:
|
||||
dev.set_param(kind, idx, "matrix", m)
|
||||
changed += 1
|
||||
return {"ok": True, "changed": changed}
|
||||
|
||||
@staticmethod
|
||||
def _get(ch: dict, path: str):
|
||||
node = ch
|
||||
for k in path.split("."):
|
||||
node = node[int(k)] if isinstance(node, list) else node[k]
|
||||
return node
|
||||
|
||||
async def check_audio_test(self, dev: Device):
|
||||
"""On connect: a DSP still playing a test signal goes straight into the audio test (outputs lowered);
|
||||
one back on its analog inputs gets the faders saved by an interrupted test back."""
|
||||
@@ -331,7 +472,7 @@ class App:
|
||||
port = self.demo_server.sockets[0].getsockname()[1]
|
||||
dev = Device("demo", f"Demo DSP {model}", "127.0.0.1", port, model, autoconnect=False, on_event=self.broadcast)
|
||||
dev.demo = True
|
||||
dev.on_online = self.check_audio_test
|
||||
dev.on_online = self.device_online
|
||||
self.devices[dev.id] = dev
|
||||
self.demo["enabled"] = True
|
||||
self.broadcast({"type": "device", "device": dev.id, "data": dev.snapshot()})
|
||||
@@ -436,7 +577,7 @@ class App:
|
||||
@staticmethod
|
||||
def allowed_while_locked(method: str, path: str) -> bool:
|
||||
"""What the locked app window may still do: look at everything, export presets."""
|
||||
if path in ("/api/unlock", "/api/events", "/api/lang"):
|
||||
if path in ("/api/unlock", "/api/events", "/api/lang", "/api/muteall"):
|
||||
return True
|
||||
if method == "GET":
|
||||
return path != "/api/backup" # holds the PIN hash
|
||||
@@ -505,6 +646,19 @@ class App:
|
||||
return [d.snapshot() for d in self.devices.values()]
|
||||
if path == "/api/devices" and method == "POST":
|
||||
return self.add_device(body).snapshot()
|
||||
if path == "/api/soundfield" and method == "PUT":
|
||||
self.soundfield = clean_soundfield(body)
|
||||
self.save()
|
||||
self.broadcast({"type": "soundfield", "data": self.soundfield})
|
||||
return self.soundfield
|
||||
if path == "/api/soundfield":
|
||||
return self.soundfield
|
||||
if path == "/api/muteall" and method == "POST":
|
||||
return self.set_mute_all(bool(body.get("mute")))
|
||||
if path == "/api/muteall":
|
||||
return self.mute_all_info()
|
||||
if path == "/api/copy" and method == "POST":
|
||||
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/usb" and method == "GET":
|
||||
@@ -773,7 +927,7 @@ class App:
|
||||
self.clients.add(q)
|
||||
try:
|
||||
hello = {"type": "hello", "devices": [d.snapshot() for d in self.devices.values()], "limiter": self.limiter,
|
||||
"demo": self.demo_info()}
|
||||
"demo": self.demo_info(), "muteall": self.mute_all_info(), "soundfield": self.soundfield}
|
||||
writer.write(f"data: {json.dumps(hello)}\n\n".encode())
|
||||
await writer.drain()
|
||||
while True:
|
||||
|
||||
Reference in new issue
Block a user