feat: sequence editor undo/redo, collapsible browser, playhead easing
Sequence editor: undo and redo, a collapsible browser with chips, search over sequences too, name in the header row, Beats/Seconds dropdown, Delete beside Save. Playhead eases between poll results. Lanes keep their phase when a step ends late, so they no longer drift. The rig's default room is two columns of bars facing each other, and the simulator has a read-only debug hook for the playback checks. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a1c8ce853b
commit
02440be55d
7 files changed
+252
-109
No files matched your search
+158
-28
@@ -25,7 +25,9 @@ const seqTl = {
|
||||
loopEndSet: false, // the user moved the end marker
|
||||
brush: '', // the browser item double-click adds
|
||||
lastLen: TL_BAR,
|
||||
head: null, // playhead {pos, at, rate, max}
|
||||
head: null, // playhead {pos, at, rate, max, wrap}
|
||||
headErr: 0, // the playhead's easing offset after a status poll: glides to the server's position instead of jumping
|
||||
headErrT: 0,
|
||||
pollTimer: null,
|
||||
raf: 0,
|
||||
drag: null,
|
||||
@@ -364,6 +366,9 @@ function seqTlOnOpen(doc) {
|
||||
: '',
|
||||
);
|
||||
seqTl.on = true;
|
||||
tlHist.undo = [];
|
||||
tlHist.redo = [];
|
||||
tlHist.cur = null; // the first render records the opened state
|
||||
tlRender();
|
||||
tlStartPoll();
|
||||
}
|
||||
@@ -415,6 +420,7 @@ function tlSelect(sel) {
|
||||
function tlRender() {
|
||||
const canvas = tlEl('tl-canvas');
|
||||
if (!canvas || !seqTl.on) return;
|
||||
tlRecord(); // every edit ends in a render: an edit since the last one becomes an undo step
|
||||
if (seqTl.snapAuto) seqTl.snap = tlAutoSnap(); // Auto follows the zoom, so drags land on the ticks shown
|
||||
const ppb = seqTl.ppb;
|
||||
const timed = tlTimed();
|
||||
@@ -426,14 +432,9 @@ function tlRender() {
|
||||
canvas.style.setProperty('--ppb', String(ppb));
|
||||
canvas.innerHTML = '';
|
||||
|
||||
// Units toggle and BPM readout
|
||||
document.querySelectorAll('#tl-units button').forEach((b) => {
|
||||
b.classList.toggle('on', (b.dataset.v === 'time') === timed);
|
||||
// A one-shot is always in seconds: Beats is greyed out while Loop is off
|
||||
b.disabled = !loop && b.dataset.v !== 'time';
|
||||
});
|
||||
const bpm = tlEl('tl-bpm');
|
||||
if (bpm) bpm.textContent = `${Math.round(tlBpm())} BPM`;
|
||||
// A one-shot is always in seconds: Beats is greyed out while Loop is off
|
||||
const beatsOpt = document.querySelector('#sequence-editor-mode option[value="beats"]');
|
||||
if (beatsOpt) beatsOpt.disabled = !loop;
|
||||
|
||||
// Ruler
|
||||
const rrow = document.createElement('div');
|
||||
@@ -721,11 +722,7 @@ function tlRenderInspector() {
|
||||
const track = sel && sel.track ? tlTrack(sel.track) : null;
|
||||
if (clip) return tlInspectClip(host, clip);
|
||||
if (track) return tlInspectTrack(host, track);
|
||||
const hint = document.createElement('div');
|
||||
hint.className = 'muted-text';
|
||||
hint.textContent =
|
||||
'Drag a preset from the browser onto a track. Drag clips to move them and their edges to resize. Double-click a track to add the preset picked in the browser. Click a track name for its groups. Delete removes the selected clip.';
|
||||
host.appendChild(hint);
|
||||
// Nothing selected: the inspector stays empty (and hidden by the stylesheet)
|
||||
}
|
||||
|
||||
function tlInspectClip(host, c) {
|
||||
@@ -797,7 +794,6 @@ function tlInspectClip(host, c) {
|
||||
const btns = document.createElement('div');
|
||||
btns.className = 'tl-insp-btns';
|
||||
btns.appendChild(tlBtn('Edit', 'Edit the preset or sequence', () => tlEditPlay(c.play)));
|
||||
btns.appendChild(tlBtn('Duplicate', 'Copy it to the next free space (Ctrl+D)', () => tlDuplicate(c)));
|
||||
btns.appendChild(tlBtn('Delete', 'Remove the clip (Delete)', () => tlDelete(c), 'btn btn-danger btn-small'));
|
||||
host.appendChild(btns);
|
||||
}
|
||||
@@ -888,6 +884,71 @@ function tlInspectTrack(host, t) {
|
||||
host.appendChild(btns);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- undo/redo */
|
||||
|
||||
const TL_HISTORY_MAX = 100;
|
||||
const tlHist = { undo: [], redo: [], cur: null }; // states as JSON; cur is the one on screen
|
||||
|
||||
/** What undo brings back: clips, tracks, the window and units. Not the selection, zoom or scroll. */
|
||||
function tlSnapshot() {
|
||||
return JSON.stringify({
|
||||
clips: seqTl.clips,
|
||||
targets: seqEd.targets,
|
||||
loopEnd: seqTl.loopEnd,
|
||||
loopEndSet: seqTl.loopEndSet,
|
||||
mode: (tlEl('sequence-editor-mode') || {}).value || '',
|
||||
loop: tlLoop(),
|
||||
});
|
||||
}
|
||||
|
||||
/** Called on each render: if the timeline changed since the last one, the old state is an undo step. */
|
||||
function tlRecord() {
|
||||
const s = tlSnapshot();
|
||||
if (tlHist.cur !== null && s !== tlHist.cur) {
|
||||
tlHist.undo.push(tlHist.cur);
|
||||
if (tlHist.undo.length > TL_HISTORY_MAX) tlHist.undo.shift();
|
||||
tlHist.redo = [];
|
||||
}
|
||||
tlHist.cur = s;
|
||||
tlUndoButtons();
|
||||
}
|
||||
|
||||
function tlUndoButtons() {
|
||||
const u = tlEl('tl-undo');
|
||||
const r = tlEl('tl-redo');
|
||||
if (u) u.disabled = !tlHist.undo.length;
|
||||
if (r) r.disabled = !tlHist.redo.length;
|
||||
}
|
||||
|
||||
function tlRestore(s) {
|
||||
const st = JSON.parse(s);
|
||||
seqTl.clips = st.clips;
|
||||
seqEd.targets = st.targets;
|
||||
seqTl.loopEnd = st.loopEnd;
|
||||
seqTl.loopEndSet = st.loopEndSet;
|
||||
const mode = tlEl('sequence-editor-mode');
|
||||
if (mode && st.mode) mode.value = st.mode;
|
||||
const loop = tlEl('sequence-editor-loop');
|
||||
if (loop) loop.checked = st.loop;
|
||||
const sel = seqTl.sel;
|
||||
if (sel && ((sel.clip && !tlClip(sel.clip)) || (sel.track && !tlTrack(sel.track)))) seqTl.sel = null;
|
||||
tlHist.cur = s; // so the render below doesn't record the restore as a new edit
|
||||
tlBuildSnap();
|
||||
tlRender();
|
||||
}
|
||||
|
||||
function tlUndo() {
|
||||
if (!tlHist.undo.length || seqTl.drag) return;
|
||||
tlHist.redo.push(tlHist.cur);
|
||||
tlRestore(tlHist.undo.pop());
|
||||
}
|
||||
|
||||
function tlRedo() {
|
||||
if (!tlHist.redo.length || seqTl.drag) return;
|
||||
tlHist.undo.push(tlHist.cur);
|
||||
tlRestore(tlHist.redo.pop());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------- edits */
|
||||
|
||||
function tlAddAt(uid, start, play) {
|
||||
@@ -967,7 +1028,6 @@ function tlSetUnits(timed) {
|
||||
seqTl.loopEnd = q(seqTl.loopEnd);
|
||||
seqTl.lastLen = timed ? 4 : TL_BAR;
|
||||
mode.value = timed ? 'time' : 'beats';
|
||||
mode.dispatchEvent(new Event('change'));
|
||||
tlBuildSnap();
|
||||
tlRender();
|
||||
}
|
||||
@@ -1221,7 +1281,6 @@ async function tlPoll() {
|
||||
let lanes = null;
|
||||
if (st && st.overlay && st.overlay.active && String(st.overlay.sequence_id) === sequenceEditorId) lanes = st.overlay.lanes;
|
||||
else if (st && st.active && String(st.sequence_id) === sequenceEditorId) lanes = st.lanes;
|
||||
seqTl.head = null;
|
||||
if (Array.isArray(lanes)) {
|
||||
const { map } = tlToLanes();
|
||||
const li = lanes.findIndex((l, i) => l && l.started && !l.done && map[i]);
|
||||
@@ -1231,11 +1290,27 @@ async function tlPoll() {
|
||||
const timed = l.mode === 'time';
|
||||
const s = m.starts[l.step] != null ? m.starts[l.step] : 0;
|
||||
const into = timed ? (l.elapsed_ms || 0) / 1000 : l.beat_in_step || 0;
|
||||
seqTl.head = { pos: s + into, at: performance.now(), rate: timed ? 1 : tlBpm() / 60, max: m.ends[l.step] != null ? m.ends[l.step] : s + into };
|
||||
}
|
||||
}
|
||||
const looping = !!(st && st.active && String(st.sequence_id) === sequenceEditorId);
|
||||
const now = performance.now();
|
||||
const next = {
|
||||
pos: s + into,
|
||||
at: now,
|
||||
rate: timed ? 1 : tlBpm() / 60,
|
||||
max: m.ends[l.step] != null ? m.ends[l.step] : s + into,
|
||||
wrap: looping ? tlLoopLen() : 0, // a looping sequence wraps at its window; a one-shot stops at its lane's end
|
||||
};
|
||||
// Keep the head where it was on screen and ease it onto the server's position, so a poll never jumps it
|
||||
const old = seqTl.head;
|
||||
if (old) {
|
||||
const d = tlHeadDiff(tlHeadAt(old, now) + seqTl.headErr, tlHeadAt(next, now), next.wrap);
|
||||
seqTl.headErr = Math.abs(d) < 0.5 ? d : 0;
|
||||
} else seqTl.headErr = 0;
|
||||
seqTl.headErrT = now;
|
||||
seqTl.head = next;
|
||||
} else seqTl.head = null;
|
||||
} else seqTl.head = null;
|
||||
} catch (_) {
|
||||
/* try again */
|
||||
/* try again: the head stays where it is */
|
||||
}
|
||||
} else {
|
||||
seqTl.head = null;
|
||||
@@ -1243,12 +1318,31 @@ async function tlPoll() {
|
||||
seqTl.pollTimer = setTimeout(tlPoll, 250);
|
||||
}
|
||||
|
||||
/** Where the head is at time now, extrapolated from its last poll. */
|
||||
function tlHeadAt(h, now) {
|
||||
const x = h.pos + ((now - h.at) / 1000) * h.rate;
|
||||
return h.wrap > 0 ? ((x % h.wrap) + h.wrap) % h.wrap : Math.min(h.max, x);
|
||||
}
|
||||
|
||||
/** a - b, the short way round a loop of length wrap (no wrap: plain difference). */
|
||||
function tlHeadDiff(a, b, wrap) {
|
||||
const d = a - b;
|
||||
return wrap > 0 ? ((((d + wrap / 2) % wrap) + wrap) % wrap) - wrap / 2 : d;
|
||||
}
|
||||
|
||||
function tlDrawHead() {
|
||||
const ph = tlEl('tl-playhead');
|
||||
const lcd = tlEl('tl-pos');
|
||||
const h = seqTl.head;
|
||||
const now = performance.now();
|
||||
let pos = 0;
|
||||
if (h) pos = Math.min(h.max, h.pos + ((performance.now() - h.at) / 1000) * h.rate);
|
||||
if (h) {
|
||||
pos = tlHeadAt(h, now) + seqTl.headErr;
|
||||
if (h.wrap > 0) pos = ((pos % h.wrap) + h.wrap) % h.wrap;
|
||||
else pos = Math.min(h.max, pos);
|
||||
seqTl.headErr *= Math.exp(-(now - seqTl.headErrT) / 150); // ease out the correction
|
||||
seqTl.headErrT = now;
|
||||
} else seqTl.headErr = 0;
|
||||
if (ph) {
|
||||
ph.hidden = !h;
|
||||
if (h) ph.style.left = `calc(var(--tl-head-w) + ${pos * seqTl.ppb}px)`;
|
||||
@@ -1279,12 +1373,36 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
if (el) el.addEventListener(ev, fn);
|
||||
};
|
||||
on('tl-add-track', 'change', (e) => tlAddTrack(e.target.value));
|
||||
on('tl-per-driver', 'click', () => {
|
||||
addTargetsPerDriver();
|
||||
if (seqEd.targets.length > TL_TRACKS_MAX) alert(`Only the first ${TL_TRACKS_MAX} tracks can have clips.`);
|
||||
tlRender();
|
||||
});
|
||||
on('tl-undo', 'click', tlUndo);
|
||||
on('tl-redo', 'click', tlRedo);
|
||||
on('tl-browser-search', 'input', tlRenderBrowser);
|
||||
// The browser panel collapses to a strip with its arrow, giving the tracks the width; the choice is remembered
|
||||
const setBrowser = (show) => {
|
||||
const panel = document.querySelector('#seq-tl .tl-browser');
|
||||
const btn = tlEl('tl-browser-toggle');
|
||||
if (panel) panel.classList.toggle('collapsed', !show);
|
||||
if (btn) {
|
||||
btn.innerHTML = show ? '›' : '‹';
|
||||
btn.title = show ? 'Hide the browser' : 'Show the browser';
|
||||
btn.setAttribute('aria-expanded', String(show));
|
||||
}
|
||||
};
|
||||
let browserShown = true;
|
||||
try {
|
||||
browserShown = localStorage.getItem('seqTlBrowser') !== '0';
|
||||
} catch (_) {
|
||||
/* private mode */
|
||||
}
|
||||
setBrowser(browserShown);
|
||||
on('tl-browser-toggle', 'click', () => {
|
||||
browserShown = !browserShown;
|
||||
setBrowser(browserShown);
|
||||
try {
|
||||
localStorage.setItem('seqTlBrowser', browserShown ? '1' : '0');
|
||||
} catch (_) {
|
||||
/* private mode */
|
||||
}
|
||||
});
|
||||
on('tl-browser-refresh', 'click', async () => {
|
||||
try {
|
||||
const r = await fetch('/presets', { headers: { Accept: 'application/json' } });
|
||||
@@ -1309,7 +1427,12 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
});
|
||||
}
|
||||
on('tl-zoom-out', 'click', () => tlZoom(1 / 1.4, seqTl.hoverX));
|
||||
document.querySelectorAll('#tl-units button').forEach((b) => b.addEventListener('click', () => tlSetUnits(b.dataset.v === 'time')));
|
||||
// Units dropdown: put the old value back first, so tlSetUnits sees a change and converts the clips
|
||||
on('sequence-editor-mode', 'change', (e) => {
|
||||
const timed = e.target.value === 'time';
|
||||
e.target.value = timed ? 'beats' : 'time';
|
||||
tlSetUnits(timed);
|
||||
});
|
||||
on('tl-play', 'click', async () => {
|
||||
const ok = await saveSequenceEditor();
|
||||
if (ok === false || !sequenceEditorId) return;
|
||||
@@ -1340,6 +1463,13 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
if (!seqTl.on || !modal || !modal.classList.contains('active')) return;
|
||||
if (e.target && e.target.closest && e.target.closest('input, select, textarea, [contenteditable]')) return;
|
||||
if (document.querySelector('.modal.active:not(#sequence-editor-modal)')) return;
|
||||
const k = e.key.toLowerCase();
|
||||
if ((e.ctrlKey || e.metaKey) && (k === 'z' || k === 'y')) {
|
||||
e.preventDefault();
|
||||
if (k === 'y' || e.shiftKey) tlRedo();
|
||||
else tlUndo();
|
||||
return;
|
||||
}
|
||||
const c = seqTl.sel && seqTl.sel.clip ? tlClip(seqTl.sel.clip) : null;
|
||||
if (!c) return;
|
||||
if (e.key === 'Delete' || e.key === 'Backspace') {
|
||||
|
||||
@@ -691,29 +691,6 @@ function addSeqTarget(t) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** One target per driver in the current zone's groups, in device-list order (for chases). */
|
||||
function addTargetsPerDriver() {
|
||||
const macs = [];
|
||||
const gids = seqEd.zoneGroupIds.length ? seqEd.zoneGroupIds : Object.keys(seqEd.groupsMap);
|
||||
gids.forEach((gid) => {
|
||||
const g = seqEd.groupsMap[gid];
|
||||
(g && Array.isArray(g.devices) ? g.devices : []).forEach((m) => {
|
||||
const mac = String(m).toLowerCase().replace(/[^0-9a-f]/g, '');
|
||||
if (mac.length === 12 && !macs.includes(mac)) macs.push(mac);
|
||||
});
|
||||
});
|
||||
if (!macs.length) {
|
||||
alert('No drivers found in this zone\'s groups.');
|
||||
return;
|
||||
}
|
||||
const have = new Set(seqEd.targets.filter((t) => t.devices.length === 1 && !t.group_ids.length).map((t) => t.devices[0]));
|
||||
macs.forEach((mac) => {
|
||||
if (have.has(mac)) return;
|
||||
const d = seqEd.devicesMap[mac];
|
||||
addSeqTarget({ name: (d && d.name) || mac, devices: [mac] });
|
||||
});
|
||||
}
|
||||
|
||||
/** Clip "what plays" picker: presets or one-shot sequences (a rest too). Values: p:<id>, a:<id>, rest. */
|
||||
function buildStepPlaySelect(step) {
|
||||
const sel = document.createElement('select');
|
||||
|
||||
+52
-26
@@ -1535,6 +1535,26 @@ html.simulated-bpm-mode .seq-switch-toggle-wrap {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* Sequence editor: the name field sits in the header row, between the title and the buttons */
|
||||
#sequence-editor-modal .modal-head {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
#sequence-editor-modal .modal-head h2 {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
#sequence-editor-modal .modal-head #sequence-editor-name {
|
||||
flex: 1 1 12rem;
|
||||
max-width: 24rem;
|
||||
min-width: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#sequence-editor-modal .modal-head .modal-top-actions {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.modal-content label {
|
||||
display: block;
|
||||
margin-top: 1rem;
|
||||
@@ -2710,10 +2730,13 @@ html.simulated-bpm-mode .seq-switch-toggle-wrap {
|
||||
* presets; --ppb is pixels per beat (or second), set on the canvas.
|
||||
*/
|
||||
#sequence-editor-modal .modal-content {
|
||||
max-width: min(1280px, 96vw);
|
||||
width: 96vw;
|
||||
max-height: 94vh;
|
||||
max-width: 100vw;
|
||||
width: 100vw;
|
||||
height: 100dvh;
|
||||
max-height: 100dvh;
|
||||
border-radius: 0;
|
||||
overflow-y: auto;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.tl {
|
||||
@@ -2770,6 +2793,12 @@ html.simulated-bpm-mode .seq-switch-toggle-wrap {
|
||||
background: #55555d;
|
||||
}
|
||||
|
||||
.tl-tbtn:disabled {
|
||||
color: #777;
|
||||
background: #45454c;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
#tl-play {
|
||||
color: #6cdc6c;
|
||||
}
|
||||
@@ -3144,21 +3173,6 @@ html.simulated-bpm-mode .seq-switch-toggle-wrap {
|
||||
padding: 1.25rem;
|
||||
}
|
||||
|
||||
.tl-addtrack {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
align-items: center;
|
||||
padding: 0.45rem 0.6rem;
|
||||
background: #26262b;
|
||||
border-top: 1px solid #111;
|
||||
}
|
||||
|
||||
#sequence-editor-modal .tl-addtrack select {
|
||||
width: auto;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.tl-browser {
|
||||
flex: 0 0 13rem;
|
||||
display: flex;
|
||||
@@ -3170,6 +3184,22 @@ html.simulated-bpm-mode .seq-switch-toggle-wrap {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
/* Collapsed: only the arrow shows, in a thin strip */
|
||||
.tl-browser.collapsed {
|
||||
flex: 0 0 auto;
|
||||
padding: 0.5rem 0.3rem;
|
||||
}
|
||||
|
||||
.tl-browser.collapsed > :not(.tl-browser-head),
|
||||
.tl-browser.collapsed .tl-browser-head > :not(#tl-browser-toggle) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.tl-browser-head > span {
|
||||
margin-right: auto;
|
||||
margin-left: 0.4rem;
|
||||
}
|
||||
|
||||
.tl-browser-head {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
@@ -3268,6 +3298,10 @@ html.simulated-bpm-mode .seq-switch-toggle-wrap {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.tl-inspector:empty {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.tl-insp-title {
|
||||
font-size: 0.72rem;
|
||||
text-transform: uppercase;
|
||||
@@ -3418,14 +3452,6 @@ html.simulated-bpm-mode .seq-switch-toggle-wrap {
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
#sequence-editor-modal .tl-addtrack {
|
||||
flex-wrap: wrap;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
#sequence-editor-modal .tl-addtrack select {
|
||||
flex: 1 1 10rem;
|
||||
min-width: 0;
|
||||
}
|
||||
#sequence-editor-modal .tl-inspector {
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user