diff --git a/CLAUDE.md b/CLAUDE.md index dadf57f..ad3b38f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -109,6 +109,10 @@ and the DSP's own mirroring inside groups, limiter-active bit mask, preset impor Not verified yet – ask for a log (`python server.py -v`) from real hardware before changing protocol code here: +* **Beta models** `206` and `408fir` – never seen on real hardware, same protocol and memory layout are only assumed + (also the USB ID). Never auto-detected (`detect_model`, a FIR device must not pass as a 408). `Device.read_only` holds + back every write (`P.READ_COMMANDS`, `BETA_READ_ACTIONS`) until the user allows changes (`beta_write`). The FIR + filters are deliberately not implemented; ask testers for a preset export (it holds the raw image) and a log first. * **DSP 408 on real hardware** (layout and frames match published captures, limiter bits for Out 5–8 assumed) * USB on Windows and Linux against a real DSP (only tested against a fake HID device) * Where the PEQ bypass flag lives in the memory image; format of the set-command acknowledgement; where the number diff --git a/README.md b/README.md index 1d37d1a..f3d61e9 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,12 @@ Control both devices at the same time from your phone, tablet or computer – ov |--------|---------|-----|-------------------------| | t.racks DSP 204 | ✓ | ✓ | yes (firmware V0104P, USB on macOS) | | t.racks DSP 408 | ✓ | ✓ | not yet – frames match published captures | +| t.racks DSP 206 (beta) | ✓ | ? | no – assumed to work like the others, testers wanted | +| t.racks FIR DSP 408 (beta) | ✓ | ? | no – as above; the FIR filters themselves are not supported | + +Beta models are not detected automatically: choose them by hand when adding the device. They start read-only. Compare +the shown values with the DSP; if they match, switch on changes in the note above the mixer (amplifiers off while +testing). If they don't match, please send the file from File… → Export. The DSPs accept only **one** connection at a time – close any other control software first. diff --git a/dsp/device.py b/dsp/device.py index 6907647..22665c1 100644 --- a/dsp/device.py +++ b/dsp/device.py @@ -22,12 +22,14 @@ class Device: def __init__(self, dev_id: str, name: str, host: str, port: int = P.PORT, model: str = "auto", addr: int = 1, autoconnect: bool = True, on_event=None, transport: str = "tcp", usb: str = "", lock_code: str = "", auto_unlock: bool = False, test_saved: list | None = None, - colors: dict | None = None, maxgain: dict | None = None, linknames: dict | None = None): + colors: dict | None = None, maxgain: dict | None = None, linknames: dict | None = None, + beta_write: bool = False): self.id = dev_id self.name = name self.host = host self.port = port - self.model_key = model # "auto", "204" or "408" + self.model_key = model # "auto" or a key of P.MODELS + self.beta_write = beta_write # beta models: the user has checked the shown values and allowed changes self.addr = addr self.autoconnect = autoconnect self.transport = "usb" if transport == "usb" else "tcp" @@ -75,7 +77,8 @@ class Device: "model": self.model_key, "addr": self.addr, "autoconnect": self.autoconnect, "transport": self.transport, "usb": self.usb, "lock_code": self.lock_code, "auto_unlock": self.auto_unlock, "test_saved": self.test_saved, - "colors": self.colors, "maxgain": self.maxgain, "linknames": self.linknames} + "colors": self.colors, "maxgain": self.maxgain, "linknames": self.linknames, + "beta_write": self.beta_write} def snapshot(self) -> dict: cfg = self.config() @@ -85,6 +88,7 @@ class Device: "detected_model": self.model_name or None, "n_in": self.model.n_in if self.model else 0, "n_out": self.model.n_out if self.model else 0, + "beta": bool(self.model and self.model.beta), "read_only": self.read_only, "presets": self.presets, "state": self.state} def start(self): @@ -104,10 +108,17 @@ class Device: await self._close() self._set_status("disconnected") + @property + def read_only(self) -> bool: + """A beta model only reads until the user has compared the shown values with the DSP.""" + return bool(self.model and self.model.beta and not self.beta_write) + def set_param(self, kind: str, idx: int, param: str, value): """Update local state and queue the command (coalesced per parameter).""" if not self.state or not self.model: raise RuntimeError("device not loaded") + if self.read_only: + raise RuntimeError("Beta model: changes are off") chans = self.state["inputs" if kind == "in" else "outputs"] ch = chans[idx] if param == "name": @@ -332,6 +343,9 @@ class Device: """Send one command and wait for its answer (the DSP is strictly request/response).""" if not self._writer: raise ConnectionError("not connected") + if self.read_only and cmd not in P.READ_COMMANDS: + log.warning("%s: read-only, command 0x%02x not sent", self.name, cmd) + return None async with self._lock: deadline = time.monotonic() + timeout self._writer.write(P.build_frame(cmd, payload, self.addr)) diff --git a/dsp/protocol.py b/dsp/protocol.py index 0bf5836..d585609 100644 --- a/dsp/protocol.py +++ b/dsp/protocol.py @@ -209,6 +209,7 @@ class Model: name: str n_in: int n_out: int + beta: bool = False # layout assumed from the other models, never seen on a real device; only selectable by hand @property def in_size(self) -> int: @@ -247,12 +248,21 @@ class Model: return idx if kind == "in" else 4 + idx -MODELS = {"204": Model("DSP 204", 2, 4), "408": Model("DSP 408", 4, 8)} +MODELS = {"204": Model("DSP 204", 2, 4), "408": Model("DSP 408", 4, 8), + "206": Model("DSP 206", 2, 6, beta=True), "408fir": Model("FIR DSP 408", 4, 8, beta=True)} + +# what a DSP may be sent while its model is read-only (see Device.read_only): connecting and looking +READ_COMMANDS = frozenset((CMD_HANDSHAKE, CMD_LOGOUT, CMD_STATUS, CMD_DEVICE_INFO, CMD_INIT_14, CMD_INIT_22, + CMD_CONFIG_REQUEST, CMD_PRESET_NAME, CMD_PRESET_COUNT, CMD_UNLOCK, CMD_METER)) def detect_model(info: str) -> str | None: - for key in MODELS: - if f"DSP{key}" in info.replace(" ", ""): + """Beta models are never detected, and a FIR device must not pass as a plain DSP 408.""" + info = info.replace(" ", "").upper() + if "FIR" in info: + return None + for key, model in MODELS.items(): + if not model.beta and f"DSP{key}" in info: return key return None diff --git a/server.py b/server.py index ff4ab47..08b3ed5 100644 --- a/server.py +++ b/server.py @@ -154,6 +154,11 @@ def clean_colors(v) -> dict: return out +# what a beta model allows before changes are switched on: nothing here writes to the DSP +BETA_READ_ACTIONS = ("connect", "disconnect", "refresh", "export", "backups", "unlock", "colors", "maxgain", + "linknames", "betawrite") + + def clean_linknames(v) -> dict: """Names of link groups, keyed by kind and members: {"out:0,1": "Tops"}. A changed group loses its name.""" out = {} @@ -337,7 +342,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")), + beta_write=bool(d.get("beta_write"))) dev.on_online = self.device_online self.devices[dev_id] = dev if dev.autoconnect: @@ -385,6 +391,8 @@ class App: return {"ok": True} async def device_online(self, dev: Device): + if dev.read_only: + return await self.check_audio_test(dev) if not self.mute_all["active"] and self.mute_all["restore"].get(dev.id): self.unmute_device(dev) # released while this DSP was offline @@ -403,7 +411,7 @@ class App: def set_mute_all(self, mute: bool) -> dict: """Mute every channel of every connected DSP; releasing unmutes only what was open before.""" - online = [d for d in self.devices.values() if d.status == "online" and d.state] + online = [d for d in self.devices.values() if d.status == "online" and d.state and not d.read_only] if mute and not self.mute_all["active"]: self.mute_all["restore"] = {} for dev in online: @@ -435,7 +443,7 @@ class App: changed = 0 for t in body.get("targets") or []: dev = self.devices.get(str(t.get("device"))) - if not dev or dev.status != "online" or not dev.state: + if not dev or dev.status != "online" or not dev.state or dev.read_only: continue if dev.test_active: raise RuntimeError("Audio test is on – switch it off first") @@ -794,6 +802,8 @@ class App: if dev.test_active and (action in ("preset/recall", "preset/store", "export", "import", "undo", "link") or action == "set" and body.get("param") != "mute"): raise RuntimeError("Audio test is on – switch it off first") + if dev.read_only and method == "POST" and action not in BETA_READ_ACTIONS: + raise RuntimeError("Beta model: changes are off") if self.demo["enabled"] and not dev.demo and action == "connect": raise RuntimeError("Demo mode is on – switch it off to connect the real DSPs") if method == "DELETE" and not action: @@ -805,6 +815,8 @@ class App: if method == "PUT" and not action: was_running = dev._want_connected await dev.stop() + if body.get("model", dev.model_key) != dev.model_key: + dev.beta_write = False # another model: check the values again for k in ("name", "host", "model", "usb"): if k in body: setattr(dev, "model_key" if k == "model" else k, str(body[k])) @@ -872,6 +884,11 @@ class App: self.save() self.broadcast({"type": "device", "device": dev.id, "data": dev.snapshot()}) return {"ok": True, "colors": dev.colors} + if action == "betawrite": # beta model: the user compared the shown values with the DSP + dev.beta_write = bool(body.get("enabled")) + self.save() + self.broadcast({"type": "device", "device": dev.id, "data": dev.snapshot()}) + return {"ok": True, "read_only": dev.read_only} if action == "linknames": # display only, like the colours dev.linknames = clean_linknames(body.get("linknames")) self.save() diff --git a/sim.py b/sim.py index 7c8de33..410b50f 100644 --- a/sim.py +++ b/sim.py @@ -34,7 +34,7 @@ class SimDSP: def handle(self, cmd: int, p: bytes) -> tuple[int, bytes]: m = self.model if cmd == P.CMD_DEVICE_INFO: - return cmd, f"DSP{self.key} V010 SIM".encode() + return cmd, f"{m.name.replace(' ', '')} V010 SIM".encode() if cmd == P.CMD_PRESET_COUNT: return cmd, bytes([0, 0, 0, 0, 0, 0 if self.unlocked else 1]) if cmd == P.CMD_UNLOCK: diff --git a/static/app.js b/static/app.js index 79f5049..f26a985 100644 --- a/static/app.js +++ b/static/app.js @@ -137,6 +137,8 @@ const chTitle = (d, kind, i) => { const n = chans(d, kind)[i].name; return n ? ` // Channel links (see protocol.py): a free channel's mask is its own bit, the first channel of a // group holds all members' bits, the others 0. The DSP mirrors changes within a group itself. +const MODEL_LABEL = { "204": "DSP 204", "408": "DSP 408", "206": "DSP 206", "408fir": "FIR DSP 408" }; +const MODEL_CH = { "204": [2, 4], "408": [4, 8], "206": [2, 6], "408fir": [4, 8] }; // inputs, outputs (before a DSP has connected) const LINK_COLORS = ["#f59e0b", "#22d3ee", "#a3e635", "#f472b6"]; function linkGroups(list) { const seen = new Set(), groups = []; @@ -173,7 +175,7 @@ const CH_PALETTE = ["#ef4444", "#f97316", "#f59e0b", "#eab308", "#84cc16", "#22c // channel groups of one kind: linked channels together, the others on their own function chanGroups(d, kind) { if (d.state) return linkGroups(chans(d, kind)); - const n = kind === "in" ? d.n_in || (d.model === "408" ? 4 : 2) : d.n_out || (d.model === "408" ? 8 : 4); + const n = (kind === "in" ? d.n_in : d.n_out) || (MODEL_CH[d.model] || MODEL_CH["204"])[kind === "in" ? 0 : 1]; return Array.from({ length: n }, (_, i) => [i]); } // the colour chosen for a channel; linked channels show their group's colour @@ -592,7 +594,8 @@ function renderTabs() { const testLock = testOn(dev()); const badge = d => { const model = d.detected_model || (d.model !== "auto" ? d.model : ""); - return testOn(d) ? h("small", { class: "test-badge" }, "TEST") : d.demo ? h("small", { class: "demo-badge" }, "DEMO") : model ? h("small", {}, model) : null; + return testOn(d) ? h("small", { class: "test-badge" }, "TEST") : d.demo ? h("small", { class: "demo-badge" }, "DEMO") + : model ? h("small", {}, (MODEL_LABEL[model] || model).replace("DSP ", "") + (d.beta ? " β" : "")) : null; }; const cur = S.devices[S.cur]; if (!cur) { @@ -796,8 +799,8 @@ async function presetFileDialog(d) { "active state – stored presets (U01 …) stay unchanged.", { name: q(d.state.preset_name || "—") })), last ? h("p", { class: "dlg-text" }, t("A backup is made automatically before every import. Last backup: {last}.", { last })) : null), actions: [{ label: t("Close") }, - ...(last && !S.locked ? [{ label: t("Undo import"), value: () => "undo" }] : []), - ...(S.locked ? [] : [{ label: t("Import…"), value: () => "import" }]), + ...(last && !viewOnly() ? [{ label: t("Undo import"), value: () => "undo" }] : []), + ...(viewOnly() ? [] : [{ label: t("Import…"), value: () => "import" }]), { label: t("Export"), primary: true, value: () => "export" }], }); try { @@ -1945,7 +1948,8 @@ function deviceForm(d) { name: h("input", { type: "text", value: d.name, placeholder: t("e.g. DSP 204 stage") }), host: h("input", { type: "text", value: d.host, placeholder: "192.168.1.101", inputmode: "decimal" }), port: h("input", { type: "number", value: d.port }), - model: h("select", {}, [["auto", t("Automatic")], ["204", "DSP 204"], ["408", "DSP 408"]] + model: h("select", {}, [["auto", t("Automatic")], ["204", "DSP 204"], ["408", "DSP 408"], + ["206", "DSP 206 (Beta)"], ["408fir", "FIR DSP 408 (Beta)"]] .map(([v, label]) => h("option", { value: v, selected: d.model === v }, label))), autoconnect: h("input", { type: "checkbox", checked: d.autoconnect }), addr: h("input", { type: "number", min: 1, max: 250, value: d.addr || 1, class: "short" }), @@ -2181,7 +2185,7 @@ async function scanDialog() { const list = await api("POST", "/api/scan"); const used = new Set(S.order.map(id => S.devices[id].host)); box.replaceChildren(...(list.length ? list.map(x => { - const title = x.model ? `DSP ${x.model}` : t("Unknown device"); + const title = MODEL_LABEL[x.model] || t("Unknown device"); const add = async b => { b.disabled = true; try { @@ -2232,6 +2236,21 @@ function viewSettings() { // ------------------------------------------------------------------ render const H_SCROLL = ".mixer, .bands, .geq, .routing"; +// beta models (never seen on a real device): read-only until the shown values were compared with the DSP +function betaBanner(d) { + const model = MODEL_LABEL[d.detected_model] || d.detected_model; + const set = async enabled => { + if (enabled && !await askConfirm(t("Allow changes"), t("Only continue if the values shown here match the DSP (names, gains, filters, routing). If they don't, a change can send wrong values – keep the amplifiers off while testing."), t("Allow changes"), true)) return; + try { await api("POST", `/api/devices/${d.id}/betawrite`, { enabled }); } + catch (e) { toast(t("Error: ") + trMsg(e.message)); } + }; + return h("div", { class: "betabar" + (d.read_only ? " ro" : "") }, + h("div", { class: "grow" }, h("b", {}, t("{model} – Beta", { model })), " ", + d.read_only ? t("Not tested on a real device yet, so changes are off. Compare the shown values with the DSP. If they don't match, send the file from File… → Export to the developer.") + : t("Not tested on a real device yet. Changes are on – keep the amplifiers off while testing.")), + h("button", { class: "small" + (d.read_only ? " on" : ""), "data-view-ok": "", onclick: () => set(d.read_only) }, d.read_only ? t("Allow changes") : t("Turn changes off"))); +} + function render() { if (S.busy) { S.dirty = true; return; } if ($("#app").hidden) return; @@ -2252,6 +2271,7 @@ function render() { const d = dev(); const field = !S.settings && S.view === "soundfield"; // the room plan works without a connected DSP document.body.dataset.view = field ? "soundfield" : S.settings || !d ? "settings" : S.view; + document.body.classList.toggle("locked", viewOnly()); if (field) content = viewSoundField(); else if (S.settings || !d) content = viewSettings(); else if (d.status !== "online" || !d.state) @@ -2262,7 +2282,7 @@ function render() { h("button", { class: "on", onclick: () => unlockDialog(d) }, t("Enter code"))) : S.demo.enabled && !d.demo ? t("Disconnected while demo mode is on") : t("Not connected.")); else content = ({ mixer: viewMixer, channel: viewChannel, routing: viewRouting, link: viewLink, limiter: viewLimiter, test: viewTest }[S.view] || viewMixer)(d); - main.replaceChildren(...[content].flat().filter(Boolean)); + main.replaceChildren(...[!field && !S.settings && d && d.beta ? betaBanner(d) : null, content].flat().filter(Boolean)); main.querySelectorAll(H_SCROLL).forEach((e, i) => { if (xs[i]) e.scrollLeft = xs[i]; }); window.scrollTo(0, y); collectMeters(); @@ -2302,10 +2322,12 @@ new ResizeObserver(() => document.documentElement.style.setProperty("--sb", $("# // ------------------------------------------------------------------ lock (desktop app window: look, don't touch) +const viewOnly = () => !!S.locked || (!S.settings && S.view !== "soundfield" && !!(dev() && dev().read_only)); + function showLock() { const b = $("#btn-lock"); b.hidden = !S.isApp; - document.body.classList.toggle("locked", !!S.locked); + document.body.classList.toggle("locked", viewOnly()); b.classList.toggle("on", !!S.locked); b.title = S.locked ? t("Locked – click to unlock") : t("Lock (view only)"); b.setAttribute("aria-label", b.title); @@ -2337,14 +2359,14 @@ $("#btn-lock").addEventListener("click", async () => { const VIEW_OK = ".chsel, .nav, .strip-head, .xout, .band, #btn-muteall, [data-view-ok]"; for (const type of ["pointerdown", "mousedown", "click", "dblclick", "keydown", "wheel"]) { document.addEventListener(type, e => { - if (!S.locked || !(e.target instanceof Element)) return; + if (!viewOnly() || !(e.target instanceof Element)) return; const tgt = e.target; if (!tgt.closest("#main, #statusbar") || tgt.closest(VIEW_OK)) return; if (type === "wheel" && !tgt.closest(".fader, input, select")) return; // page scrolling stays if (type === "keydown" && !tgt.closest("button, input, select, textarea, .fader, [tabindex]")) return; if (type === "pointerdown" && !tgt.closest("button, input, select, textarea, .fader, canvas, a")) return; e.preventDefault(); e.stopPropagation(); - if (type === "click" && Date.now() - (S.lockToast || 0) > 1500) { S.lockToast = Date.now(); toast(t("Locked – unlock at the top right to make changes")); } + if (type === "click" && Date.now() - (S.lockToast || 0) > 1500) { S.lockToast = Date.now(); toast(S.locked ? t("Locked – unlock at the top right to make changes") : t("Beta model: changes are off")); } }, { capture: true, passive: false }); } diff --git a/static/i18n.js b/static/i18n.js index 56f2f08..7c7889b 100644 --- a/static/i18n.js +++ b/static/i18n.js @@ -516,6 +516,13 @@ const DE = { "Dissolve group": "Gruppe auflösen", "{names} joins the group and takes over its settings (name{routing} stays).": "{names} kommt in die Gruppe und übernimmt ihre Einstellungen – außer Name{routing}.", "{names} leaves the group and keeps its current settings.": "{names} verlässt die Gruppe und behält seine aktuellen Einstellungen.", + "Allow changes": "Änderungen erlauben", + "Turn changes off": "Änderungen ausschalten", + "Only continue if the values shown here match the DSP (names, gains, filters, routing). If they don't, a change can send wrong values – keep the amplifiers off while testing.": "Nur weitermachen, wenn die angezeigten Werte zum DSP passen (Namen, Gains, Filter, Routing). Sonst kann eine Änderung falsche Werte senden – beim Testen die Endstufen ausgeschaltet lassen.", + "{model} – Beta": "{model} – Beta", + "Not tested on a real device yet, so changes are off. Compare the shown values with the DSP. If they don't match, send the file from File… → Export to the developer.": "Noch nicht an einem echten Gerät getestet, darum sind Änderungen aus. Vergleiche die angezeigten Werte mit dem DSP. Passen sie nicht, schick die Datei aus Datei… → Export an den Entwickler.", + "Not tested on a real device yet. Changes are on – keep the amplifiers off while testing.": "Noch nicht an einem echten Gerät getestet. Änderungen sind an – beim Testen die Endstufen ausgeschaltet lassen.", + "Beta model: changes are off": "Beta-Modell: Änderungen sind aus", }; const DE_PATTERNS = [ diff --git a/static/soundfield.js b/static/soundfield.js index e7d15e4..63a5424 100644 --- a/static/soundfield.js +++ b/static/soundfield.js @@ -504,7 +504,7 @@ const sfNum = (value, step, onset, attrs = {}) => { function sfOutputs() { // every DSP output known from the device list (also offline ones) return S.order.map(id => S.devices[id]).filter(d => !d.demo || S.demo.enabled).map(d => { - const n = d.n_out || (d.model === "204" ? 4 : d.model === "408" ? 8 : 0); + const n = d.n_out || (MODEL_CH[d.model] || [0, 0])[1]; return { d, outs: Array.from({ length: n }, (_, o) => o) }; }).filter(x => x.outs.length); } diff --git a/static/style.css b/static/style.css index 35dce5b..daa7495 100644 --- a/static/style.css +++ b/static/style.css @@ -744,3 +744,10 @@ input[type=range].haslim::-moz-range-track { .lkgroup.editing { background: color-mix(in srgb, var(--lc) 14%, var(--panel2)); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--lc) 45%, transparent); } .lkgroup.dim { opacity: .5; } .lkactions button + button { margin-left: 6px; } +/* ---- beta models */ +.betabar { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; padding: 9px 12px; border-radius: 9px; font-size: 13px; + background: #f59e0b14; border: 1px solid #f59e0b55; } +.betabar b { color: var(--warn); } +.betabar.ro { background: #f59e0b24; border-color: #f59e0b99; } +.betabar button { flex: none; } +@media (max-width: 560px) { .betabar { flex-direction: column; align-items: stretch; } } diff --git a/tests/test_protocol.py b/tests/test_protocol.py index 479d4b5..e95f741 100644 --- a/tests/test_protocol.py +++ b/tests/test_protocol.py @@ -165,6 +165,19 @@ def test_master_bypass(): assert P.MODELS["408"].test_base + 6 == 0x5A2 +def test_beta_models(): + assert P.detect_model("DSP408 V010") == "408" and P.detect_model("DSP 204") == "204" + for info in ("DSP206 V1", "FIR DSP408 V1", "FIRDSP408", "DSP408FIR"): # only selectable by hand + assert P.detect_model(info) is None, info + for key in ("206", "408fir"): + m = P.MODELS[key] + assert m.beta and not {P.CMD_GAIN, P.CMD_MUTE, P.CMD_LINK, P.CMD_PRESET_RECALL} & P.READ_COMMANDS + st = P.default_state(m) + st["outputs"][m.n_out - 1]["gain"] = 123 + back = P.parse_state(m, bytes(P.build_state_buffer(m, st))) + assert back["outputs"][m.n_out - 1]["gain"] == 123 and len(back["inputs"]) == m.n_in + + if __name__ == "__main__": for name, fn in list(globals().items()): if name.startswith("test_"):