Max level: confirm typed values above the limit, cleaner limit display

- typing a gain above the max level shows the limit and a warning; Apply has to be
  clicked twice ("Set anyway"), the forced value also passes the server's lock
- sliders and faders show the locked range as a subtle striped zone in the track with a
  stop edge at the limit, behind the knob (no more line drawn over the knob)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
GivouandClaude Opus 5.5 committed 2026-11-01 23:37:40 +01:00
1 parent 52695d20a5
commit 06bc767f2c
4 files changed
+72 -26

No files matched your search

+50 -19
View File
@@ -279,18 +279,43 @@ async function openFile(accept = ".json,.bin,application/json,application/octet-
return { name, b64: btoa(bin), json };
}
function askValue(label, spec, raw) {
// cap: highest raw value allowed without confirmation (software max level), or null.
// Above it the dialog warns and Apply has to be clicked twice; the result is then {value, force: true}.
function askValue(label, spec, raw, cap = null) {
const input = h("input", { type: "text", value: spec.fmt(raw).replace(/^Q /, "").replace(/ ·.*$/, ""),
autocomplete: "off", spellcheck: "false", enterkeyhint: "done" });
const quick = spec.zero != null
? h("button", { class: "chip", onclick: () => { input.value = "0"; input.focus(); } }, "0 dB") : null;
? h("button", { class: "chip", onclick: () => { input.value = "0"; input.focus(); check(); } }, "0 dB") : null;
const warn = h("div", { class: "overlim", hidden: true });
let armed = false;
const parsed = () => { const s = input.value.trim(); return !s || isNaN(num(s)) ? null : clamp(spec.parse(s), spec.min, spec.max); };
const applyBtn = () => document.querySelector("#modal .dlg-actions button:last-child");
const check = () => {
const v = parsed(), over = cap != null && v != null && v > cap;
warn.hidden = !over;
if (over) warn.replaceChildren(svgIcon(ICON.lock), h("span", {}, t("Above the max level of {lim} – press Apply twice to set it anyway.", { lim: spec.fmt(cap) })));
if (armed && !over) { armed = false; const b = applyBtn(); if (b) { b.textContent = t("Apply"); b.className = "on"; } }
};
input.addEventListener("input", check);
return modal({
title: label,
body: h("div", {}, h("div", { class: "row" }, input, quick), h("p", { class: "info" }, spec.hint || "")),
body: h("div", {}, h("div", { class: "row" }, input, quick),
cap != null ? h("p", { class: "info limnote" }, svgIcon(ICON.lock), t("Max level: {lim}", { lim: spec.fmt(cap) })) : null,
warn, h("p", { class: "info" }, spec.hint || "")),
onOpen: check,
actions: [{ label: t("Cancel") }, { label: t("Apply"), primary: true, value: () => {
const s = input.value.trim();
if (!s || isNaN(num(s))) { input.classList.add("bad"); return undefined; }
return clamp(spec.parse(s), spec.min, spec.max);
const v = parsed();
if (v == null) { input.classList.add("bad"); return undefined; }
if (cap != null && v > cap) {
if (!armed) { // first click: ask again
armed = true;
const b = applyBtn();
if (b) { b.textContent = t("Set anyway"); b.className = "danger-on"; }
return undefined;
}
return { value: v, force: true };
}
return v;
} }],
});
}
@@ -308,10 +333,10 @@ const showLive = (key, v) => (live.get(key) || []).forEach(fn => fn(v));
const LINK_OWN = ["name", "mix", "matrix", "link"]; // per channel even when linked (see protocol.py)
const sendTimers = new Map(), sendPending = new Map(), recentlySet = new Map();
function setParam(kind, idx, param, value) {
function setParam(kind, idx, param, value, force = false) {
const d = dev();
if (!d || !d.state) return;
if (param === "gain") { const c = gainCap(d, kind, idx); if (c != null) value = Math.min(value, c); }
if (param === "gain" && !force) { const c = gainCap(d, kind, idx); if (c != null) value = Math.min(value, c); }
setPath(chans(d, kind)[idx], param, value);
const key = `${d.id}|${kind}|${idx}|${param}`;
recentlySet.set(key, Date.now());
@@ -322,7 +347,7 @@ function setParam(kind, idx, param, value) {
recentlySet.set(`${d.id}|${kind}|${j}|${param}`, Date.now());
showLive(`${d.id}|${kind}|${j}|${param}`, value);
}
const body = { kind, idx, param, value };
const body = { kind, idx, param, value, ...(force ? { force: true } : {}) };
const fire = b => api("POST", `/api/devices/${d.id}/set`, b).catch(e => toast(t("Error: ") + e.message));
if (sendTimers.has(key)) { sendPending.set(key, body); return; }
fire(body);
@@ -364,15 +389,15 @@ function paramSlider(label, kind, idx, path, specName, onChange) {
const home = spec.zero ?? spec.def;
const wrap = h("div", { class: "param" + (cur() === spec.zero ? " atzero" : "") });
let dragging = false;
const commit = v => {
const commit = (v, force = false) => {
v = clamp(Math.round(v), spec.min, spec.max);
if (path === "gain") { const c = gainCap(dev(), kind, idx); if (c != null) v = Math.min(v, c); } // software max level
if (path === "gain" && !force) { const c = gainCap(dev(), kind, idx); if (c != null) v = Math.min(v, c); } // software max level
input.value = v;
if (v === cur()) return;
if (v === spec.zero) buzz();
val.textContent = spec.fmt(v);
wrap.classList.toggle("atzero", v === spec.zero);
setParam(kind, idx, path, v);
setParam(kind, idx, path, v, force);
onChange && onChange(v);
};
onLive(kind, idx, path, v => { input.value = v; val.textContent = spec.fmt(v); wrap.classList.toggle("atzero", v === spec.zero); });
@@ -393,13 +418,17 @@ function paramSlider(label, kind, idx, path, specName, onChange) {
input.addEventListener("pointercancel", release);
input.addEventListener("blur", release);
val.addEventListener("click", async () => {
const v = await askValue(label, spec, cur());
if (v != null) commit(v);
const v = await askValue(label, spec, cur(), path === "gain" ? gainCap(dev(), kind, idx) : null);
if (v != null) typeof v === "object" ? commit(v.value, true) : commit(v);
});
const lim = path === "gain" ? maxGain(dev(), kind, idx) : null;
if (lim != null) { // locked range above the max level, part of the track (stays behind the knob)
input.classList.add("haslim");
input.style.setProperty("--lim", (lim - spec.min) / (spec.max - spec.min));
input.title = `${t("Max level")}: ${spec.fmt(lim)}`;
}
const track = h("div", { class: "rangewrap" },
spec.zero != null ? h("div", { class: "zmark", style: `--f:${(spec.zero - spec.min) / (spec.max - spec.min)}` }) : null,
lim != null ? h("div", { class: "limmark", style: `--f:${(lim - spec.min) / (spec.max - spec.min)}`, title: t("Max level") }) : null, input);
spec.zero != null ? h("div", { class: "zmark", style: `--f:${(spec.zero - spec.min) / (spec.max - spec.min)}` }) : null, input);
wrap.append(
h("div", { class: "lbl" }, h("span", {}, label),
h("div", { class: "valbox" }, stepper(-1, d => commit(cur() + d)), val, stepper(1, d => commit(cur() + d)))),
@@ -434,7 +463,7 @@ function fader({ min, max, value, zero, ticks, label, onInput, cap, limit }) {
const tickEls = (ticks || []).map(([v, label]) => h("div", { class: "tick" + (v === zero ? " z" : ""), style: `--f:${(v - min) / (max - min)}` }, label ? h("span", {}, label) : null));
const el = h("div", { class: "fader", tabindex: "0", role: "slider", "aria-label": label || "Fader",
"aria-valuemin": min, "aria-valuemax": max }, h("div", { class: "track" }), tickEls,
limit != null ? h("div", { class: "limmark", style: `--f:${(limit - min) / (max - min)}`, title: t("Max level") }) : null, capEl);
limit != null ? h("div", { class: "limzone", style: `--f:${(limit - min) / (max - min)}`, title: t("Max level") }) : null, capEl);
let cur = value;
const place = () => {
capEl.style.setProperty("--f", (cur - min) / (max - min));
@@ -853,8 +882,10 @@ function strip(d, kind, i) {
onInput: v => { showDb(v); setParam(kind, i, "gain", v); } });
onLive(kind, i, "gain", v => { f.setValue(v); showDb(v); });
db.addEventListener("click", async () => {
const v = await askValue(`${chTitle(d, kind, i)} – Gain`, SPEC.gain, chans(dev(), kind)[i].gain);
if (v != null) { f.setValue(v); showDb(v); setParam(kind, i, "gain", v); }
const r = await askValue(`${chTitle(d, kind, i)} – Gain`, SPEC.gain, chans(dev(), kind)[i].gain, gainCap(dev(), kind, i));
if (r == null) return;
const force = typeof r === "object", v = force ? r.value : Math.min(r, gainCap(dev(), kind, i) ?? r);
f.setValue(v); showDb(v); setParam(kind, i, "gain", v, force);
});
el.append(
h("button", { class: "strip-head", onclick: () => openChannel(kind, i), title: t("Edit channel") },