DJ Brake only shows the limiter acting; presets without a look start empty
The distance to the limiter, its bar, the warn-earlier slider and the learning are gone: the page follows the DSP's limiter bits, with one second hold. Left out limiters stay. A preset without colours and group names of its own no longer inherits the ones from the preset before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
63b3c17fb7
commit
4a6eb2f513
9 files changed
+110
-304
No files matched your search
@@ -213,20 +213,7 @@ def rew_send_curve(body: dict):
|
||||
"magnitude": rew_floats(mag), "phase": rew_floats(phase)})
|
||||
|
||||
|
||||
DJ_HOLD = 1.5 # s the light of /djbrake stays on after a limiter acted, so it doesn't flicker with the music
|
||||
DJ_PEAK_HOLD = 1.5 # s the peak marker stays, then it falls ...
|
||||
DJ_PEAK_FALL = 3.0 # ... this many dB/s: the display follows the music, not every single beat
|
||||
DJ_AVG_TAU = 3.0 # s time constant of the average level
|
||||
# dB between the limiter threshold and the output meter when a limiter starts, until real hits say otherwise. Measured with
|
||||
# tools/dsp_measure.py: one DSP 204 (V0104P), one output, one piece of music: 25.1 to 27.7 in five rounds, with and without
|
||||
# -6 dB gain. It holds a share of the music's peaks the meter doesn't catch, so other music can differ by a few dB.
|
||||
DJ_METER_OFFSET = {"204": 26.0}
|
||||
DJ_LEARN_QUIET = 6.0 # s after a jump of a threshold the limiter flag teaches nothing: it was seen on for 4 s at +20 dB
|
||||
|
||||
|
||||
def clean_dj_margin(value) -> int:
|
||||
"""dB the page puts its limit below the real one, 0-12."""
|
||||
return int(max(0, min(12, value))) if type(value) in (int, float) else 0
|
||||
DJ_HOLD = 1.0 # s the light of /djbrake stays on after a limiter acted
|
||||
|
||||
|
||||
def clean_dj_ignore(data) -> dict:
|
||||
@@ -329,15 +316,10 @@ class App:
|
||||
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_margin = 0 # the page warns this many dB before the real limiter, and never says so
|
||||
self.dj_hint = True # short text on the page: the limiter is not the goal
|
||||
self.dj_hint_en = True # that text always in English, else in the language of the browser
|
||||
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_avgs: dict = {} # the same for the average level
|
||||
self.dj_env: dict = {} # "device:output" -> peak and average of the level
|
||||
self.dj_cal: dict = {} # device id -> dB the limiters sit below their threshold on the meter, learned from hits
|
||||
self.dj_cal_saved = 0.0
|
||||
self.dj_ready: dict = {} # device id -> has it an output that is watched
|
||||
self.dj_streams = 0
|
||||
self.logo = ""
|
||||
# desktop app: its own window logs in with a one-time token, other devices need the PIN
|
||||
@@ -389,9 +371,6 @@ class App:
|
||||
self.dashboard = clean_dashboard(cfg.get("dashboard"))
|
||||
self.djbrake = bool(cfg.get("djbrake"))
|
||||
self.dj_ignore = clean_dj_ignore(cfg.get("dj_ignore"))
|
||||
self.dj_margin = clean_dj_margin(cfg.get("dj_margin"))
|
||||
self.dj_cal = {str(k)[:64]: float(v) for k, v in (cfg.get("dj_cal") if isinstance(cfg.get("dj_cal"), dict) else {}).items()
|
||||
if type(v) in (int, float) and ":" not in str(k)}
|
||||
self.dj_hint = bool(cfg.get("dj_hint", True))
|
||||
self.dj_hint_en = bool(cfg.get("dj_hint_en", True))
|
||||
if "logo" in cfg:
|
||||
@@ -410,7 +389,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, "dj_ignore": self.dj_ignore, "dj_hint": self.dj_hint, "dj_hint_en": self.dj_hint_en, "dj_margin": self.dj_margin, "dj_cal": self.dj_cal}
|
||||
"dashboard": self.dashboard, "djbrake": self.djbrake, "dj_ignore": self.dj_ignore, "dj_hint": self.dj_hint, "dj_hint_en": self.dj_hint_en}
|
||||
|
||||
async def reset_config(self):
|
||||
"""Back to a fresh app. Only the app: the DSPs get disconnected first and receive nothing."""
|
||||
@@ -506,7 +485,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, "dj_ignore": self.dj_ignore, "dj_hint": self.dj_hint, "dj_hint_en": self.dj_hint_en, "dj_margin": self.dj_margin, "dj_cal": self.dj_cal,
|
||||
"soundfield": self.soundfield, "logo": self.logo, "dashboard": self.dashboard, "djbrake": self.djbrake, "dj_ignore": self.dj_ignore, "dj_hint": self.dj_hint, "dj_hint_en": self.dj_hint_en,
|
||||
"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:
|
||||
@@ -963,64 +942,25 @@ class App:
|
||||
|
||||
# ------------------------------------------------------------ events
|
||||
|
||||
def dj_offset(self, dev) -> float:
|
||||
"""Learned from this DSP's hits, else what was measured on this model. The simulator has no such offset."""
|
||||
if dev.id in self.dj_cal:
|
||||
return self.dj_cal[dev.id]
|
||||
real = "SIM" not in getattr(dev, "info", "") and not getattr(dev, "demo", False)
|
||||
return DJ_METER_OFFSET.get(getattr(dev, "model_name", ""), 0.0) if real else 0.0
|
||||
|
||||
def dj_track(self, dev, key: str, level: float, limit: bool, threshold: int, now: float) -> tuple:
|
||||
"""One meter reading of a watched output: (dB left by the peak, dB left by the average, warn now)."""
|
||||
e = self.dj_env.setdefault(key, {"peak": -120.0, "until": 0.0, "pow": 0.0, "t": now})
|
||||
dt = min(now - e["t"], 1.0)
|
||||
e["t"] = now
|
||||
db = 20 * math.log10(level) if level > 0 else -120.0
|
||||
if db >= e["peak"]:
|
||||
e["peak"], e["until"] = db, now + DJ_PEAK_HOLD
|
||||
elif now > e["until"]:
|
||||
e["peak"] = max(db, e["peak"] - DJ_PEAK_FALL * dt)
|
||||
e["pow"] += (level * level - e["pow"]) * (1 - math.exp(-dt / DJ_AVG_TAU))
|
||||
thr = P.threshold_to_db(threshold)
|
||||
# the moment a limiter starts is where it really sits on the meter. Later the level is what the limiter
|
||||
# left of it. One DSP has one meter, so this counts for all its outputs
|
||||
# only a limiter that starts by itself counts: not after a threshold jumped, up or down, and not
|
||||
# while it flickers on and off in the middle of limiting
|
||||
if thr > e.get("thr", thr) or thr < e.get("thr", thr) - 2:
|
||||
e["jumped"] = now
|
||||
e["thr"] = thr
|
||||
if limit and now - e.get("last_on", -1e9) > 3 and now - e.get("jumped", -1e9) > DJ_LEARN_QUIET and e["peak"] > -70:
|
||||
seen = max(-6.0, min(40.0, thr - e["peak"]))
|
||||
known = self.dj_offset(dev)
|
||||
self.dj_cal[dev.id] = (known * 3 + seen) / 4 if known or dev.id in self.dj_cal else seen
|
||||
if limit:
|
||||
e["last_on"] = now
|
||||
top = thr - self.dj_offset(dev) - self.dj_margin
|
||||
left = 0.0 if limit else max(0.0, top - e["peak"]) if e["peak"] > -70 else None
|
||||
mean = max(0.0, top - 10 * math.log10(e["pow"])) if e["pow"] > 1e-7 else None
|
||||
return left, mean, limit or bool(self.dj_margin and db >= top)
|
||||
|
||||
def dj_note(self, ev: dict, now: float | None = None):
|
||||
"""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
|
||||
now = time.monotonic() if now is None else now
|
||||
room, avg, ignore = False, None, self.dj_ignore.get(dev.id, ())
|
||||
for i, (level, limit) in enumerate(zip(ev["out"], ev["limit"])):
|
||||
ch, key = dev.state["outputs"][i], f"{dev.id}:{i}"
|
||||
if i in ignore or ch["mute"]:
|
||||
self.dj_env.pop(key, None)
|
||||
continue
|
||||
left, mean, warn = self.dj_track(dev, key, level, limit, ch["limit"]["threshold"], now)
|
||||
if warn:
|
||||
self.dj_hit = now
|
||||
room = left if room is False or room is None else room if left is None else min(room, left)
|
||||
avg = mean if avg is None else avg if mean is None else min(avg, mean)
|
||||
self.dj_rooms[dev.id], self.dj_avgs[dev.id] = room, avg
|
||||
if self.dj_cal and now - self.dj_cal_saved > 60: # an SD card is not for writing with every beat
|
||||
self.dj_cal_saved = now
|
||||
self.save()
|
||||
watched, ignore = False, self.dj_ignore.get(dev.id, ())
|
||||
for i, limit in enumerate(ev["limit"]):
|
||||
if i not in ignore and not dev.state["outputs"][i]["mute"]:
|
||||
watched = True
|
||||
if limit:
|
||||
self.dj_hit = now
|
||||
self.dj_ready[dev.id] = watched
|
||||
|
||||
def dj_state(self, now: float) -> dict:
|
||||
"""All /djbrake may know, without a login. Nothing else leaves here."""
|
||||
return {"on": now - self.dj_hit < DJ_HOLD,
|
||||
"ready": any(self.dj_ready.get(d.id) for d in self.devices.values() if d.status == "online"),
|
||||
"hint": ("en" if self.dj_hint_en else "auto") if self.dj_hint else None}
|
||||
|
||||
def broadcast(self, ev: dict):
|
||||
if ev["type"] == "meters":
|
||||
@@ -1057,17 +997,12 @@ class App:
|
||||
self.djbrake = bool(body["enabled"])
|
||||
if "ignore" in body:
|
||||
self.dj_ignore = clean_dj_ignore(body["ignore"])
|
||||
if body.get("relearn"):
|
||||
self.dj_cal = {}
|
||||
if "margin" in body:
|
||||
self.dj_margin = clean_dj_margin(body["margin"])
|
||||
if "hint" in body:
|
||||
self.dj_hint = bool(body["hint"])
|
||||
if "hint_en" in body:
|
||||
self.dj_hint_en = bool(body["hint_en"])
|
||||
self.save()
|
||||
ans = {"enabled": self.djbrake, "ignore": self.dj_ignore, "hint": self.dj_hint, "hint_en": self.dj_hint_en,
|
||||
"margin": self.dj_margin}
|
||||
ans = {"enabled": self.djbrake, "ignore": self.dj_ignore, "hint": self.dj_hint, "hint_en": self.dj_hint_en}
|
||||
self.broadcast({"type": "djbrake", **ans})
|
||||
return ans
|
||||
if path == "/api/dashboard" and method == "PUT":
|
||||
@@ -1423,7 +1358,6 @@ class App:
|
||||
await self.respond(writer, 200, f.read_bytes(), ctype)
|
||||
|
||||
async def dj_stream(self, writer):
|
||||
"""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
|
||||
@@ -1434,14 +1368,7 @@ class App:
|
||||
try:
|
||||
while self.djbrake:
|
||||
now = time.monotonic()
|
||||
online = [d.id for d in self.devices.values() if d.status == "online"]
|
||||
rooms = [r for r in (self.dj_rooms.get(i, False) for i in online) if r is not False]
|
||||
known = [r for r in rooms if r is not None]
|
||||
avgs = [r for r in (self.dj_avgs.get(i) for i in online) 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,
|
||||
"avg": round(min(avgs)) if avgs else None,
|
||||
"hint": ("en" if self.dj_hint_en else "auto") if self.dj_hint else None}
|
||||
state = self.dj_state(now)
|
||||
if state != last:
|
||||
writer.write(f"data: {json.dumps(state)}\n\n".encode())
|
||||
last, idle = state, 0.0
|
||||
@@ -1462,7 +1389,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, "dj_ignore": self.dj_ignore, "dj_hint": self.dj_hint, "dj_hint_en": self.dj_hint_en, "dj_margin": self.dj_margin}
|
||||
"dashboard": self.dashboard, "djbrake": self.djbrake, "dj_ignore": self.dj_ignore, "dj_hint": self.dj_hint, "dj_hint_en": self.dj_hint_en}
|
||||
writer.write(f"data: {json.dumps(hello)}\n\n".encode())
|
||||
await writer.drain()
|
||||
while True:
|
||||
|
||||
Reference in new issue
Block a user