feat: pattern gallery as a preset editor; chase steps; sim split with the preset editor
- Pattern gallery shows the controller's presets, one at a time, with a dropdown, Save, Add preset, and the controller's field labels, delay limits and colour counts. Edits show in the preview; Save writes to the controller only. - Presets are always timed in ms (beat_time is no longer sent to drivers); beats stay in sequences. - Chase steps of 0 hold still; the marquee style is removed from the controller, the gallery and the driver (submodule commit 12a8e22). - The rig's split pane opens the preset editor too (Rig / Presets switch and a Preset editor menu entry). - Sequence editor, room layout and simulator controls from earlier work are included. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8c783ab926
commit
cb51a726bc
79 files changed
+5183
-934
No files matched your search
+93
-14
@@ -13,10 +13,14 @@
|
||||
const LOCK_PX = 10; // movement before a touch counts as a swipe or a scroll
|
||||
const DRAG_CLASS = 'sim-swipe-dragging';
|
||||
|
||||
// What the pane shows: the rig, or the preset editor (the pattern gallery) in the same pane
|
||||
const VIEWS = { rig: '/sim/', presets: '/sim/gallery' };
|
||||
let pane = null;
|
||||
let frame = null;
|
||||
let pager = null;
|
||||
let width = 0;
|
||||
let page = 0; // swipe mode: 0 the controller, 1 the rig
|
||||
let view = 'rig';
|
||||
|
||||
function load() {
|
||||
try {
|
||||
@@ -56,6 +60,20 @@
|
||||
document.documentElement.style.setProperty('--sim-drag', `${Math.round(px)}px`);
|
||||
}
|
||||
|
||||
// Show the rig or the preset editor in the pane. Switching unloads the other page (its bars power off)
|
||||
function setView(v) {
|
||||
view = v === 'presets' ? 'presets' : 'rig';
|
||||
if (frame && frame.dataset.view !== view) {
|
||||
frame.dataset.view = view;
|
||||
frame.src = VIEWS[view];
|
||||
}
|
||||
if (pane) {
|
||||
pane.querySelectorAll('.sim-pane-tabs button').forEach((b) =>
|
||||
b.setAttribute('aria-pressed', String(b.dataset.view === view)));
|
||||
}
|
||||
save({ view });
|
||||
}
|
||||
|
||||
function setPage(p) {
|
||||
page = p ? 1 : 0;
|
||||
document.documentElement.style.setProperty('--sim-page', String(page));
|
||||
@@ -89,7 +107,7 @@
|
||||
}
|
||||
|
||||
function popOut() {
|
||||
const win = window.open('/sim/', 'led-simulator', 'popup,width=1200,height=800');
|
||||
const win = window.open(VIEWS[view], 'led-simulator', 'popup,width=1200,height=800');
|
||||
if (!win) {
|
||||
// Pop-ups blocked: keep the simulator here
|
||||
alert('The browser blocked the simulator window. Allow pop-ups for this site, or open /sim/ in a new tab.');
|
||||
@@ -201,20 +219,21 @@
|
||||
'<div class="sim-pane-divider" role="separator" aria-orientation="vertical" ' +
|
||||
'aria-label="Resize the simulator" title="Drag to resize"></div>' +
|
||||
'<div class="sim-pane-body">' +
|
||||
'<div class="sim-pane-bar">' +
|
||||
'<span class="sim-pane-title">Simulator</span>' +
|
||||
'<button type="button" class="btn btn-secondary btn-small" data-sim="popout" ' +
|
||||
'title="Open the simulator in its own window">Pop out ↗</button>' +
|
||||
'<button type="button" class="btn btn-secondary btn-small" data-sim="close" ' +
|
||||
'title="Close the simulator (its bars power off)" aria-label="Close the simulator">×</button>' +
|
||||
'<div class="sim-pane-tabs" role="group" aria-label="Show the rig or the preset editor">' +
|
||||
'<button type="button" data-view="rig">Rig</button>' +
|
||||
'<button type="button" data-view="presets">Presets</button>' +
|
||||
'</div>' +
|
||||
'<iframe class="sim-pane-frame" src="/sim/" title="Simulated rig"></iframe>' +
|
||||
'<iframe class="sim-pane-frame" title="Simulator"></iframe>' +
|
||||
'</div>';
|
||||
pane.querySelector('[data-sim="popout"]').addEventListener('click', popOut);
|
||||
pane.querySelector('[data-sim="close"]').addEventListener('click', close);
|
||||
pane.querySelectorAll('.sim-pane-tabs button').forEach((b) => {
|
||||
b.setAttribute('aria-pressed', String(b.dataset.view === view));
|
||||
b.addEventListener('click', () => setView(b.dataset.view));
|
||||
});
|
||||
|
||||
// Swipes that start in the rig (same origin, so its document can be listened to)
|
||||
const frame = pane.querySelector('iframe');
|
||||
frame = pane.querySelector('iframe');
|
||||
frame.dataset.view = view;
|
||||
frame.src = VIEWS[view];
|
||||
frame.addEventListener('load', () => {
|
||||
try {
|
||||
attachSwipe(frame.contentDocument);
|
||||
@@ -262,14 +281,21 @@
|
||||
document.body.appendChild(pager);
|
||||
}
|
||||
|
||||
function open() {
|
||||
function open(which) {
|
||||
if (which) {
|
||||
view = which === 'presets' ? 'presets' : 'rig';
|
||||
}
|
||||
if (!pane) {
|
||||
build();
|
||||
width = load().width || 0;
|
||||
page = swipeMode() ? 1 : 0; // on a phone, opening it shows it
|
||||
// On a phone, opening the rig shows it. Opening the preset editor leaves the controller on screen
|
||||
page = swipeMode() && view === 'rig' ? 1 : 0;
|
||||
} else {
|
||||
setView(view);
|
||||
}
|
||||
save({ open: true });
|
||||
layout();
|
||||
syncMenu();
|
||||
window.dispatchEvent(new Event('resize')); // the UI lays out for its new width
|
||||
}
|
||||
|
||||
@@ -277,6 +303,7 @@
|
||||
if (pane) {
|
||||
pane.remove(); // the iframe goes with it: its bars power off
|
||||
pane = null;
|
||||
frame = null;
|
||||
}
|
||||
if (pager) {
|
||||
pager.remove();
|
||||
@@ -290,6 +317,7 @@
|
||||
document.documentElement.style.setProperty('--sim-page', '0');
|
||||
setDrag(0);
|
||||
save({ open: false });
|
||||
syncMenu();
|
||||
window.dispatchEvent(new Event('resize'));
|
||||
}
|
||||
|
||||
@@ -304,6 +332,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
// The Menu's Preset editor entry: open the pane on the presets, or switch the open pane to them
|
||||
function openPresets() {
|
||||
if (!isOpen()) {
|
||||
open('presets');
|
||||
return;
|
||||
}
|
||||
setView('presets'); // the controller stays on screen; on a phone the pager switches to it
|
||||
}
|
||||
const paneItems = []; // the Menu's Pop out and Close entries
|
||||
|
||||
function addMenuEntries() {
|
||||
// A header button for the Menu item to forward to, as the other entries do (help.js)
|
||||
const headerActions = document.querySelector('.header-actions');
|
||||
@@ -325,6 +363,45 @@
|
||||
item.textContent = 'Simulator';
|
||||
const settingsItem = menu.querySelector('[data-target="settings-btn"]');
|
||||
menu.insertBefore(item, settingsItem);
|
||||
const presetsReal = document.createElement('button');
|
||||
presetsReal.id = 'sim-presets-btn';
|
||||
presetsReal.hidden = true;
|
||||
presetsReal.addEventListener('click', openPresets);
|
||||
document.body.appendChild(presetsReal);
|
||||
const presetsItem = document.createElement('button');
|
||||
presetsItem.type = 'button';
|
||||
presetsItem.className = 'edit-mode-only';
|
||||
presetsItem.dataset.target = 'sim-presets-btn';
|
||||
presetsItem.textContent = 'Preset editor';
|
||||
menu.insertBefore(presetsItem, settingsItem);
|
||||
|
||||
// Pop out and Close: in the Menu only while the pane is open (syncMenu). The menu forwards its clicks to
|
||||
// the real buttons with these ids (help.js)
|
||||
for (const [label, id, action] of [
|
||||
['Pop out ↗', 'sim-popout-btn', popOut],
|
||||
['Close simulator', 'sim-close-btn', close],
|
||||
]) {
|
||||
const real = document.createElement('button');
|
||||
real.id = id;
|
||||
real.hidden = true;
|
||||
real.addEventListener('click', action);
|
||||
document.body.appendChild(real);
|
||||
const entry = document.createElement('button');
|
||||
entry.type = 'button';
|
||||
entry.className = 'sim-pane-item';
|
||||
entry.dataset.target = id;
|
||||
entry.textContent = label;
|
||||
entry.style.display = 'none';
|
||||
menu.insertBefore(entry, settingsItem);
|
||||
paneItems.push(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The pane's Menu entries show while it is open. An inline display wins over the menu's own rules
|
||||
function syncMenu() {
|
||||
for (const entry of paneItems) {
|
||||
entry.style.display = isOpen() ? '' : 'none';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,16 +419,18 @@
|
||||
addMenuEntries();
|
||||
attachSwipe(document); // swipes that start on the controller's page
|
||||
const saved = load();
|
||||
view = saved.view === 'presets' ? 'presets' : 'rig';
|
||||
if (saved.open) {
|
||||
build();
|
||||
width = saved.width || 0;
|
||||
page = saved.page ? 1 : 0;
|
||||
layout();
|
||||
}
|
||||
syncMenu();
|
||||
window.addEventListener('resize', layout);
|
||||
}
|
||||
|
||||
window.simSplit = { open, close, popOut, setPage };
|
||||
window.simSplit = { open, close, popOut, setPage, setView };
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', init);
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user