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:
GivouandClaude Opus 5.5 committed 2026-11-02 22:18:09 +01:00
1 parent 63b3c17fb7
commit 4a6eb2f513
9 files changed
+110 -304

No files matched your search

+42 -95
View File
@@ -206,103 +206,35 @@ def test_fir_model():
assert st["outputs"][0]["fir"]["type"] == 1 and st["outputs"][0]["fir"]["name"] == "ABC"
def test_dj_brake_follows_music():
def test_dj_brake_light():
import server, tempfile
from types import SimpleNamespace
with tempfile.TemporaryDirectory() as d:
app = server.App(Path(d) / "c.json")
thr0 = 180 # threshold 0 dB
dev = SimpleNamespace(id="x", demo=True, state={"outputs": [{"mute": False, "limit": {"threshold": thr0}}]}, status="online")
app.devices["x"] = dev
lv = lambda db: 10 ** (db / 20)
note = lambda db, t, limit=False: app.dj_note({"device": "x", "out": [lv(db)], "limit": [limit]}, now=t)
# the peak stays while the music dips, then falls slowly
note(-10, 100.0)
note(-30, 100.5)
assert abs(app.dj_rooms["x"] - 10) < 0.01
note(-30, 102.5)
assert 10 < app.dj_rooms["x"] < 14
# the limiter acts at -12 on the meter although the threshold says 0: learned, and the distance is true afterwards
note(-12, 110.0, True)
assert abs(app.dj_cal["x"] - 12) < 3 and app.dj_rooms["x"] == 0
assert app.dj_hit == 110.0
for i in range(30):
note(-30, 120.0 + i)
note(-20, 150.0)
assert 6 < app.dj_rooms["x"] < 10
# a left out output neither warns nor counts
out = {"mute": False}
app.devices["x"] = SimpleNamespace(id="x", demo=True, state={"outputs": [out, {"mute": False}]}, status="online")
note = lambda t, *limit: app.dj_note({"device": "x", "out": [0.1, 0.1], "limit": list(limit)}, now=t)
note(10.0, False, False)
assert app.dj_state(10.0)["ready"] and not app.dj_state(10.0)["on"]
# on with the limiter, and one more second afterwards
note(100.0, True, False)
assert app.dj_state(100.0)["on"] and app.dj_state(100.9)["on"] and not app.dj_state(101.1)["on"]
# a limiter left out doesn't count, the others do
app.dj_ignore = {"x": [0]}
note(-1, 160.0, True)
assert app.dj_hit == 110.0 and app.dj_rooms["x"] is False
# what was learned survives a restart
app.save()
again = server.App(Path(d) / "c.json")
again.load()
assert abs(again.dj_cal["x"] - app.dj_cal["x"]) < 0.01
def test_dj_brake_one_hit_counts_for_the_whole_dsp():
import server, tempfile
from types import SimpleNamespace
with tempfile.TemporaryDirectory() as d:
app = server.App(Path(d) / "c.json")
out = {"mute": False, "limit": {"threshold": 180}}
app.devices["x"] = SimpleNamespace(id="x", demo=True, state={"outputs": [dict(out), dict(out)]}, status="online")
lv = lambda db: 10 ** (db / 20)
note(200.0, True, False)
assert not app.dj_state(200.0)["on"]
note(210.0, False, True)
assert app.dj_state(210.0)["on"]
# neither does a muted output, and with nothing left to watch the page says so
app.dj_ignore = {}
out["mute"] = True
note(300.0, True, False)
assert not app.dj_state(300.0)["on"] and app.dj_state(300.0)["ready"]
app.dj_ignore = {"x": [1]}
app.dj_note({"device": "x", "out": [lv(-12), lv(-40)], "limit": [True, False]}, now=100.0)
assert app.dj_cal == {"x": 12.0}
# the level the limiter leaves over while it keeps acting teaches nothing
app.dj_note({"device": "x", "out": [lv(-20), lv(-40)], "limit": [True, False]}, now=100.2)
assert app.dj_cal == {"x": 12.0}
# another output of this DSP has never limited, its distance is true anyway
app.dj_ignore = {"x": [0]}
app.dj_note({"device": "x", "out": [lv(-40), lv(-18)], "limit": [False, False]}, now=101.0)
assert abs(app.dj_rooms["x"] - 6) < 0.01
def test_dj_brake_measured_offset():
import server, tempfile
from types import SimpleNamespace
lv = lambda db: 10 ** (db / 20)
with tempfile.TemporaryDirectory() as d:
app = server.App(Path(d) / "c.json")
app.save = lambda: None
out = {"mute": False, "limit": {"threshold": 220}} # +20 dB
dev = SimpleNamespace(id="x", demo=False, model_name="204", info="DSP204 V0104P", state={"outputs": [out]}, status="online")
app.devices["x"] = dev
note = lambda db, t, limit=False: app.dj_note({"device": "x", "out": [lv(db)], "limit": [limit]}, now=t)
# measured: at +20 dB and a meter of -25 the limiter is about 19 dB away, before any hit
note(-25, 100.0)
assert app.dj_cal == {} and abs(app.dj_rooms["x"] - 19) < 0.01
# the flag right after raising the threshold teaches nothing: seen on real hardware
out["limit"]["threshold"] = 184
note(-25, 110.0)
out["limit"]["threshold"] = 220
note(-25, 111.0, True)
assert app.dj_cal == {}
note(-25, 111.2)
# a real hit moves the offset, it doesn't replace it
out["limit"]["threshold"] = 180
note(-20, 130.0)
note(-20, 130.2, True)
assert app.dj_cal == {} # that threshold has only just jumped
note(-20, 140.0)
note(-20, 140.2, True)
assert abs(app.dj_cal["x"] - 24.5) < 0.01
# it flickers: nothing new. And a jump of the threshold down teaches nothing either
note(-30, 140.4)
note(-30, 140.6, True)
assert abs(app.dj_cal["x"] - 24.5) < 0.01
out["limit"]["threshold"] = 160
note(-30, 150.0)
note(-30, 150.2, True)
assert abs(app.dj_cal["x"] - 24.5) < 0.01
with tempfile.TemporaryDirectory() as d:
app = server.App(Path(d) / "c.json")
for dev in (SimpleNamespace(id="s", demo=False, model_name="204", info="DSP204 V010 SIM"), SimpleNamespace(id="d", demo=True, model_name="204", info=""),
SimpleNamespace(id="o", demo=False, model_name="408", info="DSP408 V0104P")):
assert app.dj_offset(dev) == 0.0
note(310.0, True, True)
assert not app.dj_state(310.0)["on"] and not app.dj_state(310.0)["ready"]
# only these three things leave here
assert set(app.dj_state(1.0)) == {"on", "ready", "hint"}
def test_reset_config():
@@ -312,7 +244,7 @@ def test_reset_config():
app = server.App(path)
app.load()
app.set_pin("9999", save=False)
app.djbrake, app.lang, app.dj_cal = True, "de", {"x:0": 5.0}
app.djbrake, app.lang, app.dj_ignore = True, "de", {"x": [0]}
app.dashboard = {"modules": []}
app.app_token = "t"
app.app_sessions, app.sessions = {"a"}, {"a": 9e12, "b": 9e12}
@@ -326,7 +258,7 @@ def test_reset_config():
app.mute_all["active"] = False
app.remote["enabled"] = False
asyncio.run(app.reset_config())
assert not app.djbrake and app.lang == "" and app.dashboard is None and app.dj_cal == {} and app.check_pin("1234")
assert not app.djbrake and app.lang == "" and app.dashboard is None and app.dj_ignore == {} and app.check_pin("1234")
assert app.app_token == "t" and app.app_sessions == {"a"} and set(app.sessions) == {"a"}
assert json.loads(path.with_name("config.before-reset.json").read_text())["djbrake"] is True
@@ -337,9 +269,9 @@ def test_looks_follow_presets():
d.state = {"preset_name": "A"}
d.colors, d.linknames = {"out0": "#111111"}, {"out:0,1": "Tops"}
d.sync_look()
d.state = {"preset_name": "B"} # not seen yet: starts with what is there, then goes its own way
d.state = {"preset_name": "B"} # has no look of its own: starts without
d.sync_look()
assert d.colors == {"out0": "#111111"}
assert d.colors == {} and d.linknames == {}
d.colors, d.linknames = {"out0": "#222222"}, {"out:0,1": "Subs"}
d.remember_look()
d.state = {"preset_name": "A"}
@@ -349,6 +281,21 @@ def test_looks_follow_presets():
d.sync_look()
assert d.colors == {"out0": "#222222"} and d.linknames == {"out:0,1": "Subs"}
assert "looks" not in d.snapshot()
# the first preset ever seen keeps what is there
e = Device("y", "y", "127.0.0.1", colors={"in0": "#333333"})
e.state = {"preset_name": "First"}
e.sync_look()
assert e.colors == {"in0": "#333333"} and "First" in e.looks
# a DSP whose memory image keeps the old name after loading a preset: the listed name counts
e.state = {"preset_name": "First"}
e.recalled, e.recalled_image = "Other", None
e.sync_look()
assert e.look_name == "Other" and e.colors == {}
e.sync_look()
assert e.look_name == "Other"
e.state = {"preset_name": "Third"} # loaded on the device itself
e.sync_look()
assert e.look_name == "Third" and e.recalled == ""
if __name__ == "__main__":