From f3e70df5c8f34bfa11ac1feff63fd7b0f25e8cd6 Mon Sep 17 00:00:00 2001
From: Tom Peak Walcher <4373002+TomPeak@users.noreply.github.com>
Date: Sat, 7 Nov 2026 08:18:36 +0100
Subject: [PATCH] Skiff Editor: an APC mini mk2 plays the Song tab, entries,
scenes, MUTEs and PLAY, its LEDs following the FM-1
Co-Authored-By: Claude Opus 5.5 (1M context)
---
DESIGN.md | 3 ++
README.md | 3 +-
web/editor.html | 116 ++++++++++++++++++++++++++++++++++++++++++++++-
web/test_web.mjs | 35 +++++++++++++-
4 files changed, 153 insertions(+), 4 deletions(-)
diff --git a/DESIGN.md b/DESIGN.md
index dedff65..a65af08 100644
--- a/DESIGN.md
+++ b/DESIGN.md
@@ -501,6 +501,9 @@ track's Sound tab); PLAY, STOP and REC in the header; the projects' names (SAVE
track's list (SET, COPY, PLAY, REPS, CLEAR), SONG, LAUNCH, the scenes, the staged mutes, the pattern pool (CLEAR an
unused one). Each acts through the device's own code and the device says so on its screen; what can't be undone is
asked first, as on the device. Nothing of these is pushed: the editor reads what it shows again about once a second.
+An **APC mini mk2** on the computer plays the Song tab (`apcAction`, `apcLeds`): its pads and buttons call what the tab's
+own controls call, the faders send each track's CC7, and its LEDs show what is read back, not what was pressed, the song
+read every 400 ms while it is there. No firmware of its own and no setting: it works while it is plugged in.
**Screen grid:** Felucca's, so every page inherits the restyle (`firmware/src/ui.c`); BLOCKS' footer is one line, so its panel is 16 px taller (`foot_less`, `graph_h`):
diff --git a/README.md b/README.md
index 7d6e7ae..eb8346c 100644
--- a/README.md
+++ b/README.md
@@ -304,7 +304,8 @@ them. MENU › DISPLAY › PLAYHEAD LINE leaves HOME's playhead a line, without
The [Skiff Editor](https://illuminus5.github.io/skiff/webapp/editor/) (`web/editor.html`, Chrome or Edge over USB MIDI)
edits a connected FM-1 live: the sounds and their presets, the steps, the mixer, the Song tab (each track's list, the
-scenes, the pattern pool), the projects and their names, the DRUM-X kit and the MENU settings, with PLAY, STOP and REC
+scenes, the pattern pool; an Akai APC mini mk2 plugged into the computer launches them, its LEDs following the FM-1),
+the projects and their names, the DRUM-X kit and the MENU settings, with PLAY, STOP and REC
at the top. It looks like the unit and follows its THEME, and sets THEME › CUSTOM's colours (Settings › Device
display). It also keeps a library of sounds on the computer, imports
FM6 patches from `.syx` files and saves complete backups. Its Samples tab fills the user sample slots from WAV files
diff --git a/web/editor.html b/web/editor.html
index d2c003d..4236a10 100644
--- a/web/editor.html
+++ b/web/editor.html
@@ -370,6 +370,7 @@
+
@@ -1088,6 +1089,59 @@ function portPairs(access) {
return pairs.sort((a, b) => /felucca/i.test(b[0].name) - /felucca/i.test(a[0].name));
}
+/* An Akai APC mini mk2 plays the Song tab: its pads and buttons do what the tab's own controls do, its LEDs show the
+ device's lists and scenes as they are read back. Columns 1..6: T1..T6, the top row the page's first entry; columns 7,
+ 8: scenes 1..8, 9..16, top down; the bottom buttons 1..6: T1..T6's MUTE; the side buttons: the top two the page (A..H,
+ I..P), the bottom one PLAY; faders 1..6: T1..T6's LEVEL. It has a port for the pads ("Control") and one for its note
+ and drum modes ("Notes"). LEDs: a note-on, the status's channel a pad's brightness or blink, the velocity its colour;
+ a button's velocity 1 on, 2 flashing */
+const APC_PORT = /apc mini mk2/i;
+const APC = { MUTE: 100, PAGE: 112, PLAY: 119, FADER: 48, FULL: 0x96, DIM: 0x92, BLINK: 0x9E, BTN: 0x90,
+ GREEN: 87, BLUE: 41, ORANGE: 61, YELLOW: 74 };
+function apcPorts(access) {
+ const free = (p) => p.state !== "disconnected" && APC_PORT.test(p.name || "") && !/notes/i.test(p.name);
+ const i = [...access.inputs.values()].find(free), o = i && [...access.outputs.values()].find((x) => free(x) && x.name === i.name);
+ return o ? [i, o] : null;
+}
+/* what a message from it asks for (null: nothing) */
+function apcAction([st, d1, d2], page) {
+ const kind = st & 0xF0;
+ if (kind === 0xB0) return d1 >= APC.FADER && d1 < APC.FADER + 6 ? { do: "level", k: d1 - APC.FADER, v: d2 } : null;
+ if (kind !== 0x90 || !d2) return null;
+ if (d1 < 64) {
+ const c = d1 % 8, row = 7 - (d1 >> 3);
+ return c < 6 ? { do: "entry", k: c, e: row + 8 * page } : { do: "scene", s: row + 8 * (c - 6) };
+ }
+ if (d1 >= APC.MUTE && d1 < APC.MUTE + 6) return { do: "mute", k: d1 - APC.MUTE };
+ if (d1 === APC.PAGE || d1 === APC.PAGE + 1) return { do: "page", page: d1 - APC.PAGE };
+ return d1 === APC.PLAY ? { do: "play" } : null;
+}
+/* every LED as the song says: note -> [status, velocity]. An entry on: green, the next one blinking, the others dim
+ (a REST orange), an empty one dark. A scene kept: dim, the last one bright. list, perf: LIST's and PERFORM's replies, or none */
+function apcLeds(list, perf, page, playing) {
+ const m = new Map(), off = [APC.FULL, 0];
+ for (let n = 0; n < 64; n++) {
+ const c = n % 8, row = 7 - (n >> 3), x = c < 6 && list && list.tracks[c], e = row + 8 * page, en = x && x.ent[e];
+ let led = off;
+ if (c >= 6) {
+ const s = row + 8 * (c - 6);
+ if (perf && perf.scenes >> s & 1) led = [perf.last === s ? APC.FULL : APC.DIM, APC.YELLOW];
+ } else if (en) {
+ if (x.next === e) led = [APC.BLINK, APC.GREEN];
+ else if (x.cur === e) led = [APC.FULL, APC.GREEN];
+ else if (en.pat) led = [APC.DIM, en.pat === PAT_REST ? APC.ORANGE : APC.BLUE];
+ }
+ m.set(n, led);
+ }
+ for (let k = 0; k < 6; k++) {
+ const y = perf && perf.tracks[k];
+ m.set(APC.MUTE + k, [APC.BTN, !y ? 0 : y.staged ? 2 : +y.muted]);
+ }
+ for (let k = 0; k < 2; k++) m.set(APC.PAGE + k, [APC.BTN, list && page === k ? 1 : 0]);
+ m.set(APC.PLAY, [APC.BTN, playing ? 1 : 0]);
+ return m;
+}
+
class Link {
constructor(send, opts = {}) {
this.sendRaw = send;
@@ -3445,6 +3499,7 @@ const TEXT = {
sgConfirmEmpty: "パターン {n} を空にしますか? ステップ、NUDGE、オートメーションが消えます。パターンとそれを使うエントリーは残ります。元に戻せません。",
sgConfirmUnused: "未使用のパターン {n} 個をクリアしますか? どこからも使われていません。元に戻せません。",
sgEmpty: "空です", sgAutoFull: "完了(オートメーションなし: AUTOMATION FULL)", sgStopClear: "停止してからクリアしてください",
+ sgApc: "APC mini mk2 接続中: 1〜6列は T1〜T6 のエントリー、7・8列はシーン、下のボタン1〜6は MUTE、右上の2つはページ(A–H / I–P)、右下は PLAY、フェーダー1〜6は LEVEL",
sgFull: "パターンがいっぱいです: プールで未使用のものをクリアしてください", sgFailed: "本体で失敗しました", sgNothing: "クリアするものがありません", sgInUse: "使用中です",
sgNoFw: "このファームウェアにはソングのコマンドがありません。Skiff を更新してください。",
confirmSave: "スロット {n} に上書き保存しますか?", confirmLoad: "スロット {n} を読み込みますか? すべてのトラックの音色とシーケンスが置き換わります(元に戻せません)。",
@@ -3584,6 +3639,7 @@ const TEXT = {
sgConfirmEmpty: "Empty pattern {n}? Its steps, NUDGEs and automation go; the pattern and the entries naming it stay. It can't be undone.",
sgConfirmUnused: "Clear the {n} unused patterns? Nothing uses them. It can't be undone.",
sgEmpty: "Empty", sgAutoFull: "Done, without its automation (AUTOMATION FULL)", sgStopClear: "Stop to clear",
+ sgApc: "APC mini mk2 connected: columns 1–6 T1–T6's entries, columns 7–8 the scenes, bottom buttons 1–6 MUTE, the top two side buttons the page (A–H, I–P), the bottom one PLAY, faders 1–6 LEVEL",
sgFull: "Patterns full: clear unused ones in the pool", sgFailed: "Failed on the device", sgNothing: "Nothing to clear", sgInUse: "In use",
sgNoFw: "This firmware has no song commands: update Skiff.",
confirmSave: "Overwrite slot {n}?", confirmLoad: "Load slot {n}? The sounds and sequences of every track are replaced (no undo).",
@@ -3727,7 +3783,8 @@ function renderTransport(x) {
if (x) dev.transport = x;
const s = dev.transport;
if (!s) return;
- const playing = s.pending ? s.pending !== 2 : s.playing || s.counting;
+ const playing = transportPlaying(s);
+ apcShow();
$("tplay").setAttribute("aria-pressed", String(playing));
$("tplay").title = t("playTitle");
$("trec").setAttribute("aria-pressed", String(!!(s.rec >> s.sel & 1)));
@@ -3767,7 +3824,7 @@ async function readSong(d = dev, pool = true, poll = false) {
}
if (d.info.skiff & 16) s.perf = parse[CMD.PERFORM](await rqs(req.perform()));
if (d.info.skiff & 4 && (pool || !s.pool)) s.pool = parse[CMD.POOL](await rqs(req.pool()));
- if (d === dev) renderSong();
+ if (d === dev) { renderSong(); apcShow(); }
}
/* (2.0, INFO 58 01) the device has LIST2 (SONG ONCE, the chains), NEW, COPY+ and the pool's EMPTY, CLEAR UNUSED; a LIST
request as LIST2 then */
@@ -3811,6 +3868,58 @@ function songOp(r, kind) {
if (k) sayK(k);
});
}
+/* the APC mini mk2 (apcAction, apcLeds): found whenever the ports change; on it, the song is read every APC_POLL ms
+ whichever tab is open, so its LEDs follow the device (the keep-alive's read, more often) */
+const APC_POLL = 400;
+const apc = { input: null, output: null, page: 0, shown: new Map() };
+const transportPlaying = (s) => (s.pending ? s.pending !== 2 : s.playing || s.counting);
+function apcShow() {
+ if (!apc.output) return;
+ const s = dev && dev.song, tr = dev && dev.transport;
+ try {
+ for (const [n, [st, v]] of apcLeds(s && s.list, s && s.perf, apc.page, tr && transportPlaying(tr))) {
+ if (apc.shown.get(n) === (st << 8 | v)) continue;
+ apc.output.send([st, n, v]);
+ apc.shown.set(n, st << 8 | v);
+ }
+ } catch (e) { console.debug("APC LEDs", e); } /* (unplugged: onState says so next) */
+}
+function apcPress(data) {
+ const a = apcAction(data, apc.page), caps = dev && dev.info ? dev.info.skiff : 0;
+ if (!a) return;
+ if (a.do === "page") { apc.page = a.page; apcShow(); }
+ else if (a.do === "entry" && caps & 8) songOp(lreq(3, a.k, a.e), "list");
+ else if (a.do === "scene" && caps & 16) songOp(req.perform(2, a.s), "perf");
+ else if (a.do === "mute" && caps & 16) songOp(req.perform(3, a.k), "perf");
+ else if (a.do === "play" && caps & 1) transportOp(1);
+ else if (a.do === "level" && dev) dev.output.send([0xB0 | a.k, 7, a.v]); /* (CC7 on T1..T6's default channels) */
+}
+function apcAttach() {
+ const p = access && apcPorts(access);
+ if (apc.input && (!p || p[0].id !== apc.input.id)) {
+ apc.input.onmidimessage = null;
+ apc.input = apc.output = null;
+ }
+ if (p && !apc.input) {
+ [apc.input, apc.output] = p;
+ apc.input.onmidimessage = (e) => apcPress(e.data);
+ if (apc.input.open) apc.input.open().catch(() => {});
+ apc.page = 0;
+ apc.shown.clear();
+ apcShow();
+ }
+ $("sgapc").hidden = !apc.input;
+}
+setInterval(() => {
+ const d = dev;
+ if (!apc.input || !d || !d.info || !(d.info.skiff & 28) || busy || !d.link.idle || keepAlive.song) return;
+ keepAlive.song = true;
+ readSong(d, false, true).catch(() => {}).finally(() => { keepAlive.song = false; });
+}, APC_POLL);
+window.addEventListener("pagehide", () => {
+ if (!apc.output) return;
+ try { for (const n of apcLeds(null, null, 0, false).keys()) apc.output.send([APC.BTN, n, 0]); } catch (e) { /* unplugged */ }
+});
/* a list redrawn keeps the focus on the same control (data-key) */
function keepFocus(box, draw) {
const k = box.contains(document.activeElement) && document.activeElement.dataset.key;
@@ -4053,6 +4162,7 @@ async function connect() {
catch (e) { sayK("denied"); return; }
}
access.onstatechange = onState;
+ apcAttach();
}
const pairs = portPairs(access);
let input = null, output = null, link = null;
@@ -4111,11 +4221,13 @@ function disconnect(reasonKey = "disconnected") {
renderPreferences(true);
$("version").textContent = "";
setLabel($("connect"), t("connect"));
+ apcShow(); /* (no device: its LEDs dark) */
sayK(reasonKey);
}
function onState(e) {
const p = e.port;
+ apcAttach();
if (!p || !UNIT_PORT.test(p.name || "")) return; /* ((2.0.1, #50) the names connect() takes) */
if (dev && p.state === "disconnected" && (p.id === dev.input.id || p.id === dev.output.id)) {
disconnect("lost");
diff --git a/web/test_web.mjs b/web/test_web.mjs
index 6218d51..29687d3 100644
--- a/web/test_web.mjs
+++ b/web/test_web.mjs
@@ -35,7 +35,7 @@ const FW_ROOT = process.env.FELUCCA_ROOT || join(HERE, "..");
const html = readFileSync(join(HERE, "editor.html"), "utf8");
const proto = html.slice(html.indexOf("/*PROTO-BEGIN*/"), html.indexOf("/*PROTO-END*/"));
const E = vm.runInNewContext(proto + `
-;({ frame, unframe, parse, songReply, req, Link, parseWav, resample, normalize, takeSample, kitZones, LANES, portPairs, autoTrim, zoomView, rootFromName, buildSlot, makeMockDevice, CMD, SMP,
+;({ frame, unframe, parse, songReply, req, Link, parseWav, resample, normalize, takeSample, kitZones, LANES, portPairs, apcPorts, apcAction, apcLeds, APC, autoTrim, zoomView, rootFromName, buildSlot, makeMockDevice, CMD, SMP,
UP, bank, capturePatch, auditionPatch, lightRefuses, startWatch, libraryFile, readLibraryFile, paramKeys, patternFromSteps, stepsFromPattern, upName,
mixer, parseNotes, parseHits, hitsText, gridFromSteps, LANE_NOTE, LANE_OF, readDevicePreferences, devicePresetRows, TC_NAMES, engineOrder, ENGINE_ORDER, aliasOf, fmtValue, FM6, enumShown, F,
FM4, fromDigital, fromPerc, DRUM_KIT_E, DX_KIT_DEF, DX_KITS, DRUMX_PKIT,
@@ -1087,6 +1087,39 @@ async function editorLists() {
o.done();
}
+/* The APC mini mk2 on the Song tab: its ports, what its controls ask for, its LEDs from the song's replies */
+{
+ const port = (name, state = "connected") => ({ name, state, id: name });
+ const access = (names) => ({ inputs: new Map(names.map((n) => [n, port(n)])), outputs: new Map(names.map((n) => [n, port(n)])) });
+ const mk2 = access(["APC mini mk2 Notes", "APC mini mk2 Control", "X0X FM-1"]);
+ ok(E.apcPorts(mk2)[0].name === "APC mini mk2 Control" && E.apcPorts(mk2)[1].name === "APC mini mk2 Control", "apc: its Control port, not Notes");
+ ok(!E.apcPorts(access(["X0X FM-1"])) && E.portPairs(mk2).length === 1 && E.portPairs(mk2)[0][0].name === "X0X FM-1",
+ "apc: none without it; never taken for the unit");
+ const act = (st, n, v, page = 0) => JSON.stringify(E.apcAction([st, n, v], page));
+ ok(act(0x90, 56, 127) === '{"do":"entry","k":0,"e":0}' && act(0x90, 5, 127) === '{"do":"entry","k":5,"e":7}', "apc: top left T1 A; bottom of column 6 T6 H");
+ ok(act(0x90, 49, 127, 1) === '{"do":"entry","k":1,"e":9}', "apc: page I..P: T2's second row is J");
+ ok(act(0x90, 62, 127) === '{"do":"scene","s":0}' && act(0x90, 7, 127) === '{"do":"scene","s":15}', "apc: columns 7, 8: scenes 1 and 16");
+ ok(act(0x90, 105, 127) === '{"do":"mute","k":5}' && act(0x90, 106, 127) === "null", "apc: bottom button 6 T6's MUTE; the seventh nothing");
+ ok(act(0x90, 113, 127) === '{"do":"page","page":1}' && act(0x90, 119, 127) === '{"do":"play"}' && act(0x90, 118, 127) === "null", "apc: the side buttons: page, PLAY");
+ ok(act(0xB0, 50, 99) === '{"do":"level","k":2,"v":99}' && act(0xB0, 54, 99) === "null", "apc: fader 3 T3's LEVEL; fader 7 nothing");
+ ok(act(0x80, 56, 0) === "null" && act(0x90, 56, 0) === "null", "apc: let go: nothing");
+ const A = E.APC, none = { pat: 0 }, ent = (m) => Array.from({ length: 16 }, (_, e) => m[e] || none);
+ const list = { tracks: [{ cur: 0, next: 2, ent: ent({ 0: { pat: 1 }, 1: { pat: 2 }, 2: { pat: 3 }, 3: { pat: 65 }, 8: { pat: 4 } }) }] };
+ const perf = { last: 1, scenes: 3, tracks: [{ muted: true, staged: 0 }, { muted: false, staged: 2 }, { muted: false, staged: 0 }] };
+ let m = E.apcLeds(list, perf, 0, true);
+ const led = (n) => m.get(n).join();
+ ok(led(56) === `${A.FULL},${A.GREEN}` && led(48) === `${A.DIM},${A.BLUE}` && led(40) === `${A.BLINK},${A.GREEN}` && led(32) === `${A.DIM},${A.ORANGE}` && led(24) === `${A.FULL},0`,
+ "apc: on green, kept dim, next blinking, a REST orange, empty dark");
+ ok(led(57) === `${A.FULL},0`, "apc: a track the reply hasn't: dark");
+ ok(led(62) === `${A.DIM},${A.YELLOW}` && led(54) === `${A.FULL},${A.YELLOW}` && led(46) === `${A.FULL},0`, "apc: a scene kept dim, the last bright, none dark");
+ ok(m.get(A.MUTE)[1] === 1 && m.get(A.MUTE + 1)[1] === 2 && m.get(A.MUTE + 2)[1] === 0 && m.get(A.MUTE + 5)[1] === 0, "apc: muted lit, staged flashing");
+ ok(m.get(A.PAGE)[1] === 1 && !m.get(A.PAGE + 1)[1] && m.get(A.PLAY)[1] === 1, "apc: the page and PLAY lit");
+ m = E.apcLeds(list, perf, 1, false);
+ ok(led(56) === `${A.DIM},${A.BLUE}` && m.get(A.PAGE + 1)[1] === 1 && !m.get(A.PLAY)[1], "apc: page I..P shows I..P");
+ m = E.apcLeds(null, null, 0, false);
+ ok(m.size === 64 + 6 + 2 + 1 && [...m.values()].every((x) => x[1] === 0), "apc: no device: every LED dark");
+}
+
/* (2.0, INFO 58 01 01) LIST2 (SONG ONCE, the chains as kept), LIST's 5 0 CHAIN, 6 2 ONCE, 7 NEW, 8 COPY+ (a chain: all
of it), POOL's 2 EMPTY and 3 CLEAR UNUSED; LIST's own reply as before (ONCE: on, a CHAIN: 1x) */
async function editorSong2() {