Files
fmini-1/web/test_editor_fmini.py
T
Claude 994f6ee605 PT / EN button on the editor and both emulators; the SMK-37's BT and K4 in the editor's question
- Editor, FM-1 emulator, SMK-37 emulator: the site's language button (PT / EN) at the top right. The
  emulators get Portuguese texts (bar, hints, power button, errors, footer, titles); the panel's printed
  labels stay as on the hardware. The editor changes language in place (the connection stays).
- One choice for the four pages: localStorage "fmini-lang" (the site keeps it too); else the browser's.
- Phones: the bar fits with the button (no wrap, tighter links).
- Editor: on a port named SMK-37 the panel question says ALGORITHM (K4) = YES, then BT (BT is the SMK-37's
  SAVE); the footer names BT too. Test: the FM-1 says SAVE, the SMK-37 BT.
- docs/emu (both) and docs/index.html rebuilt.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QUF6pQ1NkTwmBC8SR8AK94
2026-11-12 15:40:11 -03:00

387 lines
24 KiB
Python

#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-only
# web/editor_fmini.html against the firmware's real editor handler: headless Chromium with a fake Web MIDI port whose
# SysEx goes to tests/editor_bridge.c (the C protocol code of the FMini-1 firmware, host build).
# web/test_editor_fmini.py [bridge-binary] [screenshot-dir]
import json, subprocess, sys, time
from pathlib import Path
from playwright.sync_api import sync_playwright
ROOT = Path(__file__).resolve().parent.parent
BRIDGE = sys.argv[1] if len(sys.argv) > 1 else None
SHOTS = Path(sys.argv[2]) if len(sys.argv) > 2 else None
if not BRIDGE:
BRIDGE = "/tmp/editor_bridge"
subprocess.run(["cc", "-O1", "-w", "-Ibuild/gen", "-Ifirmware/src", "-o", BRIDGE, "tests/editor_bridge.c", "-lm"], cwd=ROOT, check=True)
import os
proc = subprocess.Popen([BRIDGE], stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True, cwd=ROOT,
env=dict(os.environ, FM_RESTORE_ANSWER="yes")) # the device's answer to the restore question (the panel is not here)
log = []
def fw(cmd, args=()):
"""a request to the firmware: the reply's bytes after F0 7D 46 4C cmd, without F7 (None: no reply)"""
line = bytes([0xF0, 0x7D, 0x46, 0x4C, cmd, *args, 0xF7]).hex()
proc.stdin.write(line + "\n"); proc.stdin.flush()
r = proc.stdout.readline().strip()
return list(bytes.fromhex(r)) if r else None
def fa(cmd, args=()):
"""the reply's arguments (after the command byte, without F7)"""
r = fw(cmd, args)
return r[5:-1] if r else None
CUT = [False] # True: a firmware that cuts the NAMES reply at 664 bytes (up to 1.7.1)
def on_tx(data):
log.append(list(data))
r = fw(data[4], data[5:-1])
if CUT[0] and data[4] == 10 and r and len(r) > 664:
r = r[:663] + [0xF7]
if data[4] == 19 and r and r[6] == 2: # UP_STORE: the host build has no flash ("kept in RAM"): a real device answers 0
r[6] = 0
return r
bad = 0
def check(name, ok):
global bad
print(f"editor_fmini: {name:<84}{'ok' if ok else 'FAIL'}")
bad += 0 if ok else 1
MOCK = """
(() => {
const mk = (kind) => ({ name: 'FM-1 Midi', state: 'connected', type: kind, open: async () => {}, onmidimessage: null });
const inp = mk('input'), out = mk('output');
window.__delay = 0; window.__sent = 0; /* a slow device: it answers __delay ms after the request */
out.send = (d) => { window.__sent++; setTimeout(() => window.__tx(Array.from(d)).then((r) => { if (r && inp.onmidimessage) inp.onmidimessage({ data: new Uint8Array(r) }); }), window.__delay); };
const acc = { inputs: new Map([['i', inp]]), outputs: new Map([['o', out]]), onstatechange: null };
window.__acc = acc; window.__inp = inp;
navigator.requestMIDIAccess = async () => acc;
})();
"""
# two devices with one port name (an FM-1 and an SMK-37 on FMini-1 are both "FM-1 Midi"): the first never answers, the
# second is the bridge. Each input must go with its own output.
MOCK2 = """
(() => {
const mk = (kind, id) => ({ id, name: 'FM-1 Midi', state: 'connected', type: kind, open: async () => {}, onmidimessage: null });
const i1 = mk('input', 'i1'), o1 = mk('output', 'o1'), i2 = mk('input', 'i2'), o2 = mk('output', 'o2');
o1.send = () => {};
o2.send = (d) => { window.__tx(Array.from(d)).then((r) => { if (r && i2.onmidimessage) i2.onmidimessage({ data: new Uint8Array(r) }); }); };
navigator.requestMIDIAccess = async () => ({ inputs: new Map([['i1', i1], ['i2', i2]]), outputs: new Map([['o1', o1], ['o2', o2]]), onstatechange: null });
})();
"""
with sync_playwright() as pw:
br = pw.chromium.launch()
pg = br.new_page(viewport={"width": 1100, "height": 820})
errs = []
pg.on("pageerror", lambda e: errs.append(str(e)))
pg.on("console", lambda m: errs.append(m.text) if m.type == "error" else None)
pg.expose_function("__tx", on_tx)
pg.add_init_script(MOCK)
pg.goto((ROOT / "web" / "editor_fmini.html").as_uri())
check("loads off-line: panel greyed, Connect offered", pg.evaluate("document.body.classList.contains('off')") and pg.inner_text("#connect") in ("Conectar", "Connect"))
pg.click("#connect")
pg.wait_for_function("!document.body.classList.contains('off')", timeout=15000)
check("Connect: handshake, descriptors, names; status shows connected", "FMini-1" in pg.inner_text("#stxt") and not errs)
check("INFO told the page the patch commands exist", pg.evaluate("__fmini.S.canPatch") is True)
check("the preset list has the 200 slots (all factory patches)", pg.evaluate("document.querySelectorAll('#preset option').length") >= 200)
nm = pg.evaluate("__fmini.S.names")
check(" .. and every one of them has its name (the last: " + (nm[199] if len(nm) > 199 else "?") + ")", len(nm) == 200 and all(len(x) > 0 for x in nm))
pg.wait_for_timeout(300)
# a track parameter through a knob (FILT > CUTOFF = P_E0)
pg.click("#tabs button:has-text('FILT')")
pe0 = pg.evaluate("__fmini.S.pe0")
before = fa(31, [0, pe0])
knob = pg.locator(".knob", has_text="CUTOFF")
knob.focus()
v0 = pg.evaluate("__fmini.S.p[__fmini.S.pe0]")
for _ in range(3):
pg.keyboard.press("ArrowDown")
pg.wait_for_timeout(400)
after = fa(31, [0, pe0])
d0 = (before[2] | before[3] << 7) - 8192; d1 = (after[2] | after[3] << 7) - 8192
check("CUTOFF knob (keys): the firmware's P_E0 moved down", d1 < d0 and d1 == pg.evaluate("__fmini.S.p[__fmini.S.pe0]"))
knob.dblclick()
pg.wait_for_timeout(300)
after = fa(31, [0, pe0]); d2 = (after[2] | after[3] << 7) - 8192
check("double click: back to the parameter's default", d2 == pg.evaluate("__fmini.S.desc['0:' + (__fmini.S.pe0)].def"))
# drag
b = knob.bounding_box()
pg.mouse.move(b["x"] + b["width"] / 2, b["y"] + 30); pg.mouse.down(); pg.mouse.move(b["x"] + b["width"] / 2, b["y"] - 60, steps=8); pg.mouse.up()
pg.wait_for_timeout(400)
after = fa(31, [0, pe0]); d3 = (after[2] | after[3] << 7) - 8192
check("dragging a knob up raises it on the device", d3 > d2)
# a long drag with a slow device (it answers 70 ms after a request): the page keeps at most one write in flight and the
# device holds the final value soon after the mouse is released, however long the drag lasted
import math
knob.dblclick(); pg.wait_for_timeout(300) # (the default, mid-range: room to move both ways)
kb = knob.bounding_box(); cx = kb["x"] + kb["width"] / 2
pg.evaluate("window.__delay = 70; window.__sent = 0")
pg.mouse.move(cx, kb["y"] + 60); pg.mouse.down()
t_drag = time.monotonic(); n_move = 0
while time.monotonic() - t_drag < 2.0: # 2 s of dragging, one move every ~16 ms (a 60 Hz pointer)
n_move += 1 # (it swings up and down: every move is a new value)
pg.mouse.move(cx, kb["y"] + 60 - 10 * (1 + math.sin(n_move * 0.35)))
pg.wait_for_timeout(16)
pg.mouse.move(cx, kb["y"] + 60 - 50) # the last position: a value the swing never had
final = pg.evaluate("__fmini.S.p[__fmini.S.pe0]")
pg.mouse.up(); t_up = time.monotonic(); settled = None
dev_val = lambda: (lambda r: (r[2] | r[3] << 7) - 8192)(fa(31, [0, pe0]))
while time.monotonic() - t_up < 6.0:
if dev_val() == final:
settled = time.monotonic() - t_up; break
pg.wait_for_timeout(10)
sent = pg.evaluate("window.__sent")
pg.wait_for_timeout(300)
stays = dev_val() == final # (no older value arrives after it)
pg.evaluate("window.__delay = 0")
check(f"slow device, 2 s drag ({n_move} moves): the last value reaches it {'in %.0f ms' % (settled * 1000) if settled is not None else 'NEVER'} after the release (<= 400 ms)", settled is not None and settled <= 0.4)
check(f" .. and stays: no older value arrives after it ({sent} writes sent in all; the drag made {n_move} moves)", stays)
pg.wait_for_timeout(300)
# patch bytes: OSC > OSC 1 WAVE = PLS N, MOD OSC switch, GLIDE
pg.click("#tabs button:has-text('OSC')")
pg.locator(".seg", has_text="OSC 1 WAVE").locator("button", has_text="PLS N").click()
pg.wait_for_timeout(300)
g = fa(82, [0, 0])
check("OSC 1 WAVE: the firmware's patch byte (FMINI_GET) is PLS N", g[2] == 0 and g[3 + 3] == 5)
check(" .. SLOT is OWN now (200: two 7-bit bytes, protocol 3)", g[3 + 32] + 128 * g[3 + 33] == 200)
pg.click("#tabs button:has-text('CTRL')")
pg.locator(".sw", has_text="MOD OSC").click()
pg.wait_for_timeout(300)
g = fa(82, [0, 0])
check("MOD OSC switch: bit 32 of the patch's SW1 on, the rest untouched", g[3 + 12] & 32 and g[3 + 3] == 5)
pg.locator(".sw", has_text="GLIDE").click() # (patch 00 has it on, P_GLIDE not synced: the click turns it off)
pg.wait_for_timeout(300)
glide = fa(31, [0, 38]); gl = (glide[2] | glide[3] << 7) - 8192
g = fa(82, [0, 0])
check("GLIDE switch off: SW2 bit clear, P_GLIDE 0", not (g[3 + 13] & 1) and gl == 0)
pg.locator(".sw", has_text="GLIDE").click()
pg.wait_for_timeout(300)
glide = fa(31, [0, 38]); gl = (glide[2] | glide[3] << 7) - 8192
g = fa(82, [0, 0])
check("GLIDE switch on: SW2 bit set, P_GLIDE = the kept time", (g[3 + 13] & 1) and gl == g[3 + 17] and gl > 0)
# the keys' octave (extras: carried by FMINI_PUT, read back by FMINI_GET)
pg.locator(".seg", has_text="OCTAVE").locator("button", has_text="+1").click()
pg.wait_for_timeout(300)
g = fa(82, [0, 0])
check("OCTAVE +1: the device's octave (last byte of FMINI_GET) is 5 = +1 + 4", g[37] == 5 and len(g) == 38 and pg.evaluate("__fmini.S.oct") == 1)
pg.locator(".seg", has_text="OCTAVE").locator("button", has_text="+1").click() # (stays: it is a choice, not a toggle)
# FX enum
pg.click("#tabs button:has-text('FX')")
sel = pg.locator(".sel", has_text="TYPE").first
sel.locator("select").select_option(index=2)
pg.wait_for_timeout(300)
r = fa(2, [1, 24]); check("REVERB TYPE select: the global G_RTYPE = 2 (PLATE)", ((r[2] | r[3] << 7) - 8192) == 2)
# presets
pg.select_option("#preset", "7")
pg.wait_for_timeout(700)
g = fa(82, [0, 0]); f = fa(82, [2, 7])
check("PRESET 07 from the list: the track plays factory patch 7", g[3:35] == f[3:35] and g[35] == 7)
check(" .. the page shows it (select + knob values reflect the firmware)", pg.input_value("#preset") == "7")
pg.click("#next"); pg.wait_for_timeout(700)
check("next ▶: preset 08", pg.input_value("#preset") == "8" and fa(82, [0, 0])[35] == 8)
pg.click("#prev"); pg.click("#prev"); pg.wait_for_timeout(900)
check("◀ ◀: preset 06", pg.input_value("#preset") == "6")
# the panel follows the device (a change made on the panel of the FM-1)
fa(31, [0, 1, (50 + 8192) & 127, (50 + 8192) >> 7])
pg.click("#tabs button:has-text('A.ENV')")
pg.wait_for_timeout(1700)
check("a change on the FM-1 shows up on the page (polling)", pg.locator(".knob", has_text="ATTACK").get_attribute("aria-valuenow") == "50")
# sound file round trip
with pg.expect_download() as dl:
pg.click("#save")
p = Path("/tmp/claude_fmini_sound.json"); dl.value.save_as(p)
saved = fa(82, [0, 0])[3:35]
fa(83, [0, 0, *[0] * 32]) # a blank patch on the device
pg.wait_for_timeout(1500)
pg.set_input_files("#file", str(p))
pg.wait_for_timeout(700)
check("Save / Open sound: the file puts the saved patch back on the device", fa(82, [0, 0])[3:35] == saved)
# ---- phase 3: the device's presets (the PRESETS tab), A/B, randomize
pg.on("dialog", lambda d: d.accept())
pg.click("#tabs button:text-is('PRESETS')")
pg.wait_for_selector("#resetsel")
check("PRESETS: the 200 presets are listed for FACTORY RESET", pg.locator("#resetsel option").count() == 200)
check(" .. slot 150 is a factory patch, not INIT", not pg.locator("#resetsel option").nth(150).inner_text().endswith("INIT"))
check(" .. no cards, no SAVE / erase / U-bank buttons (a slot is written on the device)", pg.locator(".slot").count() == 0 and pg.locator("button:has-text('Save here')").count() == 0)
pg.select_option("#preset", "150")
pg.wait_for_timeout(900)
check("Load: slot 150 is on the track (the PRESET list)", pg.evaluate("__fmini.S.slot") == 150)
fa(83, [0, 0, *[5] * 32])
pg.click("#tabs button:text-is('CTRL')")
# A/B
pg.click("#tabs button:text-is('FILT')")
kn = pg.locator(".knob", has_text="CUTOFF"); base = kn.get_attribute("aria-valuenow")
pg.select_option("#preset", "3"); pg.wait_for_timeout(800)
base = pg.evaluate("__fmini.S.p[__fmini.S.pe0]")
kn.focus()
for _ in range(4): pg.keyboard.press("ArrowDown")
pg.wait_for_timeout(400)
moved = pg.evaluate("__fmini.S.p[__fmini.S.pe0]")
pg.click("#ab"); pg.wait_for_timeout(500)
a_val = (lambda r: (r[2] | r[3] << 7) - 8192)(fa(31, [0, pe0]))
check("A/B: switching to B gives back the sound as the preset was loaded", moved != base and a_val == base)
pg.click("#ab"); pg.wait_for_timeout(500)
b_val = (lambda r: (r[2] | r[3] << 7) - 8192)(fa(31, [0, pe0]))
check(" .. and back to A: the edit is there again", b_val == moved)
# randomize
before = fa(82, [0, 0])[3:35]
pg.fill("#amt", "100") if False else pg.evaluate("document.getElementById('amt').value = 100; document.getElementById('amt').dispatchEvent(new Event('input'))")
pg.click("#rnd"); pg.wait_for_timeout(600)
after = fa(82, [0, 0])[3:35]
check("Randomize: the patch on the device changed and OSC 1 is still on", after != before and after[12] & 1 and all(0 <= x <= 127 for x in after))
pg.wait_for_timeout(1200)
check(" .. and the page is usable again (not busy)", not pg.evaluate("document.body.classList.contains('busy')"))
# ---- phase 4: backup (.bkp) and restore: the device answers YES here (FM_RESTORE_ANSWER: the bridge)
pg.click("#tabs button:text-is('PRESETS'), #tabs button:text-is('PRESETS')"); pg.wait_for_selector("#resetsel")
with pg.expect_download(timeout=120000) as dl:
pg.click("button:has-text('Fazer backup'), button:has-text('Make backup')")
bk = Path("/tmp/claude_fmini_backup.bkp"); dl.value.save_as(bk)
check("Backup: a .bkp file", dl.value.suggested_filename.endswith(".bkp"))
bj = json.loads(bk.read_text())
check(" .. all 200 presets, each as its record", bj.get("fmini1bkp") == 1 and len(bj["slots"]) == 200 and all(x["rec"][:2] == "01" for x in bj["slots"]))
orig7 = pg.evaluate("__fmini.S.names[7]")
orig200 = pg.evaluate("__fmini.S.names.slice(0, 200)")
mod = json.loads(bk.read_text())
mod["slots"][7]["rec"] = "01" + mod["slots"][7]["rec"][2:4] + "5a" + mod["slots"][7]["rec"][6:] # slot 7's name: starts with Z
mp = Path("/tmp/claude_fmini_mod.bkp"); mp.write_text(json.dumps(mod))
pg.set_input_files("#file", str(mp))
pg.wait_for_function("/restaur|restor/i.test(document.getElementById('msg').textContent)", timeout=180000)
check("Restore: the device's presets are the file's (slot 7 starts with Z)", pg.evaluate("__fmini.S.names[7]").startswith("Z"))
pg.set_input_files("#file", str(bk))
pg.wait_for_function("!/Z/.test(__fmini.S.names[7] || '')", timeout=180000)
check(" .. and the original backup puts the name back", pg.evaluate("__fmini.S.names[7]") == orig7)
pg.wait_for_timeout(300)
# ---- FACTORY RESET: slot 7 (changed by the file) one at a time, then all the factory presets
pg.set_input_files("#file", str(mp))
pg.wait_for_function("() => !document.body.classList.contains('busy') && __fmini.S.names[7].startsWith('Z')", timeout=180000)
pg.click("#tabs button:text-is('PRESETS')"); pg.wait_for_selector("#resetsel")
pg.select_option("#resetsel", "7")
pg.click("button:text-is('Restore'), button:text-is('Restaurar')")
pg.wait_for_function("(v) => __fmini.S.names[7] === v", arg=orig7, timeout=60000)
check("FACTORY RESET one: slot 7 is its factory preset again (the name Z is gone)", pg.evaluate("__fmini.S.names[7]") == orig7)
pg.set_input_files("#file", str(mp))
pg.wait_for_function("() => !document.body.classList.contains('busy') && __fmini.S.names[7].startsWith('Z')", timeout=180000)
pg.click("#tabs button:text-is('PRESETS')"); pg.wait_for_selector("#resetsel")
pg.click("button:text-is('Restore all factory presets'), button:text-is('Restaurar todos os presets de fábrica')")
pg.wait_for_function("(v) => !document.body.classList.contains('busy') && __fmini.S.names[7] === v", arg=orig7, timeout=300000)
check("FACTORY RESET all: the 200 factory presets are back, slot 7 included", pg.evaluate("__fmini.S.names.slice(0, 200)") == orig200)
check(" .. and the last slot (199) is a factory patch again", pg.evaluate("__fmini.S.names[199]") != "INIT")
# firmware up to 1.7.1 cut the NAMES reply at 664 bytes: the page says an update is available and still works
CUT[0] = True
pg.click("#connect"); pg.wait_for_timeout(300) # (disconnect)
pg.click("#connect")
pg.wait_for_function("!document.body.classList.contains('off')", timeout=15000)
note = pg.inner_text("#msg"); got = pg.evaluate("__fmini.S.names.filter(Boolean).length")
check(f"a firmware that cuts NAMES at 664 bytes ({got} of 200 names): the page says an update is available", 60 < got < 100 and ("Update" in note or "Atualiz" in note) and str(got) in note)
CUT[0] = False
pg.click("#connect"); pg.wait_for_timeout(300)
pg.click("#connect")
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"))
# ---- PRESETS, MANAGE PRESETS, CHANGE ORDER: a pop-up with the 200 in four columns; the grid moves while dragging;
# Shift+click selects a run that moves as one; SAVE TO THE DEVICE writes the 200 in that order (the bridge answers YES)
check("the panel's question on the FM-1 names SAVE", "SAVE" in pg.evaluate("__fmini.waitText()"))
names0 = pg.evaluate("__fmini.S.names.slice(0, 200)")
pg.click("#tabs button:text-is('PRESETS')")
pg.click("button:text-is('Alterar ordem'), button:text-is('Change order')")
pg.wait_for_selector("#ordpop .ocell")
cells = pg.locator("#ordpop .ogrid .ocell")
order_now = lambda: [int(x) for x in pg.evaluate("[...document.querySelectorAll('#ordpop .ogrid .ocell')].map((c) => c.dataset.slot)")]
check("CHANGE ORDER: the pop-up holds the 200 presets in four columns",
cells.count() == 200 and pg.evaluate("getComputedStyle(document.querySelector('#ordpop .ogrid')).gridTemplateColumns.split(' ').length") == 4
and cells.nth(1).bounding_box()["y"] > cells.nth(0).bounding_box()["y"])
def center(i):
bb = cells.nth(i).bounding_box(); return bb["x"] + bb["width"] / 2, bb["y"] + bb["height"] / 2
x0, y0 = center(0); x2, y2 = center(2)
pg.mouse.move(x0, y0); pg.mouse.down(); pg.mouse.move(x2, y2, steps=12)
live = order_now()[:3]
pg.mouse.up()
check(" .. dragging 000 onto 002: the grid shows the new order before the button is let go", live == [1, 2, 0])
check(" .. and keeps it after", order_now()[:3] == [1, 2, 0])
cells.nth(3).click(); cells.nth(5).click(modifiers=["Shift"])
check(" .. click 003, Shift+click 005: the three are selected", pg.locator("#ordpop .ocell.osel").count() == 3)
x4, y4 = center(4); x8, y8 = center(8)
pg.mouse.move(x4, y4); pg.mouse.down(); pg.mouse.move(x8, y8, steps=20); pg.mouse.up()
check(" .. and dragged down, they move as one (6, 7, 8, then 3, 4, 5)", order_now()[:10] == [1, 2, 0, 6, 7, 8, 3, 4, 5, 9])
want = order_now()
pg.evaluate("document.getElementById('msg').textContent = ''")
pg.click("#ordpop button:text-is('Salvar no dispositivo'), #ordpop button:text-is('Save to device')")
pg.wait_for_function("/Ordem gravada|Order saved/.test(document.getElementById('msg').textContent)", timeout=300000)
check("SAVE TO THE DEVICE: the device's presets are in that order", pg.evaluate("__fmini.S.names.slice(0, 200)") == [names0[k] for k in want]
and pg.locator("#ordpop").count() == 0)
pg.click("button:text-is('Alterar ordem'), button:text-is('Change order')")
pg.wait_for_selector("#ordpop .ocell")
pg.locator("#ordpop .ogrid .ocell").nth(0).click()
x0, y0 = center(0); x1, y1 = center(1)
pg.mouse.move(x0, y0); pg.mouse.down(); pg.mouse.move(x1, y1, steps=8); pg.mouse.up()
pg.click("#ordpop button:text-is('Fechar'), #ordpop button:text-is('Close')") # the confirm (accepted): discard
check(" .. CLOSE with a change: the pop-up goes and the order is discarded", pg.locator("#ordpop").count() == 0
and pg.evaluate("__fmini.S.names.slice(0, 200)") == [names0[k] for k in want])
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"]):
pg.click(f"#tabs button:text-is('{name}')"); pg.wait_for_timeout(200)
pg.screenshot(path=str(SHOTS / f"ed_{i}_{name.replace('.', '')}.png"))
pg.set_viewport_size({"width": 390, "height": 800}); pg.click("#tabs button:text-is('OSC')")
pg.screenshot(path=str(SHOTS / "ed_mobile.png"))
check("no errors in the page's console", not errs)
if errs: print(errs)
pg.close()
pg2 = br.new_page(viewport={"width": 1100, "height": 820})
errs2 = []
pg2.on("pageerror", lambda e: errs2.append(str(e)))
pg2.expose_function("__tx", on_tx)
pg2.add_init_script(MOCK2)
pg2.goto((ROOT / "web" / "editor_fmini.html").as_uri())
pg2.click("#connect") # nothing picked: the silent one, then the next
pg2.wait_for_function("!document.body.classList.contains('off')", timeout=20000)
labels = pg2.evaluate("[...document.querySelectorAll('#port option')].map((o) => o.textContent)")
check("two devices named FM-1 Midi, the first silent: Connect goes on to FM-1 Midi (2), and the list shows it",
labels == ["FM-1 Midi", "FM-1 Midi (2)"] and pg2.is_visible("#port") and pg2.input_value("#port") == "FM-1 Midi (2)")
check(" .. the second one connects through its own output", "FMini-1" in pg2.inner_text("#stxt") and pg2.evaluate("__fmini.S.names.length") == 200 and not errs2)
pg2.click("#connect") # disconnect
pg2.wait_for_function("document.body.classList.contains('off')", timeout=5000)
pg2.select_option("#port", "FM-1 Midi") # picked by hand: that port alone
pg2.click("#connect")
pg2.wait_for_function("document.getElementById('connect').disabled === false && document.body.classList.contains('off')", timeout=15000)
check(" .. a port picked in the list is the only one tried (the silent one: no connection)", pg2.input_value("#port") == "FM-1 Midi")
pg2.select_option("#port", "FM-1 Midi (2)")
pg2.click("#connect")
pg2.wait_for_function("!document.body.classList.contains('off')", timeout=15000)
check(" .. and picking FM-1 Midi (2) connects again", "FMini-1" in pg2.inner_text("#stxt"))
if errs2: print(errs2)
pg2.close()
# the SMK-37 on 2.5.13 and later: the port is "SMK-37"; the editor finds it and says so in the status line
pg3 = br.new_page(viewport={"width": 1100, "height": 820})
pg3.expose_function("__tx", on_tx)
pg3.add_init_script(MOCK.replace("'FM-1 Midi'", "'SMK-37'"))
pg3.goto((ROOT / "web" / "editor_fmini.html").as_uri())
pg3.click("#connect")
pg3.wait_for_function("!document.body.classList.contains('off')", timeout=15000)
check("a port named SMK-37 connects, and the status line says SMK-37", "SMK-37" in pg3.inner_text("#stxt"))
check(" .. and the panel's question names its keys: K4 and BT (not SAVE)", "BT" in pg3.evaluate("__fmini.waitText()") and "SAVE" not in pg3.evaluate("__fmini.waitText()"))
br.close()
proc.stdin.close(); proc.wait(timeout=5)
print("editor_fmini test FAILED" if bad else "editor_fmini test passed")
sys.exit(1 if bad else 0)