mirror of
https://github.com/ruppert/fmini-1.git
synced 2026-12-05 12:24:36 +01:00
Editor: an ORDER tab to reorder the 200 presets and save the order to the device
- New tab ORDEM / ORDER: the 200 presets in the device's order. Drag a row, or use its up and down arrows (touch too). Undo order goes back to the device's order. - SAVE TO THE DEVICE reads the 200 records (FMINI_REC), puts them in the new order and writes them through the restore's own question on the panel (FMINI_RESTORE, FMINI_RPUT). The restore's writing loop is now shared (writeAll) with the backup restore. - A preset's category stays with its old slot: it is a table in the firmware, indexed by slot. - The test moves a row, saves, checks the device's order, moves it back and saves again. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QUF6pQ1NkTwmBC8SR8AK94
This commit is contained in:
2 files changed
+111
-8
No files matched your search
+90
-8
@@ -46,6 +46,12 @@
|
||||
nav.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: none; }
|
||||
nav.tabs button { background: none; border: 0; border-bottom: 3px solid transparent; padding: 10px 14px; cursor: pointer; color: var(--dim); font-weight: 600; letter-spacing: .05em; font-size: 13px; white-space: nowrap; }
|
||||
nav.tabs button[aria-selected="true"] { color: var(--or2); border-bottom-color: var(--or); }
|
||||
.orderlist { list-style: none; margin: 0; padding: 0; }
|
||||
.orow { display: flex; align-items: center; gap: 8px; padding: 5px 8px; margin-bottom: 4px; border: 1px solid var(--line); border-radius: 6px; cursor: grab; user-select: none; }
|
||||
.orow.drag { opacity: .4; }
|
||||
.orow .onum { width: 3ch; color: var(--dim); font-variant-numeric: tabular-nums; }
|
||||
.orow .oname { flex: 1; font-weight: 600; }
|
||||
.orow button { padding: 2px 9px; }
|
||||
|
||||
main.panel { margin: 18px 0 40px; padding: 22px 18px 26px; background: linear-gradient(#1c1922, #15131a); border: 1px solid var(--line); border-radius: 14px; min-height: 280px; }
|
||||
.grp { margin-bottom: 22px; }
|
||||
@@ -170,6 +176,10 @@ const TX = {
|
||||
noeng: "A trilha 1 não está com o motor FMINI.", lost: "A conexão com o aparelho foi perdida.", timeout: "O aparelho não respondeu.",
|
||||
badfile: "Arquivo de som inválido.", rnd: "Aleatorizar", amt: "Variação", abcopy: "Copiar A → B", abcopyb: "Copiar B → A", abtip: "Alterna entre dois ajustes para comparar",
|
||||
lib: "PRESETS", libload: "Carregar", libempty: "— vazio —", libtitle: "Backup", indiv: "Restaurar Presets individuais:",
|
||||
order: "ORDEM", ordhint: "Arraste os presets para mudar a ordem, ou use as setas. Salvar no dispositivo grava os 200 nessa ordem (confirme no painel). A categoria de cada um (o filtro do aparelho) continua a da posição antiga.",
|
||||
ordsave: "Salvar no dispositivo", ordundo: "Desfazer ordem", askorder: "Gravar os 200 presets nesta ordem no aparelho? Os presets atuais serão substituídos.",
|
||||
busyorder: "Gravando os 200 presets na nova ordem… não desconecte o USB.", orderdone: "Ordem gravada no aparelho.", ordnochange: "A ordem não mudou.",
|
||||
ordnone: "Para reordenar é preciso ler os 200 presets do aparelho (firmware mais novo).", ordup: "Subir", orddown: "Descer",
|
||||
resetall: "Restaurar todos os presets de fábrica", resetone: "Restaurar", askreset: "Restaurar o preset %n para o de fábrica? O que está gravado nele será substituído.",
|
||||
askresetall: "Restaurar os 200 presets de fábrica (000–199)? O que está gravado neles será substituído.", busyreset: "Restaurando os presets de fábrica… não desconecte o USB.",
|
||||
resetdone: "Presets de fábrica restaurados.", resetfail: "O aparelho não conseguiu restaurar o preset.",
|
||||
@@ -194,6 +204,10 @@ const TX = {
|
||||
noeng: "Track 1 is not on the FMINI engine.", lost: "The connection to the device was lost.", timeout: "The device did not answer.",
|
||||
badfile: "Invalid sound file.", rnd: "Randomize", amt: "Amount", abcopy: "Copy A → B", abcopyb: "Copy B → A", abtip: "Switch between two settings to compare",
|
||||
lib: "PRESETS", libload: "Load", libempty: "— empty —", libtitle: "Backup", indiv: "Restore individual presets:",
|
||||
order: "ORDER", ordhint: "Drag the presets to change the order, or use the arrows. Save to device writes the 200 in that order (confirm on the panel). Each one's category (the device's filter) stays with its old slot.",
|
||||
ordsave: "Save to device", ordundo: "Undo order", askorder: "Write the 200 presets in this order to the device? The current presets will be replaced.",
|
||||
busyorder: "Writing the 200 presets in the new order… do not unplug USB.", orderdone: "Order saved to the device.", ordnochange: "The order has not changed.",
|
||||
ordnone: "Reordering needs the 200 presets read from the device (newer firmware).", ordup: "Move up", orddown: "Move down",
|
||||
resetall: "Restore all factory presets", resetone: "Restore", askreset: "Restore preset %n to its factory preset? What is saved in it will be replaced.",
|
||||
askresetall: "Restore the 200 factory presets (000–199)? What is saved in them will be replaced.", busyreset: "Restoring the factory presets… do not unplug USB.",
|
||||
resetdone: "Factory presets restored.", resetfail: "The device could not restore the preset.",
|
||||
@@ -292,6 +306,7 @@ const PAGES = [
|
||||
{ id: "ARP", groups: [
|
||||
{ t: "Arpeggiator", c: [ { k: "sel", p: P.AMODE, lb: "MODE" }, { k: "par", p: P.ARATE, lb: "RATE" }, { k: "par", p: P.AOCT, lb: "OCTAVES" }, { k: "par", p: P.AGATE, lb: "GATE" }, { k: "glb", g: G.BPM, lb: "BPM" } ] } ] },
|
||||
{ id: "LIB", lib: true, groups: [] },
|
||||
{ id: "ORDER", order: true, groups: [] },
|
||||
];
|
||||
|
||||
const pid = (c) => (c.pe !== undefined ? S.pe0 + c.pe : c.p);
|
||||
@@ -426,6 +441,7 @@ function mkSel(c) {
|
||||
function build() {
|
||||
const panel = document.getElementById("panel"); panel.textContent = ""; ctl.length = 0;
|
||||
if (PAGES[S.page].lib) { buildLib(); return; }
|
||||
if (PAGES[S.page].order) { buildOrder(); return; }
|
||||
for (const g of PAGES[S.page].groups) {
|
||||
const grp = document.createElement("section"); grp.className = "grp";
|
||||
const h = document.createElement("h2"); h.textContent = g.t; grp.append(h);
|
||||
@@ -447,7 +463,7 @@ function refreshAll() {
|
||||
function tabs() {
|
||||
const nav = document.getElementById("tabs"); nav.textContent = "";
|
||||
PAGES.forEach((p, i) => {
|
||||
const b = document.createElement("button"); b.role = "tab"; b.textContent = p.lib ? T("lib") : p.id; b.setAttribute("aria-selected", i === S.page);
|
||||
const b = document.createElement("button"); b.role = "tab"; b.textContent = p.lib ? T("lib") : p.order ? T("order") : p.id; b.setAttribute("aria-selected", i === S.page);
|
||||
b.addEventListener("click", () => { S.page = i; tabs(); build(); }); nav.append(b);
|
||||
});
|
||||
}
|
||||
@@ -787,7 +803,7 @@ async function fmReset(k) {
|
||||
}
|
||||
async function refreshPresets() {
|
||||
await readNames(); fillPreset(); await pull(true);
|
||||
if (PAGES[S.page].lib) buildLib();
|
||||
if (PAGES[S.page].lib || PAGES[S.page].order) build();
|
||||
}
|
||||
/* the device asks on its panel (YES: it does the reset itself); args: [0, slot lo, hi] one preset, [3] every factory preset */
|
||||
async function askDevice(args, text) {
|
||||
@@ -827,6 +843,69 @@ async function resetAllFactory() {
|
||||
} catch (e) { msg(T(e.code || "lost"), true); }
|
||||
}
|
||||
|
||||
/* the ORDER tab: the 200 presets in the order the device will keep them. Drag a row, or use its arrows (touch too), then
|
||||
* SAVE TO THE DEVICE: the 200 records are read, put in that order and written through the restore's own question on the
|
||||
* panel. Only the sounds move: a preset's category (the device's filter, a table in the firmware by slot) stays with its slot */
|
||||
let ord = null; /* ord[row] = the slot shown in that row (0..199) */
|
||||
let dragSrc = null;
|
||||
const rowOf = (li) => [...li.parentNode.children].indexOf(li);
|
||||
function renumber(list) { [...list.children].forEach((li, i) => { li.querySelector(".onum").textContent = String(i).padStart(3, "0"); }); }
|
||||
function moveRow(list, from, to) {
|
||||
if (from < 0 || to < 0 || from === to || to >= list.children.length) return;
|
||||
const rows = [...list.children]; const [r] = rows.splice(from, 1); rows.splice(to, 0, r);
|
||||
const [x] = ord.splice(from, 1); ord.splice(to, 0, x);
|
||||
list.append(...rows); renumber(list);
|
||||
}
|
||||
function orderRow(list, name) {
|
||||
const li = document.createElement("li"); li.className = "orow"; li.draggable = true;
|
||||
const no = document.createElement("span"); no.className = "onum";
|
||||
const nm = document.createElement("span"); nm.className = "oname"; nm.textContent = name || "—";
|
||||
const up = document.createElement("button"); up.className = "btn"; up.textContent = "▲"; up.title = T("ordup"); up.setAttribute("aria-label", T("ordup"));
|
||||
const dn = document.createElement("button"); dn.className = "btn"; dn.textContent = "▼"; dn.title = T("orddown"); dn.setAttribute("aria-label", T("orddown"));
|
||||
up.addEventListener("click", () => moveRow(list, rowOf(li), rowOf(li) - 1));
|
||||
dn.addEventListener("click", () => moveRow(list, rowOf(li), rowOf(li) + 1));
|
||||
li.addEventListener("dragstart", (e) => { dragSrc = li; li.classList.add("drag"); e.dataTransfer.effectAllowed = "move"; e.dataTransfer.setData("text/plain", ""); });
|
||||
li.addEventListener("dragover", (e) => { e.preventDefault(); e.dataTransfer.dropEffect = "move"; });
|
||||
li.addEventListener("drop", (e) => { e.preventDefault(); if (dragSrc) moveRow(list, rowOf(dragSrc), rowOf(li)); });
|
||||
li.addEventListener("dragend", () => { if (dragSrc) dragSrc.classList.remove("drag"); dragSrc = null; });
|
||||
li.append(no, nm, up, dn);
|
||||
return li;
|
||||
}
|
||||
function buildOrder() {
|
||||
const panel = $("panel"); panel.textContent = "";
|
||||
if (!ord || ord.length !== S.names.length) ord = S.names.map((_, i) => i);
|
||||
const g = document.createElement("section"); g.className = "grp";
|
||||
const h = document.createElement("h2"); h.textContent = T("order");
|
||||
const hint = document.createElement("p"); hint.textContent = T("ordhint");
|
||||
const bar = document.createElement("div"); bar.className = "libname";
|
||||
const b1 = document.createElement("button"); b1.className = "btn"; b1.textContent = T("ordsave"); b1.addEventListener("click", saveOrder);
|
||||
const b2 = document.createElement("button"); b2.className = "btn"; b2.textContent = T("ordundo");
|
||||
b2.addEventListener("click", () => { ord = null; buildOrder(); });
|
||||
bar.append(b1, b2);
|
||||
const list = document.createElement("ol"); list.className = "orderlist"; list.setAttribute("aria-label", T("order"));
|
||||
ord.forEach((k) => list.append(orderRow(list, S.names[k])));
|
||||
renumber(list);
|
||||
g.append(h, hint, bar, list);
|
||||
panel.append(g);
|
||||
}
|
||||
async function saveOrder() {
|
||||
if (!S.canPatch) return;
|
||||
if (S.names.length !== 200) { msg(T("ordnone"), true); return; }
|
||||
if (ord.every((k, i) => k === i)) { msg(T("ordnochange")); return; }
|
||||
if (!confirm(T("askorder"))) return;
|
||||
try {
|
||||
const recs = await withBusy(T("busybak"), async () => {
|
||||
const out = [];
|
||||
for (let k = 0; k < 200; k++) { out.push(await fmRec(k)); if (k % 20 === 19) busy(T("busybak") + " " + (k + 1) + "/200"); }
|
||||
return out;
|
||||
});
|
||||
await writeAll(ord.map((k) => recs[k]), T("busyorder"));
|
||||
ord = null;
|
||||
await readNames(); fillPreset(); await pull(true); build();
|
||||
msg(T("orderdone"));
|
||||
} catch (e) { msg(T(e.code || "lost"), true); }
|
||||
}
|
||||
|
||||
/* BACKUP (protocol 4): every preset of the device, as its record (hex), in one .bkp file (JSON). RESTORE: the device asks
|
||||
* first (its own question, NO by default); only on YES are the 200 records written */
|
||||
const hexOf = (b) => Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
|
||||
@@ -857,7 +936,13 @@ async function restoreAll(o) {
|
||||
const ok = Array.isArray(o.slots) && o.slots.length === 200 &&
|
||||
o.slots.every((x, i) => x && x.slot === i && typeof x.rec === "string" && /^([0-9a-f]{2}){1,128}$/.test(x.rec));
|
||||
if (!ok) throw bad("badbkp");
|
||||
const recs = o.slots.map((x) => bytesOf(x.rec));
|
||||
await writeAll(o.slots.map((x) => bytesOf(x.rec)), T("busyrest"));
|
||||
await readNames(); fillPreset(); await pull(true);
|
||||
if (PAGES[S.page].lib || PAGES[S.page].order) build();
|
||||
msg(T("restdone"));
|
||||
}
|
||||
/* the device's question (YES), then the 200 records (recs[k] goes to slot k), then the end: RESTORE and SAVE TO THE DEVICE */
|
||||
async function writeAll(recs, busyText) {
|
||||
let asked = false;
|
||||
try {
|
||||
await withBusy(T("waitdev"), async () => {
|
||||
@@ -871,13 +956,13 @@ async function restoreAll(o) {
|
||||
if (st === 2) break;
|
||||
if (st !== 1 || Date.now() - t0 > 90000) throw bad("refused");
|
||||
}
|
||||
busy(T("busyrest"));
|
||||
busy(busyText);
|
||||
for (let k = 0; k < 200; k++) {
|
||||
const rec = recs[k], a = [k & 127, k >> 7, rec.length & 127, rec.length >> 7];
|
||||
for (const b of rec) a.push(b & 15, b >> 4);
|
||||
const w = await req(CMD.FMINI_RPUT, a, 8000);
|
||||
if (w[2] !== 0) throw bad("restfail");
|
||||
if (k % 20 === 19) busy(T("busyrest") + " " + (k + 1) + "/200");
|
||||
if (k % 20 === 19) busy(busyText + " " + (k + 1) + "/200");
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
@@ -885,9 +970,6 @@ async function restoreAll(o) {
|
||||
throw e;
|
||||
}
|
||||
await req(CMD.FMINI_RESTORE, [2], 1500);
|
||||
await readNames(); fillPreset(); await pull(true);
|
||||
if (PAGES[S.page].lib) buildLib();
|
||||
msg(T("restdone"));
|
||||
}
|
||||
for (const el of document.querySelectorAll("[data-t]")) el.textContent = T(el.dataset.t);
|
||||
$("connect").textContent = T("connect"); setStatus(false, T("disc")); $("rnd").textContent = T("rnd"); abShow();
|
||||
|
||||
@@ -282,6 +282,27 @@ with sync_playwright() as pw:
|
||||
pg.wait_for_function("!document.body.classList.contains('off')", timeout=15000)
|
||||
check(" .. and the current firmware gives all 200 again, with no notice", pg.evaluate("__fmini.S.names.filter(Boolean).length") == 200 and "Update" not in pg.inner_text("#msg") and "Atualiz" not in pg.inner_text("#msg"))
|
||||
|
||||
# ---- ORDER tab: the arrows move a row, SAVE TO THE DEVICE writes the 200 presets in that order (the bridge answers YES)
|
||||
names0 = pg.evaluate("__fmini.S.names.slice(0, 200)")
|
||||
pg.click("#tabs button:text-is('ORDEM'), #tabs button:text-is('ORDER')"); pg.wait_for_selector("ol.orderlist li.orow")
|
||||
check("ORDER tab: the 200 presets in the device's order", pg.locator("ol.orderlist li.orow").count() == 200)
|
||||
for i in range(2): # the old 0 (row 0), down twice: 1, 2, 0 ..
|
||||
pg.locator("ol.orderlist li.orow").nth(i).locator("button").nth(1).click()
|
||||
check(" .. the arrows move the row (the list shows 1, 2, 0 now)", pg.locator("ol.orderlist li.orow .oname").nth(2).inner_text() == names0[0])
|
||||
pg.evaluate("document.getElementById('msg').textContent = ''")
|
||||
pg.click("button:text-is('Salvar no dispositivo'), button:text-is('Save to device')")
|
||||
try: pg.wait_for_function("/Ordem gravada|Order saved/.test(document.getElementById('msg').textContent)", timeout=120000)
|
||||
except Exception: print("DEBUG msg:", repr(pg.inner_text("#msg")), "busy:", pg.evaluate("document.body.className"), "names0:", pg.evaluate("__fmini.S.names.length")); raise
|
||||
check("SAVE TO THE DEVICE: the device's presets are in that order (1, 2, 0 ..)",
|
||||
pg.evaluate("__fmini.S.names.slice(0, 200)") == names0[1:3] + [names0[0]] + names0[3:])
|
||||
pg.click("#tabs button:text-is('ORDEM'), #tabs button:text-is('ORDER')"); pg.wait_for_selector("ol.orderlist li.orow")
|
||||
for i in (2, 1): # the third row (the old 0) up twice: back to 0, 1, 2
|
||||
pg.locator("ol.orderlist li.orow").nth(i).locator("button").nth(0).click()
|
||||
pg.evaluate("document.getElementById('msg').textContent = ''")
|
||||
pg.click("button:text-is('Salvar no dispositivo'), button:text-is('Save to device')")
|
||||
pg.wait_for_function("/Ordem gravada|Order saved/.test(document.getElementById('msg').textContent)", timeout=300000)
|
||||
check(" .. and the original order is back on the device", pg.evaluate("__fmini.S.names.slice(0, 200)") == names0)
|
||||
|
||||
if SHOTS:
|
||||
SHOTS.mkdir(parents=True, exist_ok=True)
|
||||
for i, name in enumerate(["CTRL", "OSC", "MIX", "FILT", "F.ENV", "A.ENV", "FX", "ARP", "PRESETS"]):
|
||||
|
||||
Reference in new issue
Block a user