Add channel colours: per channel or link group, unique per DSP, shown in mixer, channel view, routing and overlays

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
GivouandClaude Opus 5.5 committed 2026-11-01 22:52:21 +01:00
1 parent a7ee66d761
commit eb647f62a9
6 files changed
+141 -11

No files matched your search

+91 -8
View File
@@ -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)));
}