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
songs: harden round-stack playback and make sheet-music rows content-sized
[._.]/ Adam Eivy311226cfbc0a
diff --git a/client/src/components/songs/RoundStack.jsx b/client/src/components/songs/RoundStack.jsxindex 68190c35cc..736951d0ef 100644--- a/client/src/components/songs/RoundStack.jsx+++ b/client/src/components/songs/RoundStack.jsx@@ -15,6 +15,7 @@import { useState, useRef, useEffect, useMemo, useCallback } from 'react';import { Link } from 'react-router-dom';import { Play, Square, Music, Layers } from 'lucide-react';+import toast from '../ui/Toast';import ScoreSheet from './ScoreSheet';import { scoreHasMusic } from '../../lib/scoreNotation';import { createLayeredPlayer } from '../../lib/songPlayback';@@ -36,9 +37,11 @@ export default function RoundStack({ songs = [] }) {}))), [songs]);const audibleCount = useMemo(() => takes.filter((t) => !t.muted).length, [takes]);- // Stop and release the mixer on unmount or when the take set changes (a new- // recording elsewhere shouldn't keep an old mix playing).- useEffect(() => () => { playerRef.current?.stop(); }, []);+ // Stop and release the mixer on unmount AND whenever the stacked takes change+ // — otherwise navigating to another partner (or any songs-prop change) while+ // ?stack=1 is open would leave the previous mix audibly playing under the new+ // stack. Resetting `playing` keeps the button in sync with the silenced mix.+ useEffect(() => () => { playerRef.current?.stop(); setPlaying(false); }, [takes]);const stop = useCallback(() => {playerRef.current?.stop();@@ -51,7 +54,12 @@ export default function RoundStack({ songs = [] }) {player.onEnded(() => setPlaying(false));playerRef.current = player;setPlaying(true);- await player.play();+ // A take URL that 404s or fails to decode rejects play() — without this the+ // button would stay stuck on "Stop" with no mix running (mirrors SongRecordings).+ await player.play().catch((err) => {+ toast.error(err?.message || 'Playback failed');+ setPlaying(false);+ });}, [takes]);if (songs.length === 0) return null;diff --git a/client/src/components/songs/RoundStack.test.jsx b/client/src/components/songs/RoundStack.test.jsxindex 0b7193b1d4..1198bd68cc 100644--- a/client/src/components/songs/RoundStack.test.jsx+++ b/client/src/components/songs/RoundStack.test.jsx@@ -1,20 +1,26 @@import { describe, it, expect, vi, beforeEach } from 'vitest';-import { render, screen, fireEvent } from '@testing-library/react';+import { render, screen, fireEvent, waitFor } from '@testing-library/react';import { MemoryRouter } from 'react-router-dom';+import toast from '../ui/Toast';-// Mock the audio mixer — jsdom has no Web Audio. Capture the takes it receives-// so we can assert RoundStack flattens recordings across ALL stacked songs.-const playerCalls = vi.hoisted(() => ({ takes: null, play: null, stop: null }));+// Mock the audio mixer — jsdom has no Web Audio. Track every created player so+// tests can assert which takes were passed and that old players get stopped.+const playerCalls = vi.hoisted(() => ({ takes: null, players: [], rejectPlay: false }));vi.mock('../../lib/songPlayback', () => ({createLayeredPlayer: (takes) => {playerCalls.takes = takes;- playerCalls.play = vi.fn().mockResolvedValue(undefined);- playerCalls.stop = vi.fn();- return { play: playerCalls.play, stop: playerCalls.stop, onEnded: vi.fn() };+ const player = {+ play: vi.fn(() => (playerCalls.rejectPlay ? Promise.reject(new Error('boom')) : Promise.resolve())),+ stop: vi.fn(),+ onEnded: vi.fn(),+ };+ playerCalls.players.push(player);+ return player;},}));// getUploadUrl is the only thing RoundStack needs from the api barrel.vi.mock('../../services/api', () => ({ getUploadUrl: (f) => `/api/uploads/${f}` }));+vi.mock('../ui/Toast', () => ({ default: { error: vi.fn(), success: vi.fn() } }));import RoundStack from './RoundStack.jsx';@@ -39,7 +45,12 @@ const renderStack = (songs) => render();describe('RoundStack', () => {- beforeEach(() => { playerCalls.takes = null; });+ beforeEach(() => {+ playerCalls.takes = null;+ playerCalls.players = [];+ playerCalls.rejectPlay = false;+ toast.error.mockClear();+ });it('renders nothing for an empty list', () => {const { container } = renderStack([]);@@ -65,7 +76,7 @@ describe('RoundStack', () => {'seed-hey-ho-nobody-home:rec-1','seed-ah-poor-bird:rec-2',]);- expect(playerCalls.play).toHaveBeenCalled();+ expect(playerCalls.players[0].play).toHaveBeenCalled();});it('hides the play button when no song has an audible take', () => {@@ -73,4 +84,23 @@ describe('RoundStack', () => {renderStack(muted);expect(screen.queryByRole('button', { name: /Play all parts/i })).toBeNull();});++ it('resets to Play (and toasts) when playback fails', async () => {+ playerCalls.rejectPlay = true;+ renderStack(SONGS);+ fireEvent.click(screen.getByRole('button', { name: /Play all parts/i }));+ // The failed play() must not leave the button stuck on "Stop".+ await waitFor(() => expect(screen.getByRole('button', { name: /Play all parts/i })).toBeTruthy());+ expect(screen.queryByRole('button', { name: /^Stop$/i })).toBeNull();+ expect(toast.error).toHaveBeenCalled();+ });++ it('stops the previous mix when the stacked songs change', () => {+ const { rerender } = renderStack(SONGS);+ fireEvent.click(screen.getByRole('button', { name: /Play all parts/i }));+ expect(playerCalls.players).toHaveLength(1);+ // Navigating to a different stack (songs prop changes) must silence the old mix.+ rerender(<MemoryRouter><RoundStack songs={[SONGS[0]]} /></MemoryRouter>);+ expect(playerCalls.players[0].stop).toHaveBeenCalled();+ });});diff --git a/client/src/components/songs/ScoreSheet.jsx b/client/src/components/songs/ScoreSheet.jsxindex a0bed7338b..2b1ddcd918 100644--- a/client/src/components/songs/ScoreSheet.jsx+++ b/client/src/components/songs/ScoreSheet.jsx@@ -42,11 +42,14 @@ const BEAT_PX = 30; // horizontal px per quarter-note beatconst MAX_STRETCH = 1.45; // cap row justification so a short row isn't blown outconst ROW_TOP_PAD = 34; // room above the staff for chord symbols-const ROW_STAFF_TO_LYRIC = 48; // room below the staff for lyrics + below-staff notes-const LYRIC_BELOW_NOTE = 14; // gap from the lowest notehead to the lyric baseline-const LYRIC_MIN_BELOW_STAFF = 22; // floor so high-only rows keep lyrics close to the staff+const LYRIC_BELOW_NOTE = 14; // gap from the lowest notehead down to the lyric baseline+const LYRIC_MIN_BELOW_STAFF = 22; // floor so a high-only row keeps lyrics close to the staff+const LYRIC_DESCENDER = 8; // room below the lyric baseline for text descendersconst ROW_GAP = 18; // gap between rows-const ROW_HEIGHT = ROW_TOP_PAD + 4 * GAP + ROW_STAFF_TO_LYRIC + ROW_GAP;+// A row's height is derived from its content (see rowLyricOffset) rather than a+// fixed constant, so a row of low ledger notes reserves enough space for its+// lyrics instead of letting them spill into the next row.+const STAFF_BLOCK = 4 * GAP; // the five staff lines span four gaps// Ink is driven off the PortOS theme text/accent CSS variables so the score// adapts to the active theme — near-black notes & lyrics in day mode, light ink@@ -112,12 +115,39 @@ const packRows = (measures, keySigCount) => {return rows;};+// Vertical room a row needs below the staff: from the staff's bottom line down+// to the lyric baseline, enough to clear the row's LOWEST notehead before the+// lyric sits under it. Floored at LYRIC_MIN_BELOW_STAFF so a row of only high+// notes still tucks its lyrics close under the staff. `bottomLineStep` is the+// diatonic step on the staff's bottom line. Single pass over the row's notes.+const rowLyricOffset = (row, bottomLineStep) => {+ let lowestStep = bottomLineStep;+ for (const rm of row.rowMeasures) {+ for (const note of rm.measure.notes) {+ if (!note.rest && note.step < lowestStep) lowestStep = note.step;+ }+ }+ const belowStaffPx = Math.max(0, bottomLineStep - lowestStep) * STEP; // staffBottom → lowest head+ return Math.max(LYRIC_MIN_BELOW_STAFF, belowStaffPx + LYRIC_BELOW_NOTE);+};+export default function ScoreSheet({ text, className = '' }) {const score = useMemo(() => parseScore(text), [text]);const { rows, height } = useMemo(() => {const packed = packRows(score.measures, score.keySig.count);- return { rows: packed, height: Math.max(ROW_HEIGHT, packed.length * ROW_HEIGHT) + 8 };+ const blStep = BOTTOM_LINE_STEP[score.clef] ?? BOTTOM_LINE_STEP.treble;+ // Lay rows out with content-derived heights and cumulative tops, so a row of+ // low notes reserves more vertical space and never overlaps the next row.+ let top = 0;+ const laid = packed.map((row) => {+ const lyricOffset = rowLyricOffset(row, blStep);+ const rowHeight = ROW_TOP_PAD + STAFF_BLOCK + lyricOffset + LYRIC_DESCENDER + ROW_GAP;+ const annotated = { ...row, top, lyricOffset };+ top += rowHeight;+ return annotated;+ });+ return { rows: laid, height: top + 8 };}, [score]);if (!score.measures.some((m) => m.notes.length > 0)) return null;@@ -127,19 +157,16 @@ export default function ScoreSheet({ text, className = '' }) {const els = [];rows.forEach((row, ri) => {- const rowTop = ri * ROW_HEIGHT;+ const rowTop = row.top;const staffTop = rowTop + ROW_TOP_PAD;- const staffBottom = staffTop + 4 * GAP;+ const staffBottom = staffTop + STAFF_BLOCK;const chordY = rowTop + 16;// y for a diatonic step within this row.const yForStep = (step) => staffBottom - (step - bottomLineStep) * STEP;- // Lyrics sit below the LOWEST notehead in the row, not at a fixed offset —- // otherwise notes that dip below the staff (ledger-line pitches like A3) draw- // on top of the lyric text. Floor at LYRIC_MIN_BELOW_STAFF so a row of only- // high notes still keeps its lyrics tucked close under the staff.- const rowPitchedNotes = row.rowMeasures.flatMap((rm) => rm.measure.notes).filter((n) => !n.rest);- const lowestStep = rowPitchedNotes.length ? Math.min(...rowPitchedNotes.map((n) => n.step)) : bottomLineStep;- const lyricY = Math.max(staffBottom + LYRIC_MIN_BELOW_STAFF, yForStep(lowestStep) + LYRIC_BELOW_NOTE);+ // Lyric baseline sits below the row's lowest notehead (row.lyricOffset is the+ // content-derived gap), so below-staff ledger notes (e.g. A3) never draw on+ // top of the lyric text and the row height already reserves the space.+ const lyricY = staffBottom + row.lyricOffset;// Staff: five lines across the full content width.for (let line = 0; line < 5; line += 1) {diff --git a/client/src/components/songs/ScoreSheet.test.jsx b/client/src/components/songs/ScoreSheet.test.jsxindex 75d173e5fa..c25fb0ed12 100644--- a/client/src/components/songs/ScoreSheet.test.jsx+++ b/client/src/components/songs/ScoreSheet.test.jsx@@ -84,6 +84,17 @@ describe('ScoreSheet renderer', () => {expect(lyricY).toBeGreaterThan(headY);});+ it('grows the row height for low ledger notes so lyrics never clip the next row', () => {+ const vb = (html) => Number(/viewBox="0 0 \d+ ([\d.]+)"/.exec(html)?.[1]);+ const low = renderToStaticMarkup(<ScoreSheet text={'| C3q(low) |'} />); // well below the staff+ const high = renderToStaticMarkup(<ScoreSheet text={'| C5q(high) |'} />); // above the staff+ // A low-note row reserves more vertical space than a high-note row.+ expect(vb(low)).toBeGreaterThan(vb(high));+ // The low note's lyric baseline stays inside the SVG height (not clipped).+ const lyricY = Number(new RegExp('<text[^>]*\\by="([\\d.]+)"[^>]*>low<').exec(low)?.[1]);+ expect(lyricY).toBeLessThan(vb(low));+ });+it('renders a bass clef score without error', () => {const html = renderToStaticMarkup(<ScoreSheet text={'clef: bass\n| G2q C3q |'} />);expect(html).not.toMatch(/NaN/);