From 8919f0016c3d3528e4e8dc3bfaaf4cb7c09216c9 Mon Sep 17 00:00:00 2001 From: Givou Date: Mon, 2 Nov 2026 18:42:56 +0100 Subject: [PATCH] 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 --- CLAUDE.md | 4 ++- README.md | 5 ++-- server.py | 61 +++++++++++++++++++++++++++++++++++++-------- static/app.js | 24 +++++++++++++++--- static/djbrake.html | 59 +++++++++++++++++++++++++++++++++++-------- static/i18n.js | 4 ++- static/style.css | 9 ++++++- 7 files changed, 136 insertions(+), 30 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index d061ff4..a356e75 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -58,7 +58,7 @@ pi_writer.py → pi_image.py (cloud-init SD card, installs server.py as a system * **Sound Lab / REW** (`static/rew.js`, handbooks in `static/docs.js`, `rew_call` in `server.py`) – the server talks to REW's API on `127.0.0.1:4735`, which only answers on REW's own computer; so Sound Lab is only in the desktop apps (`S.isApp`, the server refuses `/api/rew/` otherwise). Only checked against a fake server built from its OpenAPI spec. * **DJ Brake** (`static/djbrake.html`, `App.dj_stream`) – the only page without a login, off by default. It may only ever learn - `{on, ready}` from `/djbrake/state`: never add device data or controls there. On its own on purpose, without `app.js`. + `{on, ready, room}` from `/djbrake/state`: never add device data or controls there. On its own on purpose, without `app.js`. * **Network search** – `App.scan_network` probes the local /24 networks on TCP 9761 (handshake + device info), skipping DSPs this app is connected to. * **Copy settings / mute all** – `App.copy_settings` (`POST /api/copy`, groups level/filters/eq/dynamics/routing) and @@ -136,6 +136,8 @@ Not verified yet – ask for a log (`python server.py -v`) from real hardware be only; whether the generator is pre or post input gain is unknown (the app therefore only lowers the outputs) * Device lock (`0x2C` byte 5, `0x2D`, `0x2F`, `0x11`) – implemented from the control software's behaviour and tested against the simulator only; no command to remove a lock is known +* DJ Brake distance to the limiter: output meter dB minus threshold dB, assumes both share one reference (only the + light, from the limiter-active bits, is certain) * Limiter calculator reference level (assumes limiter 0 dB = 0 dBu at the output; adjustable per device) * Pi Writer: raw write to a real SD card and first boot on a real Pi (only tested with an image file) diff --git a/README.md b/README.md index c02f95d..f0909dc 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,9 @@ Control both devices at the same time from your phone, tablet or computer – ov * **Read-only switch** – on phones and tablets the web UI starts read-only; a small switch at the top allows changes * **Sound Lab** (Windows and macOS apps) – together with REW (Room EQ Wizard): take the filters of a measurement or a REW filter file onto a channel, compare before applying, send a channel's curve or filters back to REW. Handbook with real cases here and in SoundField -* **DJ Brake** – optional page `/djbrake` for a tablet at the DJ booth: a big red light while a limiter is working. Needs no PIN - and shows nothing else +* **DJ Brake** – optional page `/djbrake` for a tablet at the DJ booth: a big red light while a limiter is working and a horizontal + bar with the distance to the limiter. You choose which limiters count (a monitor can be left out). Needs no PIN and shows + nothing else * **Mixer** – faders, mute and live meters for all inputs and outputs, limiter LED on every output (status read from the DSP) * **Channel** – name, gain, delay, polarity, high/low pass, 8/9-band PEQ with a draggable curve; the curve shows diff --git a/server.py b/server.py index fe7ea01..5d367fa 100644 --- a/server.py +++ b/server.py @@ -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: diff --git a/static/app.js b/static/app.js index fae01d7..864f7c9 100644 --- a/static/app.js +++ b/static/app.js @@ -2384,7 +2384,25 @@ function djBrakeCard() { try { await navigator.clipboard.writeText(url); toast(t("Address copied")); } catch { toast(url); } } }, t("Copy"))) : null, S.djbrake && !url ? h("p", { class: "info djwarn" }, t("Switch on remote access below so other devices can reach it.")) : null, - S.djbrake ? h("p", { class: "info" }, t("Anyone in your network can open it without a PIN. It shows only the light, watches all outputs of all connected DSPs and changes nothing.")) : null); + S.djbrake ? djLimiters() : null, + S.djbrake ? h("p", { class: "info" }, t("Anyone in your network can open it without a PIN. It shows only the light and the distance to the limiter and changes nothing.")) : null); +} + +function djLimiters() { + const devs = S.order.map(id => S.devices[id]).filter(d => d.state && !d.demo); + const toggle = async (id, i) => { + const cur = S.djIgnore[id] || []; + const ignore = { ...S.djIgnore, [id]: cur.includes(i) ? cur.filter(x => x !== i) : [...cur, i] }; + try { S.djIgnore = (await api("PUT", "/api/djbrake", { ignore })).ignore; render(); } + catch (e) { toast(t("Error: ") + trMsg(e.message)); } + }; + return h("div", { class: "djlim" }, h("b", {}, t("Limiters that count")), + devs.length ? devs.map(d => h("div", { class: "djdev" }, devs.length > 1 ? h("small", {}, d.name) : null, + h("div", { class: "djchs" }, chans(d, "out").map((c, i) => { + const on = !(S.djIgnore[d.id] || []).includes(i); + return h("button", { class: "djch" + (on ? " on" : ""), "aria-pressed": String(on), onclick: () => toggle(d.id, i) }, + chLabel("out", i), c.name ? h("small", {}, c.name) : null); + })))) : h("p", { class: "info" }, t("Connect a DSP to choose."))); } function langCard() { @@ -2637,7 +2655,7 @@ function connectEvents() { if (ev.muteall) { S.muteAll = ev.muteall.active; showMuteAll(); } if (ev.soundfield) S.sf = ev.soundfield; if ("dashboard" in ev) S.dash = ev.dashboard && ev.dashboard.modules; - S.djbrake = !!ev.djbrake; + S.djbrake = !!ev.djbrake; S.djIgnore = ev.dj_ignore || {}; if ("logo" in ev) { S.logo = ev.logo; showLogo(); } if (S.demo.enabled && S.devices.demo && !S.devices[S.cur]?.demo) S.cur = "demo"; S.order.forEach(id => maybeAskUnlock(S.devices[id])); @@ -2673,7 +2691,7 @@ function connectEvents() { case "dashboard": dashRemote(ev.data); break; case "djbrake": - S.djbrake = ev.enabled; if (S.settings) render(); break; + S.djbrake = ev.enabled; S.djIgnore = ev.ignore; if (S.settings && !S.busy) render(); break; case "logo": S.logo = ev.data; showLogo(); if (S.settings) render(); break; case "muteall": diff --git a/static/djbrake.html b/static/djbrake.html index 88283a9..1c1f4eb 100644 --- a/static/djbrake.html +++ b/static/djbrake.html @@ -16,14 +16,26 @@ body.on #wash, body.on #halo, body.on #core { transition: opacity .09s ease-out; opacity: 1; } #wash { position: fixed; inset: 0; background: radial-gradient(circle at 50% 46%, #6e0a0a 0%, #2a0505 42%, #050608 78%); } - #lamp { position: relative; width: 66vmin; height: 66vmin; display: grid; place-items: center; } + #lamp { position: relative; width: 52vmin; height: 52vmin; display: grid; place-items: center; } #halo, #core, #glass, #ring { position: absolute; inset: 0; border-radius: 50%; } #glass { background: radial-gradient(circle at 50% 38%, #171a20, #0b0d11 70%); box-shadow: inset 0 0 0 1px #ffffff14; } #core { background: radial-gradient(circle at 50% 36%, #ff6a5c 0%, #f4201c 46%, #b80c0f 100%); box-shadow: inset 0 0 0 1px #ffb3a8, inset 0 -3vmin 7vmin #5e000380; } #halo { inset: -7vmin; background: radial-gradient(circle, #ff2a1f 44%, #ff2a1f00 70%); filter: blur(3vmin); } #ring { border: .5vmin solid #ff5a4c; opacity: 0; pointer-events: none; } - #word { position: relative; font-size: 10.5vmin; font-weight: 800; letter-spacing: .03em; line-height: 1; color: #4b5260; transition: color .5s; } - #sub { position: relative; min-height: 1.3em; font-size: 4.4vmin; font-weight: 500; color: #6b7280; transition: color .5s; } + #word { position: relative; font-size: 8.6vmin; font-weight: 800; letter-spacing: .03em; line-height: 1; color: #4b5260; transition: color .5s; } + #sub { position: relative; min-height: 1.3em; font-size: 4.4vmin; font-weight: 500; color: #8b93a1; transition: color .5s; font-variant-numeric: tabular-nums; } + + /* distance to the limiter: the colours belong to the scale, the dark cover shows what is still left */ + #gauge { position: relative; width: min(88vw, 130vmin); } + #track { position: relative; height: 3.6vmin; border-radius: 1.8vmin; overflow: hidden; box-shadow: 0 0 0 1px #ffffff1c; + background: linear-gradient(90deg, #17a34a 0%, #22c55e 55%, #eab308 78%, #f97316 90%, #ef2b24 100%); } + #cover { position: absolute; top: 0; right: 0; bottom: 0; width: 100%; background: #12151a; } + #ticks { position: absolute; inset: 0; background: repeating-linear-gradient(90deg, transparent 0 calc(20% - 2px), #050608b0 calc(20% - 2px) 20%); } + #scale { position: relative; height: 3vmin; margin-top: 1vmin; font-size: 2.3vmin; color: #6b7280; font-variant-numeric: tabular-nums; } + #scale span { position: absolute; transform: translateX(-50%); white-space: nowrap; } + #scale span:first-child { transform: none; } + #scale span:last-child { transform: translateX(-100%); } + body.on #scale { color: #ffc9c4; } body.on #word { color: #fff; transition: color .09s; } body.on #sub { color: #ffd9d4; transition: color .09s; } @@ -44,6 +56,10 @@
—
+
+
+
−30−24−18−12−60 dB
+