Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (codex): clear per-voice playhead at its own end; rebuild layered player on score-content change
[._.]/ Adam Eivya667cf880d8d
diff --git a/client/src/lib/scorePlayback.js b/client/src/lib/scorePlayback.jsindex bdb3eda891..54adf5f2dc 100644--- a/client/src/lib/scorePlayback.js+++ b/client/src/lib/scorePlayback.js@@ -314,12 +314,16 @@ export const createMultiScorePlayer = (parts, options = {}) => {let bpm = Number.isFinite(options.bpm) && options.bpm > 0 ? options.bpm : null;// A voice carries its part id, its schedule, and per-voice scheduler cursors.+ // `endNotified` tracks whether this voice's playhead has been cleared at its+ // own end — voices have different lengths, so a short part must clear when IT+ // finishes, not when the longest part does (else its last note stays lit).const buildVoices = () => (parts || []).map((p) => ({id: p.id,schedule: buildSchedule(p.score, bpm),nextScheduleIdx: 0,nextNotifyIdx: 0,lastNotified: -1,+ endNotified: false,}));let voices = [];@@ -365,6 +369,7 @@ export const createMultiScorePlayer = (parts, options = {}) => {v.nextScheduleIdx = idx;v.nextNotifyIdx = idx;v.lastNotified = -1;+ v.endNotified = false;}};@@ -395,6 +400,13 @@ export const createMultiScorePlayer = (parts, options = {}) => {v.lastNotified = newest;safeCall(onNote, v.id, newest);}++ // Clear this voice's playhead the moment IT finishes (its last note's+ // duration has elapsed), independent of longer voices still sounding.+ if (!v.endNotified && now - startTime >= v.schedule.totalSec) {+ v.endNotified = true;+ safeCall(onNote, v.id, null);+ }}if (now - startTime >= totalSec) finish();diff --git a/client/src/lib/scorePlayback.test.js b/client/src/lib/scorePlayback.test.jsindex d92a758a70..c93b701b8a 100644--- a/client/src/lib/scorePlayback.test.js+++ b/client/src/lib/scorePlayback.test.js@@ -207,6 +207,21 @@ describe('createMultiScorePlayer', () => {expect(ended).toHaveBeenCalledTimes(1);});+ it('clears a short voice\'s playhead when IT ends, before a longer voice finishes', async () => {+ const SHORT = parseScore('time: 4/4\ntempo: 120\n| C4q |'); // 1 note → 0.5 s+ const LONG = parseScore('time: 4/4\ntempo: 120\n| C4q D4q E4q F4q |'); // 4 notes → 2 s+ const seen = [];+ const player = createMultiScorePlayer(+ [{ id: 'short', score: SHORT }, { id: 'long', score: LONG }],+ { bpm: 120, onNote: (id, i) => seen.push([id, i]) },+ );+ await player.play();+ drive(1.0); // short (0.5 s) has ended; long (2 s) is still sounding+ expect(seen).toContainEqual(['short', null]); // short cleared at its own end+ expect(seen.some(([id, i]) => id === 'long' && i === null)).toBe(false); // long not cleared yet+ player.stop();+ });+it('plays only the parts it is given (a deselected part contributes nothing)', async () => {const player = createMultiScorePlayer([{ id: 'bass', score: BASS }], { bpm: 120 });await player.play();diff --git a/client/src/pages/SongEditor.jsx b/client/src/pages/SongEditor.jsxindex 8f40de9ce5..4ed52769a0 100644--- a/client/src/pages/SongEditor.jsx+++ b/client/src/pages/SongEditor.jsx@@ -912,6 +912,10 @@ function LayeredSheetMusic({ tabs }) {const [activeByPart, setActiveByPart] = useState({}); // partKey → now-sounding note indexconst selectionKey = tabs.filter((t) => selected.has(t.key)).map((t) => t.key).join('|');+ // Notation content of every tab — changes when a score's TEXT changes even if+ // its id/tempo don't (e.g. "Refresh from template"), so the player is rebuilt+ // against the freshly-parsed scores rather than playing the stale ones.+ const scoresKey = tabs.map((t) => t.score).join('');const teardown = useCallback(() => {if (playerRef.current) { playerRef.current.stop(); playerRef.current = null; }@@ -919,8 +923,8 @@ function LayeredSheetMusic({ tabs }) {setActiveByPart({});}, []);- // A changed selection / tab set / tempo invalidates the combined player.- useEffect(() => { teardown(); }, [selectionKey, tabsKey, tempo, teardown]);+ // A changed selection / tab set / score content / tempo invalidates the player.+ useEffect(() => { teardown(); }, [selectionKey, tabsKey, scoresKey, tempo, teardown]);// Tear down live audio on unmount.useEffect(() => () => teardown(), [teardown]);