DJ Brake: choose which limiters count, horizontal distance to the limiter

Outputs can be left out per device, muted outputs never count. The page also
shows how far the closest watched output is from its limiter threshold.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
GivouandClaude Opus 5.5 committed 2026-11-02 18:42:56 +01:00
1 parent e56524a8cd
commit 8919f0016c
7 files changed
+136 -30

No files matched your search

+50 -11
View File
@@ -213,6 +213,17 @@ def rew_send_curve(body: dict):
DJ_HOLD = 0.8 # s the light of /djbrake stays on after a limiter acted, so short hits are seen
def clean_dj_ignore(data) -> dict:
"""Outputs the DJ Brake does not watch, per device id. Everything else is watched, so new DSPs count by default."""
if not isinstance(data, dict):
return {}
out = {str(k)[:64]: sorted({i for i in v if type(i) is int and 0 <= i < 16})
for k, v in list(data.items())[:64] if isinstance(v, list)}
return {k: v for k, v in out.items() if v}
DASH_TYPES = ("status", "meters", "mixer", "curve", "channel", "limiter", "routing", "delays", "fir", "notes")
@@ -294,7 +305,9 @@ class App:
self.soundfield: dict = clean_soundfield({})
self.dashboard: dict | None = None
self.djbrake = False # page /djbrake for the DJ: without PIN, shows only whether a limiter acts
self.dj_ignore: dict = {} # device id -> outputs not watched
self.dj_hit = 0.0 # when a limiter was last seen acting
self.dj_rooms: dict = {} # device id -> dB left to the nearest watched limiter, False = nothing watched
self.dj_streams = 0
self.logo = ""
# desktop app: its own window logs in with a one-time token, other devices need the PIN
@@ -345,6 +358,7 @@ class App:
if "dashboard" in cfg:
self.dashboard = clean_dashboard(cfg.get("dashboard"))
self.djbrake = bool(cfg.get("djbrake"))
self.dj_ignore = clean_dj_ignore(cfg.get("dj_ignore"))
if "logo" in cfg:
self.logo = clean_logo(cfg.get("logo"))
r = cfg.get("remote") or {}
@@ -361,7 +375,7 @@ class App:
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, "soundfield": self.soundfield, "logo": self.logo,
"dashboard": self.dashboard, "djbrake": self.djbrake}
"dashboard": self.dashboard, "djbrake": self.djbrake, "dj_ignore": self.dj_ignore}
async def restore_config(self, doc: dict, session: str):
if not isinstance(doc, dict) or doc.get("format") != CONFIG_FORMAT:
@@ -419,7 +433,7 @@ class App:
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, "lock_dash": self.lock_dash,
"soundfield": self.soundfield, "logo": self.logo, "dashboard": self.dashboard, "djbrake": self.djbrake,
"soundfield": self.soundfield, "logo": self.logo, "dashboard": self.dashboard, "djbrake": self.djbrake, "dj_ignore": self.dj_ignore,
"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:
@@ -875,9 +889,27 @@ class App:
# ------------------------------------------------------------ events
def dj_note(self, ev: dict):
"""Keeps the state of the /djbrake page. A muted output is not watched: nobody hears it."""
dev = self.devices.get(ev["device"])
if not dev or not dev.state:
return
room, ignore = False, self.dj_ignore.get(dev.id, ())
for i, (level, limit) in enumerate(zip(ev["out"], ev["limit"])):
ch = dev.state["outputs"][i]
if i in ignore or ch["mute"]:
continue
if limit:
self.dj_hit = time.monotonic()
left = 0.0 if limit else None
if not limit and level > 0:
left = max(0.0, P.threshold_to_db(ch["limit"]["threshold"]) - 20 * math.log10(level))
room = left if room is False or room is None else room if left is None else min(room, left)
self.dj_rooms[dev.id] = room
def broadcast(self, ev: dict):
if ev.get("type") == "meters" and any(ev.get("limit") or ()):
self.dj_hit = time.monotonic()
if ev["type"] == "meters":
self.dj_note(ev)
msg = json.dumps(ev, separators=(",", ":"))
for q in list(self.clients):
if ev["type"] == "meters" and q.qsize() > 50:
@@ -901,10 +933,14 @@ class App:
if path == "/api/logo":
return {"logo": self.logo}
if path == "/api/djbrake" and method == "PUT":
self.djbrake = bool(body.get("enabled"))
if "enabled" in body:
self.djbrake = bool(body["enabled"])
if "ignore" in body:
self.dj_ignore = clean_dj_ignore(body["ignore"])
self.save()
self.broadcast({"type": "djbrake", "enabled": self.djbrake})
return {"enabled": self.djbrake}
ans = {"enabled": self.djbrake, "ignore": self.dj_ignore}
self.broadcast({"type": "djbrake", **ans})
return ans
if path == "/api/dashboard" and method == "PUT":
self.dashboard = clean_dashboard(body)
self.save()
@@ -1246,7 +1282,7 @@ class App:
await self.respond(writer, 200, f.read_bytes(), ctype)
async def dj_stream(self, writer):
"""The one thing /djbrake may know, without a login: is a limiter acting. Nothing else leaves here."""
"""All /djbrake may know, without a login: is a limiter acting and how far away is it. Nothing else leaves here."""
if not self.djbrake or self.dj_streams >= 20:
await self.respond(writer, 404, b"not found", "text/plain")
return
@@ -1257,8 +1293,11 @@ class App:
try:
while self.djbrake:
now = time.monotonic()
state = {"on": now - self.dj_hit < DJ_HOLD,
"ready": any(d.status == "online" for d in self.devices.values())}
rooms = [self.dj_rooms.get(d.id, False) for d in self.devices.values() if d.status == "online"]
rooms = [r for r in rooms if r is not False]
known = [r for r in rooms if r is not None]
state = {"on": now - self.dj_hit < DJ_HOLD, "ready": bool(rooms),
"room": round(min(known) * 2) / 2 if known else None}
if state != last:
writer.write(f"data: {json.dumps(state)}\n\n".encode())
last, idle = state, 0.0
@@ -1279,7 +1318,7 @@ class App:
try:
hello = {"type": "hello", "devices": [d.snapshot() for d in self.devices.values()], "limiter": self.limiter,
"demo": self.demo_info(), "muteall": self.mute_all_info(), "soundfield": self.soundfield, "logo": self.logo,
"dashboard": self.dashboard, "djbrake": self.djbrake}
"dashboard": self.dashboard, "djbrake": self.djbrake, "dj_ignore": self.dj_ignore}
writer.write(f"data: {json.dumps(hello)}\n\n".encode())
await writer.drain()
while True: