Edit mover patterns from the SMC-PAD and save the corner aims.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
1b181640dd
commit
b1181e6f28
8 files changed
+859
No files matched your search
@@ -0,0 +1,127 @@
|
||||
const $ = (id) => document.getElementById(id);
|
||||
|
||||
const pan = $("pan");
|
||||
const tilt = $("tilt");
|
||||
const rotate = $("rotate");
|
||||
const loop = $("loop");
|
||||
let dragging = false;
|
||||
let seenDev = null;
|
||||
let devDown = false;
|
||||
|
||||
function paint(data, writeSliders) {
|
||||
$("meta").textContent = `${data.artnet} · ${data.midi}`;
|
||||
for (const button of document.querySelectorAll("#corners button")) {
|
||||
const name = button.dataset.corner;
|
||||
const aim = data.corners[name];
|
||||
button.classList.toggle("active", name === data.selected);
|
||||
button.querySelector("small").textContent = `pan ${aim.pan} tilt ${aim.tilt} rot ${aim.rotate}`;
|
||||
}
|
||||
for (const button of document.querySelectorAll("#modes button")) {
|
||||
button.classList.toggle("active", button.dataset.mode === data.mode);
|
||||
}
|
||||
if (writeSliders) {
|
||||
const aim = data.corners[data.selected];
|
||||
pan.value = aim.pan;
|
||||
tilt.value = aim.tilt;
|
||||
rotate.value = aim.rotate;
|
||||
}
|
||||
$("pan-out").textContent = pan.value;
|
||||
$("tilt-out").textContent = tilt.value;
|
||||
$("rot-out").textContent = rotate.value;
|
||||
if (document.activeElement !== loop) loop.value = data.loop_s;
|
||||
const live = data.live;
|
||||
$("live").textContent = `${data.label} ${live.pan} / ${live.tilt} / ${live.rotate}`;
|
||||
}
|
||||
|
||||
async function post(url, body) {
|
||||
const res = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify(body || {}),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) throw new Error(data.error || "request failed");
|
||||
paint(data, !dragging);
|
||||
return data;
|
||||
}
|
||||
|
||||
function sendAim() {
|
||||
$("pan-out").textContent = pan.value;
|
||||
$("tilt-out").textContent = tilt.value;
|
||||
$("rot-out").textContent = rotate.value;
|
||||
post("/api/aim", {
|
||||
pan: Number(pan.value),
|
||||
tilt: Number(tilt.value),
|
||||
rotate: Number(rotate.value),
|
||||
}).catch((err) => {
|
||||
$("status").textContent = err.message;
|
||||
});
|
||||
}
|
||||
|
||||
for (const input of [pan, tilt, rotate]) {
|
||||
input.addEventListener("pointerdown", () => {
|
||||
dragging = true;
|
||||
});
|
||||
input.addEventListener("input", sendAim);
|
||||
}
|
||||
window.addEventListener("pointerup", () => {
|
||||
dragging = false;
|
||||
});
|
||||
|
||||
$("corners").addEventListener("click", (ev) => {
|
||||
const button = ev.target.closest("button");
|
||||
if (!button) return;
|
||||
post("/api/select", {name: button.dataset.corner}).catch((err) => {
|
||||
$("status").textContent = err.message;
|
||||
});
|
||||
});
|
||||
|
||||
$("modes").addEventListener("click", (ev) => {
|
||||
const button = ev.target.closest("button");
|
||||
if (!button) return;
|
||||
post("/api/play", {mode: button.dataset.mode}).catch((err) => {
|
||||
$("status").textContent = err.message;
|
||||
});
|
||||
});
|
||||
|
||||
loop.addEventListener("change", () => {
|
||||
post("/api/loop", {seconds: Number(loop.value)}).catch((err) => {
|
||||
$("status").textContent = err.message;
|
||||
});
|
||||
});
|
||||
|
||||
$("save").addEventListener("click", () => {
|
||||
post("/api/save").then(() => {
|
||||
$("status").textContent = "Saved";
|
||||
}).catch((err) => {
|
||||
$("status").textContent = err.message;
|
||||
});
|
||||
});
|
||||
|
||||
async function poll() {
|
||||
try {
|
||||
const data = await fetch("/api/state", {cache: "no-store"}).then((res) => res.json());
|
||||
paint(data, !dragging);
|
||||
} catch {
|
||||
$("meta").textContent = "Reconnecting…";
|
||||
}
|
||||
setTimeout(poll, 200);
|
||||
}
|
||||
|
||||
async function watchDev() {
|
||||
try {
|
||||
const dev = await fetch("/api/dev", {cache: "no-store"}).then((res) => res.json());
|
||||
if (devDown || (seenDev && (dev.boot !== seenDev.boot || dev.static !== seenDev.static))) {
|
||||
location.reload();
|
||||
return;
|
||||
}
|
||||
seenDev = dev;
|
||||
devDown = false;
|
||||
} catch {
|
||||
devDown = seenDev !== null;
|
||||
}
|
||||
setTimeout(watchDev, 400);
|
||||
}
|
||||
|
||||
poll();
|
||||
watchDev();
|
||||
Reference in new issue
Block a user