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
fix: inherit drum preview transport settings (#3222)
[._.]/ Adam Eivybac9179c52c8
diff --git a/client/src/components/songbook/DrumPreview.jsx b/client/src/components/songbook/DrumPreview.jsxindex 6318bd3b7b..ecfbb614da 100644--- a/client/src/components/songbook/DrumPreview.jsx+++ b/client/src/components/songbook/DrumPreview.jsx@@ -21,7 +21,7 @@ export default function DrumPreview({settingsMirror,}) {const [snapshot, setSnapshot] = useState(text);- const player = useDrumPlayer(snapshot, { songId });+ const player = useDrumPlayer(snapshot, { songId, initialSettings: settingsMirror });const chartChanged = text !== snapshot;const liveHasMusic = useMemo(() => chartHasMusic(parseDrumChart(text)), [text]);useWakeLock(player.playing);diff --git a/client/src/hooks/useDrumPlayer.js b/client/src/hooks/useDrumPlayer.jsindex acd62ff0c3..c0483e8878 100644--- a/client/src/hooks/useDrumPlayer.js+++ b/client/src/hooks/useDrumPlayer.js@@ -40,9 +40,11 @@ import { safeReadStorage, safeWriteStorage } from '../lib/safeStorage.js';* chart/song change, and on unmount — nothing survives the view.** @param {string} text — the raw drum-chart source.- * @param {{ songId?: string }} [options] — `songId` keys the persisted tempo.+ * @param {{ songId?: string, initialSettings?: object }} [options] — `songId`+ * keys the persisted tempo; `initialSettings` seeds a second transport that+ * should inherit the first transport's count-in and loop configuration.*/-export default function useDrumPlayer(text, { songId } = {}) {+export default function useDrumPlayer(text, { songId, initialSettings } = {}) {const chart = useMemo(() => parseDrumChart(text), [text]);const barCount = chart.bars.length;// Bars can parse while every cell is a rest — there'd be nothing to hear, so@@ -55,10 +57,19 @@ export default function useDrumPlayer(text, { songId } = {}) {const storageKey = songId ? `songbook:drumBpm:${songId}` : null;const [bpm, setBpmState] = useState(writtenTempo);- const [countInBars, setCountInBarsState] = useState(1);- const [loopEnabled, setLoopEnabledState] = useState(false);- const [loopFrom, setLoopFromState] = useState(1);- const [loopTo, setLoopToState] = useState(1);+ const initialLoop = resolveLoopRange(+ barCount,+ initialSettings?.loopEnabled+ ? { from: initialSettings.loopFrom, to: initialSettings.loopTo }+ : null,+ );+ const initialCountIn = initialSettings?.countInBars == null+ ? 1+ : Math.max(0, Math.min(4, Math.trunc(Number(initialSettings.countInBars)) || 0));+ const [countInBars, setCountInBarsState] = useState(initialCountIn);+ const [loopEnabled, setLoopEnabledState] = useState(!!initialSettings?.loopEnabled);+ const [loopFrom, setLoopFromState] = useState(initialLoop?.from ?? 1);+ const [loopTo, setLoopToState] = useState(initialLoop?.to ?? Math.max(1, barCount));// The click is a play-along METRONOME, so it defaults on — practising a groove// against no pulse is the unusual case, and "never chosen" must not read as// "chosen off" (the hook's own default handles that distinction).@@ -85,8 +96,13 @@ export default function useDrumPlayer(text, { songId } = {}) {setBpmState(stored ?? writtenTempo);}, [storageKey, writtenTempo]);- // A chart change invalidates the loop range (the bar count differs).+ // A later chart change invalidates the loop range. The initial bar count is+ // already represented by the state initializers above, including any range+ // inherited by an edit preview.+ const previousBarCountRef = useRef(barCount);useEffect(() => {+ if (previousBarCountRef.current === barCount) return;+ previousBarCountRef.current = barCount;setLoopFromState(1);setLoopToState(Math.max(1, barCount));}, [barCount]);diff --git a/client/src/pages/SongBookViewer.test.jsx b/client/src/pages/SongBookViewer.test.jsxindex 9e2a829a71..16844d7732 100644--- a/client/src/pages/SongBookViewer.test.jsx+++ b/client/src/pages/SongBookViewer.test.jsx@@ -338,6 +338,20 @@ K: o - - - - - o -`;await waitFor(() => expect(screen.getByLabelText('Practice tempo (BPM)').value).toBe('72'));});+ it('inherits play-mode count-in and loop settings when entering edit mode', async () => {+ api.getSong.mockResolvedValue(drumSong());+ renderPage();+ await screen.findByLabelText('Count-in');+ fireEvent.change(screen.getByLabelText('Count-in'), { target: { value: '2' } });+ fireEvent.click(screen.getByLabelText('Enable loop'));+ fireEvent.change(screen.getByLabelText('Loop from bar'), { target: { value: '2' } });+ fireEvent.click(screen.getByRole('button', { name: 'Edit' }));++ await waitFor(() => expect(screen.getByLabelText('Count-in').value).toBe('2'));+ expect(screen.getByLabelText('Disable loop')).toBeTruthy();+ expect(screen.getByLabelText('Loop from bar').value).toBe('2');+ });+it('keeps an unknown stored instrument/format selectable and preserves it on save', async () => {// A song synced from a NEWER peer carrying values this client doesn't list.api.getSong.mockResolvedValue(song({