mirror of
https://github.com/isod89/sloop-fm1.git
synced 2026-12-05 12:24:33 +01:00
613 lines
36 KiB
HTML
613 lines
36 KiB
HTML
<!doctype html>
|
||
<!-- SPDX-License-Identifier: GPL-3.0-only
|
||
Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments -->
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>SLOOP installer</title>
|
||
<!--PWA--><link rel="manifest" href="../sloop.webmanifest"><meta name="theme-color" content="#000000"><link rel="icon" href="../icon-192.png"><!--/PWA-->
|
||
<style>
|
||
:root { --bg: #000; --fg: #f2f2f2; --dim: #8a8a92; --tile: #16161a; --line: #2a2a30;
|
||
--blue: #287cff; --green: #1ecc70; --yellow: #ffc618; --orange: #ff621a; --red: #ff2c34; }
|
||
:root[data-theme="light"] { --bg: #f4f4f2; --fg: #111; --dim: #666; --tile: #e6e6e2; --line: #d0d0cc; }
|
||
* { box-sizing: border-box; }
|
||
body { margin: 0; background: var(--bg); color: var(--fg);
|
||
font: 15px/1.6 "Helvetica Neue", -apple-system, BlinkMacSystemFont, Arial, sans-serif; }
|
||
main { max-width: 560px; margin: 0 auto; padding: 32px 16px 48px; }
|
||
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
|
||
.logo svg { display: block; width: 220px; height: auto; }
|
||
.logo rect:first-child { fill: transparent; }
|
||
.lang { font-size: 12px; color: var(--dim); cursor: pointer; text-decoration: underline; background: none;
|
||
border: 0; padding: 0; text-transform: lowercase; }
|
||
.strip { display: flex; height: 4px; margin: 20px 0 24px; }
|
||
.strip i { flex: 1; } .strip i:nth-child(1) { background: var(--blue); } .strip i:nth-child(2) { background: var(--green); }
|
||
.strip i:nth-child(3) { background: var(--yellow); } .strip i:nth-child(4) { background: var(--orange); }
|
||
h1 { font-size: 13px; font-weight: 500; letter-spacing: .12em; text-transform: uppercase; color: var(--dim); margin: 0 0 8px; }
|
||
.lead { font-size: 20px; line-height: 1.35; margin: 0 0 24px; }
|
||
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 0 0 28px; }
|
||
.tile { background: var(--tile); padding: 10px 10px 12px; border-top: 3px solid var(--c); min-height: 92px; }
|
||
.tile b { display: block; font-size: 22px; font-weight: 600; color: var(--c); line-height: 1.1; }
|
||
.tile span { display: block; font-size: 12px; color: var(--dim); text-transform: lowercase; margin-top: 4px; }
|
||
p { margin: 0 0 14px; }
|
||
button#go { font: 600 15px/1 inherit; font-family: inherit; background: var(--orange); color: #000; border: 0;
|
||
padding: 16px 0; width: 100%; cursor: pointer; letter-spacing: .08em; text-transform: uppercase; }
|
||
button#go:disabled { background: var(--tile); color: var(--dim); cursor: default; }
|
||
#status { margin-top: 14px; min-height: 1.6em; font-variant-numeric: tabular-nums; }
|
||
.small { color: var(--dim); font-size: 12.5px; }
|
||
.small a, a { color: inherit; }
|
||
progress { -webkit-appearance: none; appearance: none; width: 100%; height: 6px; margin-top: 16px; border: 0; background: var(--tile); }
|
||
progress::-webkit-progress-bar { background: var(--tile); }
|
||
progress::-webkit-progress-value { background: var(--orange); }
|
||
progress::-moz-progress-bar { background: var(--orange); }
|
||
pre { color: var(--dim); font-size: 11px; white-space: pre-wrap; margin-top: 12px; max-height: 160px; overflow: auto; }
|
||
hr { border: 0; border-top: 1px solid var(--line); margin: 28px 0 18px; }
|
||
[hidden] { display: none !important; }
|
||
button.ed { font: inherit; color: var(--fg); border: 0; cursor: pointer; }
|
||
.ed { display: inline-block; margin: 8px 0 0; padding: 10px 14px; background: var(--tile); text-decoration: none; }
|
||
details { margin: 22px 0 0; } summary { cursor: pointer; font-weight: 600; }
|
||
button#stock-go { font: 600 14px/1 inherit; font-family: inherit; background: var(--tile); color: var(--fg); border: 1px solid var(--line);
|
||
padding: 12px 16px; cursor: pointer; }
|
||
button#stock-go:disabled { color: var(--dim); cursor: default; }
|
||
@media (max-width: 420px) { .tiles { grid-template-columns: repeat(2, 1fr); } .logo svg { width: 170px; } }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<main>
|
||
<div class="top"><div class="logo"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 760 260" width="760" height="260" role="img" aria-label="SLOOP">
|
||
<rect width="760" height="260" fill="#000"/>
|
||
<path d="M59.29 200.71 A100.00 100.00 0 1 1 200.71 200.71" fill="none" stroke="#F2F2F2" stroke-width="12" stroke-linecap="round"/>
|
||
<rect x="95.00" y="46.00" width="10" height="136.00" rx="5" fill="#F2F2F2"/>
|
||
<polygon points="111.00,50.00 111.00,50.00 131.34,75.00 111.00,75.00" fill="#287CFF"/>
|
||
<polygon points="111.00,81.00 136.22,81.00 156.56,106.00 111.00,106.00" fill="#1ECC70"/>
|
||
<polygon points="111.00,112.00 161.44,112.00 181.78,137.00 111.00,137.00" fill="#FFC618"/>
|
||
<polygon points="111.00,143.00 186.66,143.00 207.00,168.00 111.00,168.00" fill="#FF621A"/>
|
||
<rect x="66.00" y="192.00" width="128" height="12" rx="6" fill="#F2F2F2"/>
|
||
<path d="M290.88 130.00 A14.88 15.00 0 1 1 304.37 108.66" fill="none" stroke="#F2F2F2" stroke-width="12" stroke-linecap="round"/>
|
||
<path d="M290.88 130.00 A14.88 15.00 0 1 1 277.39 151.34" fill="none" stroke="#F2F2F2" stroke-width="12" stroke-linecap="round"/>
|
||
<line x1="337.76" y1="68.00" x2="337.76" y2="160.00" stroke="#F2F2F2" stroke-width="12" stroke-linecap="round"/>
|
||
<circle cx="399.76" cy="130.00" r="30.00" fill="none" stroke="#F2F2F2" stroke-width="12"/>
|
||
<circle cx="489.76" cy="130.00" r="30.00" fill="none" stroke="#F2F2F2" stroke-width="12"/>
|
||
<circle cx="579.76" cy="130.00" r="30.00" fill="none" stroke="#F2F2F2" stroke-width="12"/>
|
||
<line x1="549.76" y1="130.00" x2="549.76" y2="196.00" stroke="#F2F2F2" stroke-width="12" stroke-linecap="round"/>
|
||
</svg>
|
||
</div><button class="lang" id="lang"></button></div>
|
||
<div class="strip"><i></i><i></i><i></i><i></i></div>
|
||
|
||
|
||
<h1>Firmware for the M-VAVE FM-1</h1>
|
||
<p class="lead">A groovebox you play live: four tracks — three synths and a drum machine — 12 synth engines (with six-operator FM and DX7 patches), 153 sounds, 37 drum kits from 808 to techno, amapiano and ambient, your own samples and drum kits, 27 punch-in effects. House, techno, hip-hop, drum & bass, synthwave, lo-fi, ambient: make what you want. No factory patterns, nothing to load: everything you hear, you play.</p>
|
||
<div class="tiles">
|
||
<div class="tile" style="--c: var(--blue)"><b>153</b><span>sounds, 12 engines, your samples</span></div>
|
||
<div class="tile" style="--c: var(--green)"><b>37</b><span>drum kits, 909 to afro, + your own</span></div>
|
||
<div class="tile" style="--c: var(--yellow)"><b>27</b><span>punch-in fx: hold fx + key</span></div>
|
||
<div class="tile" style="--c: var(--orange)"><b>rec</b><span>no click: the loop follows you</span></div>
|
||
</div>
|
||
<p data-t="intro"></p>
|
||
<p data-t="warn"></p>
|
||
<p><button id="go" disabled data-t="install"></button></p>
|
||
<progress id="bar" max="100" value="0"></progress>
|
||
<p id="status"></p>
|
||
<pre id="log"></pre>
|
||
<a class="ed" href="../editor/" data-t="editor"></a>
|
||
<p class="small"><a href="../editor/sloop-editor.html" download="sloop-editor-2.8.4.html" data-t="edOffline"></a></p>
|
||
<p><button id="app" class="ed" hidden data-t="appInstall"></button></p>
|
||
<hr>
|
||
<p class="small" data-t="direct"></p>
|
||
<p class="small" data-t="beta"></p>
|
||
<p class="small"><span data-t="brick"></span>
|
||
<a href="https://github.com/kurogedelic/FM-1-transporter" target="_blank" rel="noopener">FM-1-transporter</a></p>
|
||
<p class="small" data-t="back"></p>
|
||
<p class="small"><a href="https://www.m-vave.com/download" target="_blank" rel="noopener">www.m-vave.com/download</a></p>
|
||
<p class="small">SLOOP is based on Felucca by Leo Kuroshita (@kurogedelic), <a href="https://hugelton.com" target="_blank" rel="noopener">Hügelton Instruments</a>.
|
||
Hold OCT− alone while switching on for USB rescue.<br>
|
||
Font: Terminus (Dimitar Toshkov Zhekov, SIL OFL 1.1). Samples: Versilian Studios VSCO-2 Community Edition and VCSL (CC0 1.0), and the Hügelton Sample Pack (© Hügelton Instruments, not CC0).<br>
|
||
M-VAVE and FM-1 are trademarks of their respective owners; SLOOP is not affiliated with them.<br>
|
||
<span data-t="license"></span> <a href="https://github.com/hugelton/Felucca" target="_blank" rel="noopener">github.com/hugelton/Felucca</a></p>
|
||
</main>
|
||
<script type="module">
|
||
// SPDX-License-Identifier: GPL-3.0-only
|
||
// Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments
|
||
//
|
||
// FM-1 .fwsc packages in the browser: the package identity and the image the
|
||
// device reads during an update.
|
||
|
||
const BLOCKS = 20, BLK = 0x30, KEEP = 0x2F;
|
||
|
||
// the package identity ("FM-1_904"): one marker byte after each of the first 20 blocks
|
||
function productOf(fwsc) {
|
||
if (fwsc.length < BLOCKS * BLK) throw new Error("not an FM-1 package (too short)");
|
||
let s = "";
|
||
for (let i = 0; i < BLOCKS; i++) {
|
||
const m = fwsc[i * BLK + KEEP];
|
||
if (m !== 0x7D) s += String.fromCharCode((m - i - 1) & 0xFF);
|
||
}
|
||
return s;
|
||
}
|
||
|
||
// the image the device addresses during an update: the .fwsc without the 20 marker bytes
|
||
function logicalImage(fwsc) {
|
||
const out = new Uint8Array(fwsc.length - BLOCKS);
|
||
for (let i = 0; i < BLOCKS; i++) out.set(fwsc.subarray(i * BLK, i * BLK + KEEP), i * KEEP);
|
||
out.set(fwsc.subarray(BLOCKS * BLK), BLOCKS * KEEP);
|
||
return out;
|
||
}
|
||
|
||
// The official FM-1 V15 (M-VAVE Downloads -> PC Firmware -> FM-1 V15, FM-1.fwsc), for the return to the
|
||
// official firmware: only that exact file is accepted (its SHA-256 pins every byte: the loader, the app, the
|
||
// layout; the name of the file proves nothing). The digest is the one Felucca 1.0 pins.
|
||
const STOCK_V15_SHA256 = "db1642b2b6fa5c2cccb11ffd13878068bb28601678d3644049f99dc40e7edb8a";
|
||
const STOCK_V15_SIZE = 699956;
|
||
const STOCK_V15_PRODUCT = "FM-1_015";
|
||
|
||
async function sha256hex(bytes) {
|
||
const d = await crypto.subtle.digest("SHA-256", bytes);
|
||
return [...new Uint8Array(d)].map((x) => x.toString(16).padStart(2, "0")).join("");
|
||
}
|
||
|
||
async function validateStockPackage(bytes) {
|
||
if (bytes.length !== STOCK_V15_SIZE || await sha256hex(bytes) !== STOCK_V15_SHA256 || productOf(bytes) !== STOCK_V15_PRODUCT)
|
||
throw new Error("select the unmodified official FM-1 V15 file (FM-1.fwsc)");
|
||
return { product: STOCK_V15_PRODUCT, image: logicalImage(bytes) };
|
||
}
|
||
|
||
// SPDX-License-Identifier: GPL-3.0-only
|
||
// Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments
|
||
//
|
||
// The FM-1 USB-MIDI update protocol (M-UPGRADE compatible) over WebMIDI.
|
||
// Step 1: the running firmware reads parts of the package and stages the update
|
||
// loader. Step 2: the loader reads the whole image and writes it. In both steps
|
||
// the device sends cmd 0x30 read requests on the logical image and we answer.
|
||
|
||
const HS_QUERY = [0xF0, 0x00, 0x32, 0x45, 0x00, 0x00, 0x00, 0x40, 0x7F, 0xF7];
|
||
const UPGRADE = [0xF0, 0x22, 0x24, 0x35, 0x7F, 0xF7];
|
||
const MAXDATA = 512;
|
||
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
||
const IS_OTA = (id) => /^ota-/i.test(id.model);
|
||
// the update loader of SLOOP / Felucca packages ("ota-FM-1_9XX"). A device left in the update mode of another
|
||
// firmware (the stock updater's loader) is never written: its loader may lay the image out differently.
|
||
const OUR_LOADER = (id) => /^ota-FM-1_9\d\d$/i.test(id.text);
|
||
// the MIDI ports the installer may probe (never other gear): the FM-1 under SLOOP / Felucca ("Felucca"), under
|
||
// CLIPPER ("Clipper", its sister firmware), under a firmware named after itself ("SLOOP"), the update loaders, and
|
||
// the names Windows / macOS give the stock firmware
|
||
const FM1_PORT = /fm-1|felucca|sloop|clipper|ota|composite|sinco|usb-midi/i;
|
||
|
||
// errors carry a code the pages translate: notfound, model, stopped, noloader, lost, noreturn,
|
||
// mismatch (detail: the identity the device reports), badreq, foreign (detail: the loader's identity)
|
||
function fail(code, msg, detail = "") { const e = new Error(msg); e.code = code; e.detail = detail; return e; }
|
||
|
||
function pack7(data) {
|
||
const out = []; let acc = 0, nb = 0;
|
||
for (const b of data) {
|
||
acc |= b << nb; nb += 8;
|
||
while (nb >= 7) { out.push(acc & 0x7F); acc >>>= 7; nb -= 7; }
|
||
}
|
||
if (nb) out.push(acc & 0x7F);
|
||
return out;
|
||
}
|
||
|
||
function unpack7(s) {
|
||
const out = []; let acc = 0, nb = 0;
|
||
for (const b of s) {
|
||
acc |= (b & 0x7F) << nb; nb += 7;
|
||
while (nb >= 8) { out.push(acc & 0xFF); acc >>>= 8; nb -= 8; }
|
||
}
|
||
return out;
|
||
}
|
||
|
||
function response(addr, data, fl = 0) {
|
||
const len = data.length;
|
||
const body = [0x00, 0x59, 0x30, (len + 8) & 0xFF, ((len + 8) >> 8) & 0xFF, 0, fl,
|
||
addr & 0xFF, (addr >>> 8) & 0xFF, (addr >>> 16) & 0xFF, (addr >>> 24) & 0xFF,
|
||
len & 0xFF, (len >> 8) & 0xFF, 0, ...data];
|
||
let s = 0;
|
||
for (let i = 6; i < body.length; i++) s += body[i];
|
||
body.push(~s & 0xFF);
|
||
return [0xF0, ...pack7(body), 0xF7];
|
||
}
|
||
|
||
function parseRequest(pkt) {
|
||
if (pkt[0] !== 0xF0 || pkt[pkt.length - 1] !== 0xF7) return null;
|
||
const u = unpack7(pkt.slice(1, -1));
|
||
if (u.length !== 15 || u[0] !== 0 || u[1] !== 0x59 || u[2] !== 0x30) return null;
|
||
let s = 0;
|
||
for (let i = 6; i < 14; i++) s += u[i];
|
||
if ((~s & 0xFF) !== u[14]) return null;
|
||
return { fl: u[6], addr: (u[7] | (u[8] << 8) | (u[9] << 16) | (u[10] << 24)) >>> 0, len: u[11] | (u[12] << 8) | (u[13] << 16) };
|
||
}
|
||
|
||
function parseIdentity(pkt) {
|
||
const d = unpack7(pkt.slice(1, -1));
|
||
if (d.length !== 34 || d[0] !== 0 || d[1] !== 0x59 || d[2] !== 0x11) return null;
|
||
const txt = String.fromCharCode(...d.slice(6, 33)).replace(/\0+$/, "");
|
||
const m = /^([^_]+)_(\d+)$/.exec(txt);
|
||
return m ? { text: txt, model: m[1], version: parseInt(m[2], 10) } : null;
|
||
}
|
||
|
||
// one MIDI in/out pair with a SysEx queue
|
||
class Link {
|
||
constructor(input, output) {
|
||
this.input = input; this.output = output; this.q = []; this.waiter = null;
|
||
input.onmidimessage = (ev) => {
|
||
if (ev.data[0] !== 0xF0) return;
|
||
this.q.push(Array.from(ev.data));
|
||
if (this.waiter) { const w = this.waiter; this.waiter = null; w(); }
|
||
};
|
||
}
|
||
get lost() { return this.input.state === "disconnected" || this.output.state === "disconnected"; }
|
||
// false when the port is gone (unplugged): WebMIDI throws on a disconnected output
|
||
send(bytes) {
|
||
try { this.output.send(bytes); return true; } catch (_) { return false; }
|
||
}
|
||
drain() { this.q.length = 0; }
|
||
async read(ms) {
|
||
if (!this.q.length) {
|
||
let tm;
|
||
await Promise.race([new Promise((r) => { this.waiter = r; }), new Promise((r) => { tm = setTimeout(r, ms); })]);
|
||
clearTimeout(tm);
|
||
this.waiter = null;
|
||
}
|
||
return this.q.shift() || null;
|
||
}
|
||
// detach the callback only; do NOT close the MIDI ports. find()/probe() reuse the same input across
|
||
// several output candidates (e.g. the always-present "Microsoft GS Wavetable Synth" is probed before
|
||
// the FM-1's own output), and closing the input between candidates raced its re-open and broke the
|
||
// handshake with a device that is present ("FM-1 not found" with the port listed). Leaving ports open
|
||
// is the long-standing behaviour.
|
||
close() { this.input.onmidimessage = null; }
|
||
}
|
||
|
||
async function handshake(link, tries = 3) {
|
||
link.drain();
|
||
for (let t = 0; t < tries; t++) {
|
||
if (!link.send(HS_QUERY)) return null;
|
||
const end = Date.now() + 1000;
|
||
while (Date.now() < end) {
|
||
const p = await link.read(end - Date.now());
|
||
if (!p) break;
|
||
const id = parseIdentity(p);
|
||
if (id) return id;
|
||
}
|
||
}
|
||
return null;
|
||
}
|
||
|
||
class Updater {
|
||
constructor(access, log) {
|
||
this.access = access;
|
||
this.log = log || (() => {});
|
||
}
|
||
|
||
// one input against its candidate outputs: the matching port first (same name, or one name contains
|
||
// the other, so input "Felucca" pairs with output "MIDIOUT2 (Felucca)" without probing unrelated
|
||
// outputs like "Microsoft GS Wavetable Synth"), then (the fallback) any live output. A pair counts
|
||
// only when it answers the FM-1 handshake and passes the filter.
|
||
async probe(input, outs, filter) {
|
||
if (input.state === "disconnected") return null;
|
||
const live = outs.filter((o) => o.state !== "disconnected");
|
||
const nm = input.name || "";
|
||
const named = live.filter((o) => o.name === nm || (nm && o.name && (o.name.includes(nm) || nm.includes(o.name))));
|
||
for (const output of (named.length ? named : live)) {
|
||
try { await input.open(); await output.open(); } catch (_) { continue; }
|
||
const link = new Link(input, output);
|
||
const id = await handshake(link, 2);
|
||
if (id && (!filter || filter(id))) return { link, id, name: input.name };
|
||
link.close();
|
||
}
|
||
return null;
|
||
}
|
||
|
||
// the FM-1 (or its update loader) among the MIDI ports. Named ports first (fast, and other gear is
|
||
// never touched). With deep=true (hunting the re-enumerated update loader only), if no named port
|
||
// matched, the remaining ports are probed too and accepted SOLELY when they answer the FM-1 handshake
|
||
// (other gear returns no valid identity). Windows often names the update loader generically (e.g.
|
||
// "USB MIDI Device"), so a name filter alone misses it and the loader seems to "not appear": this
|
||
// handshake fallback is what makes the loader reliably found, without probing other gear when looking
|
||
// for the running firmware (which always names itself).
|
||
async find(filter, deep = false) {
|
||
const outs = [...this.access.outputs.values()];
|
||
const inputs = [...this.access.inputs.values()].filter((i) => i.state !== "disconnected");
|
||
for (const input of inputs)
|
||
if (FM1_PORT.test(input.name || "")) {
|
||
const dev = await this.probe(input, outs, filter);
|
||
if (dev) return dev;
|
||
}
|
||
if (deep)
|
||
for (const input of inputs)
|
||
if (!FM1_PORT.test(input.name || "")) {
|
||
const dev = await this.probe(input, outs, filter);
|
||
if (dev) return dev;
|
||
}
|
||
return null;
|
||
}
|
||
|
||
// the MIDI inputs there are, for the "not found" message: " (MIDI: a, b)" (a port the installer skipped shows)
|
||
seen() {
|
||
const names = [...this.access.inputs.values()].filter((p) => p.state !== "disconnected").map((p) => p.name || "?");
|
||
return names.length ? ` (MIDI: ${names.join(", ")})` : " (MIDI: none)";
|
||
}
|
||
|
||
async waitFor(filter, ms, deep = false) {
|
||
const end = Date.now() + ms;
|
||
while (Date.now() < end) {
|
||
const dev = await this.find(filter, deep);
|
||
if (dev) return dev;
|
||
await sleep(1000);
|
||
}
|
||
return null;
|
||
}
|
||
|
||
// serve read requests until the device asks for one of the finish addresses; stops early
|
||
// when the port disappears (lost: true) instead of waiting out idleMs
|
||
async serve(link, image, finishAddr, idleMs, onProgress) {
|
||
let served = 0, last = Date.now();
|
||
for (;;) {
|
||
const pkt = await link.read(1000);
|
||
if (!pkt) {
|
||
if (link.lost) return { served, finished: false, lost: true };
|
||
if (Date.now() - last > idleMs) return { served, finished: false };
|
||
continue;
|
||
}
|
||
const r = parseRequest(pkt);
|
||
if (!r) continue;
|
||
last = Date.now();
|
||
if (r.addr === 0xE0000000 || r.addr === 0xF0000000) {
|
||
link.send(response(r.addr, [...new TextEncoder().encode("success"), 0]));
|
||
if (r.addr === finishAddr) return { served, finished: true };
|
||
continue;
|
||
}
|
||
if (r.len > MAXDATA || r.addr + r.len > image.length) throw fail("badreq", `bad request ${r.addr.toString(16)}+${r.len}`);
|
||
await sleep(10);
|
||
if (!link.send(response(r.addr, Array.from(image.subarray(r.addr, r.addr + r.len)), r.fl))) {
|
||
return { served, finished: false, lost: true };
|
||
}
|
||
served++;
|
||
if (onProgress) onProgress(served, r.addr);
|
||
}
|
||
}
|
||
|
||
// full install: running firmware -> loader -> new firmware
|
||
async install(image, product, onStep) {
|
||
const step = onStep || (() => {});
|
||
const dev = await this.find((id) => !IS_OTA(id));
|
||
if (!dev) throw fail("notfound", "FM-1 not found (USB cable, and no other app using it?)", this.seen());
|
||
const [model] = product.split("_");
|
||
if (dev.id.model !== model) { dev.link.close(); throw fail("model", `the device is ${dev.id.text}, the package is for ${product}`); }
|
||
step("start", dev.id.text);
|
||
dev.link.send(UPGRADE);
|
||
await sleep(2000);
|
||
const s1 = await this.serve(dev.link, image, 0xE0000000, 8000, (n) => step("verify", n));
|
||
dev.link.close();
|
||
if (!s1.finished) throw fail(s1.lost ? "lost" : "stopped", `the device ${s1.lost ? "was disconnected" : "stopped"} after ${s1.served} requests: nothing was written`);
|
||
step("loader");
|
||
await sleep(3000);
|
||
const ota = await this.waitFor(IS_OTA, 60000, true);
|
||
if (!ota) throw fail("noloader", "the update loader did not appear. Replug the USB cable and press Install again: the device stays in update mode until it is finished.", this.seen());
|
||
const s2 = await this.write(ota, image, step);
|
||
if (!s2.finished) throw fail(s2.lost ? "lost" : "stopped", `the loader ${s2.lost ? "was disconnected" : "stopped"} after ${s2.served} requests. Replug and press Install again to resume.`);
|
||
step("reboot");
|
||
await sleep(3000);
|
||
const back = await this.waitFor((id) => !IS_OTA(id), 60000);
|
||
if (!back) throw fail("noreturn", "the device did not come back: power-cycle it");
|
||
back.link.close();
|
||
if (back.id.text !== product) throw fail("mismatch", `installed, but the device reports ${back.id.text}`, back.id.text);
|
||
step("done", back.id.text);
|
||
return back.id.text;
|
||
}
|
||
|
||
// step 2 with the loader found by find()/waitFor()
|
||
async write(ota, image, step) {
|
||
ota.link.send(UPGRADE);
|
||
await sleep(2000);
|
||
const s2 = await this.serve(ota.link, image, 0xF0000000, 180000, (n) => step("write", n));
|
||
ota.link.close();
|
||
return s2;
|
||
}
|
||
|
||
// resume: the device is already in update mode (loader) -> true when the write finished. Only SLOOP's
|
||
// own loader is resumed, except for the return to the official firmware (opts.product: the official
|
||
// package, its identity checked once the FM-1 is back, after Felucca 1.0): that one is the official
|
||
// loader's own image, as M-UPGRADE would write it
|
||
async resume(image, onStep, opts = {}) {
|
||
const ota = await this.find(IS_OTA, true);
|
||
if (!ota) return false;
|
||
if (!OUR_LOADER(ota.id) && !opts.product) {
|
||
ota.link.close();
|
||
throw fail("foreign", `the FM-1 is in the update mode of another firmware (${ota.id.text}): finish that update with its own updater`, ota.id.text);
|
||
}
|
||
const step = onStep || (() => {});
|
||
if (!(await this.write(ota, image, step)).finished) return false;
|
||
if (opts.product) {
|
||
step("reboot");
|
||
await sleep(3000);
|
||
const back = await this.waitFor((id) => !IS_OTA(id), 60000);
|
||
if (!back) throw fail("noreturn", "the FM-1 did not come back after the write: power-cycle it");
|
||
back.link.close();
|
||
if (back.id.text !== opts.product) throw fail("mismatch", `written, but the FM-1 reports ${back.id.text}`, back.id.text);
|
||
step("done", back.id.text);
|
||
}
|
||
return true;
|
||
}
|
||
}
|
||
|
||
const $ = (id) => document.getElementById(id);
|
||
const TEXT = {
|
||
ja: {
|
||
intro: "FM-1 を USB で接続してください。(Chrome か Edge で使えます)",
|
||
warn: "書き込み中は USB を抜かないでください。",
|
||
install: "インストール", other: "English",
|
||
editor: "エディタ(インストール後、パソコンから音色やシーケンスを編集)",
|
||
edOffline: "エディタをダウンロード(パソコンでインターネットなしで使う:ファイルを Chrome / Edge で開く)",
|
||
appInstall: "アプリとしてインストール(エディタとインストーラーがオフラインで使える・Android も)",
|
||
direct: "USB ケーブルはパソコンに直接つないでください。Probe や Transporter などの機材は不要です。",
|
||
brick: "万一インストールに失敗して起動しなくなった場合は、復旧に Transporter が必要です:",
|
||
beta: "これはベータ版で、不安定な場合があります。このカスタムファームウェアを使ったことで FM-1 が壊れたり不具合が起きたりしても、作者は一切の責任を負いません。自己責任でお使いください。",
|
||
back: "公式ファームウェアに戻すには、M-VAVE 公式のアップデーター M-UPGRADE(Downloads → PC Software → M-UPGRADE)と公式ファームウェア(PC Firmware → FM-1、V16)が必要です。",
|
||
nomidi: "このブラウザでは使えません。Chrome か Edge で開いてください。", loadfail: "読み込めませんでした: ",
|
||
start: "開始します", verify: "確認中", loader: "書き込みモードに切り替え中", write: "書き込み中",
|
||
reboot: "再起動中", done: "完了しました", stopped: "途中で止まりました。USB を挿し直してもう一度押してください。",
|
||
error: "エラー: ",
|
||
denied: "MIDI(SysEx)の使用が許可されませんでした。アドレスバーのサイト設定で MIDI を許可して、もう一度押してください。",
|
||
notfound: "FM-1 が見つかりません。USB ケーブル(データ通信用か)を確かめ、MIDI を使う他のアプリを閉じてから、もう一度押してください。",
|
||
model: "接続されている機器は FM-1 ではありません。",
|
||
lost: "USB の接続が切れました。挿し直してもう一度押してください。",
|
||
noloader: "書き込みモードの FM-1 が見つかりません。USB を挿し直してもう一度押してください(終わるまで書き込みモードのままです)。",
|
||
noreturn: "FM-1 が戻ってきません。電源を入れ直してください。",
|
||
mismatch: "書き込みは終わりましたが、FM-1 が別のバージョンを報告しています: ",
|
||
foreign: "FM-1 は別のファームウェアの書き込みモードです。そのアップデーター(M-UPGRADE)で書き込みを終えてから、もう一度インストールしてください: ",
|
||
badpkg: "インストールするファイルが壊れています。ページを再読み込みしてください。",
|
||
leave: "書き込み中です。ページを閉じないでください。",
|
||
license: "GPL-3.0、無保証。ソース:",
|
||
stockTitle: "公式ファームウェア(V15)に戻す",
|
||
stockHelp: "M-VAVE のサイトから公式の FM-1 V15 をダウンロードし、中の FM-1.fwsc(変更していないもの)を選んでください。ファイルはこのブラウザの中で確認され、どこにも送られません。",
|
||
stockBackup: "公式ファームウェアは SLOOP の曲・プロジェクト・サンプルを開けません。先にエディタでバックアップを保存してください(Projects → Backup)。SLOOP を入れ直せば、エディタから復元できます。",
|
||
stockEditor: "エディタを開いてバックアップする", stockSaved: "バックアップをパソコンに保存しました",
|
||
stockFile: "公式の FM-1.fwsc", stockGo: "公式 V15 をインストール",
|
||
stockValid: "公式 V15 を確認しました", stockBad: "公式 V15 ではありません: ",
|
||
stockConfirm: "FM-1 に公式 V15 をインストールします。SLOOP の曲は公式ファームウェアでは開けません。バックアップは保存しましたか?",
|
||
stockFinish: "FM-1 は SLOOP の書き込みモードです。先に「インストール」で SLOOP の書き込みを終えてから、公式 V15 に戻してください。",
|
||
back: "公式ファームウェアに戻すには、M-VAVE 公式のアップデーター M-UPGRADE(Downloads → PC Software → M-UPGRADE)と公式ファームウェアを使ってください。FM-1 が見つからない場合は、MIDI を使う他のアプリとブラウザのタブを閉じてください。それでも見つからない場合は、Clipper のインストールページを開き、その「Return to the official firmware」を使ってください(Clipper を入れる必要はありません)。",
|
||
},
|
||
en: {
|
||
intro: "Connect the FM-1 by USB. (Works in Chrome or Edge.)",
|
||
warn: "Do not unplug the USB cable while writing.",
|
||
install: "Install", other: "日本語",
|
||
editor: "Editor (after installing: edit sounds and sequences from the computer)",
|
||
edOffline: "Download the editor to use it without internet on a computer (open the file in Chrome or Edge)",
|
||
appInstall: "Install the app (the editor and the installer offline, Android too)",
|
||
direct: "Connect the USB cable directly to the computer. No probe or Transporter is needed.",
|
||
brick: "If an install fails and the FM-1 no longer starts, recovering it needs a Transporter:",
|
||
beta: "This is a beta and may be unstable. The author accepts no responsibility if your FM-1 is damaged or misbehaves because of this custom firmware. Use it at your own risk.",
|
||
back: "To go back to the official firmware you need M-VAVE's official updater, M-UPGRADE (Downloads → PC Software → M-UPGRADE), and the official firmware (PC Firmware → FM-1, V16).",
|
||
nomidi: "This browser cannot do it. Open the page in Chrome or Edge.", loadfail: "Could not load: ",
|
||
start: "Starting", verify: "Verifying", loader: "Switching to update mode", write: "Writing",
|
||
reboot: "Restarting", done: "Done", stopped: "Stopped. Replug the USB cable and press Install again.",
|
||
error: "Error: ",
|
||
denied: "MIDI (SysEx) access was not allowed. Allow MIDI in the site settings (address bar) and press Install again.",
|
||
notfound: "FM-1 not found. Check the USB cable (a data cable), close other apps that use MIDI, and press Install again.",
|
||
model: "The connected device is not an FM-1.",
|
||
lost: "The USB connection was lost. Replug it and press Install again.",
|
||
noloader: "The FM-1 in update mode was not found. Replug the USB cable and press Install again (it stays in update mode until it is finished).",
|
||
noreturn: "The FM-1 did not come back. Power-cycle it.",
|
||
mismatch: "Written, but the FM-1 reports another version: ",
|
||
foreign: "The FM-1 is in the update mode of another firmware. Finish that update with its own updater (M-UPGRADE), then press Install again: ",
|
||
badpkg: "The file to install is damaged. Reload the page.",
|
||
leave: "Writing. Do not close the page.",
|
||
license: "GPL-3.0, no warranty. Source:",
|
||
stockTitle: "Return to the official firmware (V15)",
|
||
stockHelp: "Download the official FM-1 V15 from M-VAVE and select the FM-1.fwsc inside it, unmodified. The file is checked in this browser; it is not sent anywhere.",
|
||
stockBackup: "The official firmware cannot open SLOOP's music, projects or samples. Save a backup with the editor first (Projects → Backup); reinstall SLOOP and restore it from the editor whenever you want them back.",
|
||
stockEditor: "Open the editor to back up", stockSaved: "I saved a backup on this computer",
|
||
stockFile: "The official FM-1.fwsc", stockGo: "Install the official V15",
|
||
stockValid: "Official V15 verified", stockBad: "Not the official V15: ",
|
||
stockConfirm: "Install the official V15 on the FM-1? The official firmware cannot open SLOOP's music. Did you save a backup?",
|
||
stockFinish: "The FM-1 is in SLOOP's update mode. Press Install to finish the SLOOP update first, then return to the official V15.",
|
||
back: "To return to the official firmware, use M-VAVE's own updater, M-UPGRADE (Downloads → PC Software → M-UPGRADE), with the official firmware from M-VAVE (PC Firmware → FM-1, V16). If it does not find the FM-1, close every other app and browser tab that uses MIDI; if it still does not, open Clipper's installer page and use its Return to the official firmware (no need to install Clipper).",
|
||
},
|
||
};
|
||
let lang = (navigator.language || "en").toLowerCase().startsWith("ja") ? "ja" : "en";
|
||
const t = (k) => TEXT[lang][k];
|
||
let lastKey = null, lastArg = "";
|
||
function applyLang() {
|
||
document.documentElement.lang = lang;
|
||
document.querySelectorAll("[data-t]").forEach((e) => { e.textContent = t(e.dataset.t); });
|
||
$("lang").textContent = t("other");
|
||
if (lastKey) $("status").textContent = t(lastKey) + lastArg;
|
||
}
|
||
$("lang").addEventListener("click", () => { lang = lang === "ja" ? "en" : "ja"; applyLang(); });
|
||
applyLang();
|
||
/* the site without internet (SLOOP 2.6, webapp/sw.js): opened once online, the installer, the firmware and the
|
||
* editor work offline too, still on https (Android: a downloaded file opens as content://, where Chrome refuses MIDI) */
|
||
if ("serviceWorker" in navigator && /^https?:$/.test(location.protocol))
|
||
navigator.serviceWorker.register("../sw.js").catch(() => {});
|
||
{
|
||
let ask = null;
|
||
window.addEventListener("beforeinstallprompt", (e) => { e.preventDefault(); ask = e; $("app").hidden = false; });
|
||
window.addEventListener("appinstalled", () => { ask = null; $("app").hidden = true; });
|
||
$("app").addEventListener("click", async () => {
|
||
if (!ask) return;
|
||
ask.prompt();
|
||
await ask.userChoice.catch(() => {});
|
||
ask = null;
|
||
$("app").hidden = true;
|
||
});
|
||
}
|
||
const sayK = (k, arg = "") => { lastKey = k; lastArg = arg; $("status").textContent = t(k) + arg; };
|
||
const say = (txt) => { lastKey = null; $("status").textContent = txt; };
|
||
const log = (t) => { $("log").textContent += t + "\n"; };
|
||
let image = null;
|
||
const meta = {"version": "2.8.4", "product": "FM-1_900", "pkg": "../../firmware/sloop-2.8.4.fwsc", "sha256": "5a6a0843c868650dba6718cf85e43e719aec18c3dc5cc803c57c38b382158d4e"};
|
||
|
||
let writing = false;
|
||
const lockAll = (on) => {
|
||
writing = on;
|
||
$("go").disabled = on || !image;
|
||
};
|
||
window.addEventListener("beforeunload", (e) => { if (writing) { e.preventDefault(); e.returnValue = t("leave"); } });
|
||
|
||
(async () => {
|
||
if (!navigator.requestMIDIAccess) { sayK("nomidi"); return; }
|
||
try {
|
||
/* (2.7) never the browser's old copy: a new build keeps the file's name (sloop-2.7.fwsc), and a copy kept from the
|
||
build before is "damaged" here. no-cache asks the server first; a mismatch is fetched once more, bypassing the cache */
|
||
const sha = async (pkg) => [...new Uint8Array(await crypto.subtle.digest("SHA-256", pkg))].map((b) => b.toString(16).padStart(2, "0")).join("");
|
||
const get = async (cache) => {
|
||
const r = await fetch(meta.pkg, { cache });
|
||
if (!r.ok) throw new Error(`${meta.pkg}: HTTP ${r.status}`);
|
||
return new Uint8Array(await r.arrayBuffer());
|
||
};
|
||
const check = meta.sha256 && self.crypto && crypto.subtle;
|
||
let pkg = await get("no-cache");
|
||
if (check && (await sha(pkg)) !== meta.sha256) pkg = await get("reload");
|
||
if (productOf(pkg) !== meta.product) { sayK("badpkg"); return; }
|
||
if (check) { /* a damaged download is never offered (the loader checks its CRC too) */
|
||
const h = await sha(pkg);
|
||
if (h !== meta.sha256) { sayK("badpkg"); log(`sha256 ${h}, expected ${meta.sha256}`); return; }
|
||
}
|
||
image = logicalImage(pkg);
|
||
say(`SLOOP ${meta.version}`);
|
||
lockAll(writing);
|
||
} catch (e) { sayK("loadfail", e.message); }
|
||
})();
|
||
|
||
const total = 74 + 1179; /* reads: step 1, step 2 (head + app area, SLOOP 2.0 loader) */
|
||
const step = (k, a) => {
|
||
log(`${k} ${a ?? ""}`);
|
||
if (k === "start") sayK("start");
|
||
if (k === "verify") { sayK("verify"); $("bar").value = Math.min(100, (a / total) * 100); }
|
||
if (k === "loader") sayK("loader");
|
||
if (k === "write") { sayK("write"); $("bar").value = Math.min(100, ((74 + a) / total) * 100); }
|
||
if (k === "reboot") sayK("reboot");
|
||
if (k === "done") { $("bar").value = 100; sayK("done"); }
|
||
};
|
||
const failed = (e) => {
|
||
if (e && e.code && TEXT[lang][e.code]) sayK(e.code, e.detail || "");
|
||
else sayK("error", e && e.message);
|
||
log(String(e && e.stack || e));
|
||
};
|
||
|
||
$("go").addEventListener("click", async () => {
|
||
if (writing) return;
|
||
lockAll(true);
|
||
let midi;
|
||
try { midi = await navigator.requestMIDIAccess({ sysex: true }); }
|
||
catch (e) { sayK("denied"); lockAll(false); return; }
|
||
try {
|
||
const up = new Updater(midi, log);
|
||
const ota = await up.find((id) => /^ota-/i.test(id.model), true);
|
||
if (ota) {
|
||
ota.link.close();
|
||
sayK((await up.resume(image, step)) ? "done" : "stopped");
|
||
} else {
|
||
await up.install(image, meta.product, step);
|
||
}
|
||
} catch (e) { failed(e); }
|
||
lockAll(false);
|
||
});
|
||
|
||
/* Returning to the official firmware is done with M-VAVE's own updater (M-UPGRADE): the in-browser
|
||
revert was removed because it is not reliable on every system. The note under "stockTitle" points there. */
|
||
</script>
|
||
</body>
|
||
</html>
|