mirror of
https://github.com/juanjiant-bit/JIANT.git
synced 2026-12-05 12:24:42 +01:00
mathGenerate in the editor's MATH section (which JIANT Studio also loads from the published editor page) now builds
formulas by family and by CHAOS, and checks every one against the device (V10.8.75 MATH USER).
- MATH_FAMILIES, each with an id and EN/ES/JA labels: sierpinski (classic bit patterns, xor), melodic (scales as
string tables, plucks, sine echoes, arpeggios, hex nibble tables), fm (FIX: sin(w) phase modulation, index
envelopes, stepped carriers, harmonic stacks, ring), glitch (stutters, random grains, reversed and modulo-chopped
t, bit-crush), drone (FIX: detuned saws and sines, slow LFO phase modulation, beating chords; a detuned INT pair),
rhythm (a falling-pitch sine kick, hashed-noise hats and snares, pattern masks, toms), chip (pulses and PWM, fast
arpeggios, triangle bass, noise).
- mathGenerate(seed, {family, chaos}) -> {src, fix, wave (5 INT / 6 FIX), family, chaos, bytes, stack}; one
(seed, family, chaos) is one formula; "any" takes the seed's family whatever the CHAOS. mathGenerate(seed) is the
old call: a text, the seed's family at CHAOS 40. mathGenerate.FAMILIES too, for Studio's loader.
- CHAOS changes the build: at 0, one of the family's shapes with musical numbers; above, odd numbers and more rewrites
(each kept only while the formula still fits 64 bytes and sounds): a gate or a second voice (15), the family's own
idioms: t bent, crush, xor, phase modulation, octave jumps, vibrato, swing, layers (30); modulo, waveshapers,
switching to another formula, other families mixed in, odd constants (55); t replaced by a whole formula, every t
bent, formulas multiplied, other families' idioms (80).
- Every formula: FVM compiles it, at most 64 B and a stack of 12, no ph lp hp eu nor FUNC calls, only t w a n v; heard
with FVM.run in four windows (sounding, not stuck at full-scale DC, not white noise, changing); else the next try.
- The MATH tab: a Family selector (Any and the seven) and a Chaos slider (0..100) by Generate formula, EN/ES/JA,
40 px touch targets; the status names the family and the CHAOS. A FIX result is shown as FIX -> FLOAT and sent on
WAVE 6, as one's own FIX formulas are.
- math_test.mjs: 1056 formulas (7 families and any x CHAOS 0..100 x 12 seeds) all valid, 0 silent; determinism;
variety (10 seeds a family at CHAOS 50, eleven audio features: every family's median pair distance 4.0..6.1x a
formula's distance from itself 4 s later, 76..98% of pairs past that one's 90th percentile, high-passed waveform
correlation at most 0.43); families apart (nearest family centroid right for 48/70 at CHAOS 0, 37/70 at 50, chance
10/70; 26/70 at 90, the families mixed); CHAOS 0 -> 100 terms 1.5..3.9x and nesting 3..6 levels deeper; the old
call as Studio loads it; with EMU_WASM, 28 generated formulas sent to the V10.8.75 emulator: all taken and heard.
- editor_browser_test.mjs: the family and CHAOS controls (FM 80: FIX, RHYTHM 0: INT, seeded), the slider's height on
a phone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh
337 lines
25 KiB
JavaScript
337 lines
25 KiB
JavaScript
// SPDX-License-Identifier: GPL-3.0-only
|
|
// Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant)
|
|
// (SMK-37, ports/) the editor in a real browser (Playwright's Chromium) on its mock device (?mock=1: Web MIDI faked by
|
|
// the page itself):
|
|
// node web/editor_browser_test.mjs [out-dir-for-screenshots]
|
|
// An FM-1 (no 'D' / 'H' tags): "FM-1" shown, no SAMPLE / GRAIN offered, no sample pages on DRUM. An SMK-37 ('D' 1 1):
|
|
// its name. A big CPU (?hp=1: 'D' 1 3, 'H' 2 15 16): SAMPLE and GRAIN offered, their pages (SAMPLE WARP TRIG REC,
|
|
// GRAIN CLOUD TRAVEL SOURCE PITCH) and DRUM-X's SAMPLES; the FILTER section of P_COUNT 123 firmware.
|
|
import path from "path";
|
|
import fs from "fs";
|
|
import { createRequire } from "module";
|
|
const require = createRequire(import.meta.url);
|
|
const { chromium } = require("playwright");
|
|
|
|
const HERE = path.dirname(new URL(import.meta.url).pathname);
|
|
const OUT = process.argv[2] || null;
|
|
const page0 = "file://" + path.join(HERE, "editor.html");
|
|
let fails = 0;
|
|
const check = (what, ok, extra = "") => { console.log(`editor (browser): ${what.padEnd(70)} ${ok ? "ok" : "FAIL"} ${extra}`); if (!ok) fails++; };
|
|
|
|
const b = await chromium.launch();
|
|
async function open(qs) {
|
|
const p = await b.newPage({ viewport: { width: 1280, height: 900 }, deviceScaleFactor: 2 });
|
|
p.on("pageerror", (e) => { console.log("pageerror:", e.message); fails++; });
|
|
await p.goto(`${page0}?mock=1${qs}`);
|
|
await p.click("#connect");
|
|
await p.waitForFunction(() => /·/.test(document.querySelector("#version").textContent), null, { timeout: 60000 });
|
|
return p;
|
|
}
|
|
const heads = (p) => p.$$eval("#groups h2, #groups h3", (a) => a.map((x) => x.textContent.replace(/[^\x20-\x7e]/g, "").trim())); /* (an icon's glyph out) */
|
|
const engines = (p) => p.$$eval("#engine option", (a) => a.map((x) => x.textContent));
|
|
/* the controls are rebuilt as the replies come: wait until the headings hold what is expected (or 20 s) */
|
|
async function settle(p, want = []) {
|
|
let last = "", same = 0;
|
|
for (let i = 0; i < 200 && same < 10; i++) {
|
|
await p.waitForTimeout(100);
|
|
const h = await heads(p), now = JSON.stringify(h);
|
|
same = now === last && want.every((x) => h.includes(x)) ? same + 1 : 0;
|
|
last = now;
|
|
}
|
|
}
|
|
async function engine(p, e, want) {
|
|
await p.selectOption("#engine", String(e));
|
|
await settle(p, want);
|
|
}
|
|
|
|
{
|
|
const p = await open("");
|
|
await settle(p, ["FILTER"]);
|
|
const h = await heads(p), en = await engines(p);
|
|
check("FM-1: its name, the structured layout (ENV .. FILTER)", (await p.textContent("#version")).startsWith("FM-1 ·") &&
|
|
h.includes("ENV") && h.includes("FILTER"));
|
|
check("FM-1: no SAMPLE / GRAIN to pick", !en.includes("SAMPLE") && !en.includes("GRAIN"));
|
|
await engine(p, 10, ["EDIT DRUM"]);
|
|
check("FM-1: DRUM without the sample pages", !(await heads(p)).includes("SAMPLES"));
|
|
await p.close();
|
|
}
|
|
{
|
|
const p = await open("&board=1&port=JIANT%20SMK-37");
|
|
check("SMK-37: shown by its tag", (await p.textContent("#version")).startsWith("SMK-37 Pro ·"));
|
|
await p.close();
|
|
}
|
|
{
|
|
const p = await open("&hp=1");
|
|
check("big CPU: shown, SAMPLE and GRAIN offered", (await p.textContent("#version")).startsWith("JIANT FM app / plugin ·") &&
|
|
(await engines(p)).slice(-2).join() === "SAMPLE,GRAIN");
|
|
for (const [e, name, want] of [[4, "sample", ["EDIT SAMPLE", "SAMPLE", "WARP", "TRIG", "REC"]],
|
|
[8, "grain", ["EDIT GRAIN", "GRAIN", "CLOUD", "TRAVEL", "SOURCE", "PITCH"]], [10, "drum", ["EDIT DRUM", "SAMPLES", "SAMPLES 2"]]]) {
|
|
await engine(p, e, want);
|
|
const h = await heads(p);
|
|
check(`big CPU: ${name.toUpperCase()}'s pages (${want.slice(1).join(" ")})`, want.every((x) => h.includes(x)), want.filter((x) => !h.includes(x)).join());
|
|
if (OUT) await p.screenshot({ path: path.join(OUT, `editor-${name}.png`), fullPage: true });
|
|
}
|
|
const labels = await p.$$eval("#groups .row", (a) => a.map((x) => x.textContent));
|
|
check("big CPU: DRUM-X's SMORPH BLEND SLOT MAP SLEVEL", ["SMORPH", "BLEND", "MAP", "SLEVEL"].every((l) => labels.some((t) => t.startsWith(l))));
|
|
await engine(p, 0, ["EDIT ANALOG"]);
|
|
check("big CPU: ANALOG without them", !(await heads(p)).some((x) => ["TRIG", "TRAVEL", "SAMPLES"].includes(x)));
|
|
await p.close();
|
|
}
|
|
|
|
/* ------------------------------------------------------------------------------------------- the piano roll --- */
|
|
/* (Part 1) the roll on the mock (?mock=1&test=1) and, given the emulator's wasm (EMU_WASM, default build/emu/felucca.wasm),
|
|
on the firmware itself behind a Web MIDI port of its own: every edit read back from the device */
|
|
const R = (p) => p.evaluate(() => JSON.parse(JSON.stringify(window.jiantRollTest.read())));
|
|
async function rollReady(p, track) {
|
|
await p.waitForFunction((tr) => { const r = window.jiantRollTest && window.jiantRollTest.read(); return r && r.track === tr && r.steps.length === 64 && /T\d/.test(document.querySelector("#rollstat").textContent); }, track, { timeout: 60000 });
|
|
await p.waitForTimeout(300);
|
|
}
|
|
async function tapCell(p, step, row) {
|
|
await p.evaluate(() => window.jiantRollTest.roll.cv.scrollIntoView({ block: "center" }));
|
|
const c = await p.evaluate(([s, r]) => window.jiantRollTest.cell(s, r), [step, row]);
|
|
await p.mouse.click(c.x, c.y);
|
|
await p.waitForTimeout(250);
|
|
return c;
|
|
}
|
|
async function dragCell(p, from, to) {
|
|
await p.evaluate(() => window.jiantRollTest.roll.cv.scrollIntoView({ block: "center" }));
|
|
const a = await p.evaluate(([s, r]) => window.jiantRollTest.cell(s, r), from), z = await p.evaluate(([s, r]) => window.jiantRollTest.cell(s, r), to);
|
|
await p.mouse.move(a.x, a.y); await p.mouse.down();
|
|
for (let k = 1; k <= 8; k++) await p.mouse.move(a.x + (z.x - a.x) * k / 8, a.y + (z.y - a.y) * k / 8);
|
|
await p.mouse.up(); await p.waitForTimeout(400);
|
|
}
|
|
const idle = (p) => p.evaluate(() => window.jiantRollTest.idle()).then(() => p.waitForFunction(() => !document.querySelector("#rollstat").textContent.includes("/"), null, { timeout: 30000 })).then(() => p.waitForTimeout(300));
|
|
async function openRoll(qs, vp = { width: 1280, height: 900 }, touch = false, init = null) {
|
|
const p = await b.newPage({ viewport: vp, deviceScaleFactor: 2, hasTouch: touch, isMobile: touch });
|
|
p.on("pageerror", (e) => { console.log("pageerror:", e.message); fails++; });
|
|
if (init) await init(p);
|
|
await p.goto(`${page0}?test=1${qs}#roll`);
|
|
await p.click("#connect");
|
|
await p.waitForFunction(() => /·/.test(document.querySelector("#version").textContent), null, { timeout: 90000 });
|
|
await rollReady(p, 0);
|
|
return p;
|
|
}
|
|
{
|
|
const p = await openRoll("&mock=1");
|
|
let r = await R(p);
|
|
check("roll (mock): track 1 read whole (64 steps, LEN, the kinds of its motion)", r.steps.length === 64 && r.p[29] === 16 && !!r.motion);
|
|
const drum = (await p.textContent("#rollstat")).includes("DRUM");
|
|
check("roll (mock): a DRUM track shows as the grid", drum);
|
|
const empty = r.steps.findIndex((s, i) => i < 16 && !(s.hit & 4));
|
|
await tapCell(p, empty, 2); // CP
|
|
r = await R(p);
|
|
check("roll (mock): a tap on an empty cell writes the hit (CP)", (r.steps[empty].hit & 4) && r.steps[empty].time === 0);
|
|
await p.click("#rollinsp button:text-is('FLAM')"); await p.waitForTimeout(300);
|
|
await p.click("#rollreload"); await idle(p);
|
|
r = await R(p);
|
|
check("roll (mock): its lane mode (FLAM) and the hit, read back from the device", (r.steps[empty].hit & 4) && r.steps[empty].lanes[2] === 6);
|
|
await tapCell(p, empty, 2); // (still the selected hit: off)
|
|
r = await R(p);
|
|
check("roll (mock): the selected hit tapped again goes", !(r.steps[empty].hit & 4));
|
|
if (OUT) await p.screenshot({ path: path.join(OUT, "roll-drum-desktop.png"), fullPage: true });
|
|
/* a melodic track: track 5 (the mock's bass) */
|
|
await p.click("#trackbtns button[data-i='4']");
|
|
await rollReady(p, 4);
|
|
await p.evaluate(() => { const t = window.jiantRollTest; t.roll.view.sx = 36; t.show(52); });
|
|
await tapCell(p, 40, 50);
|
|
r = await R(p);
|
|
check("roll (mock): a tap adds a note (D3 at step 41)", r.steps[40].time === 0 && r.steps[40].notes.slice(0, r.steps[40].n).includes(50));
|
|
await p.evaluate(() => { const t = window.jiantRollTest; t.roll.view.sx = 36; t.show(52); });
|
|
await dragCell(p, [40, 50], [43, 50]);
|
|
r = await R(p);
|
|
check("roll (mock): dragged right, the note held over TIE steps 42..44", [41, 42, 43].every((i) => r.steps[i].time === 1));
|
|
await dragCell(p, [40, 50], [40, 52]);
|
|
r = await R(p);
|
|
check("roll (mock): dragged up, the note two semitones higher", r.steps[40].notes.slice(0, r.steps[40].n).includes(52) && !r.steps[40].notes.slice(0, r.steps[40].n).includes(50));
|
|
await p.click("#rollundo"); await p.waitForTimeout(400);
|
|
r = await R(p);
|
|
check("roll (mock): UNDO puts the pitch back", r.steps[40].notes.slice(0, r.steps[40].n).includes(50));
|
|
/* a lock on the step (MOTION op 5), its kind read back (op 7) */
|
|
await tapCell(p, 40, 50);
|
|
const lockSel = await p.$("#rollinsp .rlocks select");
|
|
if (lockSel) {
|
|
await lockSel.selectOption({ label: "CHORUS" }).catch(() => lockSel.selectOption({ index: 3 }));
|
|
await p.fill("#rollinsp .rlocks .bar input[type=number]", "90");
|
|
await p.click("#rollinsp .rlocks .bar button"); await p.waitForTimeout(400);
|
|
}
|
|
r = await R(p);
|
|
check("roll (mock): a parameter lock added on the step (kind 1)", !!r.motion.events.find((e) => e.step === 40 && e.kind === 1 && e.value === 90));
|
|
/* LEN on the HUD: + */
|
|
await p.click("#rollhud .rcard[data-id='29'] button[aria-label$='+']"); await p.waitForTimeout(400);
|
|
await p.click("#rollreload"); await idle(p);
|
|
r = await R(p);
|
|
check("roll (mock): LEN + on the card, read back (TRACK_PARAM)", r.p[29] === 17);
|
|
/* EUCLID: 3 over 8 at C3, written */
|
|
await p.click("#rolleubox summary");
|
|
await p.$eval("#rolleu [name=steps]", (e) => { e.value = 8; e.dispatchEvent(new Event("input", { bubbles: true })); });
|
|
await p.$eval("#rolleu [name=hits]", (e) => { e.value = 3; e.dispatchEvent(new Event("input", { bubbles: true })); });
|
|
await p.click("#rolleuprev"); await p.click("#rolleuwrite"); await idle(p);
|
|
await p.click("#rollreload"); await idle(p);
|
|
r = await R(p);
|
|
const eu = (i) => (i % 8 * 3) % 8 < 3;
|
|
check("roll (mock): EUCLID 3/8 written over LEN 17", r.steps.slice(0, 17).every((s, i) => (s.time === 0 && s.n === 1) === eu(i)));
|
|
/* the velocity lane: drawn across four steps */
|
|
const v0 = await p.evaluate(() => { const t = window.jiantRollTest; t.roll.view.sx = 0; t.roll.cv.scrollIntoView({ block: "end" }); const g = t.roll.cv.getBoundingClientRect(); return { x: t.cell(0, 0).x, y: g.bottom - 12 }; });
|
|
await p.mouse.move(v0.x, v0.y); await p.mouse.down(); await p.mouse.move(v0.x + 3 * (await R(p)).view.cw, v0.y, { steps: 6 }); await p.mouse.up(); await p.waitForTimeout(500);
|
|
r = await R(p);
|
|
check("roll (mock): the velocity lane drawn low over steps 1..4", r.steps.slice(0, 4).every((s) => s.vel < 30));
|
|
if (OUT) await p.screenshot({ path: path.join(OUT, "roll-notes-desktop.png"), fullPage: true });
|
|
/* closed: nothing runs */
|
|
await p.click("#tabs button[data-tab='sound']"); await p.waitForTimeout(200);
|
|
check("roll (mock): closed, no drawing scheduled", await p.evaluate(() => !window.jiantRollTest.roll.open && !window.jiantRollTest.roll.raf));
|
|
await p.close();
|
|
}
|
|
{
|
|
const p = await openRoll("&mock=1", { width: 390, height: 844 }, true);
|
|
const cell = await p.evaluate(() => { const t = window.jiantRollTest; return { cw: t.roll.view.cw, rh: t.roll.view.rh }; });
|
|
check(`roll (phone): cells at least 40 px (${Math.round(cell.cw)} x ${Math.round(cell.rh)})`, cell.cw >= 40 && cell.rh >= 40);
|
|
const small = await p.$$eval("#p-roll button", (a) => a.filter((x) => x.offsetParent && x.getBoundingClientRect().height < 39.5).map((x) => x.textContent));
|
|
check("roll (phone): every button of the roll at least 40 px high", !small.length, small.join());
|
|
const c = await p.evaluate(() => { window.jiantRollTest.roll.cv.scrollIntoView({ block: "center" }); return window.jiantRollTest.cell(5, 1); });
|
|
await p.touchscreen.tap(c.x, c.y); await p.waitForTimeout(400);
|
|
check("roll (phone): a touch writes a hit", ((await R(p)).steps[5].hit & 2) !== 0);
|
|
if (OUT) await p.screenshot({ path: path.join(OUT, "roll-drum-phone.png"), fullPage: true });
|
|
await p.click("#trackbtns button[data-i='4']"); await rollReady(p, 4);
|
|
if (OUT) await p.screenshot({ path: path.join(OUT, "roll-notes-phone.png"), fullPage: true });
|
|
await p.close();
|
|
}
|
|
/* the firmware itself: felucca.wasm (web/emu/editor-api.h) answering the editor over a Web MIDI port of the page */
|
|
const WASM = process.env.EMU_WASM || path.join(HERE, "..", "build", "emu", "felucca.wasm");
|
|
if (fs.existsSync(WASM)) {
|
|
const { edServe } = await import("./emu/worklet.js");
|
|
const { instance } = await WebAssembly.instantiate(fs.readFileSync(WASM), {});
|
|
const ex = instance.exports;
|
|
ex._initialize(); ex.web_nor_erase(); ex.web_master(700); ex.web_seed(3); ex.web_boot();
|
|
for (let i = 0; i < 12; i++) ex.web_render(1024);
|
|
if (ex.web_gen) { ex.web_gen(6, 11, 60, 2); for (let i = 0; i < 30; i++) ex.web_render(1024); }
|
|
const dev = (a) => edServe(ex, a);
|
|
const init = async (p) => {
|
|
await p.exposeFunction("__fm1", (bytes) => { const r = dev(bytes.slice(4, -1)); return r ? [0xF0, 0x7D, 0x46, 0x4C, bytes[4], ...r, 0xF7] : null; });
|
|
await p.addInitScript(() => {
|
|
const input = { id: "in", name: "JIANT", manufacturer: "JIANT", type: "input", state: "connected", onmidimessage: null, open: async () => {}, close: async () => {} };
|
|
const output = { id: "out", name: "JIANT", manufacturer: "JIANT", type: "output", state: "connected", open: async () => {}, close: async () => {},
|
|
send: (d) => { window.__fm1(Array.from(d)).then((r) => { if (r) setTimeout(() => input.onmidimessage && input.onmidimessage({ data: Uint8Array.from(r) }), 1); }); } };
|
|
navigator.requestMIDIAccess = async () => ({ inputs: new Map([["in", input]]), outputs: new Map([["out", output]]), onstatechange: null });
|
|
});
|
|
};
|
|
const p = await openRoll("", { width: 1280, height: 900 }, false, init);
|
|
const ver = await p.textContent("#version");
|
|
let r = await R(p);
|
|
const same = r.steps.every((s, i) => { const d = dev([30, 0, i, 1]); return d && d[2] === s.n && d[7] === s.time && d[10] === (s.hit & 127) && d[13] === s.chance && d[14] === s.ratchet; });
|
|
check(`roll (firmware ${ver.split("·").pop().trim()}): track 1's 64 steps as the device holds them`, same);
|
|
/* a melodic track: the first that is not DRUM */
|
|
const tr = dev([27]), engs = []; for (let k = 0; k < tr[1]; k++) engs.push(tr[2 + k * 6]);
|
|
const mel = engs.findIndex((e) => e !== 10);
|
|
await p.click(`#trackbtns button[data-i='${mel}']`); await rollReady(p, mel);
|
|
await p.evaluate(() => { const t = window.jiantRollTest; t.roll.view.sx = 56; t.show(72); });
|
|
r = await R(p);
|
|
const free = [57, 58, 59, 60, 61, 62].find((i) => r.steps[i].time !== 0) ?? 60;
|
|
await tapCell(p, free, 70);
|
|
const d1 = dev([30, mel, free]);
|
|
check(`roll (firmware): a tap writes A#4 into track ${mel + 1}'s step ${free + 1} (TRACK_STEP read back)`, d1[7] === 0 && d1.slice(3, 3 + d1[2]).includes(70));
|
|
await p.click("#rollinsp button:text-is('x3')").catch(() => {}); await p.waitForTimeout(300);
|
|
check("roll (firmware): its ratchet x3 on the device", dev([30, mel, free])[14] === 3);
|
|
const lockSel = await p.$("#rollinsp .rlocks select");
|
|
if (lockSel) {
|
|
await lockSel.selectOption({ index: 1 });
|
|
await p.click("#rollinsp .rlocks .bar button"); await p.waitForTimeout(400);
|
|
}
|
|
const m = dev([64, mel, 7]), cnt = m[3];
|
|
check("roll (firmware): a lock on the step (MOTION op 7: kind 1)", cnt > 0 && Array.from({ length: cnt }, (_, k) => [m[5 + k * 4], m[5 + cnt * 4 + k]]).some(([st, kd]) => st === free && kd === 1));
|
|
await p.click("#rollundo"); await p.waitForTimeout(400); await p.click("#rollundo"); await p.waitForTimeout(400);
|
|
check("roll (firmware): UNDO twice: the step as it was", dev([30, mel, free])[7] === r.steps[free].time);
|
|
if (OUT) await p.screenshot({ path: path.join(OUT, "roll-firmware-desktop.png"), fullPage: true });
|
|
/* (Part 2) MATH on the firmware: a sound sent to track 3, read back from the device, and read into the editor */
|
|
await p.click("#tabs button[data-tab='math']"); await p.waitForTimeout(300);
|
|
await p.click("#mgenp"); await p.waitForTimeout(200);
|
|
const before = await p.evaluate(() => window.jiantRollTest.math());
|
|
await p.selectOption("#mtrk", "2"); await p.dispatchEvent("#mtrk", "change");
|
|
await p.click("#msend"); await p.waitForFunction(() => /T3/.test(document.querySelector("#status").textContent), null, { timeout: 30000 });
|
|
const td = dev([29, 2]), pe0 = 115, e = Array.from({ length: 8 }, (_, k) => (td[3 + (pe0 + k) * 2] | td[4 + (pe0 + k) * 2] << 7) - 8192);
|
|
check(`MATH (firmware): a generated sound sent to track 3: engine MATH, ${before.wave === 6 ? "F" : "B"}${before.f + 1} (E ${e.join(" ")})`,
|
|
td[1] === 3 && e[1] === before.wave && e[2] === before.f * 4 && e[3] === before.v.var && e[4] === before.v.motion && e[7] === before.v.loop);
|
|
await p.click("#mgen"); await p.click("#mread"); await p.waitForTimeout(800);
|
|
const after = await p.evaluate(() => window.jiantRollTest.math());
|
|
check("MATH (firmware): read back from the track into the editor", after.wave === before.wave && after.f === before.f && after.v.var === before.v.var && after.stock !== -1 || (after.wave === 6 && after.f === before.f));
|
|
/* (V10.8.75) MATH USER: a formula of one's own sent to track 4 (FORMULA 100, then ALGO USER), read back */
|
|
const ownSrc = "(t * (t >> 9 | t >> 13) & 46) + sin(t >> 2) / 4";
|
|
await p.fill("#mf", ownSrc); await p.waitForTimeout(150);
|
|
const own = await p.evaluate(() => window.jiantRollTest.math());
|
|
await p.selectOption("#mtrk", "3"); await p.dispatchEvent("#mtrk", "change");
|
|
check("MATH USER (firmware): one's own formula compiled to the device's bytecode, sendable", own.ok && own.user && own.code && !(await p.isDisabled("#msend")));
|
|
await p.click("#msend"); await p.waitForFunction(() => /T4: USER/.test(document.querySelector("#status").textContent), null, { timeout: 30000 });
|
|
const fo = dev([100, 3, 0]), tdu = dev([29, 3]), algo = (tdu[3 + (pe0 + 2) * 2] | tdu[4 + (pe0 + 2) * 2] << 7) - 8192;
|
|
const bytes = []; for (let i = 3; i < fo.length; i += 8) { const m = fo[i]; for (let j = 1; j <= 7 && i + j < fo.length; j++) bytes.push(fo[i + j] | ((m >> (j - 1)) & 1) << 7); }
|
|
check(`MATH USER (firmware): on track 4 (FORMULA 4 0: ${fo[2]} B, the editor's), ALGO ${algo} (USER)`, fo[1] === 0 && fo[2] === own.code.length &&
|
|
bytes.slice(0, fo[2]).join() === own.code.join() && algo === -4 && tdu[1] === 3);
|
|
await p.fill("#mf", "t"); await p.click("#mread"); await p.waitForTimeout(800);
|
|
const back = await p.evaluate(() => window.jiantRollTest.math());
|
|
check("MATH USER (firmware): read back into the editor: its text (kept with its bytes), USER", back.src === ownSrc && back.user);
|
|
if (OUT) await p.screenshot({ path: path.join(OUT, "math-firmware-desktop.png"), fullPage: true });
|
|
await p.close();
|
|
} else console.log(`editor (browser): the roll on the firmware: no ${WASM} (EMU_WASM=...)`.padEnd(80) + " skip");
|
|
/* (Part 2) the formula editor without a device: the grammar, the picture, the sound (the emulator's for the device's
|
|
formulas, the model for one's own), the generator; on a phone too */
|
|
for (const [vp, touch, tag] of [[{ width: 1280, height: 900 }, false, "desktop"], [{ width: 390, height: 844 }, true, "phone"]]) {
|
|
const p = await b.newPage({ viewport: vp, deviceScaleFactor: 2, hasTouch: touch, isMobile: touch });
|
|
p.on("pageerror", (e) => { console.log("pageerror:", e.message); fails++; });
|
|
if (fs.existsSync(WASM)) await p.route("http://emu.test/felucca.wasm", (r) => r.fulfill({ body: fs.readFileSync(WASM), contentType: "application/wasm", headers: { "access-control-allow-origin": "*" } }));
|
|
await p.goto(`${page0}?test=1&mock=1&wasm=http://emu.test/felucca.wasm#sound`);
|
|
const cold = await p.evaluate(() => window.jiantRollTest.math().built);
|
|
await p.click("#tabs button[data-tab='math']"); await p.waitForTimeout(300);
|
|
let m = await p.evaluate(() => window.jiantRollTest.math());
|
|
check(`MATH (${tag}): nothing built until the tab opens, then B05 (BYTEBEAT's formula)`, !cold && m.built && m.ok && m.stock === 4);
|
|
await p.fill("#mf", "t * (42 & t >> 10"); await p.waitForTimeout(100);
|
|
check(`MATH (${tag}): an error said with its place`, /18/.test(await p.textContent("#merr")) && (await p.getAttribute("#merr", "class")).includes("bad"));
|
|
await p.fill("#mf", "t * (42 & t >> 10) | t >> 6"); await p.waitForTimeout(100);
|
|
m = await p.evaluate(() => window.jiantRollTest.math());
|
|
const rm = await p.evaluate(() => window.jiantRollTest.mathRender());
|
|
const want = fs.existsSync(WASM) ? "emu" : "model"; /* (V10.8.75: the emulator's own VM plays one's own formulas) */
|
|
check(`MATH (${tag}): one's own formula heard through the ${want} (peak ${rm && rm.peak.toFixed(2)}), not sendable unconnected`, m.ok && m.stock === -1 && m.user && rm && rm.src === want && rm.peak > 0.005 && await p.isDisabled("#msend"));
|
|
await p.fill("#mf", "sin(w * (1 + (t >> 12 & 3))) * 0.5"); await p.waitForTimeout(100);
|
|
m = await p.evaluate(() => window.jiantRollTest.math());
|
|
check(`MATH (${tag}): a floatbeat of one's own (FIX: BYTE's language, sent on WAVE FLOAT)`, m.ok && m.user && m.code && (m.code[0] & 1) === 1 && /FLOAT/.test(await p.textContent("#merr")));
|
|
await p.selectOption("#mstock", "6"); await p.waitForTimeout(100);
|
|
if (fs.existsSync(WASM)) {
|
|
const re = await p.evaluate(() => window.jiantRollTest.mathRender());
|
|
check(`MATH (${tag}): a device formula (B07) heard through the emulator's own code (peak ${re && re.peak.toFixed(3)})`, re && re.src === "emu" && re.peak > 0.005);
|
|
await p.click("#mwave button[data-w='6']"); await p.selectOption("#mstock", "27");
|
|
const rf = await p.evaluate(() => window.jiantRollTest.mathRender());
|
|
check(`MATH (${tag}): FLOAT F28 through the emulator`, rf && rf.src === "emu" && rf.peak > 0.005);
|
|
await p.click("#mplay"); await p.waitForFunction(() => /emulator|emulador/.test(document.querySelector("#msrc").textContent), null, { timeout: 20000 });
|
|
await p.click("#mstop");
|
|
await p.click("#mwave button[data-w='5']");
|
|
}
|
|
await p.fill("#mseed", "5"); await p.click("#mgen"); await p.waitForTimeout(100);
|
|
const g1 = (await p.evaluate(() => window.jiantRollTest.math())).src;
|
|
await p.fill("#mseed", "5"); await p.click("#mgen"); await p.waitForTimeout(100);
|
|
m = await p.evaluate(() => window.jiantRollTest.math());
|
|
check(`MATH (${tag}): the generator, seeded: seed 5 twice, the same formula, valid`, m.ok && m.src === g1);
|
|
/* the generator's family and CHAOS: FM at 80 a FIX formula (sent on WAVE FLOAT), RHYTHM at 0 an INT one; the family's
|
|
name in the status; the same seed, family and CHAOS the same formula */
|
|
const fams = await p.$$eval("#mfam option", (a) => a.map((o) => o.value));
|
|
await p.selectOption("#mfam", "fm"); await p.fill("#mchaos", "80"); await p.fill("#mseed", "9"); await p.click("#mgen"); await p.waitForTimeout(100);
|
|
const gf = await p.evaluate(() => window.jiantRollTest.math()), st1 = await p.textContent("#status");
|
|
await p.selectOption("#mfam", "rhythm"); await p.fill("#mchaos", "0"); await p.click("#mgen"); await p.waitForTimeout(100);
|
|
const gr = await p.evaluate(() => window.jiantRollTest.math());
|
|
await p.selectOption("#mfam", "fm"); await p.fill("#mchaos", "80"); await p.fill("#mseed", "9"); await p.click("#mgen"); await p.waitForTimeout(100);
|
|
const gf2 = await p.evaluate(() => window.jiantRollTest.math());
|
|
check(`MATH (${tag}): the generator's families (${fams.length - 1} and any) and CHAOS: FM 80 a FIX formula, RHYTHM 0 an INT one, seeded`,
|
|
fams[0] === "any" && fams.length >= 7 && gf.ok && gf.user && gf.fix && /FLOAT/.test(await p.textContent("#merr")) && /FM/.test(st1) && /80/.test(st1) &&
|
|
gr.ok && gr.user && !gr.fix && gf2.src === gf.src, `${gf.src} | ${gr.src}`);
|
|
await p.click("#mgenp"); await p.waitForTimeout(100);
|
|
m = await p.evaluate(() => window.jiantRollTest.math());
|
|
check(`MATH (${tag}): a generated sound is one the device plays`, m.wave === 6 || m.stock >= 0);
|
|
if (touch) {
|
|
const small = await p.$$eval("#p-math button, #p-math select, #p-math input[type=range]", (a) => a.filter((x) => x.offsetParent && x.getBoundingClientRect().height < 39.5).map((x) => x.textContent || x.id));
|
|
check("MATH (phone): every button at least 40 px high", !small.length, small.join());
|
|
}
|
|
await p.click("#tabs button[data-tab='sound']");
|
|
check(`MATH (${tag}): its sound stops with the tab`, !(await p.evaluate(() => window.jiantRollTest.math().playing)));
|
|
if (OUT) { await p.click("#tabs button[data-tab='math']"); await p.selectOption("#mstock", "4"); await p.waitForTimeout(300); await p.screenshot({ path: path.join(OUT, `math-${tag}.png`), fullPage: true }); }
|
|
await p.close();
|
|
}
|
|
await b.close();
|
|
console.log(fails ? `EDITOR BROWSER TEST FAILED (${fails})` : "editor browser test passed");
|
|
process.exit(fails ? 1 : 0);
|