Looks per preset, steadier DJ Brake, no zoom on phones, simple dashboard on touch
Colours and link group names now belong to the preset (by name, the DSP has no IDs) and travel in preset files. DJ Brake: limiters are left out instead of chosen; a slowly falling peak mark, an average bar, a warning before the limit, and it learns from real hits where the limiter sits on the meter. Pinch and double tap zoom are off. On touchscreens the dashboard only offers widget settings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
99613327f8
commit
cf35a1faa1
11 files changed
+232
-48
No files matched your search
@@ -212,7 +212,10 @@ 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
|
||||
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
|
||||
|
||||
|
||||
def clean_dj_margin(value) -> int:
|
||||
@@ -271,6 +274,15 @@ def clean_linknames(v) -> dict:
|
||||
return out
|
||||
|
||||
|
||||
def clean_looks(v) -> dict:
|
||||
"""Colours and group names per preset name: {"Party": {"colors": {...}, "linknames": {...}}}."""
|
||||
out = {}
|
||||
for k, look in list(v.items() if isinstance(v, dict) else [])[:64]:
|
||||
if isinstance(look, dict):
|
||||
out[str(k)[:14]] = {"colors": clean_colors(look.get("colors")), "linknames": clean_linknames(look.get("linknames"))}
|
||||
return out
|
||||
|
||||
|
||||
def clean_maxgain(v) -> dict:
|
||||
"""Software gain limits per channel: {"in0": raw 0..399} (400 = +12 dB would be no limit)."""
|
||||
out = {}
|
||||
@@ -316,6 +328,10 @@ class App:
|
||||
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:output" -> dB the limiter sits below its threshold on the meter, learned from hits
|
||||
self.dj_cal_saved = 0.0
|
||||
self.dj_streams = 0
|
||||
self.logo = ""
|
||||
# desktop app: its own window logs in with a one-time token, other devices need the PIN
|
||||
@@ -368,6 +384,8 @@ class App:
|
||||
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)[:80]: 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)}
|
||||
self.dj_hint = bool(cfg.get("dj_hint", True))
|
||||
self.dj_hint_en = bool(cfg.get("dj_hint_en", True))
|
||||
if "logo" in cfg:
|
||||
@@ -386,7 +404,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}
|
||||
"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}
|
||||
|
||||
async def restore_config(self, doc: dict, session: str):
|
||||
if not isinstance(doc, dict) or doc.get("format") != CONFIG_FORMAT:
|
||||
@@ -428,8 +446,17 @@ class App:
|
||||
for old in self.undo_files(dev.id)[MAX_UNDO:]:
|
||||
old.unlink(missing_ok=True)
|
||||
diffs = await dev.import_preset(state)
|
||||
self.take_look(dev, body.get("doc"))
|
||||
return {"ok": not diffs, "differences": diffs[:20], "name": state.get("preset_name", "")}
|
||||
|
||||
def take_look(self, dev: Device, doc):
|
||||
"""Colours and group names that came with a preset file (older files have none)."""
|
||||
look = doc.get("look") if isinstance(doc, dict) else None
|
||||
if isinstance(look, dict):
|
||||
dev.colors, dev.linknames = clean_colors(look.get("colors")), clean_linknames(look.get("linknames"))
|
||||
dev.remember_look()
|
||||
self.broadcast({"type": "device", "device": dev.id, "data": dev.snapshot()})
|
||||
|
||||
async def undo_import(self, dev: Device) -> dict:
|
||||
files = self.undo_files(dev.id)
|
||||
if not files:
|
||||
@@ -437,6 +464,7 @@ class App:
|
||||
doc = json.loads(files[0].read_text(encoding="utf-8"))
|
||||
state = preset.read_file(dev.model_name, dev.model, dev.state, doc=doc)
|
||||
diffs = await dev.import_preset(state)
|
||||
self.take_look(dev, doc)
|
||||
files[0].unlink()
|
||||
return {"ok": not diffs, "differences": diffs[:20]}
|
||||
|
||||
@@ -460,7 +488,8 @@ class App:
|
||||
transport="usb" if usb else "tcp", usb=str(d.get("usb") or ""),
|
||||
lock_code=str(d.get("lock_code") or ""), auto_unlock=bool(d.get("auto_unlock")),
|
||||
test_saved=clean_gains(d.get("test_saved")), colors=clean_colors(d.get("colors")),
|
||||
maxgain=clean_maxgain(d.get("maxgain")), linknames=clean_linknames(d.get("linknames")))
|
||||
maxgain=clean_maxgain(d.get("maxgain")), linknames=clean_linknames(d.get("linknames")),
|
||||
looks=clean_looks(d.get("looks")), look_name=str(d.get("look_name") or "")[:14])
|
||||
dev.on_online = self.device_online
|
||||
self.devices[dev_id] = dev
|
||||
if dev.autoconnect:
|
||||
@@ -900,29 +929,56 @@ class App:
|
||||
|
||||
# ------------------------------------------------------------ events
|
||||
|
||||
def dj_note(self, ev: dict):
|
||||
def dj_track(self, 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)
|
||||
if limit and e["peak"] > -70: # the limiter acts: this is where it really sits on the meter
|
||||
seen = max(-6.0, min(30.0, thr - e["peak"]))
|
||||
self.dj_cal[key] = seen if key not in self.dj_cal else self.dj_cal[key] + (seen - self.dj_cal[key]) * (1 - math.exp(-dt))
|
||||
top = thr - self.dj_cal.get(key, 0.0) - 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
|
||||
room, ignore = False, self.dj_ignore.get(dev.id, ())
|
||||
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 = dev.state["outputs"][i]
|
||||
ch, key = dev.state["outputs"][i], f"{dev.id}:{i}"
|
||||
if i in ignore or ch["mute"]:
|
||||
self.dj_env.pop(key, None)
|
||||
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"]) - self.dj_margin - 20 * math.log10(level))
|
||||
if self.dj_margin and left == 0:
|
||||
self.dj_hit = time.monotonic()
|
||||
left, mean, warn = self.dj_track(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)
|
||||
self.dj_rooms[dev.id] = room
|
||||
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()
|
||||
|
||||
def broadcast(self, ev: dict):
|
||||
if ev["type"] == "meters":
|
||||
self.dj_note(ev)
|
||||
elif ev["type"] == "device":
|
||||
dev = self.devices.get(ev["device"])
|
||||
if dev and dev.look_dirty:
|
||||
dev.look_dirty = False
|
||||
self.save()
|
||||
msg = json.dumps(ev, separators=(",", ":"))
|
||||
for q in list(self.clients):
|
||||
if ev["type"] == "meters" and q.qsize() > 50:
|
||||
@@ -950,6 +1006,8 @@ 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:
|
||||
@@ -1097,11 +1155,13 @@ class App:
|
||||
return {"ok": True}
|
||||
if action == "colors": # display only, stays in the app (the DSP doesn't know colours)
|
||||
dev.colors = clean_colors(body.get("colors"))
|
||||
dev.remember_look()
|
||||
self.save()
|
||||
self.broadcast({"type": "device", "device": dev.id, "data": dev.snapshot()})
|
||||
return {"ok": True, "colors": dev.colors}
|
||||
if action == "linknames": # display only, like the colours
|
||||
dev.linknames = clean_linknames(body.get("linknames"))
|
||||
dev.remember_look()
|
||||
self.save()
|
||||
self.broadcast({"type": "device", "device": dev.id, "data": dev.snapshot()})
|
||||
return {"ok": True, "linknames": dev.linknames}
|
||||
@@ -1313,11 +1373,13 @@ class App:
|
||||
try:
|
||||
while self.djbrake:
|
||||
now = time.monotonic()
|
||||
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]
|
||||
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}
|
||||
if state != last:
|
||||
writer.write(f"data: {json.dumps(state)}\n\n".encode())
|
||||
|
||||
Reference in new issue
Block a user