diff --git a/CLAUDE.md b/CLAUDE.md index cee3aed..d061ff4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -57,6 +57,8 @@ pi_writer.py → pi_image.py (cloud-init SD card, installs server.py as a system the swallowing of the app lock. A safety catch per browser tab only: not stored, the server doesn't know it. Mute all stays. * **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`. * **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 diff --git a/README.md b/README.md index ac9fd05..c02f95d 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,8 @@ 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 * **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 3a0c087..fe7ea01 100644 --- a/server.py +++ b/server.py @@ -212,6 +212,7 @@ def rew_send_curve(body: dict): "magnitude": rew_floats(mag), "phase": rew_floats(phase)}) +DJ_HOLD = 0.8 # s the light of /djbrake stays on after a limiter acted, so short hits are seen DASH_TYPES = ("status", "meters", "mixer", "curve", "channel", "limiter", "routing", "delays", "fir", "notes") @@ -292,6 +293,9 @@ class App: self.limiter: dict = clean_limiter({}) 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_hit = 0.0 # when a limiter was last seen acting + self.dj_streams = 0 self.logo = "" # desktop app: its own window logs in with a one-time token, other devices need the PIN self.app_token: str | None = None @@ -340,6 +344,7 @@ class App: self.soundfield = clean_soundfield(cfg.get("soundfield")) if "dashboard" in cfg: self.dashboard = clean_dashboard(cfg.get("dashboard")) + self.djbrake = bool(cfg.get("djbrake")) if "logo" in cfg: self.logo = clean_logo(cfg.get("logo")) r = cfg.get("remote") or {} @@ -356,7 +361,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} + "dashboard": self.dashboard, "djbrake": self.djbrake} async def restore_config(self, doc: dict, session: str): if not isinstance(doc, dict) or doc.get("format") != CONFIG_FORMAT: @@ -414,7 +419,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, + "soundfield": self.soundfield, "logo": self.logo, "dashboard": self.dashboard, "djbrake": self.djbrake, "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: @@ -871,6 +876,8 @@ class App: # ------------------------------------------------------------ events def broadcast(self, ev: dict): + if ev.get("type") == "meters" and any(ev.get("limit") or ()): + self.dj_hit = time.monotonic() msg = json.dumps(ev, separators=(",", ":")) for q in list(self.clients): if ev["type"] == "meters" and q.qsize() > 50: @@ -893,6 +900,11 @@ class App: return {"logo": self.logo} if path == "/api/logo": return {"logo": self.logo} + if path == "/api/djbrake" and method == "PUT": + self.djbrake = bool(body.get("enabled")) + self.save() + self.broadcast({"type": "djbrake", "enabled": self.djbrake}) + return {"enabled": self.djbrake} if path == "/api/dashboard" and method == "PUT": self.dashboard = clean_dashboard(body) self.save() @@ -1096,6 +1108,11 @@ class App: else: await self.respond(writer, 401, b"invalid app token", "text/plain") return + if path == "/djbrake/state": + await self.dj_stream(writer) + return + if path in ("/djbrake", "/djbrake/"): + path = "/djbrake.html" if path.startswith("/api/"): try: data = json.loads(body) if body else {} @@ -1216,6 +1233,9 @@ class App: async def static(self, writer, path: str): rel = "index.html" if path in ("/", "") else path.lstrip("/") + if rel == "djbrake.html" and not self.djbrake: + await self.respond(writer, 404, b"not found", "text/plain") + return f = (STATIC / rel).resolve() if STATIC not in f.parents or not f.is_file(): await self.respond(writer, 404, b"not found", "text/plain") @@ -1225,6 +1245,32 @@ class App: ctype += "; charset=utf-8" 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.""" + if not self.djbrake or self.dj_streams >= 20: + await self.respond(writer, 404, b"not found", "text/plain") + return + self.dj_streams += 1 + writer.write(b"HTTP/1.1 200 OK\r\nContent-Type: text/event-stream\r\nCache-Control: no-cache\r\n" + b"Connection: keep-alive\r\nX-Accel-Buffering: no\r\n\r\n") + last, idle = None, 0.0 + 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())} + if state != last: + writer.write(f"data: {json.dumps(state)}\n\n".encode()) + last, idle = state, 0.0 + elif idle > 15: + writer.write(b": ping\n\n") + idle = 0.0 + await writer.drain() + await asyncio.sleep(0.1) + idle += 0.1 + finally: + self.dj_streams -= 1 + async def sse(self, writer): writer.write(b"HTTP/1.1 200 OK\r\nContent-Type: text/event-stream\r\nCache-Control: no-cache\r\n" b"Connection: keep-alive\r\nX-Accel-Buffering: no\r\n\r\n") @@ -1233,7 +1279,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} + "dashboard": self.dashboard, "djbrake": self.djbrake} 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 72056a8..fae01d7 100644 --- a/static/app.js +++ b/static/app.js @@ -1506,7 +1506,8 @@ function mixList(d, o) { const m = chans(dev(), "out")[o].matrix ^ (1 << i); setParam("out", o, "matrix", m); render(); } }, h("span", { class: "sw" }), chTitle(d, "in", i)); - return h("div", { class: "mixrow" + (on ? "" : " off") }, btn, paramSlider(t("Level"), "out", o, `mix.${i}`, "mix")); + return h("div", { class: "mixrow" + (on ? "" : " off") }, btn, paramSlider(t("Level"), "out", o, `mix.${i}`, "mix", + v => showLive(`${d.id}|out|${o}|mix.${i}`, v))); }); } @@ -1516,6 +1517,14 @@ function routingCard(d, o) { // ------------------------------------------------------------------ routing view +function xpLevel(o, i, raw) { + const el = h("small"); + const show = v => { const db = gainDb(v); el.textContent = db === 0 ? "0" : sign(db); el.title = `${sign(db)} dB`; }; + show(raw); + onLive("out", o, `mix.${i}`, show); + return el; +} + function viewRouting(d) { const ins = chans(d, "in"), outs = chans(d, "out"); const grid = h("div", { class: "xmatrix", style: `--n:${ins.length}` }); @@ -1540,7 +1549,7 @@ function viewRouting(d) { const m = chans(dev(), "out")[o].matrix ^ (1 << i); S.xpFx = `${d.id}|${o}|${i}`; setParam("out", o, "matrix", m); render(); - } }, h("span", { class: "node" }), on ? h("small", { title: `${sign(gainDb(oc.mix[i]))} dB` }, gainDb(oc.mix[i]) === 0 ? "0" : sign(gainDb(oc.mix[i]))) : null)); + } }, h("span", { class: "node" }), on ? xpLevel(o, i, oc.mix[i]) : null)); }); if (open) grid.append(h("div", { class: "xpanel" }, h("div", { class: "xpanel-h" }, t("Level for {ch}", { ch: chTitle(d, "out", o) }), h("button", { class: "small", onclick: () => openChannel("out", o) }, t("Open channel"))), mixList(d, o))); @@ -2358,6 +2367,26 @@ function logoCard() { } // Language per device (stored in the browser); the desktop app also tells the server, for its own dialogs +function djBrakeCard() { + // the app's own address only works on this computer: other devices come through remote access + const r = S.remote || {}; + const base = S.isApp ? (r.enabled && r.urls && r.urls[0]) || "" : location.origin; + const url = base ? `${base}/djbrake` : ""; + const box = h("input", { type: "checkbox", checked: !!S.djbrake, onchange: async () => { + try { S.djbrake = (await api("PUT", "/api/djbrake", { enabled: box.checked })).enabled; render(); } + catch (e) { box.checked = !!S.djbrake; toast(t("Error: ") + trMsg(e.message)); } + } }); + return h("div", { class: "card" }, h("h3", {}, "DJ Brake"), + h("p", { class: "info" }, t("A page for a tablet at the DJ booth: a big red light comes on when a limiter is working, so turning up more won't help.")), + h("label", { class: "chk" }, box, t("Share the page /djbrake")), + S.djbrake && url ? h("div", { class: "row djurl" }, h("code", {}, url), + h("button", { class: "small", "data-view-ok": "", onclick: async () => { + 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); +} + function langCard() { const set = async lang => { if (lang === LANG) return; @@ -2413,7 +2442,7 @@ function scanCard() { function viewSettings() { const sections = [ - ["general", t("General"), t("Language, demo mode and your logo."), "", [langCard(), demoCard(), logoCard()]], + ["general", t("General"), t("Language, demo mode and your logo."), "", [langCard(), demoCard(), logoCard(), djBrakeCard()]], ["devices", t("Devices"), t("Several DSPs can be connected at the same time – pick one at the top. A DSP accepts only one connection: close the Thomann editor first."), "wide", [...S.order.filter(id => !S.devices[id].demo).map(id => deviceForm(S.devices[id])), scanCard(), addDeviceCard()]], ["access", S.isApp ? t("Remote access") : t("Security"), S.isApp ? t("Let phones and tablets in your network control this computer – they log in with the PIN.") : t("Who may use this web interface."), @@ -2608,6 +2637,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; 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])); @@ -2642,6 +2672,8 @@ function connectEvents() { sfOnRemote(ev.data); break; case "dashboard": dashRemote(ev.data); break; + case "djbrake": + S.djbrake = ev.enabled; if (S.settings) 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 new file mode 100644 index 0000000..88283a9 --- /dev/null +++ b/static/djbrake.html @@ -0,0 +1,81 @@ + + + + + + + + +DJ Brake + + + +
+
+
+
+
+
+
—
+
+
+ + + diff --git a/static/i18n.js b/static/i18n.js index 5e92b73..98ca839 100644 --- a/static/i18n.js +++ b/static/i18n.js @@ -674,6 +674,11 @@ const DE = { "Check the result by ear or with a measurement: temperature, reflections and real speakers differ from the model.": "Das Ergebnis mit dem Ohr oder per Messung prüfen: Temperatur, Reflexionen und echte Lautsprecher weichen vom Modell ab.", "Only show dashboard while locked": "Während der Sperre nur das Dashboard zeigen", "With the lock on, this window then shows just your dashboard, until it is unlocked with the PIN.": "Bei aktiver Sperre zeigt dieses Fenster dann nur dein Dashboard, bis es mit der PIN entsperrt wird.", + "A page for a tablet at the DJ booth: a big red light comes on when a limiter is working, so turning up more won't help.": "Eine Seite für ein Tablet am DJ-Pult: Ein großes rotes Licht geht an, wenn ein Limiter arbeitet, mehr Gas also nichts mehr bringt.", + "Share the page /djbrake": "Seite /djbrake freigeben", + "Address copied": "Adresse kopiert", + "Switch on remote access below so other devices can reach it.": "Schalte unten den Fernzugriff ein, damit andere Geräte sie erreichen.", + "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.": "Jeder in deinem Netzwerk kann sie ohne PIN öffnen. Sie zeigt nur das Licht, beobachtet alle Ausgänge aller verbundenen DSPs und ändert nichts.", }; const DE_PATTERNS = [ diff --git a/static/style.css b/static/style.css index 1054a01..696a843 100644 --- a/static/style.css +++ b/static/style.css @@ -979,3 +979,8 @@ body.dashonly .dlink { cursor: default; } @keyframes xptext { from { opacity: 0; } } @media (prefers-reduced-motion: reduce) { .xp.fx .node, .xp.fx .node::after, .xp.fx.on small { animation: none; } } .lockopt { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); } +/* ---- DJ Brake setting */ +.djurl { margin-top: 8px; align-items: center; flex-wrap: nowrap; } +.djurl code { flex: 1; min-width: 0; padding: 5px 8px; border-radius: 6px; background: var(--bg2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.djwarn { color: var(--warn); } +.djurl button { flex: none; }