mirror of
https://github.com/juanjiant-bit/JIANT.git
synced 2026-12-06 04:44:33 +01:00
- pm.js the device-neutral core (bank, names, files; the adapter interface in its header), pm-ui.js the panel (EN/ES, mobile-first, imported only when first opened), pm-fm.js JIANT FM's adapter: JIANT BYTE can mount the same panel with its own - pm-api.h: SAVE > PROJECT n (song_save_as) and LOAD (song_select), which the editor protocol has no command for; appended to the pinned felucca_web.c by emulator.yml as additive-api.h is, either edition, when the pin has song_save_as; worklet.js pmServe on the "edport" channel - emulator.yml / build.sh ship pm.js, pm-fm.js, pm-ui.js beside transfer.js - tests: pm_test.mjs (model + the firmware on both sides: 57 checks, Studio's readers included), browser_pm_test.mjs (Chromium: 26 checks, phone width, no Web MIDI, SMK-37, MPC) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh
265 lines
22 KiB
JavaScript
265 lines
22 KiB
JavaScript
// SPDX-License-Identifier: GPL-3.0-only
|
|
// Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant)
|
|
// (pm) The Project Manager (pm.js, pm-fm.js; the panel pm-ui.js has browser_pm_test.mjs), as transfer_test.mjs tests the
|
|
// FM-1 panel:
|
|
// node web/emu/pm_test.mjs the files and banks on the protocol model (fm1mock.mjs jsDevice)
|
|
// node web/emu/pm_test.mjs build/emu/felucca.wasm then the firmware itself: the emulator (with pm-api.h) and a
|
|
// second instance as the FM-1 behind the mocked Web MIDI
|
|
// Checks: list, SAVE, LOAD, RENAME, COPY, MOVE, DELETE of projects and presets; .jfm / .jfmp / .jfmb written and read
|
|
// back (round trip byte-exact); a bank's chosen presets into chosen slots; JIANT Studio's readers taking the files (its
|
|
// project editor's import: readBackup of file.backup; its SEND: restoreBackup, the project then on the FM-1); SEND TO /
|
|
// GET FROM the FM-1 for a project, a preset and a bank.
|
|
import fs from "fs";
|
|
import * as X from "./transfer.js";
|
|
import * as PM from "./pm.js";
|
|
import FM from "./pm-fm.js";
|
|
import { jsDevice, wasmDevice, midiAccess } from "./fm1mock.mjs";
|
|
import { edServe, edVersion, pmServe } from "./worklet.js";
|
|
import { readBackup, restoreBackup } from "../fm1backup.js";
|
|
|
|
let fails = 0;
|
|
const check = (what, ok) => { console.log(`pm: ${what.padEnd(90)} ${ok ? "ok" : "FAIL"}`); if (!ok) fails++; };
|
|
const same = (a, b) => !!a && !!b && a.length === b.length && a.every((v, i) => v === b[i]);
|
|
const rejects = async (p) => { try { await p; return null; } catch (e) { return e; } };
|
|
const viaJSON = (o) => JSON.parse(JSON.stringify(o));
|
|
|
|
// ---------------------------------------------------------------------------------------------- made-up contents
|
|
const rnd = (n, seed) => Uint8Array.from({ length: n }, (_, i) => (i * 131 + seed * 17 + (i >> 3)) & 255);
|
|
const le = (b, o, v) => { b[o] = v & 255; b[o + 1] = v >> 8 & 255; b[o + 2] = v >> 16 & 255; b[o + 3] = v >>> 24 & 255; };
|
|
function section(seed, name) { const b = rnd(3840, seed); b.fill(0, 3824, 3836); for (let i = 0; i < name.length; i++) b[3824 + i] = name.charCodeAt(i); return b; }
|
|
function index(seed) { const b = rnd(X.IDX.SIZE, seed); le(b, 0, X.IDX.MAGIC); b[4] = 4; b[5] = 0; return b; }
|
|
function record(name, engine = 0) {
|
|
const r = new Uint8Array(192); r[0] = 0xA5; r[1] = 4; r[2] = engine; r[3] = 99;
|
|
for (let i = 0; i < name.length; i++) r[4 + i] = name.charCodeAt(i);
|
|
for (let i = 16; i < 192; i++) r[i] = (i * 7 + name.length) % 120;
|
|
return r;
|
|
}
|
|
function bank(recs) { const b = X.emptyBank(); for (const [k, r] of recs) b.set(r, 8 + k * 192); return b; }
|
|
function upf(ents) { const b = X.emptyUpf(); let used = 0; for (const [k, seed] of ents) { b.set(rnd(116, seed), 16 + k * 116); used |= 1 << k; } le(b, 8, used); return b; }
|
|
const content = () => new Map([[0, rnd(3840, 1)], [1, rnd(572, 2)], [10, index(3)],
|
|
[40, section(4, "MY SONG")], [41, section(5, "")], [43, section(6, "")], [44, section(7, "SECOND")],
|
|
[6, bank([[0, record("PAD ONE", 12)], [4, record("BASS 5", 0)], [9, record("KEYS 10", 2)]])], [7, bank([[3, record("LEAD 20", 5)]])],
|
|
[9, upf([[0, 9], [19, 21]])]]);
|
|
const jsSide = (d, kind = "emu") => ({ kind, version: "V10.8.73", slow: 1, request: async ([cmd, a]) => {
|
|
const r = d.handle(cmd, a); if (!r) throw new Error("Backup timed out"); return r; } });
|
|
const recOf = (d, k) => (d.objs.get(6 + (k >> 4)) || X.emptyBank()).slice(8 + (k & 15) * 192, 8 + ((k & 15) + 1) * 192);
|
|
const entOf = (d, k) => (d.objs.get(9) || X.emptyUpf()).slice(16 + k * 116, 16 + (k + 1) * 116);
|
|
const usedBit = (d, k) => (X.le32(d.objs.get(9) || X.emptyUpf(), 8) >>> k) & 1;
|
|
|
|
// ---------------------------------------------------------------------------------------------- the files, on the model
|
|
async function modelTests() {
|
|
{ /* the adapter's description: what the panel needs, nothing of the FM in pm.js */
|
|
const k = FM.kinds;
|
|
check(`adapter: ${FM.product} on the ${FM.device}: ${k.project.count} projects (.${k.project.ext}), ${k.preset.count} presets (.${k.preset.ext}), banks (.${k.bank.ext})`,
|
|
k.project.count === 6 && k.preset.count === 32 && k.project.ext === "jfm" && k.preset.ext === "jfmp" && k.bank.ext === "jfmb");
|
|
const strip = (t) => t.replace(/\/\*[\s\S]*?\*\//g, "").replace(/^\s*\/\/.*$/gm, "");
|
|
const src = strip(fs.readFileSync(new URL("./pm.js", import.meta.url), "utf8"));
|
|
const ui = strip(fs.readFileSync(new URL("./pm-ui.js", import.meta.url), "utf8"));
|
|
const neutral = (code) => !/jiant-fm|jiant-preset|\.jfm|transfer\.js|pm-fm|\b(95|96|97|65|66|67)\b/.test(code);
|
|
check("pm.js and pm-ui.js (the panel) name no device format, protocol id or FM module: the adapter's", neutral(src) && neutral(ui));
|
|
check("file names: project, preset, bank", PM.fileName(FM, "project", 0, "NIGHT") === "JIANT-FM-project-1-NIGHT.jfm" &&
|
|
PM.fileName(FM, "preset", 4, "PAD ONE") === "JIANT-FM-preset-05-PAD_ONE.jfmp" && /^JIANT-FM-bank-\d{4}-\d\d-\d\d\.jfmb$/.test(PM.fileName(FM, "bank", 0, "")));
|
|
check("names as the device takes them: upper case, printable, 12", PM.cleanName(" dub ñ techno 2026 x ") === "DUB TECHNO 2" && PM.cleanName("") === "");
|
|
}
|
|
{ /* a preset: .jfmp out and in, its record and patch byte-exact, into another slot */
|
|
const d = jsDevice(content()), emu = jsSide(d);
|
|
const list = await FM.list(emu, "preset").catch(() => null); // (the model has no UP_LIST: the files work without it)
|
|
const f = viaJSON(await FM.exportItem(emu, "preset", 0));
|
|
check(`preset file: "${f.format}" v${f.version}, "${f.name}", record (id ${f.objects[0].id}, ${f.objects[0].size} B) and patch (id ${f.objects[1].id}, ${f.objects[1].size} B)`,
|
|
f.format === "jiant-preset" && f.version === 1 && f.name === "PAD ONE" && f.slot === 0 && f.objects[0].id === 6 && f.objects[0].size === 192 && f.objects[1].id === 9 && f.objects[1].size === 116 && !list);
|
|
const { kind, file } = PM.parseFile(FM, JSON.stringify(f));
|
|
await FM.importItem(emu, "preset", 22, file);
|
|
check("preset file -> slot 23: the record and its FM6 patch byte-exact, its used bit set", kind === "preset" && same(recOf(d, 22), recOf(d, 0)) && same(entOf(d, 22), entOf(d, 0)) && usedBit(d, 22) === 1);
|
|
const g = viaJSON(await FM.exportItem(emu, "preset", 4));
|
|
check("a preset without a patch: its patch object empty (size 0)", g.objects[1].size === 0 && g.objects[1].data === "");
|
|
await FM.importItem(emu, "preset", 0, PM.parseFile(FM, g).file);
|
|
check("... into a slot that had one: the record replaced, the old patch dropped (used bit clear)", same(recOf(d, 0), recOf(d, 4)) && usedBit(d, 0) === 0 && entOf(d, 0).every((v) => !v));
|
|
const bad = viaJSON(f); bad.objects[0].data = bad.objects[0].data.replace(/^../, "AA");
|
|
check("a damaged preset file: refused (\"file\": its checksum), nothing written", (await rejects(Promise.resolve().then(() => PM.parseFile(FM, bad))))?.code === "file");
|
|
check("a project file offered as a preset: refused (\"wrongKind\")", (() => { try { PM.parseFile(FM, { format: "jiant-fm-project", version: 1 }, "preset"); } catch (e) { return e.code === "wrongKind"; } })());
|
|
}
|
|
{ /* copy / move / rename of presets (the bank objects: the model has them) */
|
|
const d = jsDevice(content()), emu = jsSide(d);
|
|
await FM.copy(emu, "preset", 19, 30);
|
|
check("preset COPY 20 -> 31: record and patch, the source kept", same(recOf(d, 30), recOf(d, 19)) && same(entOf(d, 30), entOf(d, 19)) && usedBit(d, 30) && usedBit(d, 19));
|
|
await FM.rename(emu, "preset", 30, "glass lead");
|
|
check("preset RENAME 31 -> \"GLASS LEAD\": the name bytes only, the patch kept", X.presetOf(recOf(d, 30)).name === "GLASS LEAD" && same(recOf(d, 30).subarray(16), recOf(d, 19).subarray(16)) && usedBit(d, 30) === 1);
|
|
}
|
|
{ /* a bank: several presets in one file; all of it, or chosen ones into chosen slots */
|
|
const d = jsDevice(content()), emu = jsSide(d);
|
|
const entries = await FM.presets(emu, Array.from({ length: 32 }, (_, k) => k));
|
|
const b = viaJSON(PM.makeBank(FM, FM.firmware(emu), "my bank", entries));
|
|
check(`bank file: "${b.format}" v${b.version} "${b.name}", ${b.presets.length} presets (the stored ones of 32): ${b.presets.map((p) => p.slot + 1).join(", ")}`,
|
|
b.format === "jiant-preset-bank" && b.version === 1 && b.name === "MY BANK" && b.presets.map((p) => p.slot).join() === "0,4,9,19");
|
|
const { kind, file } = PM.parseFile(FM, JSON.stringify(b));
|
|
const d2 = jsDevice(new Map([[0, rnd(3840, 1)], [1, rnd(572, 2)], [10, index(3)]])), emu2 = jsSide(d2);
|
|
await FM.putPresets(emu2, PM.bankPlan(file));
|
|
let all = true;
|
|
for (const k of [0, 4, 9, 19]) all &&= same(recOf(d2, k), recOf(d, k)) && same(entOf(d2, k), entOf(d, k)) && usedBit(d2, k) === usedBit(d, k);
|
|
check("bank -> an empty device, all of it: every record and patch byte-exact in its own slot", kind === "bank" && all && !X.presetOf(recOf(d2, 1)));
|
|
const d3 = jsDevice(content()), emu3 = jsSide(d3);
|
|
const plan = PM.bankPlan(file, { 0: 31, 19: 2, 4: -1, 9: -1 });
|
|
await FM.putPresets(emu3, plan);
|
|
check("bank, chosen: PAD ONE -> 32, LEAD 20 -> 3, the others left out; slots 5, 10 as they were",
|
|
plan.length === 2 && same(recOf(d3, 31), recOf(d, 0)) && same(entOf(d3, 31), entOf(d, 0)) && same(recOf(d3, 2), recOf(d, 19)) && usedBit(d3, 2) === 1 &&
|
|
same(recOf(d3, 4), recOf(d, 4)) && same(recOf(d3, 9), recOf(d, 9)));
|
|
check("bank, two presets into one slot: refused (\"twice\")", (() => { try { PM.bankPlan(file, { 0: 5, 4: 5 }); } catch (e) { return e.code === "twice"; } })());
|
|
check("the slots a write replaces, for the question first", PM.replaced([{ n: 0, used: true, name: "A" }, { n: 1, used: false }], [0, 1]).map((x) => x.name).join() === "A");
|
|
}
|
|
{ /* a project: .jfm out (Studio's project editor's file) and back in, into another project */
|
|
const d = jsDevice(content()), emu = jsSide(d);
|
|
const f = viaJSON(await FM.exportItem(emu, "project", 0));
|
|
check(`project file: "${f.format}" v${f.version} "${f.name}", Studio's keys (format version firmware created name gen web backup)`,
|
|
f.format === "jiant-fm-project" && f.version === 1 && f.name === "MY SONG" && ["format", "version", "firmware", "created", "name", "gen", "web", "backup"].every((k) => k in f));
|
|
check(`project file: its backup a complete "${f.backup.format}" (${f.backup.objects.length} objects, readBackup takes it), web.pm.project ${f.web.pm.project}`,
|
|
readBackup(f.backup).objects.length === 35 && f.web.pm.project === 0 && f.parts.length === 4);
|
|
/* JIANT Studio's project editor reads it as studio.js does ($("pefile").onchange): JSON, file.backup, readBackup */
|
|
const studio = fs.readFileSync(new URL("../studio/studio.js", import.meta.url), "utf8");
|
|
const studioReads = /if \(!file\.backup\) throw new Error\("format"\); readBackup\(file\.backup\)/.test(studio);
|
|
let ok = false; try { const s = JSON.parse(JSON.stringify(f)); if (!s.backup) throw 0; readBackup(s.backup); ok = true; } catch (_) {}
|
|
check("JIANT Studio's project editor opens it (its import: file.backup through readBackup)", studioReads && ok);
|
|
const { file } = PM.parseFile(FM, JSON.stringify(f), "project");
|
|
await FM.importItem(emu, "project", 4, file);
|
|
const ix = d.objs.get(10), rows = (s) => ix.slice(8 + s * 36, 8 + (s + 1) * 36);
|
|
check("project file -> PROJECT 5: its sections A, B, D byte-exact, C empty, its rows the song's", same(d.objs.get(56), section(4, "MY SONG")) && same(d.objs.get(57), section(5, "")) &&
|
|
(d.objs.get(58) || new Uint8Array(0)).length === 0 && same(d.objs.get(59), section(6, "")) && same(rows(4), index(3).slice(8, 44)));
|
|
/* Studio's project library file ("jiant-project": the parts alone) */
|
|
const lib = { format: "jiant-project", version: 1, firmware: "x", created: "", name: "MY SONG", parts: f.parts };
|
|
await FM.importItem(emu, "project", 5, PM.parseFile(FM, lib, "project").file);
|
|
check("Studio's project library file (\"jiant-project\", parts only) -> PROJECT 6: the sections", same(d.objs.get(60), section(4, "MY SONG")) && same(d.objs.get(63), section(6, "")));
|
|
const g = viaJSON(f); g.web = {}; g.backup.objects.find((o) => o.id === 10).data; // (a .jfm of Studio's: no web.pm)
|
|
const s = PM.parseFile(FM, g, "project").file;
|
|
check("a .jfm of Studio's own (no web.pm): the backup's open project (index cur)", s.from === 0);
|
|
const e = await rejects(FM.exportItem(emu, "project", 2));
|
|
check("an empty project: nothing to export (\"empty\")", e?.code === "empty");
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------- the firmware itself
|
|
async function wasmTests(path) {
|
|
const bytes = fs.readFileSync(path);
|
|
const boot = async (seed) => {
|
|
const { instance } = await WebAssembly.instantiate(bytes, { env: { emscripten_notify_memory_growth() {} } });
|
|
const ex = instance.exports; ex._initialize(); ex.web_nor_erase(); ex.web_master(700); ex.web_seed(seed); ex.web_boot();
|
|
for (let i = 0; i < 12; i++) ex.web_render(1024);
|
|
return ex;
|
|
};
|
|
const ex = await boot(7), fx = await boot(8);
|
|
if (!ex.web_ed) { check("the wasm has the editor's commands (web_ed)", false); return; }
|
|
check("the wasm has the Project Manager's SAVE / LOAD (pm-api.h: web_pm_save, web_pm_load)", !!ex.web_pm_save && !!ex.web_pm_load);
|
|
ex.web_gen(6, 11, 60, 2); // a piece: TECHNO, FORM CLUB (a draft: sections and rows)
|
|
for (let i = 0; i < 30; i++) ex.web_render(1024);
|
|
const emu = X.emuSideFromExports(ex, edServe, edVersion(ex), pmServe);
|
|
const run = (n = 8) => { for (let i = 0; i < n; i++) ex.web_render(1024); };
|
|
|
|
// ------------------------------------------------------------------ projects
|
|
let L = await FM.list(emu, "project");
|
|
check(`list: 6 projects (PROJ_LIST), the generator's piece open as a draft (${L.map((p) => p.open ? "*" : p.used ? "x" : ".").join("")})`, L.length === 6 && L.some((p) => p.open && p.draft));
|
|
await FM.save(emu, "project", 1, "night");
|
|
L = await FM.list(emu, "project");
|
|
check(`SAVE the music playing into PROJECT 2 "NIGHT": stored (parts ${L[1].detail}), open, no longer a draft`, L[1].used && L[1].name === "NIGHT" && L[1].open && !L[1].draft && emu.pm && (await emu.pm("cur"))[0] === 1);
|
|
ex.web_play(1); run(4);
|
|
await FM.save(emu, "project", 1, "NIGHT");
|
|
check("SAVE while it plays: stopped first, saved (as the editor's saves)", !ex.web_playing() && (await FM.list(emu, "project"))[1].used);
|
|
await FM.rename(emu, "project", 1, "dub night");
|
|
L = await FM.list(emu, "project");
|
|
check(`RENAME PROJECT 2 -> "${L[1].name}" (PROJ_NAME, live)`, L[1].name === "DUB NIGHT");
|
|
await FM.copy(emu, "project", 1, 3);
|
|
L = await FM.list(emu, "project");
|
|
check(`COPY PROJECT 2 -> 4: "${L[3].name}", parts ${L[3].detail} as 2's`, L[3].used && L[3].name === "DUB NIGHT" && L[3].parts === L[1].parts);
|
|
const eOpen = await rejects(FM.copy(emu, "project", 3, 1));
|
|
check("COPY onto the open project: refused by the device (\"refused\")", eOpen?.code === "refused");
|
|
await FM.move(emu, "project", 3, 4);
|
|
L = await FM.list(emu, "project");
|
|
check("MOVE PROJECT 4 -> 5: 5 holds it, 4 empty", L[4].used && L[4].name === "DUB NIGHT" && !L[3].used);
|
|
await FM.load(emu, "project", 4);
|
|
L = await FM.list(emu, "project");
|
|
check(`LOAD PROJECT 5: it is the open one (${L.findIndex((p) => p.open) + 1}), its rows playing (${ex.web_song_rows()})`, L[4].open && !L[1].open && ex.web_song_rows() >= 2);
|
|
check("LOAD of the open project: said (\"isOpen\")", (await rejects(FM.load(emu, "project", 4)))?.code === "isOpen");
|
|
await FM.load(emu, "project", 1);
|
|
await FM.remove(emu, "project", 4);
|
|
check("DELETE PROJECT 5: empty", !(await FM.list(emu, "project"))[4].used);
|
|
|
|
// .jfm out and in
|
|
const jfm = viaJSON(await FM.exportItem(emu, "project", 1));
|
|
check(`.jfm of PROJECT 2: "${jfm.name}", a complete backup (${jfm.backup.objects.length}), its parts ${jfm.web.pm.parts}`, jfm.name === "DUB NIGHT" && jfm.backup.objects.length === 35);
|
|
await FM.importItem(emu, "project", 5, PM.parseFile(FM, JSON.stringify(jfm), "project").file);
|
|
const back = X.readBackup(await X.backupFile(emu)), by = new Map(back.objects.map((o) => [o.id, o.bytes]));
|
|
let secs = true;
|
|
for (let k = 0; k < 4; k++) secs &&= same(by.get(60 + k), by.get(44 + k));
|
|
const rowsOf = (b, s) => { const r = b.slice(8 + s * 36, 8 + (s + 1) * 36); r[3] = 0; return r; };
|
|
check("import the .jfm -> PROJECT 6: the firmware took its sections (byte-exact) and its rows", secs && same(rowsOf(by.get(10), 5), rowsOf(by.get(10), 1)));
|
|
L = await FM.list(emu, "project");
|
|
check(`... PROJECT 6 listed as "${L[5].name}" (parts ${L[5].detail})`, L[5].name === "DUB NIGHT" && L[5].parts === L[1].parts);
|
|
/* JIANT Studio's SEND of the .jfm (restoreBackup of file.backup) to a real FM-1: that project there */
|
|
const studioFm = await boot(9), sreq = (r, o) => Promise.resolve(edServe(studioFm, [r[0], ...r[1]]));
|
|
await restoreBackup(sreq, jfm.backup);
|
|
const sl = await FM.list(X.emuSideFromExports(studioFm, edServe, edVersion(studioFm)), "project");
|
|
check(`JIANT Studio's SEND of the .jfm (restoreBackup): the FM-1 has PROJECT 2 "${sl[1].name}"`, sl[1].name === "DUB NIGHT" && sl[1].used);
|
|
|
|
// ------------------------------------------------------------------ presets
|
|
const P = (await FM.list(emu, "preset"));
|
|
check(`list: 32 user presets (UP_LIST), ${P.filter((p) => p.used).length} stored`, P.length === 32);
|
|
edServe(ex, [8, 12, 0]); // (the selected track: FM6's first preset)
|
|
await FM.save(emu, "preset", 2, "glass");
|
|
let Q = await FM.list(emu, "preset");
|
|
check(`SAVE the selected track's sound into preset 3 "${Q[2].name}" (${Q[2].detail})`, Q[2].used && Q[2].name === "GLASS" && Q[2].detail === "FM6" && ex.web_test_user_preset(2) === 1);
|
|
await FM.rename(emu, "preset", 2, "glass keys");
|
|
const [e3] = await FM.presets(emu, [2]);
|
|
check(`RENAME preset 3 -> "${(await FM.list(emu, "preset"))[2].name}": its FM6 patch kept (${e3.objects[1].size} B)`, (await FM.list(emu, "preset"))[2].name === "GLASS KEYS" && e3.objects[1].size === 116);
|
|
edServe(ex, [8, 0, 0]); // (the selected track: ANALOG's first preset, then preset 3 loaded)
|
|
const engSel = () => { const t = edServe(ex, [27]); return t[2 + t[0] * 6]; };
|
|
const before = engSel();
|
|
await FM.load(emu, "preset", 2);
|
|
check(`LOAD preset 3 (UP_LOAD): the selected track's engine ${X.ENGINES[before]} -> ${X.ENGINES[engSel()]}`, before === 0 && engSel() === 12);
|
|
check("LOAD of an empty preset: said (\"empty\")", (await rejects(FM.load(emu, "preset", 30)))?.code === "empty");
|
|
await FM.copy(emu, "preset", 2, 9);
|
|
const [e10] = await FM.presets(emu, [9]);
|
|
check("COPY preset 3 -> 10: the record and its patch (the firmware's tag holds: the patch listed)", e10 && e10.name === "GLASS KEYS" && e10.objects[1].size === 116 && e10.objects[1].data === e3.objects[1].data);
|
|
await FM.move(emu, "preset", 9, 19);
|
|
Q = await FM.list(emu, "preset");
|
|
check("MOVE preset 10 -> 20: 20 holds it, 10 empty", Q[19].used && Q[19].name === "GLASS KEYS" && !Q[9].used);
|
|
await FM.remove(emu, "preset", 19);
|
|
check("DELETE preset 20 (UP_ERASE): empty", !(await FM.list(emu, "preset"))[19].used && !ex.web_test_user_preset(19));
|
|
edServe(ex, [8, 0, 1]);
|
|
await FM.save(emu, "preset", 6, "ana bass");
|
|
// .jfmp and .jfmb
|
|
const jfmp = viaJSON(await FM.exportItem(emu, "preset", 2));
|
|
await FM.importItem(emu, "preset", 27, PM.parseFile(FM, JSON.stringify(jfmp), "preset").file);
|
|
const [e28] = await FM.presets(emu, [27]);
|
|
check(".jfmp of preset 3 -> slot 28: the firmware took record and patch, byte-exact", e28 && e28.objects[0].data === jfmp.objects[0].data && e28.objects[1].data === jfmp.objects[1].data && ex.web_test_user_preset(27) === 1);
|
|
const bank = viaJSON(PM.makeBank(FM, FM.firmware(emu), "set", await FM.presets(emu, [2, 6, 27])));
|
|
const bf = PM.parseFile(FM, JSON.stringify(bank), "bank").file;
|
|
await FM.putPresets(emu, PM.bankPlan(bf, { 2: 14, 6: 15, 27: -1 }));
|
|
Q = await FM.list(emu, "preset");
|
|
check(`.jfmb (3 presets), 2 chosen into 15, 16: "${Q[14].name}", "${Q[15].name}"`, Q[14].name === "GLASS KEYS" && Q[15].name === "ANA BASS" && ex.web_test_user_preset(14) && ex.web_test_user_preset(15));
|
|
const B2 = await boot(10), emu2 = X.emuSideFromExports(B2, edServe, edVersion(B2), pmServe);
|
|
await FM.putPresets(emu2, PM.bankPlan(bf));
|
|
const Q2 = await FM.list(emu2, "preset");
|
|
check("the whole .jfmb into a fresh emulator: every preset in its own slot (3, 7, 28)", [2, 6, 27].every((k) => Q2[k].used && Q2[k].name === Q[k].name) && Q2.filter((p) => p.used).length === 3);
|
|
|
|
// ------------------------------------------------------------------ the FM-1
|
|
const acc = midiAccess(wasmDevice(fx, edServe, "JIANT " + edVersion(fx)));
|
|
const c = await FM.connect(acc);
|
|
check(`FM-1 found (${c.version}), the shared link (the FM-1 panel's too)`, /JIANT/.test(c.version) && (await FM.connect(acc)).side === c.side);
|
|
await FM.send(emu, c.side, "project", 1, 2);
|
|
const fl = await FM.list(c.side, "project");
|
|
check(`SEND TO FM-1: PROJECT 2 -> the FM-1's PROJECT 3 "${fl[2].name}" (verified)`, fl[2].used && fl[2].name === "DUB NIGHT" && fl[2].parts === L[1].parts);
|
|
await FM.send(c.side, emu, "project", 2, 3);
|
|
check("GET FROM FM-1: its PROJECT 3 -> the emulator's PROJECT 4", (await FM.list(emu, "project"))[3].name === "DUB NIGHT");
|
|
await FM.send(emu, c.side, "preset", 2, 0);
|
|
check("SEND TO FM-1: preset 3 -> the FM-1's 1, with its patch", (await FM.presets(c.side, [0]))[0]?.objects[1].data === jfmp.objects[1].data);
|
|
await FM.sendPresets(emu, c.side, [[2, 10], [6, 11], [14, 12]]);
|
|
const fq = await FM.list(c.side, "preset");
|
|
check(`SEND BANK TO FM-1: 3 presets into 11..13 (${fq.slice(10, 13).map((p) => p.name).join(", ")})`, fq[10].name === "GLASS KEYS" && fq[11].name === "ANA BASS" && fq[12].name === "GLASS KEYS");
|
|
await FM.sendPresets(c.side, emu, [[10, 29], [11, 30]]);
|
|
const eq = await FM.list(emu, "preset");
|
|
check("GET BANK FROM FM-1: its 11, 12 -> the emulator's 30, 31", eq[29].name === "GLASS KEYS" && eq[30].name === "ANA BASS");
|
|
}
|
|
|
|
await modelTests();
|
|
if (process.argv[2]) await wasmTests(process.argv[2]);
|
|
else console.log("pm: (no felucca.wasm given: the firmware checks skipped)");
|
|
console.log(fails ? `pm: ${fails} FAILED` : "pm: all ok");
|
|
process.exit(fails ? 1 : 0);
|