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
refactor: share one BeatPulse indicator across the metronome and transports (#4130)
Adam Eivyc0a934bf56c9
diff --git a/client/src/components/songbook/ChordTransportBar.jsx b/client/src/components/songbook/ChordTransportBar.jsxindex 23815c0016..b3f5d7be2f 100644--- a/client/src/components/songbook/ChordTransportBar.jsx+++ b/client/src/components/songbook/ChordTransportBar.jsx@@ -22,8 +22,9 @@ import { useState } from 'react';import { SlidersHorizontal, Volume2, VolumeX } from 'lucide-react';import { CHORD_BEATS_MIN, CHORD_BEATS_MAX } from '../../lib/chordPlayback.js';import { ctrlBtnClass, activeCtrlClass, smallSelectClass } from './constants.js';+import BeatPulse from '../ui/BeatPulse.jsx';import {- BeatDots, CountInSelect, PercentButtons, PlayStopButton, TempoControls,+ CountInSelect, PercentButtons, PlayStopButton, TempoControls,} from './TransportControls.jsx';const BEATS_OPTIONS = Array.from(@@ -78,7 +79,7 @@ export default function ChordTransportBar({{/* Where you are: the visual pulse plus the chord counter */}<div className="flex items-center gap-2">- <BeatDots beatsPerBar={beatsPerBar} beat={pulse?.beat ?? null} countingIn={!!pulse?.countingIn} />+ <BeatPulse beatsPerBar={beatsPerBar} beat={pulse?.beat ?? null} countingIn={!!pulse?.countingIn} /><span className="text-xs text-gray-400 tabular-nums whitespace-nowrap">{pulse?.countingIn? 'count-in'diff --git a/client/src/components/songbook/DrumTransportBar.jsx b/client/src/components/songbook/DrumTransportBar.jsxindex ad7209a956..e933fd569f 100644--- a/client/src/components/songbook/DrumTransportBar.jsx+++ b/client/src/components/songbook/DrumTransportBar.jsx@@ -27,8 +27,9 @@ import { Repeat, SlidersHorizontal, Volume2, VolumeX } from 'lucide-react';import { DRUM_KIT_LIST, resolveDrumKit } from '../../lib/drumKits.js';import { clampClickVolume, DEFAULT_CLICK_VOLUME } from '../../lib/drumPlayback.js';import { ctrlBtnClass, activeCtrlClass, smallSelectClass } from './constants.js';+import BeatPulse from '../ui/BeatPulse.jsx';import {- BeatDots, CountInSelect, PercentButtons, PlayStopButton, TempoControls,+ CountInSelect, PercentButtons, PlayStopButton, TempoControls,} from './TransportControls.jsx';export default function DrumTransportBar({@@ -108,7 +109,7 @@ export default function DrumTransportBar({{/* Where you are: the visual pulse plus the bar counter */}<div className="flex items-center gap-2">- <BeatDots beatsPerBar={beatsPerBar} beat={pulse?.beat ?? null} countingIn={!!pulse?.countingIn} />+ <BeatPulse beatsPerBar={beatsPerBar} beat={pulse?.beat ?? null} countingIn={!!pulse?.countingIn} /><span className="text-xs text-gray-400 tabular-nums whitespace-nowrap">{pulse?.countingIn ? 'count-in' : `${currentBar || 1}/${Math.max(1, barCount)}`}</span>diff --git a/client/src/components/songbook/TransportControls.jsx b/client/src/components/songbook/TransportControls.jsxindex 709d48b81b..63475386cc 100644--- a/client/src/components/songbook/TransportControls.jsx+++ b/client/src/components/songbook/TransportControls.jsx@@ -2,7 +2,8 @@* Shared presentational pieces for the SongBook play-along transports — the* drum-kit bar (`DrumTransportBar`) and the chord-sheet bar* (`ChordTransportBar`) render the same play button, practice-tempo cluster,- * percent-of-written buttons, count-in select and beat pulse.+ * percent-of-written buttons and count-in select. The beat pulse they also share+ * lives in `components/ui/BeatPulse.jsx` — the song Metronome draws it too.** Extracted rather than copied so the two bars can't drift on touch-target size,* label wording or the ±5 stepper behaviour. Everything here is stateless: the@@ -142,30 +143,3 @@ export const CountInSelect = ({ idPrefix, countInBars, onCountInChange }) => (</select></div>);--/**- * The pulse row: one dot per beat of the bar, the current one lit. This is the- * metronome you can SEE — the audible click is easy to lose under a backing,- * and on a phone the dots double as "yes, it's actually running".- */-export const BeatDots = ({ beatsPerBar, beat, countingIn }) => (- <div- className="flex items-center gap-1"- role="status"- aria-live="off"- aria-label={countingIn ? `Counting in, beat ${beat || 1}` : (beat ? `Beat ${beat}` : 'Stopped')}- >- {Array.from({ length: beatsPerBar }, (_, i) => {- const lit = beat === i + 1;- return (- <span- key={i}- aria-hidden="true"- className={`rounded-full ${lit ? 'w-2.5 h-2.5' : 'w-1.5 h-1.5'} ${- !lit ? 'bg-port-border' : (countingIn ? 'bg-port-warning' : 'bg-port-accent')- }`}- />- );- })}- </div>-);diff --git a/client/src/components/songs/Metronome.jsx b/client/src/components/songs/Metronome.jsxindex dcc942daa4..c7f584fcd9 100644--- a/client/src/components/songs/Metronome.jsx+++ b/client/src/components/songs/Metronome.jsx@@ -4,8 +4,9 @@* Drives client/src/lib/metronome.js (sample-accurate Web Audio scheduler). The* BPM defaults from the song `tempo`; the time signature is derived from the* score header (default 4/4). Beat 1 is accented both audibly (brighter click)- * and visually (filled accent dot). The optional one-bar count-in lets a singer- * find beat 1 before recording / color-match begins.+ * and visually (the shared `BeatPulse` draws the downbeat a size larger). The+ * optional one-bar count-in lets a singer find beat 1 before recording /+ * color-match begins.** Reads tempo + score from props already on the song record — issues no fetch of* its own. Tears the metronome down on stop and on unmount so a navigation-away@@ -15,6 +16,7 @@import { useCallback, useEffect, useMemo, useRef, useState } from 'react';import { Play, Square, Timer } from 'lucide-react';import toast from '../ui/Toast';+import BeatPulse from '../ui/BeatPulse.jsx';import {createMetronome,clampBpm,@@ -75,8 +77,7 @@ export default function Metronome({ tempo = null, score = '', countInBars = 1 })if (metroRef.current) metroRef.current.setBpm(next);}, []);- const dots = useMemo(() => Array.from({ length: beatsPerBar }, (_, i) => i + 1), [beatsPerBar]);- const activeBeat = running && pulse ? pulse.beat : 0;+ const activeBeat = running && pulse ? pulse.beat : null;return (<div className="bg-port-card border border-port-border rounded-lg p-3">@@ -106,21 +107,9 @@ export default function Metronome({ tempo = null, score = '', countInBars = 1 })</div></div>- {/* Visual beat pulse — one dot per beat; beat 1 is the accent. */}- <div className="flex items-center gap-2 mt-3" aria-hidden="true">- {dots.map((n) => {- const isActive = n === activeBeat;- const isAccent = n === 1;- const tone = isActive- ? (pulse?.countIn ? 'bg-port-warning' : 'bg-port-success')- : 'bg-port-border';- return (- <span- key={n}- className={`rounded-full transition-transform duration-75 ${isAccent ? 'w-3.5 h-3.5' : 'w-2.5 h-2.5'} ${tone} ${isActive ? 'scale-125' : 'scale-100'}`}- />- );- })}+ {/* Visual beat pulse — shared with the SongBook play-along transports. */}+ <div className="flex items-center gap-2 mt-3">+ <BeatPulse beatsPerBar={beatsPerBar} beat={activeBeat} countingIn={!!pulse?.countIn} />{running && (<span className="text-xs text-gray-500 ml-1">{pulse?.countIn ? 'Count-in…' : pulse?.bar ? `Bar ${pulse.bar}` : ''}diff --git a/client/src/components/ui/BeatPulse.jsx b/client/src/components/ui/BeatPulse.jsxnew file mode 100644index 0000000000..e9a555c354--- /dev/null+++ b/client/src/components/ui/BeatPulse.jsx@@ -0,0 +1,56 @@+/**+ * BeatPulse — the metronome you can SEE: one dot per beat of the bar, the+ * current one lit.+ *+ * Three surfaces draw this same row (the song `Metronome`, and the SongBook+ * drum + chord play-along transports). They each grew their own copy and had+ * already drifted on lit color and dot size, so the widget lives here once and+ * every host renders it. Rendering only the dots is deliberate: each host pairs+ * them with a different readout ("Bar 3", "2/8 bars", "5/12 chords"), so the+ * text stays with the host.+ *+ * Conventions the copies agreed on and this keeps:+ * - beat 1 is the downbeat and reads a size larger, matching the accented click;+ * - a count-in beat lights amber (`port-warning`) so "not yet" is unmistakable;+ * - unlit dots are `port-border`, i.e. the same weight as any inert chrome.+ *+ * `beat` is 1-based and `null`/`0` when stopped — the audible click is easy to+ * lose under a backing track, so "nothing lit" has to read as stopped.+ */++// Lit dots are `port-success`, not `port-accent`: in the transport bars the+// accent color already means "this control is engaged" (`activeCtrlClass`), and+// a beat dot borrowing it competed with the play button. Green reads as+// "sounding now" and stays clearly distinct from the amber count-in.+const litTone = (countingIn) => (countingIn ? 'bg-port-warning' : 'bg-port-success');++export default function BeatPulse({ beatsPerBar = 4, beat = null, countingIn = false, className = '' }) {+ // A malformed time signature must not blank the row out.+ const beats = Number.isFinite(beatsPerBar) ? Math.max(1, Math.floor(beatsPerBar)) : 4;+ const label = countingIn+ ? `Counting in, beat ${beat || 1}`+ : (beat ? `Beat ${beat}` : 'Stopped');++ return (+ <div+ className={`flex items-center gap-1.5 ${className}`.trim()}+ role="status"+ aria-live="off"+ aria-label={label}+ >+ {Array.from({ length: beats }, (_, i) => {+ const lit = beat === i + 1;+ const downbeat = i === 0;+ return (+ <span+ key={i}+ aria-hidden="true"+ className={`rounded-full transition-transform duration-75 ${+ downbeat ? 'w-3 h-3' : 'w-2 h-2'+ } ${lit ? litTone(countingIn) : 'bg-port-border'} ${lit ? 'scale-125' : 'scale-100'}`}+ />+ );+ })}+ </div>+ );+}diff --git a/client/src/components/ui/BeatPulse.test.jsx b/client/src/components/ui/BeatPulse.test.jsxnew file mode 100644index 0000000000..19d4d901d9--- /dev/null+++ b/client/src/components/ui/BeatPulse.test.jsx@@ -0,0 +1,67 @@+import { describe, it, expect } from 'vitest';+import { render, screen } from '@testing-library/react';++import BeatPulse from './BeatPulse.jsx';++// The dots are aria-hidden, so read them off the container rather than by role.+const dotsOf = (container) => Array.from(container.querySelectorAll('span'));++describe('BeatPulse', () => {+ it('renders one dot per beat of the bar', () => {+ const { container } = render(<BeatPulse beatsPerBar={7} beat={null} />);+ expect(dotsOf(container)).toHaveLength(7);+ });++ it('lights only the current beat, in the running tone', () => {+ const { container } = render(<BeatPulse beatsPerBar={4} beat={3} />);+ const dots = dotsOf(container);+ expect(dots[2].className).toContain('bg-port-success');+ expect(dots[2].className).toContain('scale-125');+ // Every other dot stays inert.+ [0, 1, 3].forEach((i) => {+ expect(dots[i].className).toContain('bg-port-border');+ expect(dots[i].className).not.toContain('bg-port-success');+ });+ });++ it('lights a count-in beat amber instead of green', () => {+ const { container } = render(<BeatPulse beatsPerBar={4} beat={2} countingIn />);+ const dots = dotsOf(container);+ expect(dots[1].className).toContain('bg-port-warning');+ expect(dots[1].className).not.toContain('bg-port-success');+ });++ it('draws the downbeat a size larger than the rest', () => {+ const { container } = render(<BeatPulse beatsPerBar={3} beat={null} />);+ const dots = dotsOf(container);+ expect(dots[0].className).toContain('w-3 h-3');+ expect(dots[1].className).toContain('w-2 h-2');+ expect(dots[2].className).toContain('w-2 h-2');+ });++ it('leaves every dot unlit when stopped', () => {+ const { container } = render(<BeatPulse beatsPerBar={4} beat={null} />);+ dotsOf(container).forEach((dot) => expect(dot.className).toContain('bg-port-border'));+ expect(screen.getByRole('status')).toHaveAttribute('aria-label', 'Stopped');+ });++ it.each([+ ['stopped', { beat: null, countingIn: false }, 'Stopped'],+ ['running', { beat: 3, countingIn: false }, 'Beat 3'],+ ['counting in', { beat: 2, countingIn: true }, 'Counting in, beat 2'],+ ['counting in before the first beat lands', { beat: null, countingIn: true }, 'Counting in, beat 1'],+ ])('announces %s', (_label, props, expected) => {+ render(<BeatPulse beatsPerBar={4} {...props} />);+ expect(screen.getByRole('status')).toHaveAttribute('aria-label', expected);+ });++ it('falls back to 4 beats when the time signature is unusable', () => {+ const { container } = render(<BeatPulse beatsPerBar={NaN} beat={null} />);+ expect(dotsOf(container)).toHaveLength(4);+ });++ it('never renders an empty row for a zero or negative beat count', () => {+ const { container } = render(<BeatPulse beatsPerBar={0} beat={null} />);+ expect(dotsOf(container)).toHaveLength(1);+ });+});