Rename padeditor to padcontroller, with the MIDI intercept as padcontroller.midi and its virtual port as padcontroller.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Opus 5.5 committed 2026-10-22 13:25:06 +13:00
1 parent 1e09cb3825
commit 9742121144
31 files changed
+79 -79

No files matched your search

+490
View File
@@ -0,0 +1,490 @@
const PAGE = 16;
const state = {
doc: null,
saved: null,
preset: 0,
page: 2,
bank: 0,
kind: null,
index: 0,
};
const $ = (id) => document.getElementById(id);
// Colours are stored as the picker gives them, 0–255, as MidiSuite writes them.
function cssColour(rgb) {
return `rgb(${rgb.join(",")})`;
}
function ink(rgb) {
const [r, g, b] = rgb;
return (r * 0.3 + g * 0.59 + b * 0.11) > 150 ? "#111" : "#f4f6fb";
}
function hexColour(rgb) {
return `#${rgb.map((part) => part.toString(16).padStart(2, "0")).join("")}`;
}
function setStatus(text, kind) {
const node = $("status");
node.textContent = text;
node.className = kind || "";
}
function dirty() {
return state.doc !== null && JSON.stringify(state.doc) !== state.saved;
}
function preset() {
return state.doc.presets[state.preset];
}
function selected() {
if (!state.doc || !state.kind) return null;
const block = preset();
if (state.kind === "pad") return block.pads[state.page * PAGE + state.index];
if (state.kind === "knob") return block.knobs[state.bank * 8 + state.index];
return block.buttons[state.index];
}
function typeChoices(kind, current) {
const known = (state.doc.types && state.doc.types[kind]) || [];
const options = known.map((item) => ({ value: item.value, name: item.name }));
if (!options.some((item) => item.value === current)) {
const hex = current.toString(16).padStart(2, "0");
options.push({ value: current, name: `0x${hex}` });
}
return options;
}
async function request(url, options) {
const response = await fetch(url, options);
const type = response.headers.get("Content-Type") || "";
if (type.includes("application/json")) {
const body = await response.json();
if (!response.ok) throw new Error(body.error || response.statusText);
return body;
}
if (!response.ok) throw new Error(response.statusText);
return response.blob();
}
function mark() {
const unsaved = dirty();
$("save").disabled = !state.doc;
$("export").disabled = !state.doc;
$("save").classList.toggle("dirty", unsaved);
return unsaved;
}
function touch() {
if (mark()) setStatus("Not saved on the pad.", "dirty");
else setStatus("No unsaved edits.", "ok");
}
function showEmpty(text, kind) {
const node = $("empty");
node.hidden = false;
node.textContent = text;
node.className = kind || "";
$("board").classList.remove("ready");
}
async function load(manual) {
if (manual && dirty() && !window.confirm("Load from the pad and drop these edits?")) return;
setStatus("Loading the pad…");
showEmpty("Loading the pad…");
try {
state.doc = await request("/api/load", { method: "POST" });
state.saved = JSON.stringify(state.doc);
render();
setStatus("Loaded from the pad.", "ok");
} catch (error) {
setStatus(error.message, "err");
showEmpty(error.message, "err");
}
}
async function save() {
if (!state.doc) return;
setStatus("Saving…");
$("save").disabled = true;
try {
const body = await request("/api/save", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(state.doc),
});
state.saved = JSON.stringify(state.doc);
setStatus(body.message, "ok");
} catch (error) {
setStatus(error.message, "err");
}
mark();
}
async function exportFile() {
if (!state.doc) return;
try {
const blob = await request("/api/export", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(state.doc),
});
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = "smc-pad-preset.bin";
link.click();
URL.revokeObjectURL(url);
} catch (error) {
setStatus(error.message, "err");
}
}
async function importFile(file) {
setStatus("Reading file…");
try {
const raw = new Uint8Array(await file.arrayBuffer());
state.doc = await request("/api/import", {
method: "POST",
headers: { "Content-Type": "application/octet-stream" },
body: raw,
});
render();
setStatus("Imported. Save to pad to store it.", "dirty");
} catch (error) {
setStatus(error.message, "err");
}
}
function withBank(global, bank) {
const raw = global.raw.slice(0, 22) + bank.toString(16).padStart(2, "0") + global.raw.slice(24);
return { ...global, bank, raw };
}
async function switchBank(bank) {
try {
await request("/api/bank", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ bank }),
});
const wasDirty = dirty();
state.doc.global = withBank(state.doc.global, bank);
if (!wasDirty) {
const saved = JSON.parse(state.saved);
saved.global = withBank(saved.global, bank);
state.saved = JSON.stringify(saved);
}
state.page = bank ? 7 : 2;
$("page").value = String(state.page);
state.kind = state.kind === "pad" ? null : state.kind;
render();
setStatus(`Pad bank ${bank + 1}.`, "ok");
} catch (error) {
setStatus(error.message, "err");
}
}
async function factory() {
if (!window.confirm("Replace all eight presets with the factory settings? Nothing reaches the pad until you Save.")) return;
setStatus("Reading the factory preset…");
try {
state.doc = await request("/api/factory", { method: "POST" });
render();
setStatus("Factory settings loaded. Save to pad to store them.", "dirty");
} catch (error) {
setStatus(error.message, "err");
}
mark();
}
function render() {
if (!state.doc) return;
$("board").classList.add("ready");
renderGlobal();
renderPresets();
renderPages();
renderPads();
renderKnobs();
renderButtons();
renderInspector();
mark();
}
function renderGlobal() {
const row = $("global");
row.replaceChildren();
const block = state.doc.global;
if (!block) return;
const fields = [
["Tempo", "tempo", 1, 999],
["Swing", "swing", 0, 255],
["Pad curve", "curve", 0, 255],
["Transpose", "transpose", -128, 127],
];
for (const [label, key, min, max] of fields) {
row.append(field(label, numberInput(block, key, min, max)));
}
const toggle = document.createElement("button");
toggle.type = "button";
toggle.textContent = `Pad bank ${block.bank + 1}`;
toggle.title = "Switch the pad's bank now, as MidiSuite does";
toggle.addEventListener("click", () => switchBank(1 - block.bank));
row.append(toggle);
}
function renderPresets() {
const row = $("presets");
row.replaceChildren();
state.doc.presets.forEach((_preset, index) => {
const button = document.createElement("button");
button.type = "button";
button.textContent = String(index + 1);
button.classList.toggle("selected", index === state.preset);
button.addEventListener("click", () => {
state.preset = index;
render();
});
row.append(button);
});
}
function renderPages() {
const select = $("page");
const current = select.value;
select.replaceChildren();
const order = [2, 7, 0, 1, 3, 4, 5, 6];
const names = { 2: "Bank 1", 7: "Bank 2", 3: "Page 4 (not lit)" };
for (const page of order) {
const pads = preset().pads.slice(page * PAGE, page * PAGE + PAGE);
const option = document.createElement("option");
option.value = String(page);
const name = names[page] || `Page ${page + 1}`;
option.textContent = `${name} · notes ${pads[0].note}–${pads[PAGE - 1].note}`;
select.append(option);
}
select.value = current || String(state.page);
state.page = Number(select.value);
const pads = preset().pads.slice(state.page * PAGE, state.page * PAGE + PAGE);
$("page-notes").textContent = `notes ${pads[0].note}–${pads[PAGE - 1].note}`;
}
function paint(node, rgb) {
node.style.background = cssColour(rgb);
node.style.color = ink(rgb);
}
function renderPads() {
const grid = $("pads");
grid.replaceChildren();
const pads = preset().pads;
for (let row = 3; row >= 0; row -= 1) {
for (let col = 0; col < 4; col += 1) {
const index = row * 4 + col;
const pad = pads[state.page * PAGE + index];
const button = document.createElement("button");
button.type = "button";
button.className = "pad";
button.textContent = String(index + 1);
paint(button, pad.rgb);
button.style.opacity = pad.led ? "" : "0.35";
button.classList.toggle("selected", state.kind === "pad" && state.index === index);
button.addEventListener("click", () => select("pad", index));
grid.append(button);
}
}
}
function renderKnobs() {
const row = $("knobs");
row.replaceChildren();
for (let index = 0; index < 8; index += 1) {
const knob = preset().knobs[state.bank * 8 + index];
const button = document.createElement("button");
button.type = "button";
button.className = "knob";
button.textContent = String(state.bank * 8 + index + 1);
button.title = `CC ${knob.number}`;
button.classList.toggle("selected", state.kind === "knob" && state.index === index);
button.addEventListener("click", () => select("knob", index));
row.append(button);
}
}
function renderButtons() {
const row = $("buttons");
row.replaceChildren();
preset().buttons.forEach((button, index) => {
const node = document.createElement("button");
node.type = "button";
node.className = "btn";
node.textContent = button.name;
node.classList.toggle("selected", state.kind === "button" && state.index === index);
node.addEventListener("click", () => select("button", index));
row.append(node);
});
}
let colourTimer = 0;
function paintColour(index, rgb) {
const edited = state.preset;
preset().pads[index].rgb = rgb.slice();
renderPads();
window.clearTimeout(colourTimer);
colourTimer = window.setTimeout(() => sendColour(edited, index, rgb), 180);
}
async function sendColour(preset, index, rgb) {
try {
await request("/api/colour", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ preset, index, rgb }),
});
} catch (error) {
setStatus(error.message, "err");
}
}
function select(kind, index) {
state.kind = kind;
state.index = index;
render();
}
function field(label, node) {
const wrap = document.createElement("label");
wrap.className = "field";
wrap.append(label, node);
return wrap;
}
function numberInput(item, key, min, max) {
const input = document.createElement("input");
input.type = "number";
input.min = String(min);
input.max = String(max);
input.value = String(item[key]);
input.addEventListener("input", () => {
const value = Number(input.value);
if (!Number.isInteger(value) || value < min || value > max) return;
item[key] = value;
if (key === "led") renderPads();
if (key === "note") {
const pads = preset().pads.slice(state.page * PAGE, state.page * PAGE + PAGE);
$("page-notes").textContent = `notes ${pads[0].note}–${pads[PAGE - 1].note}`;
}
touch();
});
return input;
}
function renderInspector() {
const aside = $("inspector");
const item = selected();
aside.replaceChildren();
const title = document.createElement("h2");
if (!item) {
title.textContent = "Control";
const note = document.createElement("p");
note.className = "muted";
note.textContent = "Pick a pad, knob, or button.";
aside.append(title, note);
return;
}
if (state.kind === "pad") title.textContent = `Pad ${state.index + 1}`;
else if (state.kind === "knob") title.textContent = `Knob ${state.bank * 8 + state.index + 1}`;
else title.textContent = item.name;
aside.append(title);
if (state.kind !== "pad") {
const type = document.createElement("select");
typeChoices(state.kind, item.type).forEach((option) => {
const node = document.createElement("option");
node.value = String(option.value);
node.textContent = option.name;
node.selected = option.value === item.type;
type.append(node);
});
type.addEventListener("change", () => {
item.type = Number(type.value);
touch();
});
aside.append(field(state.kind === "button" ? "Mode" : "Type", type));
}
aside.append(field("Channel", numberInput(item, "channel", 1, 16)));
if (state.kind === "pad") {
aside.append(field("Note", numberInput(item, "note", 0, 127)));
aside.append(field("Min velocity", numberInput(item, "min", 0, 127)));
aside.append(field("Max velocity", numberInput(item, "max", 0, 127)));
const colour = document.createElement("input");
colour.type = "color";
colour.value = hexColour(item.rgb);
colour.addEventListener("input", () => {
const hex = colour.value;
const rgb = [1, 3, 5].map((at) => parseInt(hex.slice(at, at + 2), 16));
paintColour(state.page * PAGE + state.index, rgb);
touch();
});
aside.append(field("Colour", colour));
aside.append(field("Led", numberInput(item, "led", 0, 255)));
} else if (state.kind === "knob") {
aside.append(field("CC", numberInput(item, "number", 0, 127)));
aside.append(field("Speed", numberInput(item, "speed", 0, 127)));
aside.append(field("Min", numberInput(item, "left", 0, 127)));
aside.append(field("Max", numberInput(item, "right", 0, 127)));
if (state.doc.relative) {
const hint = document.createElement("p");
hint.className = "hint";
hint.textContent = "Relative sends the left value one way and the right value the other.";
aside.append(hint);
}
} else {
aside.append(field("CC", numberInput(item, "number", 0, 127)));
aside.append(field("Value 1", numberInput(item, "min", 0, 127)));
aside.append(field("Value 2", numberInput(item, "max", 0, 127)));
aside.append(field("Led", numberInput(item, "led", 0, 255)));
const sysex = document.createElement("input");
sysex.type = "text";
sysex.value = item.sysex;
sysex.spellcheck = false;
sysex.addEventListener("input", () => {
const hex = sysex.value.replace(/\s+/g, "").toLowerCase();
if (hex.length % 2 || /[^0-9a-f]/.test(hex) || hex.length > 32) return;
item.sysex = hex;
touch();
});
aside.append(field("SysEx", sysex));
}
const hint = document.createElement("p");
hint.className = "hint";
hint.textContent = "A pad colour lights the lamp as you pick it. Save keeps every edit after a power cycle.";
aside.append(hint);
}
$("load").addEventListener("click", () => load(true));
$("save").addEventListener("click", save);
$("export").addEventListener("click", exportFile);
$("factory").addEventListener("click", factory);
$("import").addEventListener("change", () => {
const file = $("import").files[0];
$("import").value = "";
if (file) importFile(file);
});
$("page").addEventListener("change", () => {
state.page = Number($("page").value);
state.kind = state.kind === "pad" ? null : state.kind;
render();
});
$("bank").addEventListener("change", () => {
state.bank = Number($("bank").value);
state.kind = state.kind === "knob" ? null : state.kind;
render();
});
load(false);
+46
View File
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pad Controller</title>
<link rel="stylesheet" href="/style.css">
</head>
<body>
<header>
<h1>Pad Controller</h1>
<button id="load" type="button">Load</button>
<button id="save" type="button" class="primary" disabled>Save to pad</button>
<button id="factory" type="button">Factory reset</button>
<button id="export" type="button" disabled>Export</button>
<label class="file">Import
<input id="import" type="file" accept=".bin,application/octet-stream">
</label>
<span class="spacer"></span>
<span id="status">Load the preset from the pad.</span>
</header>
<main>
<section id="board">
<p id="empty">Loading the pad…</p>
<div class="row" id="global"></div>
<div class="row" id="presets"></div>
<div class="row">
<label>Pad page <select id="page"></select></label>
<label>Knob bank <select id="bank">
<option value="0">1 · knobs 1–8</option>
<option value="1">2 · knobs 9–16</option>
</select></label>
<span id="page-notes" class="muted"></span>
</div>
<div id="pads"></div>
<div id="knobs"></div>
<div id="buttons"></div>
</section>
<aside id="inspector">
<h2>Control</h2>
<p class="muted">Load a preset, then pick a pad, knob, or button.</p>
</aside>
</main>
<script src="/app.js"></script>
</body>
</html>
+102
View File
@@ -0,0 +1,102 @@
:root {
--bg: #15171c;
--panel: #1e2129;
--panel-2: #262a34;
--line: #343946;
--text: #e6e8ee;
--muted: #8d94a6;
--accent: #5aa9ff;
--danger: #ff6b6b;
--ok: #52d273;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
background: var(--bg);
color: var(--text);
font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
display: flex;
flex-direction: column;
}
header {
display: flex;
align-items: center;
gap: 10px;
padding: 8px 14px;
background: var(--panel);
border-bottom: 1px solid var(--line);
}
header h1 { font-size: 15px; margin: 0 8px 0 0; }
.spacer { flex: 1; }
#status { color: var(--muted); max-width: 46ch; }
#status.err { color: var(--danger); }
#status.ok { color: var(--ok); }
#status.dirty { color: var(--accent); }
button, select, input[type="number"], input[type="text"] {
background: var(--panel-2);
color: var(--text);
border: 1px solid var(--line);
border-radius: 6px;
padding: 6px 10px;
font: inherit;
}
button { cursor: pointer; }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: #245a9e; border-color: #3d7dcc; }
button.primary.dirty { background: #1e6b38; border-color: var(--ok); }
button.selected, .pad.selected, .knob.selected, .btn.selected {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
label.file { color: var(--muted); }
label.file input { display: none; }
label.file { cursor: pointer; border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; background: var(--panel-2); color: var(--text); }
main { display: flex; min-height: 0; flex: 1; }
#empty { color: var(--muted); margin: 48px 0; }
#empty.err { color: var(--danger); }
#board.ready #empty { display: none; }
#board, #inspector { padding: 16px; }
#board { flex: 1; }
#inspector {
width: 320px;
background: var(--panel);
border-left: 1px solid var(--line);
overflow: auto;
}
#inspector h2 { margin: 0 0 12px; font-size: 15px; }
.muted { color: var(--muted); }
.row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.row label { display: flex; align-items: center; gap: 6px; color: var(--muted); }
#presets { gap: 6px; }
#pads {
display: grid;
grid-template-columns: repeat(4, 76px);
gap: 8px;
margin: 8px 0 18px;
}
.pad, .knob, .btn {
border: 1px solid #0008;
color: #111;
font-weight: 650;
text-align: center;
}
.pad { height: 64px; border-radius: 8px; }
.knob {
width: 64px;
height: 64px;
border-radius: 50%;
background: #d7dbe6;
}
#knobs, #buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.btn { min-width: 72px; height: 36px; border-radius: 6px; background: #c9ceda; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; color: var(--muted); }
.field input, .field select { width: 100%; }
.hint { color: var(--muted); margin-top: 8px; }
#global .field { margin-bottom: 0; }
#global input { width: 90px; }