DJ Brake: warn a few dB before the real limiter
The page moves its limit down by a chosen margin. The limiter itself does not change and the page never reveals the setting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d6be627f32
commit
910cf3fc17
6 files changed
+39
-9
No files matched your search
@@ -215,6 +215,11 @@ 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_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
|
||||
|
||||
|
||||
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):
|
||||
@@ -306,6 +311,7 @@ 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
|
||||
@@ -361,6 +367,7 @@ 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_hint = bool(cfg.get("dj_hint", True))
|
||||
self.dj_hint_en = bool(cfg.get("dj_hint_en", True))
|
||||
if "logo" in cfg:
|
||||
@@ -379,7 +386,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}
|
||||
"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}
|
||||
|
||||
async def restore_config(self, doc: dict, session: str):
|
||||
if not isinstance(doc, dict) or doc.get("format") != CONFIG_FORMAT:
|
||||
@@ -437,7 +444,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,
|
||||
"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,
|
||||
"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:
|
||||
@@ -907,7 +914,9 @@ class App:
|
||||
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))
|
||||
left = max(0.0, P.threshold_to_db(ch["limit"]["threshold"]) - self.dj_margin - 20 * math.log10(level))
|
||||
if self.dj_margin and left == 0:
|
||||
self.dj_hit = time.monotonic()
|
||||
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
|
||||
|
||||
@@ -941,12 +950,15 @@ class App:
|
||||
self.djbrake = bool(body["enabled"])
|
||||
if "ignore" in body:
|
||||
self.dj_ignore = clean_dj_ignore(body["ignore"])
|
||||
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}
|
||||
ans = {"enabled": self.djbrake, "ignore": self.dj_ignore, "hint": self.dj_hint, "hint_en": self.dj_hint_en,
|
||||
"margin": self.dj_margin}
|
||||
self.broadcast({"type": "djbrake", **ans})
|
||||
return ans
|
||||
if path == "/api/dashboard" and method == "PUT":
|
||||
@@ -1327,7 +1339,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}
|
||||
"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}
|
||||
writer.write(f"data: {json.dumps(hello)}\n\n".encode())
|
||||
await writer.drain()
|
||||
while True:
|
||||
|
||||
Reference in new issue
Block a user