diff --git a/README.md b/README.md index e4567cd..5aed1d5 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ Control both devices at the same time from your phone, tablet or computer – ov from the speed of sound and writes them to the assigned DSP outputs * **Copy channel settings** – level/delay/polarity, filters, EQ, dynamics and routing from one channel to any number of channels on all connected DSPs +* **Channel colours** – pick a colour per channel in the settings (line and lightly tinted name in the mixer, channel view, + routing and curve overlays); linked channels share one colour, every colour is used once per DSP * **Mute all** – one button mutes every channel of every connected DSP; releasing it unmutes only what was open before * **Settings backup** – devices, amplifier data, SoundField plan, PIN and remote access in one file * **Device lock** – DSPs locked with their 4-character code (e.g. `A1BA`) are detected on connect and the app asks diff --git a/dsp/device.py b/dsp/device.py index 83ba4df..cac173a 100644 --- a/dsp/device.py +++ b/dsp/device.py @@ -21,7 +21,8 @@ LINK_RESYNC_DELAY = 1.5 # re-read the config this long after the last change on 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): + lock_code: str = "", auto_unlock: bool = False, test_saved: list | None = None, + colors: dict | None = None): self.id = dev_id self.name = name self.host = host @@ -36,6 +37,7 @@ class Device: self.lock_code = lock_code if P.LOCK_CODE.fullmatch(lock_code or "") else "" self.auto_unlock = auto_unlock self.demo = False # in-process simulator of the demo mode, never saved + self.colors: dict[str, str] = colors or {} # channel colours chosen in the app, e.g. {"in0": "#38bdf8"} # audio test: output gains from before the test (restored when it ends) and the test fader level self.test_saved: list[int] | None = test_saved if isinstance(test_saved, list) else None self.test_level = -50.0 @@ -70,7 +72,8 @@ class Device: return {"id": self.id, "name": self.name, "host": self.host, "port": self.port, "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} + "lock_code": self.lock_code, "auto_unlock": self.auto_unlock, "test_saved": self.test_saved, + "colors": self.colors} def snapshot(self) -> dict: cfg = self.config() diff --git a/server.py b/server.py index 928204d..29ad6f0 100644 --- a/server.py +++ b/server.py @@ -126,6 +126,17 @@ def clean_soundfield(data) -> dict: } +def clean_colors(v) -> dict: + """Channel colours: {"in0": "#rrggbb", "out3": ...}. Linked channels carry their group's colour; that a colour + belongs to one channel/group only is ensured by the colour picker (it knows the link groups).""" + out = {} + for k, c in (v.items() if isinstance(v, dict) else []): + c = str(c).lower() + if re.fullmatch(r"(in|out)\d{1,2}", str(k)) and re.fullmatch(r"#[0-9a-f]{6}", c): + out[str(k)] = c + return out + + def clean_gains(v) -> list[int] | None: """Saved output gains of an interrupted audio test (from config.json).""" if not isinstance(v, list) or not v or len(v) > 8: @@ -283,7 +294,7 @@ class App: bool(d.get("autoconnect", True)), on_event=self.broadcast, 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"))) + test_saved=clean_gains(d.get("test_saved")), colors=clean_colors(d.get("colors"))) dev.on_online = self.device_online self.devices[dev_id] = dev if dev.autoconnect: @@ -744,6 +755,11 @@ class App: if action == "refresh": await dev.refresh() 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")) + self.save() + self.broadcast({"type": "device", "device": dev.id, "data": dev.snapshot()}) + return {"ok": True, "colors": dev.colors} if action == "test": return await self.audio_test(dev, body) if action == "testlevel": diff --git a/static/app.js b/static/app.js index 7140f51..b43f264 100644 --- a/static/app.js +++ b/static/app.js @@ -163,6 +163,25 @@ const linkBadge = (d, kind, i) => { const polBadge = (d, kind, i) => chans(d, kind)[i].polarity ? h("span", { class: "pol", title: t("Phase inverted") }, "Ø") : null; +// ------------------------------------------------------------------ channel colours (chosen in the settings, kept by the app) + +const CH_PALETTE = ["#ef4444", "#f97316", "#f59e0b", "#eab308", "#84cc16", "#22c55e", "#14b8a6", "#06b6d4", + "#38bdf8", "#3b82f6", "#6366f1", "#8b5cf6", "#a855f7", "#d946ef", "#ec4899", "#f43f5e", "#e5e7eb", "#94a3b8"]; +// 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); + return Array.from({ length: n }, (_, i) => [i]); +} +// the colour chosen for a channel; linked channels show their group's colour +function custColor(d, kind, i) { + const cols = d.colors || {}, li = d.state && linkInfo(d, kind, i); + for (const j of li ? li.group : [i]) if (cols[kind + j]) return cols[kind + j]; + return null; +} +const inColor = (d, i) => custColor(d, "in", i) || IN_COLORS[i]; +const ccStyle = (d, kind, i) => { const c = custColor(d, kind, i) || (kind === "in" ? IN_COLORS[i] : null); return c ? `--cc:${c}` : ""; }; + function getPath(obj, path) { return path.split(".").reduce((o, k) => o[Array.isArray(o) ? +k : k], obj); } @@ -584,6 +603,69 @@ function maybeAskUnlock(d) { setTimeout(() => unlockDialog(S.devices[d.id] || d), 50); } +const colorOpen = new Set(); +function colorSection(d) { + const row = (kind, g) => { + const c = custColor(d, kind, g[0]), label = g.map(j => chLabel(kind, j)).join(" + "); + const name = d.state ? chans(d, kind)[g[0]].name : ""; + return h("button", { class: "colrow", type: "button", onclick: () => colorDialog(d, kind, g) }, + h("span", { class: "swatch" + (c ? "" : " none"), style: c ? `background:${c}` : "" }), + h("span", { class: "grow" }, label, name ? h("small", {}, name) : null), + g.length > 1 ? h("span", { class: "lnk" }, svgIcon(ICON.link)) : null); + }; + const box = h("details", { class: "more full colorbox", open: colorOpen.has(d.id), + ontoggle: () => box.open ? colorOpen.add(d.id) : colorOpen.delete(d.id) }, + h("summary", {}, t("Channel colours")), + h("p", { class: "info" }, t("Shown on the mixer strips and in the channel view. Linked channels share one colour; every colour can only be used once per DSP.")), + h("div", { class: "colgrid" }, + h("div", {}, h("div", { class: "sub" }, t("Inputs")), chanGroups(d, "in").map(g => row("in", g))), + h("div", {}, h("div", { class: "sub" }, t("Outputs")), chanGroups(d, "out").map(g => row("out", g))))); + return box; +} + +async function colorDialog(d, kind, members) { + // colours already taken by other channels / groups of this DSP (also the hidden ones of linked members, + // so no colour turns up twice when a group is dissolved again) + const taken = new Map(); + for (const [key, c] of Object.entries(d.colors || {})) { + const k = key.startsWith("in") ? "in" : "out", j = +key.replace(/\D/g, ""); + if (k === kind && members.includes(j)) continue; + const g = chanGroups(d, k).find(x => x.includes(j)) || [j]; + taken.set(c.toLowerCase(), g.map(x => chLabel(k, x)).join(" + ")); + } + let chosen = custColor(d, kind, members[0]) || ""; + const sw = []; + const mark = () => sw.forEach(b => b.classList.toggle("on", b.dataset.c === chosen)); + const swatches = CH_PALETTE.map(c => { + const by = taken.get(c); + const b = h("button", { class: "swatch big", type: "button", style: `background:${c}`, "data-c": c, disabled: !!by, + title: by ? t("Used by {ch}", { ch: by }) : c, onclick: () => { chosen = c; picker.value = c; mark(); } }); + sw.push(b); + return b; + }); + const picker = h("input", { type: "color", value: chosen || "#38bdf8", "aria-label": t("Custom colour") }); + picker.addEventListener("input", () => { + const c = picker.value.toLowerCase(); + if (taken.has(c)) { toast(t("Used by {ch}", { ch: taken.get(c) })); return; } + chosen = c; mark(); + }); + mark(); + const label = members.map(j => chLabel(kind, j)).join(" + "); + const res = await modal({ + title: t("Colour for {ch}", { ch: label }), + body: h("div", { class: "coldlg" }, h("div", { class: "swatches" }, swatches), + h("label", { class: "row custom" }, h("span", { class: "grow" }, t("Custom colour")), picker), + members.length > 1 ? h("p", { class: "info" }, t("Linked channels always share their colour.")) : null), + actions: [{ label: t("Cancel") }, { label: t("Default"), value: () => "" }, + { label: t("Apply"), primary: true, value: () => chosen || undefined }], + }); + if (res === null) return; + const colors = { ...(d.colors || {}) }; + for (const j of members) { if (res) colors[kind + j] = res; else delete colors[kind + j]; } + try { await api("POST", `/api/devices/${d.id}/colors`, { colors }); } + catch (e) { toast(t("Error: ") + trMsg(e.message)); } +} + const lockOpen = new Set(); // device ids whose lock section is open (survives re-rendering) function lockSection(d) { const online = d.status === "online"; @@ -752,7 +834,7 @@ function strip(d, kind, i) { const ch = chans(d, kind)[i]; const db = h("button", { class: "db" + (ch.gain === 280 ? " z" : ""), title: t("Enter value") }, sign(gainDb(ch.gain))); const showDb = v => { db.textContent = sign(gainDb(v)); db.classList.toggle("z", v === 280); }; - const el = h("div", { class: `strip ${kind}` + (ch.mute ? " muted" : ""), style: kind === "in" ? `--cc:${IN_COLORS[i]}` : "" }); + const el = h("div", { class: `strip ${kind}` + (ch.mute ? " muted" : "") + (custColor(d, kind, i) ? " tinted" : ""), style: ccStyle(d, kind, i) }); const f = fader({ min: 0, max: 400, value: ch.gain, zero: 280, ticks: GAIN_TICKS, label: `${chLabel(kind, i)} Gain`, onInput: v => { showDb(v); setParam(kind, i, "gain", v); } }); onLive(kind, i, "gain", v => { f.setValue(v); showDb(v); }); @@ -848,7 +930,7 @@ function channelH(ch, f) { const hasGain = type => type <= 2; const hasQ = type => [0, 4, 6, 7, 8].includes(type); const OUT_COLORS = ["#f97316", "#facc15", "#4ade80", "#e879f9", "#60a5fa", "#fb7185", "#2dd4bf", "#c084fc"]; -const chColor = (kind, i) => kind === "in" ? IN_COLORS[i] : OUT_COLORS[i]; +const chColor = (d, kind, i) => custColor(d, kind, i) || (kind === "in" ? IN_COLORS[i] : OUT_COLORS[i]); // opts: { mode: "mag" | "phase", overlays: [{ ch, color }] } function drawCurve(canvas, ch, selBand, opts = canvas.curveOpts ? canvas.curveOpts() : {}) { @@ -945,7 +1027,7 @@ function overlayChips(d, kind, idx, onChange) { return h("div", { class: "chips overlay" }, h("span", { class: "sub" }, t("Overlay")), all.map(([k, i]) => { const key = `${k}${i}`, on = sel.has(key); - const btn = h("button", { class: "chip ov" + (on ? " on" : ""), style: `--oc:${chColor(k, i)}`, "aria-pressed": String(on), + const btn = h("button", { class: "chip ov" + (on ? " on" : ""), style: `--oc:${chColor(d, k, i)}`, "aria-pressed": String(on), title: chTitle(d, k, i), "data-view-ok": "", onclick: () => { // always from the stored set: the chip may be older than the last change const cur = overlaySet(d), now = !cur.has(key); @@ -961,7 +1043,7 @@ function overlaysFor(d, kind, idx) { return [...overlaySet(d)].map(key => { const k = key.startsWith("in") ? "in" : "out", i = +key.replace(/\D/g, ""); const list = chans(d, k); - return i < list.length && !(k === kind && i === idx) ? { ch: list[i], color: chColor(k, i) } : null; + return i < list.length && !(k === kind && i === idx) ? { ch: list[i], color: chColor(d, k, i) } : null; }).filter(Boolean); } @@ -1096,7 +1178,7 @@ function channelBar(d) { }))); return h("div", { class: "chbar" }, h("button", { class: "icon nav", "aria-label": t("Previous channel"), onclick: () => go(pos - 1) }, svgIcon(ICON.prev)), - h("div", { class: "chselwrap", style: kind === "in" ? `--cc:${IN_COLORS[idx]}` : "" }, sel), + h("div", { class: "chselwrap", style: ccStyle(d, kind, idx) }, sel), h("button", { class: "icon nav", "aria-label": t("Next channel"), onclick: () => go(pos + 1) }, svgIcon(ICON.next)), ledMeter(d.id, kind, idx, "h"), kind === "out" ? limLed(d.id, idx, "h") : null, @@ -1165,7 +1247,7 @@ function viewChannel(d) { function mixList(d, o) { return chans(d, "in").map((inp, i) => { const on = chans(d, "out")[o].matrix >> i & 1; - const btn = h("button", { class: "src" + (on ? " on" : ""), style: `--cc:${IN_COLORS[i]}`, "aria-pressed": String(!!on), + const btn = h("button", { class: "src" + (on ? " on" : ""), style: `--cc:${inColor(d, i)}`, "aria-pressed": String(!!on), onclick: () => { const m = chans(dev(), "out")[o].matrix ^ (1 << i); setParam("out", o, "matrix", m); render(); @@ -1184,7 +1266,7 @@ function viewRouting(d) { const ins = chans(d, "in"), outs = chans(d, "out"); const grid = h("div", { class: "xmatrix", style: `--n:${ins.length}` }); grid.append(h("div", { class: "xcorner" }, h("span", {}, t("Input →")), h("span", {}, t("Output ↓")))); - ins.forEach((c, i) => grid.append(h("div", { class: "xin", style: `--cc:${IN_COLORS[i]}` }, + ins.forEach((c, i) => grid.append(h("div", { class: "xin", style: `--cc:${inColor(d, i)}` }, h("b", {}, chLabel("in", i)), h("small", {}, c.name || " "), ledMeter(d.id, "in", i, "h")))); outs.forEach((oc, o) => { const open = S.routeOpen === o; @@ -1196,7 +1278,7 @@ function viewRouting(d) { h("span", { class: "chev" }, open ? "▴" : "▾"))); ins.forEach((_, i) => { const on = oc.matrix >> i & 1; - grid.append(h("button", { class: "xp" + (on ? " on" : ""), style: `--cc:${IN_COLORS[i]}`, + grid.append(h("button", { class: "xp" + (on ? " on" : ""), style: `--cc:${inColor(d, i)}`, "aria-label": `${chLabel("in", i)} → ${chLabel("out", o)}`, "aria-pressed": String(!!on), onclick: () => { const m = chans(dev(), "out")[o].matrix ^ (1 << i); @@ -1732,6 +1814,7 @@ function deviceForm(d) { ...netRows, usbRow, h("label", {}, t("Model"), f.model), h("label", { class: "chk" }, f.autoconnect, t("Connect automatically")), + isNew ? null : colorSection(d), isNew ? null : lockSection(d), h("div", { class: "actions" }, actions))); } diff --git a/static/i18n.js b/static/i18n.js index 9afc6f1..f2a1fa7 100644 --- a/static/i18n.js +++ b/static/i18n.js @@ -431,6 +431,14 @@ const DE = { "{m} m to the nearest main": "{m} m zum nächsten Main", "{n} output delay(s) set": "{n} Ausgangs-Delay(s) gesetzt", "{n} output(s) not connected": "{n} Ausgang/Ausgänge nicht verbunden", + // channel colours + "Channel colours": "Kanalfarben", + "Shown on the mixer strips and in the channel view. Linked channels share one colour; every colour can only be used once per DSP.": "Wird im Mixer und in der Kanalansicht angezeigt. Verknüpfte Kanäle teilen sich eine Farbe; jede Farbe gibt es pro DSP nur einmal.", + "Used by {ch}": "Vergeben an {ch}", + "Custom colour": "Eigene Farbe", + "Colour for {ch}": "Farbe für {ch}", + "Linked channels always share their colour.": "Verknüpfte Kanäle teilen sich immer ihre Farbe.", + "Default": "Standard", }; const DE_PATTERNS = [ diff --git a/static/style.css b/static/style.css index 5901fde..93412e8 100644 --- a/static/style.css +++ b/static/style.css @@ -565,3 +565,21 @@ button.chip.on { border-color: var(--accent); background: color-mix(in srgb, var .sftable td.num { font-variant-numeric: tabular-nums; white-space: nowrap; } .sfdelays .info label.inline { display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; } .sfdelays .info input.short { width: 70px; } + +/* ---- channel colours */ +.strip.tinted .nm { color: color-mix(in srgb, var(--cc) 55%, #fff); } +.colorbox .colgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 14px; margin-top: 6px; } +.colorbox .sub { margin: 4px 0; } +button.colrow { display: flex; align-items: center; gap: 10px; width: 100%; margin-top: 6px; padding: 6px 10px; min-height: 0; + text-transform: none; letter-spacing: 0; font-weight: 500; text-align: left; } +button.colrow small { display: block; color: var(--dim); font-size: 11px; font-weight: 400; } +.swatch { width: 18px; height: 18px; border-radius: 5px; flex: none; border: 1px solid #ffffff33; } +.swatch.none { background: repeating-linear-gradient(45deg, #ffffff22 0 3px, transparent 3px 6px); } +.coldlg .swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; } +button.swatch.big { width: 100%; height: 38px; padding: 0; min-height: 0; border-radius: 8px; border: 2px solid transparent; } +button.swatch.big.on { border-color: #fff; box-shadow: 0 0 0 2px #0b0c0f inset; } +button.swatch.big:disabled { opacity: .25; cursor: not-allowed; + background-image: linear-gradient(135deg, transparent 46%, #0b0c0f 46%, #0b0c0f 54%, transparent 54%) !important; } +.coldlg .custom { margin-top: 12px; align-items: center; } +.coldlg input[type=color] { width: 56px; height: 34px; padding: 2px; border-radius: 8px; background: var(--panel2); border: 1px solid var(--line); } +.coldlg .custom input[type=color] { flex: none; width: 56px; }