Skip to content

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

address review (codex): a rest-only looped bar must finish, and the tempo mark names its real beat unit

[._.]/ Adam Eivydb9a2df3dcfc
diff --git a/client/src/components/songbook/DrumSheetView.jsx b/client/src/components/songbook/DrumSheetView.jsx
index f2c72774e5..48be306c77 100644
--- a/client/src/components/songbook/DrumSheetView.jsx
+++ b/client/src/components/songbook/DrumSheetView.jsx
@@ -52,6 +52,12 @@ const UI_FONT = 'ui-sans-serif, system-ui, sans-serif';
const strokeStyle = (color) => ({ stroke: color });
const fillStyle = (color) => ({ fill: color });
+// Time-signature denominator → the note glyph for one BEAT at that value, for the
+// tempo marking. The tempo counts notated beats, so 6/8 must read "♪ = 96", not
+// "♩ = 96" — an unlisted denominator falls back to a plain "1/N" fraction rather
+// than a wrong glyph.
+const BEAT_GLYPH = { 1: '𝅝', 2: '𝅗𝅥', 4: '♩', 8: '♪', 16: '𝅘𝅥𝅯' };
+
// One hit's glyph. `cross` pieces (cymbals, hats) draw an ×; `head` pieces
// (drums) draw a notehead. The cell's own flags then modify it: a ring for an
// open hi-hat, a small hollow head for a ghost, a leading grace head for a flam,
@@ -252,7 +258,11 @@ function DrumSheetView({ text, fontSizeRem = 0.875, activeStep = null, onStepCli
<div className={className} style={{ fontSize: `${fontSizeRem}rem` }}>
<div className="flex flex-wrap items-center gap-x-3 gap-y-1 mb-2 text-xs text-gray-500">
<span>{chart.time.beats}/{chart.time.beatValue}</span>
- <span>♩ = {chart.tempo}</span>
+ {/* The tempo counts NOTATED beats — the time-signature denominator — so
+ 6/8 is eighth = bpm, not quarter = bpm. Label the actual beat unit
+ rather than always printing ♩, which would misstate the tempo the
+ playback schedule uses (drumPlayback.buildDrumSchedule). */}
+ <span>{BEAT_GLYPH[chart.time.beatValue] || `1/${chart.time.beatValue}`} = {chart.tempo}</span>
<span>
{chart.subdivision} per beat
</span>
diff --git a/client/src/components/songbook/DrumSheetView.test.jsx b/client/src/components/songbook/DrumSheetView.test.jsx
index bf990b6f65..00d269b86e 100644
--- a/client/src/components/songbook/DrumSheetView.test.jsx
+++ b/client/src/components/songbook/DrumSheetView.test.jsx
@@ -32,6 +32,16 @@ describe('DrumSheetView', () => {
expect(html).toContain('1 bar');
});
+ it('labels the tempo with the ACTUAL beat unit, not always a quarter note', () => {
+ // The tempo counts notated beats (the time-signature denominator), which is
+ // what playback schedules against — so 6/8 must read as eighth = bpm.
+ expect(renderToStaticMarkup(<DrumSheetView text={'time: 4/4\ntempo: 96\n\nK: o'} />)).toContain('♩ = 96');
+ expect(renderToStaticMarkup(<DrumSheetView text={'time: 6/8\ntempo: 96\n\nK: o'} />)).toContain('♪ = 96');
+ expect(renderToStaticMarkup(<DrumSheetView text={'time: 2/2\ntempo: 60\n\nK: o'} />)).toContain('= 60');
+ // An unlisted denominator degrades to a fraction rather than a wrong glyph.
+ expect(renderToStaticMarkup(<DrumSheetView text={'time: 4/3\ntempo: 60\n\nK: o'} />)).toContain('1/3 = 60');
+ });
+
it('takes ink from the theme CSS vars via style, never a var() attribute', () => {
const html = renderToStaticMarkup(<DrumSheetView text={ROCK_BEAT} />);
// SVG presentation attributes don't evaluate var() — every themed color must
diff --git a/client/src/lib/drumPlayback.js b/client/src/lib/drumPlayback.js
index 63d7f44be4..ab79723562 100644
--- a/client/src/lib/drumPlayback.js
+++ b/client/src/lib/drumPlayback.js
@@ -389,9 +389,12 @@ export const createDrumPlayer = (chart, options = {}) => {
};
const transport = createLookaheadTransport({
- // A looping player never "ends" on its own — the transport's end check must
- // not finish it, so its length is unbounded until stop().
- getTotalSec: () => (schedule.loop ? Infinity : schedule.totalSec),
+ // A LOOPING player never "ends" on its own, so the transport's end check must
+ // not finish it — unbounded until stop(). But `canLoop()` is the same gate the
+ // scheduler uses: when a selected range holds no music (a rest-only bar) there
+ // is nothing to repeat, so the run must be allowed to finish at its natural
+ // length instead of sitting "playing" forever after the count-in.
+ getTotalSec: () => (canLoop() ? Infinity : schedule.totalSec),
scheduleWindow,
prepare: () => {
schedule = build();
diff --git a/client/src/lib/drumPlayer.test.js b/client/src/lib/drumPlayer.test.js
index 692b5c41bc..d2793a61df 100644
--- a/client/src/lib/drumPlayer.test.js
+++ b/client/src/lib/drumPlayer.test.js
@@ -192,17 +192,21 @@ describe('createDrumPlayer', () => {
player.stop();
});
- it('does NOT wedge when the looped bar is all rests but the chart has hits', async () => {
- // canLoop must check for a music EVENT, not just pass duration: a rest-only
- // selected bar has real duration but no events, so the pass-rebase branch
- // would reset to the exhausted index and spin forever (a frozen tab, not
- // just silence). The chart's OTHER bar has hits, so Play is enabled.
+ it('finishes (never wedges) when the looped bar is all rests', async () => {
+ // Two coupled guards, both keyed on canLoop(): the scheduler must not spin its
+ // pass-rebase branch on a range with no music events (a rest-only bar has real
+ // duration but nothing to repeat), AND the transport must not report an
+ // Infinite length for it — otherwise playback sits "playing" forever after the
+ // count-in. The chart's OTHER bar has hits, so Play is enabled.
+ const ended = vi.fn();
const chart = parseDrumChart('tempo: 240\nsubdivision: 1\n\n# A\nK: o---\n\n# B\nK: ----');
- const player = createDrumPlayer(chart, { loopBars: { from: 2, to: 2 }, countInBars: 1 });
+ const player = createDrumPlayer(chart, {
+ loopBars: { from: 2, to: 2 }, countInBars: 1, onEnded: ended,
+ });
await player.play();
- // Would never return if the rebase spun; the count-in still sounds.
- drive(3);
- expect(audio.oscillators.length).toBeGreaterThan(0);
- player.stop();
+ drive(3); // would never return if the rebase spun
+ expect(audio.oscillators.length).toBeGreaterThan(0); // the count-in still sounds
+ expect(ended).toHaveBeenCalledTimes(1);
+ expect(player.isPlaying()).toBe(false);
});
});