Files
JIANT/web/emu/devices.html
T
Claude 0d40a294d3 devices.html: the SMK-37 with the buttons printed on it (FX SCALE CHORD NOTE REPEAT PARA GLOBE PATCH BT ... K1-K8), its pads the FM-1's 16 white keys
As Melodee names and maps them, tried on an SMK-37 Elite: K5 MASTER, K6
SELECT, K7 ALGORITHM, K8 PRESETS, < > one step of SELECT, the pads the
FM-1's step grid with the lowest notes on the bottom row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UVqsRpEnNJfjWWrH3C4opq
2026-11-20 17:14:24 +00:00

654 lines
36 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!doctype html>
<!-- SPDX-License-Identifier: GPL-3.0-only
Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant)
JIANT FM on every device it runs on, in the browser: one firmware (felucca.wasm, the FM-1's own code, and
worklet.js, as index.html runs it), each device's own panel. FM-1: the emulator (index.html) itself. SMK-37 Pro /
Elite and MPC Sample: their panels here, mapped to the FM-1's as the ports map them (ports/README.md;
ports/mpc-sample/src/jiant/panel_map.h for the MPC). The music saved is the same on all of them (the flash kept in
this browser, as index.html keeps it). -->
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>JIANT FM devices</title>
<meta name="description" content="JIANT FM on the M-VAVE FM-1, the M-VAVE SMK-37 and the Akai MPC Sample, in your browser: pick a device, play it with its own panel.">
<style>
@font-face { font-family: "DotGothic16"; src: url("fonts/DotGothic16-subset.woff") format("woff"); font-display: swap; }
:root { --bg: #8e8e93; --fg: #111; --dim: #2c2c2e; --rule: #5a5a5e;
--body: #1d1d1f; --tray: #141415; --part: #2a2a2d; --edge: #3a3a3e; --label: #d6d6d8;
--lit: #fff4d6; --green: #5fe08a; --accent: #ff7a00; color-scheme: light; }
html, body { background: var(--bg); }
body { margin: 0; color: var(--fg); font: 13px/1.6 -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif; }
main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 32px; }
h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: .02em; }
.lede { margin: 0 0 14px; color: var(--dim); max-width: 60em; }
.picker { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0 0 16px; }
.picker button { font: inherit; text-align: left; padding: 10px 12px; border: 1px solid var(--rule); border-radius: 10px;
background: #a7a7ac; color: var(--fg); cursor: pointer; min-width: 0; }
.picker button[aria-pressed="true"] { background: var(--body); color: #f2f2f4; border-color: var(--body); }
.picker b { display: block; font-size: 15px; }
.picker small { display: block; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: .06em; padding: 0 6px; border-radius: 6px;
margin-left: 6px; vertical-align: 2px; background: var(--green); color: #0d2414; }
.chip.dev { background: var(--accent); color: #1d1d1f; }
@media (max-width: 640px) { .picker small { display: none; } .chip { display: none; } }
.stage { position: relative; }
.fm1 { width: 100%; border: 0; display: block; min-height: 600px; background: var(--bg); }
.device { position: relative; width: 100%; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.device svg { display: block; width: 100%; height: auto; touch-action: none; }
.device canvas { position: absolute; image-rendering: pixelated; background: #000; pointer-events: none; }
.ctl { cursor: pointer; }
.ctl.knob, .ctl.fader { cursor: ns-resize; }
.ctl:focus { outline: none; }
.ctl:focus-visible .face { stroke: var(--lit); stroke-width: 3; }
.face { transition: fill .05s; }
.btn .face { fill: var(--part); stroke: var(--edge); stroke-width: 1.5; }
.btn.dim .face { fill: #3a3934; }
.btn.lit .face { fill: var(--lit); }
.btn.lit text { fill: #1d1d1f; }
.btn.green .face { fill: var(--green); }
.btn.green text { fill: #0d2414; }
.btn.port .face { fill: #232326; stroke-dasharray: 3 3; }
.btn.on .face { stroke: var(--accent); stroke-width: 3; }
.held .face { stroke: var(--lit); stroke-width: 3; }
.pad .face { fill: #26262a; stroke: #3c3c41; stroke-width: 1.5; }
.key .face { stroke: #2a2a2e; stroke-width: 1.2; }
.key.white .face { fill: #ededef; }
.key.black .face { fill: #151517; }
.key.off .face { opacity: .45; }
.key.white.lit .face { fill: #ffd29e; }
.key.black.lit .face { fill: #b45400; }
.key.held .face { fill: var(--accent); }
.start { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px;
background: rgba(0, 0, 0, .5); border-radius: 20px; }
.start[hidden] { display: none; }
.start button { font: inherit; font-size: 18px; padding: 12px 28px; background: #fff; color: #000; border: 0; cursor: pointer; }
.start button:disabled { opacity: .4; cursor: progress; }
.start p { margin: 0; max-width: 32em; text-align: center; color: #fff; }
.map { margin: 14px 0 0; color: var(--dim); columns: 2 22em; column-gap: 32px; }
.map p { margin: 0 0 4px; break-inside: avoid; }
.note { margin: 10px 0 0; color: var(--dim); }
kbd { font: 600 11px ui-monospace, Menlo, monospace; border: 1px solid var(--rule); padding: 0 4px; color: var(--fg); }
footer { margin-top: 20px; font-size: 12px; color: var(--dim); text-align: center; }
footer a { color: inherit; }
</style>
</head>
<body>
<main>
<h1>JIANT FM, on every device</h1>
<p class="lede">One firmware, the FM-1's own code, on each device with that device's own panel. Pick one and switch it
on; what you save on one is there on the others.</p>
<div class="picker" role="group" aria-label="Device">
<button type="button" data-dev="fm1"><b>M-VAVE FM-1<span class="chip">TODAY</span></b><small>27 keys · 14 buttons · 7 encoders</small></button>
<button type="button" data-dev="smk37"><b>M-VAVE SMK-37<span class="chip dev">IN DEVELOPMENT</span></b><small>37 keys · 16 pads · 8 encoders · 4 faders</small></button>
<button type="button" data-dev="mpc"><b>Akai MPC Sample<span class="chip dev">PREVIEW</span></b><small>16 pads · 3 knobs · fader · wheel</small></button>
</div>
<div class="stage" id="stage"></div>
<div id="info"></div>
<footer>
JIANT FM by Juan Jiant · <a href="https://www.gnu.org/licenses/gpl-3.0.html">GPL-3.0</a> ·
<a href="index.html">FM-1 emulator alone</a> · <a href="https://github.com/juanjiant-bit/JIANT/tree/main/ports">The ports</a><br>
M-VAVE, FM-1, SMK-37, Akai and MPC are trademarks of their owners; JIANT is not affiliated with or endorsed by them.
The SMK-37 and MPC panels are drawings of their controls, not their exact look.
</footer>
</main>
<script type="module">
const NS = "http://www.w3.org/2000/svg";
const STORE = "felucca-emu-flash"; // (index.html's: the same music on every device)
// the FM-1's panel as the firmware reads it (panel.c): buttons by label, encoders by role, keys F3..G5
const B = { FX: 0, SCL: 1, ENV: 2, LFO: 3, EDIT: 4, GLO: 5, HOME: 6, SAVE: 7, ARP: 8, SEQ: 9, PLAY: 10, REC: 11, "OCT-": 12, "OCT+": 13 };
const EN = { SELECT: 0, ALGORITHM: 1, PRESETS: 2, K1: 3, K2: 4, K3: 5, K4: 6 };
const PLAY_GREEN = 14, FM1_KEYS = 27;
const WINDOWS = [0, 4, 8, 11]; // pads -> keys: bank A F3..G#4, B A3..C5, C C#4..E5, D E4..G5
const NOTES = ["C", "C♯", "D", "D♯", "E", "F", "F♯", "G", "G♯", "A", "A♯", "B"];
const noteName = (midi) => NOTES[midi % 12] + (Math.floor(midi / 12) - 1);
const fm1KeyName = (k) => noteName(53 + k);
// ------------------------------------------------------------------ the firmware in an AudioWorklet
const emu = {
node: null, ac: null, btn: new Map(), key: new Map(), btnMask: -1, keyMask: -1, leds: [0, 0, 0, 0], fb: null,
send(m) { if (this.node) this.node.port.postMessage(m); },
syncButtons() {
let m = 0;
for (const b of this.btn.values()) m |= 1 << b;
if (m !== this.btnMask) { this.btnMask = m; this.send({ type: "buttons", mask: m }); }
},
syncKeys() {
let m = 0;
for (const k of this.key.values()) if (k >= 0 && k < FM1_KEYS) m |= 1 << k;
if (m !== this.keyMask) { this.keyMask = m; this.send({ type: "keys", mask: m }); }
},
press(id, bit) { this.btn.set(id, bit); this.syncButtons(); },
unpress(id) { if (this.btn.delete(id)) this.syncButtons(); },
keyDown(id, k) { this.key.set(id, k); this.syncKeys(); },
keyUp(id) { if (this.key.delete(id)) this.syncKeys(); },
enc(role, n) { if (n) this.send({ type: "enc", role, n }); },
master(v) { this.send({ type: "master", value: Math.max(0, Math.min(1023, Math.round(v))) }); },
midi(a, b, c) { this.send({ type: "midi", data: [a, b, c] }); },
playing() { return !!(this.leds[0] & (1 << PLAY_GREEN)) || !!(this.leds[0] & (1 << B.PLAY)); },
async start(onFrame, master) {
const ac = new AudioContext({ sampleRate: 44100, latencyHint: "interactive" });
const [wasm] = await Promise.all([
fetch("felucca.wasm", { cache: "no-cache" }).then((r) => { if (!r.ok) throw new Error(`felucca.wasm: ${r.status}`); return r.arrayBuffer(); }),
ac.audioWorklet.addModule("worklet.js?v=" + Date.now())]);
const node = new AudioWorkletNode(ac, "felucca", { numberOfInputs: 0, numberOfOutputs: 1, outputChannelCount: [2] });
node.connect(ac.destination);
await new Promise((res, rej) => {
node.port.onmessage = (e) => {
const m = e.data;
if (m.type === "ready") res();
else if (m.type === "error") rej(new Error(m.message));
else if (m.type === "frame") {
if (m.leds) this.leds = m.leds;
if (m.fb) this.fb = m.fb;
onFrame(m.fb, m.leds ? m.leds : null);
if (m.sectors) saveFlash(m.sectors);
}
};
node.port.postMessage({ type: "load", wasm, sectors: loadFlash(), master }, [wasm]);
});
await ac.resume();
this.ac = ac; this.node = node; this.btnMask = this.keyMask = -1;
this.syncButtons(); this.syncKeys();
this.send({ type: "visible", on: !document.hidden });
},
stop() {
if (this.node) { this.node.port.onmessage = null; this.node.disconnect(); }
if (this.ac) this.ac.close().catch(() => {});
this.node = this.ac = null; this.btn.clear(); this.key.clear(); this.leds = [0, 0, 0, 0]; this.fb = null;
},
};
document.addEventListener("visibilitychange", () => emu.send({ type: "visible", on: !document.hidden }));
function loadFlash() {
try {
const raw = JSON.parse(localStorage.getItem(STORE) || "{}"), out = {};
for (const [off, b64] of Object.entries(raw)) out[off] = Uint8Array.from(atob(b64), (c) => c.charCodeAt(0));
return out;
} catch { return {}; }
}
function saveFlash(sectors) {
try {
const raw = {};
for (const [off, u8] of Object.entries(sectors)) {
let s = "";
for (let i = 0; i < u8.length; i += 4096) s += String.fromCharCode.apply(null, u8.subarray(i, i + 4096));
raw[off] = btoa(s);
}
localStorage.setItem(STORE, JSON.stringify(raw));
} catch { /* private mode, full: this session only */ }
}
// the FM-1's 240 x 240 frame (RGB565, the panel's byte order) into a canvas at (x, y)
function blitScreen(ctx, fb, x, y) {
if (!fb) return;
const img = blitScreen.img || (blitScreen.img = ctx.createImageData(240, 240)), d = img.data;
for (let i = 0; i < 240 * 240; i++) {
const v = fb[i], p = ((v >> 8) | (v << 8)) & 0xFFFF;
d[i * 4] = ((p >> 11) & 31) * 255 / 31; d[i * 4 + 1] = ((p >> 5) & 63) * 255 / 63;
d[i * 4 + 2] = (p & 31) * 255 / 31; d[i * 4 + 3] = 255;
}
ctx.putImageData(img, x, y);
}
// ------------------------------------------------------------------ drawing a panel
let svg = null;
function el(tag, attrs, parent = svg) {
const e = document.createElementNS(NS, tag);
for (const [k, v] of Object.entries(attrs)) e.setAttribute(k, v);
parent.appendChild(e);
return e;
}
const SANS = "-apple-system, 'Helvetica Neue', Arial, sans-serif", DOT = "'DotGothic16', " + SANS;
function label(parent, x, y, s, size, font = SANS, ink = "var(--label)") {
const t = el("text", { x, y, "text-anchor": "middle", "font-family": font, "font-size": size, "font-weight": 600,
fill: ink, "letter-spacing": ".04em", "pointer-events": "none" }, parent);
t.textContent = s;
return t;
}
function control(cls, name) {
const g = el("g", { class: "ctl " + cls, tabindex: 0, role: cls.includes("knob") || cls.includes("fader") ? "slider" : "button",
"aria-label": name });
g.addEventListener("contextmenu", (e) => e.preventDefault());
return g;
}
// a held control: down(id) on press, up(id) on release (pointer, Enter / Space)
function holdable(g, down, up) {
const ids = new Set();
g.addEventListener("pointerdown", (e) => {
e.preventDefault(); g.setPointerCapture(e.pointerId);
const id = "p" + e.pointerId; ids.add(id); g.classList.add("held"); down(id, e);
});
const end = (e) => { const id = "p" + e.pointerId; if (ids.delete(id)) { if (!ids.size) g.classList.remove("held"); up(id); } };
for (const t of ["pointerup", "pointercancel", "lostpointercapture"]) g.addEventListener(t, end);
g.addEventListener("keydown", (e) => {
if ((e.key === "Enter" || e.key === " ") && !e.repeat && !ids.has("f")) { e.preventDefault(); ids.add("f"); g.classList.add("held"); down("f", e); }
});
g.addEventListener("keyup", (e) => { if ((e.key === "Enter" || e.key === " ") && ids.delete("f")) { if (!ids.size) g.classList.remove("held"); up("f"); } });
}
// an endless encoder: n detents (drag up, wheel, arrows)
function turnable(g, turn, step = 8) {
let drag = null, wheel = 0;
g.addEventListener("pointerdown", (e) => { e.preventDefault(); g.setPointerCapture(e.pointerId); drag = { y: e.clientY, acc: 0 }; });
g.addEventListener("pointermove", (e) => {
if (!drag) return;
drag.acc += drag.y - e.clientY; drag.y = e.clientY;
const n = Math.trunc(drag.acc / step);
if (n) { drag.acc -= n * step; turn(n); }
});
for (const t of ["pointerup", "pointercancel"]) g.addEventListener(t, () => { drag = null; });
g.addEventListener("wheel", (e) => {
e.preventDefault();
const dy = e.deltaMode === 1 ? e.deltaY * 33 : e.deltaY;
if (Math.abs(dy) >= 50) { turn(dy < 0 ? 1 : -1); wheel = 0; return; }
wheel -= dy;
const n = Math.trunc(wheel / 25);
if (n) { wheel -= n * 25; turn(n); }
}, { passive: false });
g.addEventListener("keydown", (e) => {
const d = { ArrowUp: 1, ArrowRight: 1, ArrowDown: -1, ArrowLeft: -1 }[e.key];
if (d) { e.preventDefault(); e.stopPropagation(); turn(d); }
});
}
// an absolute control, 0..127 (a pot, a fader): set(v) on every change; vertical drag, wheel, arrows
function positional(g, get, set, span = 220) {
let drag = null;
g.addEventListener("pointerdown", (e) => { e.preventDefault(); g.setPointerCapture(e.pointerId); drag = { y: e.clientY, v: get() }; });
g.addEventListener("pointermove", (e) => {
if (!drag) return;
const v = Math.max(0, Math.min(127, Math.round(drag.v + (drag.y - e.clientY) * 127 / span)));
if (v !== get()) set(v);
});
for (const t of ["pointerup", "pointercancel"]) g.addEventListener(t, () => { drag = null; });
g.addEventListener("wheel", (e) => { e.preventDefault(); set(Math.max(0, Math.min(127, get() + (e.deltaY < 0 ? 2 : -2)))); }, { passive: false });
g.addEventListener("keydown", (e) => {
const d = { ArrowUp: 2, ArrowRight: 2, ArrowDown: -2, ArrowLeft: -2 }[e.key];
if (d) { e.preventDefault(); e.stopPropagation(); set(Math.max(0, Math.min(127, get() + d))); }
});
}
function button(x, y, w, h, name, opts = {}) {
const g = control("btn" + (opts.port ? " port" : ""), name);
el("rect", { x, y, width: w, height: h, rx: 7, class: "face" }, g);
const lines = name.split("\n");
lines.forEach((s, i) => label(g, x + w / 2, y + h / 2 + 4 + (i - (lines.length - 1) / 2) * 12, s, opts.size || 11,
SANS, opts.ink));
return g;
}
function knob(x, y, r, name, pointer = false) {
const g = control("knob", name);
el("circle", { cx: x, cy: y, r: r + 5, fill: "var(--tray)" }, g);
el("circle", { cx: x, cy: y, r, fill: "var(--part)", stroke: "var(--edge)", "stroke-width": 2, class: "face" }, g);
const ind = el("line", { x1: x, y1: y - r + 4, x2: x, y2: y - r + (pointer ? 13 : 9), stroke: "var(--label)",
"stroke-width": 3, "stroke-linecap": "round" }, g);
label(g, x, y - r - 11, name, 13, DOT);
return { g, rotate: (deg) => ind.setAttribute("transform", `rotate(${deg} ${x} ${y})`) };
}
function fader(x, y, w, h, name) {
const g = control("fader", name);
el("rect", { x: x + w / 2 - 3, y, width: 6, height: h, rx: 3, fill: "#0b0b0c" }, g);
el("rect", { x, y: y - 8, width: w, height: h + 16, fill: "transparent" }, g);
const cap = el("rect", { x, y: y + h - 10, width: w, height: 20, rx: 4, fill: "#d6d6d8", class: "face" }, g);
label(g, x + w / 2, y + h + 26, name, 12, DOT);
return { g, place: (v) => cap.setAttribute("y", y + h - 10 - v / 127 * h) };
}
function keybed(x, y, w, h, first, count, opts) {
// first: the first key's MIDI note; white keys across w, black ones over them
const whites = [], keys = [];
for (let m = first; m < first + count; m++) if (![1, 3, 6, 8, 10].includes(m % 12)) whites.push(m);
const kw = w / whites.length;
el("rect", { x: x - 6, y: y - 6, width: w + 12, height: h + 12, rx: 10, fill: "var(--tray)" });
const make = (m, black) => {
const i = whites.indexOf(black ? m - 1 : m), g = control("key " + (black ? "black" : "white"), noteName(m));
const bx = black ? x + (i + 1) * kw - kw * 0.32 : x + i * kw + 1;
el("rect", { x: bx, y, width: black ? kw * 0.64 : kw - 2, height: black ? h * 0.6 : h, rx: 3, class: "face" }, g);
if (!black && m % 12 === 0) label(g, bx + (kw - 2) / 2, y + h - 8, noteName(m), 9, SANS, "#666");
keys.push({ m, g });
opts.bind(g, m);
};
whites.forEach((m) => make(m, false));
for (let m = first; m < first + count; m++) if ([1, 3, 6, 8, 10].includes(m % 12)) make(m, true);
return keys;
}
const padLit = (g, rgb) => { g.querySelector(".face").style.fill = rgb || ""; };
// the computer keyboard as the FM-1's keys (as index.html: Z..' and Q..O), arrows SELECT / ALGORITHM
const KEYCODES = {};
[0, 2, 4, 6, 7, 9, 11, 12, 14, 16].forEach((k, i) => KEYCODES[["KeyZ", "KeyX", "KeyC", "KeyV", "KeyB", "KeyN", "KeyM", "Comma", "Period", "Slash"][i]] = k);
[["KeyS", 1], ["KeyD", 3], ["KeyF", 5], ["KeyH", 8], ["KeyJ", 10], ["KeyL", 13], ["Semicolon", 15], ["Quote", 17]].forEach(([c, k]) => KEYCODES[c] = k);
["KeyQ", "KeyW", "KeyE", "KeyR", "KeyT", "KeyY", "KeyU", "KeyI", "KeyO"].forEach((c, i) => KEYCODES[c] = 18 + i);
const ARROWS = { ArrowUp: [EN.SELECT, 1], ArrowDown: [EN.SELECT, -1], ArrowRight: [EN.ALGORITHM, 1], ArrowLeft: [EN.ALGORITHM, -1] };
addEventListener("keydown", (e) => {
if (!emu.node || e.metaKey || e.ctrlKey || e.altKey || e.target.closest?.(".ctl")) return;
if (ARROWS[e.code]) { e.preventDefault(); emu.enc(...ARROWS[e.code]); return; }
if (KEYCODES[e.code] === undefined) return;
e.preventDefault();
if (!e.repeat) emu.keyDown("k" + e.code, KEYCODES[e.code]);
});
addEventListener("keyup", (e) => emu.keyUp("k" + e.code));
addEventListener("blur", () => { for (const id of [...emu.key.keys()]) if (id[0] === "k") emu.keyUp(id); });
// ------------------------------------------------------------------ the devices
// Each: build(stage) draws its panel, binds its controls to the FM-1's and returns { frame(fb, leds), info }.
// M-VAVE SMK-37 Pro / Elite: the FM-1's chip, its 240 x 240 screen; the mapping the SMK-37 build of JIANT will have
// the buttons as printed on the SMK-37 (Melodee's SMK37.md, tried on an SMK-37 Elite): [label, the FM-1's button or a
// port's own role]
const SMK_BUTTONS = [
["FX", "FX"], ["SCALE", "SCL"], ["CHORD", "ENV"], ["NOTE\nREPEAT", "LFO"], ["PARA", "EDIT"], ["GLOBE", "GLO"],
["PATCH", "HOME"], ["BT", "SAVE"], ["ARP", "ARP"], ["SEQ", "SEQ"], ["SEQ\nPLAY", "PLAY"], ["SEQ\nREC", "REC"],
["OCTAVE -", "OCT-"], ["OCTAVE +", "OCT+"], ["KNOB\nBANK", "none"], ["FADER\nBANK", "bank"], ["<", "prev"], [">", "next"],
];
const SMK_ENCODERS = [["K1", EN.K1], ["K2", EN.K2], ["K3", EN.K3], ["K4", EN.K4],
["K5", "master"], ["K6", EN.SELECT], ["K7", EN.ALGORITHM], ["K8", EN.PRESETS]];
const SMK_FADER_BANKS = [ // bank A the levels of tracks 1-4 (CC7, channels 1-4); B track 1's CUTOFF, RESO, REVERB, DELAY
{ name: "LEVEL T1-T4", cc: (i) => [0xB0 | i, 7] },
{ name: "T1 CUT RES REV DLY", cc: (i) => [0xB0, [74, 71, 91, 94][i]] },
];
// the pads: the FM-1's 16 white keys (its step grid), the lowest on the bottom row
const WHITE_KEYS = [0, 2, 4, 6, 7, 9, 11, 12, 14, 16, 18, 19, 21, 23, 24, 26];
const smkPadKey = (p) => WHITE_KEYS[p < 8 ? p + 8 : p - 8];
function buildSMK(stage) {
const W = 1400, H = 620;
const dev = document.createElement("div");
dev.className = "device";
stage.appendChild(dev);
svg = document.createElementNS(NS, "svg");
svg.setAttribute("viewBox", `0 0 ${W} ${H}`);
dev.appendChild(svg);
el("rect", { x: 4, y: 4, width: W - 8, height: H - 8, rx: 28, fill: "var(--body)" });
label(svg, 90, 42, "SMK-37", 18, DOT, "#8a8a8e");
// the screen (the FM-1's: 240 x 240)
const S = [196, 26, 268];
el("rect", { x: S[0], y: S[1], width: S[2], height: S[2], rx: 14, fill: "#0b0b0c" });
const canvas = document.createElement("canvas");
canvas.width = canvas.height = 240;
Object.assign(canvas.style, { left: `${(S[0] + 14) / W * 100}%`, top: `${(S[1] + 14) / H * 100}%`, width: `${240 / W * 100}%` });
dev.appendChild(canvas);
const ctx = canvas.getContext("2d");
let bank = 0, masterValue = 700;
// wheels
const wheel = (x, name, onValue, spring) => {
const f = fader(x, 90, 34, 170, name);
let v = spring ? 64 : 0;
f.place(v);
positional(f.g, () => v, (nv) => { v = nv; f.place(v); onValue(v); }, 170);
if (spring) f.g.addEventListener("pointerup", () => { v = 64; f.place(v); onValue(64); });
};
wheel(40, "PITCH", (v) => { const b = Math.min(16383, v * 129); emu.midi(0xE0, b & 127, b >> 7); }, true);
wheel(110, "MOD", (v) => emu.midi(0xB0, 1, v), false);
// encoders: K1..K4 on top, K5 (MASTER) K6 (SELECT) K7 (ALGORITHM) K8 (PRESETS) under them
SMK_ENCODERS.forEach(([name, role], i) => {
const k = knob(526 + (i % 4) * 82, 82 + Math.floor(i / 4) * 116, 25, name, role === "master");
let angle = role === "master" ? -135 + 270 * masterValue / 1023 : 0;
k.rotate(angle);
turnable(k.g, (n) => {
if (role === "master") {
masterValue = Math.max(0, Math.min(1023, masterValue + n * 16));
emu.master(masterValue);
angle = -135 + 270 * masterValue / 1023;
} else {
emu.enc(role, n);
angle = (angle + n * 18) % 360;
}
k.rotate(angle);
});
});
// 18 buttons, 3 rows of 6
const btns = [];
const showBank = () => { if (bankText) bankText.textContent = "FADERS: " + SMK_FADER_BANKS[bank].name; };
SMK_BUTTONS.forEach(([name, role], i) => {
const x = 870 + (i % 6) * 84, y = 30 + Math.floor(i / 6) * 76;
const own = !(role in B);
const g = button(x, y, 74, 56, name, { port: own, size: 10.5, ink: name === "REC" ? "#ff453a" : undefined });
btns.push({ g, role });
holdable(g, (id) => {
if (role === "bank") { bank = (bank + 1) % SMK_FADER_BANKS.length; showBank(); return; }
if (role === "prev" || role === "next") { emu.enc(EN.SELECT, role === "next" ? 1 : -1); return; }
if (role === "none") return;
emu.press("b" + i + id, B[role]);
}, (id) => emu.unpress("b" + i + id));
});
const bankText = label(svg, 1123, 268, "", 11, SANS, "#8a8a8e");
showBank();
// 16 pads, 2 rows of 8, and 4 faders
const pads = [];
label(svg, 330, 318, "PADS: THE 16 WHITE KEYS (STEPS)", 11, SANS, "#8a8a8e");
for (let p = 0; p < 16; p++) {
const x = 196 + (p % 8) * 66, y = 330 + Math.floor(p / 8) * 66; // pads 1-8 on top, 9-16 under them
const g = control("pad", "Pad " + (p + 1));
el("rect", { x, y, width: 58, height: 58, rx: 8, class: "face" }, g);
label(g, x + 29, y + 34, String(p + 1).padStart(2, "0"), 11, SANS, "#77777b");
pads.push(g);
holdable(g, (id) => emu.keyDown("pad" + p + id, smkPadKey(p)), (id) => emu.keyUp("pad" + p + id));
}
for (let i = 0; i < 4; i++) {
const f = fader(760 + i * 54, 340, 30, 100, "F" + (i + 1));
let v = 100;
f.place(v);
positional(f.g, () => v, (nv) => { v = nv; f.place(v); const [st, cc] = SMK_FADER_BANKS[bank].cc(i); emu.midi(st, cc, v); }, 100);
}
// 37 keys, C3..C6: F3..G5 are the FM-1's 27; the five below and five above play nothing yet
const keys = keybed(70, 486, 1260, 110, 48, 37, {
bind: (g, m) => {
const k = m - 53;
if (k < 0 || k >= FM1_KEYS) { g.classList.add("off"); g.setAttribute("aria-label", noteName(m) + " (not on the FM-1)"); return; }
holdable(g, (id) => emu.keyDown("key" + k + id, k), (id) => emu.keyUp("key" + k + id));
},
});
function frame(fb, leds) {
if (fb) blitScreen(ctx, fb, 0, 0);
if (!leds) return;
const [litB, litK, dimB] = leds;
for (const b of btns) {
if (!(b.role in B)) continue;
const bit = 1 << B[b.role], green = b.role === "PLAY" && (litB & (1 << PLAY_GREEN));
b.g.classList.toggle("lit", !!(litB & bit) && !green);
b.g.classList.toggle("green", !!green);
b.g.classList.toggle("dim", !!(dimB & bit));
}
for (const { m, g } of keys) { const k = m - 53; g.classList.toggle("lit", k >= 0 && k < FM1_KEYS && !!(litK & (1 << k))); }
pads.forEach((g, p) => padLit(g, litK & (1 << smkPadKey(p)) ? "#b45400" : ""));
}
return { dev, frame };
}
const SMK_INFO = `
<div class="map">
<p><b>Keys</b> F3–G5 are the FM-1's 27 keys, note for note; C3–E3 and G♯5–C6 play nothing yet.</p>
<p><b>Buttons</b> FX FX · SCALE SCL · CHORD ENV · NOTE REPEAT LFO · PARA EDIT · GLOBE GLO · PATCH HOME · BT SAVE ·
ARP · SEQ · SEQ PLAY PLAY · SEQ REC REC · OCTAVE − / + OCT − / +. <b>&lt; &gt;</b> one step of SELECT.
<b>FADER BANK</b> the faders' bank; KNOB BANK nothing yet.</p>
<p><b>Encoders</b> K1–K4 KNOB 1–4 · K5 MASTER · K6 SELECT · K7 ALGORITHM · K8 PRESETS.</p>
<p><b>Pads</b> the FM-1's 16 white keys (its steps), the lowest on the bottom row.</p>
<p><b>Faders</b> bank A the levels of tracks 1–4, B track 1's cutoff, resonance, reverb and delay.
<b>Wheels</b> pitch bend and modulation on track 1.</p>
<p>Computer keyboard: <kbd>Z</kbd>–<kbd>'</kbd> <kbd>Q</kbd>–<kbd>O</kbd> keys, <kbd>↑</kbd> <kbd>↓</kbd> SELECT, <kbd>←</kbd> <kbd>→</kbd> ALGORITHM.</p>
</div>
<p class="note">In development: JIANT on the SMK-37 itself runs on its own chip (the FM-1's), bare metal as on the FM-1.
The button names are the ones printed on the keyboard (as Melodee, tried on an SMK-37 Elite, names them); this panel is
the mapping it will have.</p>`;
// Akai MPC Sample: the app in ports/mpc-sample, its controls as panel_map.h maps them; the screen 320 x 240 with
// JIANT's 240 x 240 in the middle
function buildMPC(stage) {
const W = 1100, H = 700;
const dev = document.createElement("div");
dev.className = "device";
stage.appendChild(dev);
svg = document.createElementNS(NS, "svg");
svg.setAttribute("viewBox", `0 0 ${W} ${H}`);
dev.appendChild(svg);
el("rect", { x: 4, y: 4, width: W - 8, height: H - 8, rx: 28, fill: "var(--body)" });
label(svg, 112, 44, "MPC SAMPLE", 16, DOT, "#8a8a8e");
const S = [40, 70, 400, 300]; // the screen: 320 x 240 shown at x1.25
el("rect", { x: S[0] - 10, y: S[1] - 10, width: S[2] + 20, height: S[3] + 20, rx: 12, fill: "#0b0b0c" });
const canvas = document.createElement("canvas");
canvas.width = 320; canvas.height = 240;
Object.assign(canvas.style, { left: `${S[0] / W * 100}%`, top: `${S[1] / H * 100}%`, width: `${S[2] / W * 100}%` });
dev.appendChild(canvas);
const ctx = canvas.getContext("2d");
let shift = false, win = 0;
const held = new Set(), pos = { K1: 64, K2: 64, K3: 64, F: 0 };
const btns = [];
const mpcButton = (x, y, w, h, name, role, opts = {}) => {
const own = !(role in B) && role !== "stop";
const g = button(x, y, w, h, name, { port: own, size: opts.size || 10.5, ink: opts.ink });
btns.push({ g, role });
holdable(g, (id) => {
if (role === "shift") { shift = true; g.classList.add("on"); return; }
if (role === "bank") { win = (win + (shift ? 3 : 1)) % 4; side(); return; }
if (role === "stop") { if (emu.playing()) emu.press("stop" + id, B.PLAY); return; }
if (role in B) emu.press(name + id, B[role]);
}, (id) => {
if (role === "shift") { shift = false; g.classList.remove("on"); return; }
emu.unpress(name + id); emu.unpress("stop" + id);
});
return g;
};
// above the screen: HOME, EDIT, GLO (the soft keys)
[["HOME", "HOME"], ["EDIT", "EDIT"], ["GLO", "GLO"]].forEach(([n, r], i) => mpcButton(70 + i * 120, 14, 100, 34, n === "HOME" ? "◀ HOME" : n, r, { size: 10 }));
// the left and lower buttons
const ROWS = [
[["SAMPLE", "none"], ["SEQ", "SEQ"], ["PAD FX", "FX"], ["KNOB FX", "LFO"]],
[["CHOP", "ENV"], ["MUTE", "none"], ["LOOP", "ARP"], ["16 LEVELS", "SCL"]],
[["SAMPLE\nSELECT", "SAVE"], ["TAP\nTEMPO", "none"], ["ERASE", "none"], ["NOTE\nREPEAT", "none"]],
[["SHIFT", "shift"], ["PAD BANK", "bank"], ["−", "OCT-"], ["+", "OCT+"]],
[["SAMPLE\nREC", "REC"], ["SEQ REC", "REC"], ["STOP", "stop"], ["PLAY", "PLAY"]],
];
ROWS.forEach((row, r) => row.forEach(([n, role], c) =>
mpcButton(40 + c * 102, 400 + r * 56, 92, 44, n, role, { ink: role === "REC" ? "#ff453a" : undefined })));
// knobs K1..K3 (pots: their positions), MAIN VOLUME, the wheel, the fader
const pot = (x, y, name, onMove) => {
const k = knob(x, y, 24, name, true);
const deg = () => -135 + 270 * pos[name] / 127;
k.rotate(deg());
positional(k.g, () => pos[name], (v) => { const d = v - pos[name]; pos[name] = v; k.rotate(deg()); onMove(d, v); }, 160);
};
pot(500, 120, "K1", (d) => emu.enc(shift ? EN.ALGORITHM : EN.K1, d));
pot(590, 120, "K2", (d) => emu.enc(EN.K2, d));
pot(680, 120, "K3", (d) => emu.enc(EN.K3, d));
pos.VOL = 88;
const vol = knob(500, 250, 24, "VOL", true);
const vdeg = () => -135 + 270 * pos.VOL / 127;
vol.rotate(vdeg());
positional(vol.g, () => pos.VOL, (v) => { pos.VOL = v; vol.rotate(vdeg()); emu.master(v * 1023 / 127); }, 160);
const wheel = knob(615, 268, 46, "WHEEL", true);
let wa = 0;
turnable(wheel.g, (n) => { emu.enc(shift ? EN.PRESETS : EN.SELECT, n); wa = (wa + n * 15) % 360; wheel.rotate(wa); }, 10);
const f = fader(720, 200, 34, 160, "FADER");
f.place(pos.F);
positional(f.g, () => pos.F, (v) => { const d = v - pos.F; pos.F = v; f.place(v); emu.enc(EN.K4, d); }, 160);
// the pads: 1 bottom left, 16 top right
const pads = [];
for (let p = 0; p < 16; p++) {
const c = p % 4, r = 3 - Math.floor(p / 4), x = 800 + c * 72, y = 330 + r * 72;
const g = control("pad", "Pad " + (p + 1));
el("rect", { x, y, width: 64, height: 64, rx: 8, class: "face" }, g);
label(g, x + 32, y + 38, String(p + 1), 12, SANS, "#77777b");
pads.push(g);
holdable(g, (id) => emu.keyDown("pad" + p + id, WINDOWS[win] + p), (id) => emu.keyUp("pad" + p + id));
}
const bankLights = "ABCD".split("").map((ch, i) => {
const x = 810 + i * 70;
const c = el("circle", { cx: x, cy: 300, r: 6, fill: "#333" });
label(svg, x + 18, 304, ch, 11, SANS, "#8a8a8e");
return c;
});
// the MPC's screen as the app draws it: JIANT's frame in the middle, the pad bank on the left
const side = () => {
ctx.fillStyle = "#000"; ctx.fillRect(0, 0, 40, 240); ctx.fillRect(280, 0, 40, 240);
ctx.textAlign = "center"; ctx.fillStyle = "#8a8a8a"; ctx.font = "600 9px " + SANS;
ctx.fillText("PADS", 20, 16);
ctx.fillStyle = "#ff7a00"; ctx.font = "600 24px " + SANS; ctx.fillText("ABCD"[win], 20, 44);
ctx.fillStyle = "#8a8a8a"; ctx.font = "600 9px " + SANS;
ctx.fillText(fm1KeyName(WINDOWS[win]).replace("♯", "#"), 20, 66); ctx.fillText(fm1KeyName(WINDOWS[win] + 15).replace("♯", "#"), 20, 80);
if (shift) { ctx.fillStyle = "#ff7a00"; ctx.fillText("SHIFT", 20, 226); }
ctx.fillStyle = "#ff7a00"; ctx.fillText("JIANT", 300, 16);
bankLights.forEach((c, i) => c.setAttribute("fill", i === win ? "#ff7a00" : "#333"));
frame(null, emu.leds);
};
function frame(fb, leds) {
if (fb) blitScreen(ctx, fb, 40, 0);
if (!leds) return;
const [litB, litK, dimB] = leds;
for (const b of btns) {
if (b.role === "stop") { b.g.classList.toggle("lit", emu.playing()); continue; }
if (!(b.role in B)) continue;
const bit = 1 << B[b.role], green = b.role === "PLAY" && (litB & (1 << PLAY_GREEN));
b.g.classList.toggle("lit", !!(litB & bit) && !green);
b.g.classList.toggle("green", !!green);
b.g.classList.toggle("dim", !!(dimB & bit));
}
pads.forEach((g, p) => padLit(g, litK & (1 << (WINDOWS[win] + p)) ? "#b45400" : ""));
}
side();
const shiftWatch = setInterval(side, 250); // (SHIFT on the screen)
return { dev, frame, stop: () => clearInterval(shiftWatch) };
}
const MPC_INFO = `
<div class="map">
<p><b>Pads</b> 16 of the FM-1's keys: PAD BANK moves them (A F3–G♯4, B A3–C5, C C♯4–E5, D E4–G5; SHIFT back).</p>
<p><b>Above the screen</b> HOME, EDIT, GLO. <b>PAD FX</b> FX · <b>KNOB FX</b> LFO · <b>CHOP</b> ENV · <b>16 LEVELS</b> SCL ·
<b>LOOP</b> ARP · <b>SEQ</b> SEQ · <b>SAMPLE SELECT</b> SAVE.</p>
<p><b>PLAY</b> PLAY, <b>STOP</b> stops it, <b>SEQ REC</b> / <b>SAMPLE REC</b> REC, <b>− +</b> OCT − / OCT +.</p>
<p><b>Wheel</b> SELECT (SHIFT: PRESETS). <b>K1 K2 K3</b> and the <b>fader</b> KNOB 1–4 (SHIFT + K1: ALGORITHM).
<b>VOL</b> MASTER. Pushing the wheel goes back to the MPC's own app.</p>
<p>Computer keyboard: <kbd>Z</kbd>–<kbd>'</kbd> <kbd>Q</kbd>–<kbd>O</kbd> keys, <kbd>↑</kbd> <kbd>↓</kbd> SELECT.</p>
</div>
<p class="note">Preview: the MPC Sample app (ports/mpc-sample) is built and tested, not yet tried on an MPC. On the MPC
JIANT runs at full power: every track its own 8 voices.</p>`;
// ------------------------------------------------------------------ the picker
const stage = document.getElementById("stage"), info = document.getElementById("info");
let current = null;
function teardown() {
emu.stop();
if (current?.stop) current.stop();
stage.innerHTML = ""; info.innerHTML = ""; current = null; svg = null;
}
function overlay(dev, onFrame) {
const start = document.createElement("div");
start.className = "start";
start.innerHTML = '<button type="button">Switch on</button><p hidden></p>';
dev.appendChild(start);
const go = start.querySelector("button"), msg = start.querySelector("p");
go.addEventListener("click", async () => {
go.disabled = true; go.textContent = "Starting…";
try {
await emu.start(onFrame, 700);
start.hidden = true;
} catch (err) {
emu.stop();
go.disabled = false; go.textContent = "Switch on";
msg.hidden = false; msg.textContent = "Could not start: " + (err?.message || err) + ". A current Chrome, Edge, Firefox or Safari should work.";
}
});
}
function select(name) {
if (!["fm1", "smk37", "mpc"].includes(name)) name = "fm1";
teardown();
for (const b of document.querySelectorAll(".picker button")) b.setAttribute("aria-pressed", String(b.dataset.dev === name));
if (name === "fm1") {
const f = document.createElement("iframe");
f.className = "fm1"; f.src = "index.html"; f.title = "JIANT FM on the FM-1"; f.allow = "midi; autoplay";
f.addEventListener("load", () => { // (as tall as the emulator's page)
try { const fit = () => { f.style.height = f.contentDocument.documentElement.scrollHeight + "px"; }; fit(); new ResizeObserver(fit).observe(f.contentDocument.body); } catch {}
});
stage.appendChild(f);
} else {
current = name === "smk37" ? buildSMK(stage) : buildMPC(stage);
overlay(current.dev, (fb, leds) => current?.frame(fb, leds));
info.innerHTML = name === "smk37" ? SMK_INFO : MPC_INFO;
}
if (location.hash !== "#" + name) history.replaceState(null, "", "#" + name);
try { localStorage.setItem("jiant-device", name); } catch {}
}
for (const b of document.querySelectorAll(".picker button")) b.addEventListener("click", () => select(b.dataset.dev));
addEventListener("hashchange", () => { const n = location.hash.slice(1); if (n && !document.querySelector(`.picker [data-dev="${n}"][aria-pressed="true"]`)) select(n); });
let first = location.hash.slice(1);
try { first = first || localStorage.getItem("jiant-device") || "fm1"; } catch { first = first || "fm1"; }
document.fonts?.load("13px DotGothic16").finally(() => select(first));
</script>
</body>
</html>