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): resolve the legend's "o" row for the pieces a chart actually uses

[._.]/ Adam Eivy170bc41306bc
diff --git a/client/src/components/songbook/DrumSheetView.jsx b/client/src/components/songbook/DrumSheetView.jsx
index 58f5a78bbd..39eac3f586 100644
--- a/client/src/components/songbook/DrumSheetView.jsx
+++ b/client/src/components/songbook/DrumSheetView.jsx
@@ -52,7 +52,7 @@
*/
import { memo, useEffect, useId, useMemo, useRef, useState } from 'react';
-import { parseDrumChart, kitPiece, describeDrumCell, describeDrumPosition, DRUM_GLYPH_LEGEND } from '../../lib/drumNotation.js';
+import { parseDrumChart, kitPiece, describeDrumCell, describeDrumPosition, drumGlyphLegend } from '../../lib/drumNotation.js';
import useEscapeKey from '../../hooks/useEscapeKey.js';
import { ctrlBtnClass, activeCtrlClass } from './constants.js';
@@ -225,7 +225,7 @@ const HitReadout = ({ info, position, onClose }) => (
const KitLegend = ({ id, pieces }) => (
<div id={id} className="mt-2 rounded-lg border border-port-border bg-port-bg/60 px-3 py-2 text-xs">
<dl className="grid gap-x-4 gap-y-1 sm:grid-cols-2">
- {DRUM_GLYPH_LEGEND.map((glyph) => (
+ {drumGlyphLegend(pieces).map((glyph) => (
<div key={glyph.char} className="flex items-start gap-2">
<dt className="shrink-0 rounded border border-port-border bg-port-card px-1.5 font-mono text-sm text-port-accent">
{glyph.char}
diff --git a/client/src/lib/README.md b/client/src/lib/README.md
index afafb0c1ae..231e9069ed 100644
--- a/client/src/lib/README.md
+++ b/client/src/lib/README.md
@@ -126,7 +126,7 @@ grep -i "what you want to do" client/src/lib/README.md
| `universeBuilderExpand.js` | `mergeExpandIntoDraft(draft, result)` — pure merge of a Universe Builder draft with the LLM expand-API response (lock honoring, category/sheet merge with `kind` precedence, canon dedupe by name/slugline/alias). Also exports `mergeVariations`, `mergeCanonByName`, and `extractPreservedFromDraft` for callers that need the building blocks (per-category Generate, save-time refetch+merge). |
| `editorialChecks.js` | Pure helpers for the Editorial Checks page (`/pipeline/editorial-checks`, #1285): `groupChecksByScope(checks)` buckets catalog rows into ordered Noun/Scene/Issue/Series sections; `groupFindingsByCheck(comments, rowsById)` groups check-sourced review comments per check with open/total + severity counts; `openFindingsTotal(groups)` sums open findings; `findingManuscriptLink(seriesId, comment)` builds the `?comment=` deep-link into the manuscript editor; the triage filter/sort helpers (#1600) `deriveFindingFacets(groups)` (enumerate present severities/statuses/scopes/checks/issues), `applyFindingsView(groups, filters, sort)` (filter + recount + sort findings and groups), `normalizeFindingSort`, `findingIssueKey`, and the `FINDING_SORT_OPTIONS` table; the per-check maturity/quality helpers (#1629) `checkDismissalRate(group)` and `checkMaturity(group)` (→ `{ findings, dismissalRate, falsePositiveRate, level }`, `level` ∈ new/unproven/noisy/reliable) plus the `CHECK_MATURITY_MIN_SAMPLE`/`CHECK_NOISY_DISMISSAL_RATE` thresholds; plus `scopeLabel` and the `CHECK_SCOPE_ORDER`/`CHECK_SCOPE_LABELS` tables. No React/window — the page and its tests share them. |
| `editorialHealth.js` | Pure presentation helpers for the editorial health panel (`/pipeline/editorial-checks`, #1316): `scoreBand(score)` bands a 0–100 health score into a label + Tailwind tone; `deltaDisplay(delta)` formats the revision-to-revision score change (arrow + tone); `sparklineGeometry(points, box)` projects the trend's score points into SVG polyline coords; `orderedCategories(openByCategory)` sorts the per-category open-finding breakdown; `orderedChecks(openByCheck, labelFor)` sorts the per-check breakdown resolving each id to its catalog label (#1597); `checkCountSeries(points, checkId)` extracts one check's count series across the trend points; `countSparklineGeometry(values, box)` projects a non-negative count series into SVG polyline coords normalized to its own max (per-check finding-count sparkline); `diffCountMaps(current, previous)` lists the buckets whose open-finding count changed between two snapshots (#1630); `snapshotDiff(point, previous)` builds a trend snapshot's drill-down (its own breakdown + per-severity/category/check diff vs the prior revision, null-aware for pre-#1597 per-check telemetry, #1630); plus the `SEVERITY_ORDER`/`SEVERITY_LABELS` and `READINESS_GATE_LABELS`/`READINESS_GATE_ORDER` tables. No React/window — the panel and its tests share them. |
-| `drumNotation.js` | Parser for the PortOS drum-kit notation (#3115) — a dependency-free GRID DSL (`HH: x x x x`) for the SongBook `drum` content format, drawn by `<DrumSheetView>` (hand-rolled SVG, no engraving lib). `parseDrumChart(text)` → `{ time, tempo, subdivision, stepsPerBar, bars:[{index,label,repeat,repeatPass,rows:[{piece,cells}]}], pieces, errors }` — `key: value` headers (`time`/`tempo`/`subdivision`/`kit` row-order override), blank-line-separated bar blocks with a `# label x2` repeat suffix expanded into real bars, nine kit pieces (`CR RD HH T1 T2 S FT K HF`, long aliases accepted), six cell glyphs (`-` rest, `x` normal, `X` accent, `o` open, `g` ghost, `f` flam) with spacing optional. Forgiving: short rows pad with rests, over-long rows truncate, unknown pieces/cells collect into `errors` — never throws. Plus `KIT_PIECES` (label / GM `midi` / synth `sound` / `glyph`), `kitPiece(id)`, `CELL_GLYPHS` (per-glyph velocity + flags), `isDrumNotation(text)` (import-page format sniff, runs BEFORE `tabNotation.detectFormat`), `drumChartHasMusic(text)` and its already-parsed twin `chartHasMusic(chart)`. Also the plain-language explainers the sheet's tap-a-note readout and Legend panel read — `describeDrumCell(pieceId, cell)` → `{ pieceLabel, char, articulation, detail, technique, velocityPercent, rest }` (piece-aware: `o` is "Open" on a hi-hat/cymbal but a normal hit on a drum; a null/unknown cell describes as a rest, an unknown piece returns null), `describeDrumPosition(bar, step, subdivision)` → `bar 6, count “2 e”` (count-along syllables, exact `+n/N` fallback for an unconventional subdivision), `DRUM_GLYPH_LEGEND` (all six cell characters) and each `KIT_PIECES` row's `technique` (how that piece is struck). NOT the lead-sheet parser (`scoreNotation.js`). |
+| `drumNotation.js` | Parser for the PortOS drum-kit notation (#3115) — a dependency-free GRID DSL (`HH: x x x x`) for the SongBook `drum` content format, drawn by `<DrumSheetView>` (hand-rolled SVG, no engraving lib). `parseDrumChart(text)` → `{ time, tempo, subdivision, stepsPerBar, bars:[{index,label,repeat,repeatPass,rows:[{piece,cells}]}], pieces, errors }` — `key: value` headers (`time`/`tempo`/`subdivision`/`kit` row-order override), blank-line-separated bar blocks with a `# label x2` repeat suffix expanded into real bars, nine kit pieces (`CR RD HH T1 T2 S FT K HF`, long aliases accepted), six cell glyphs (`-` rest, `x` normal, `X` accent, `o` open, `g` ghost, `f` flam) with spacing optional. Forgiving: short rows pad with rests, over-long rows truncate, unknown pieces/cells collect into `errors` — never throws. Plus `KIT_PIECES` (label / GM `midi` / synth `sound` / `glyph`), `kitPiece(id)`, `CELL_GLYPHS` (per-glyph velocity + flags), `isDrumNotation(text)` (import-page format sniff, runs BEFORE `tabNotation.detectFormat`), `drumChartHasMusic(text)` and its already-parsed twin `chartHasMusic(chart)`. Also the plain-language explainers the sheet's tap-a-note readout and Legend panel read — `describeDrumCell(pieceId, cell)` → `{ pieceLabel, char, articulation, detail, technique, velocityPercent, rest }` (piece-aware: `o` is "Open" on a hi-hat/cymbal but a normal hit on a drum; a null/unknown cell describes as a rest, an unknown piece returns null), `describeDrumPosition(bar, step, subdivision)` → `bar 6, count “2 e”` (count-along syllables, exact `+n/N` fallback for an unconventional subdivision), `drumGlyphLegend(pieceIds)` (all six cell characters, with the `o` row resolved for the pieces a chart uses — a fixed row would tell a crash-only chart to work the hi-hat pedal; a mixed kit gets every applicable reading) and each `KIT_PIECES` row's `technique` (how that piece is struck). Only the hi-hat voice sustains an `o` in playback, so the `open` wording follows the piece's `sound`, not its glyph shape. NOT the lead-sheet parser (`scoreNotation.js`). |
| `drumPlayback.js` | Synthesized drum-kit play-along for the SongBook `drum` format (#3115) — the third consumer of `lookaheadTransport.js` alongside `scorePlayback`/`midiPlayback`. `buildDrumSchedule(chart, { bpm, loop, countInBars })` is the PURE chart→`[{ bar, step, piece, sound, velocity, startSec, durSec, countIn }]` mapping (one notated beat = `60/bpm`, one grid step = beat/`subdivision`; per-glyph velocity; a looped bar range is sliced and rebased while keeping the CHART's bar numbers for the playhead) — unit-tested with no Web Audio; `resolveLoopRange(barCount, loop)` clamps/normalizes a 1-based inclusive bar range; the count-in is scheduled as real `countIn: true` events on the same clock so there is no second timer. `createDrumPlayer(chart, { bpm, countInBars, loopBars, clickEnabled, onStep, onEnded })` sounds it on the shared `AudioContext` from a SYNTHESIZED kit (no shipped samples — bandpassed noise burst for snare/hats/cymbals, pitch-dropping sine for kick/toms, open-hat tail, flam grace note) with an optional layered metronome click, loops the range scheduler-exactly (count-in only on the first pass), and reports `onStep({ bar, step, countIn })` for the `<DrumSheetView>` playhead. Pure (no React) — `SongBookViewer` owns the transport UI. |
| `lookaheadTransport.js` | Shared lookahead-transport state machine for the synth players (#2493) — `createLookaheadTransport({ getTotalSec, scheduleWindow, prepare?, seekCursors?, onStop?, onEnded?, onTeardown? })` owns the Web Audio clock + live-node lifecycle (playing / interval / startTime / offsetSec / nodes / playToken, the suspended-context resume with the teardown-race guard, `track()` node pruning, and the play / pause / stop / seek / position transitions); each player supplies only the scheduling + notify callbacks and stays a thin scheduler over it, so a fix to the token-guard race or teardown lands in one place. Also the single source of the `SYNTH_TIMING` lookahead constants (`LEAD`/`LOOKAHEAD_MS`/`SCHEDULE_AHEAD`) `scorePlayback`/`midiPlayback` share. No React, no score/MIDI concepts — imports only the shared `AudioContext`. |
| `lossSparkline.js` | `lossSparklineGeometry(series, box)` — projects an unbounded training-loss series (`{step,loss}[]`) into SVG polyline coords, normalized to its own min/max (unlike `editorialHealth.sparklineGeometry`'s fixed 0–100 axis). Returns `{ points, coords, last, min, max }`. Drives the Render Queue's training-row loss curve (#1408). No React. |
diff --git a/client/src/lib/drumNotation.js b/client/src/lib/drumNotation.js
index 421c0e96f2..e8dd90fb38 100644
--- a/client/src/lib/drumNotation.js
+++ b/client/src/lib/drumNotation.js
@@ -131,11 +131,38 @@ const openArticulationFor = (piece) => (piece.glyph === 'cross'
? (OPEN_BY_SOUND[piece.sound] || 'openRing')
: 'openHead');
-// The six cell characters for a legend panel. Each shows the articulation as
-// written for a cymbal (the `open` wording names the hi-hat pedal), which is the
-// form the glyph is defined by; `describeDrumCell` is what re-reads it per piece.
-export const DRUM_GLYPH_LEGEND = Object.values(CELL_GLYPHS)
- .map((glyph) => ({ char: glyph.char, ...ARTICULATIONS[glyph.id] }));
+// Deterministic order for the `open` variants when a legend has to describe more
+// than one of them (see below) — kit order, cymbals first.
+const OPEN_KEYS = ['open', 'openRing', 'openFoot', 'openHead'];
+
+/**
+ * The six cell characters for a legend panel, resolved FOR THE PIECES A CHART
+ * ACTUALLY USES.
+ *
+ * `o` is the reason this takes an argument rather than being a constant: its
+ * meaning is per-piece (see `openArticulationFor`), so a fixed legend row would
+ * tell someone reading a crash-only chart to work the hi-hat pedal — contradicting
+ * what tapping that same note says. A chart whose pieces all resolve to one
+ * variant gets exactly that variant; a mixed kit gets each applicable reading, in
+ * kit order, so the row is right no matter which row of the chart you're looking at.
+ *
+ * @param {string[]} [pieceIds] - The chart's piece ids (`chart.pieces`).
+ * @returns {{ char: string, name: string, detail: string }[]}
+ */
+export const drumGlyphLegend = (pieceIds = []) => {
+ const present = pieceIds.map(kitPiece).filter(Boolean).map(openArticulationFor);
+ const keys = OPEN_KEYS.filter((key) => present.includes(key));
+ const open = keys.length === 1
+ ? ARTICULATIONS[keys[0]]
+ : {
+ name: 'Open',
+ // Mixed kit (or no pieces at all): every applicable reading, since one
+ // sentence can't cover a hi-hat and a crash at once.
+ detail: (keys.length ? keys : OPEN_KEYS).map((key) => ARTICULATIONS[key].detail).join(' '),
+ };
+ return Object.values(CELL_GLYPHS)
+ .map((glyph) => ({ char: glyph.char, ...(glyph.id === 'open' ? open : ARTICULATIONS[glyph.id]) }));
+};
/**
* Explain ONE cell of a parsed chart in plain language — what the glyph means,
diff --git a/client/src/lib/drumNotation.test.js b/client/src/lib/drumNotation.test.js
index 1815ef1700..c66d2ff628 100644
--- a/client/src/lib/drumNotation.test.js
+++ b/client/src/lib/drumNotation.test.js
@@ -1,7 +1,7 @@
import { describe, it, expect } from 'vitest';
import {
parseDrumChart, isDrumNotation, drumChartHasMusic, kitPiece,
- describeDrumCell, describeDrumPosition, DRUM_GLYPH_LEGEND,
+ describeDrumCell, describeDrumPosition, drumGlyphLegend,
KIT_PIECES, CELL_GLYPHS, DEFAULT_DRUM_TEMPO, SUBDIVISION_MAX,
} from './drumNotation.js';
@@ -358,13 +358,41 @@ describe('describeDrumCell', () => {
describe('notation legend coverage', () => {
it('covers every cell character exactly once, with text', () => {
- expect(DRUM_GLYPH_LEGEND.map((g) => g.char).sort()).toEqual(Object.keys(CELL_GLYPHS).sort());
- for (const glyph of DRUM_GLYPH_LEGEND) {
- expect(glyph.name).toBeTruthy();
- expect(glyph.detail).toBeTruthy();
+ for (const pieces of [[], ['HH'], ['CR', 'S', 'K', 'HF']]) {
+ const legend = drumGlyphLegend(pieces);
+ expect(legend.map((g) => g.char).sort()).toEqual(Object.keys(CELL_GLYPHS).sort());
+ for (const glyph of legend) {
+ expect(glyph.name).toBeTruthy();
+ expect(glyph.detail).toBeTruthy();
+ }
}
});
+ it('resolves the legend\'s "o" row for the pieces the chart actually uses', () => {
+ // A fixed row would tell someone reading a crash-only chart to work the
+ // hi-hat pedal — contradicting what tapping that same note says.
+ const openRow = (pieces) => drumGlyphLegend(pieces).find((g) => g.char === 'o');
+ expect(openRow(['HH']).name).toBe('Open');
+ expect(openRow(['HH']).detail).toMatch(/pedal/i);
+ expect(openRow(['CR', 'RD']).name).toBe('Open (let it ring)');
+ expect(openRow(['CR', 'RD']).detail).not.toMatch(/pedal/i);
+ expect(openRow(['S', 'K']).name).toBe('Normal hit');
+ expect(openRow(['HF']).name).toBe('Open (foot splash)');
+ });
+
+ it('gives a mixed kit every applicable reading of "o", in kit order', () => {
+ // One sentence can't cover a hi-hat and a crash at once, so the row carries
+ // both rather than silently picking one.
+ const mixed = drumGlyphLegend(['CR', 'HH', 'K']).find((g) => g.char === 'o');
+ expect(mixed.name).toBe('Open');
+ expect(mixed.detail).toMatch(/pedal/i); // the hi-hat reading
+ expect(mixed.detail).toMatch(/let the cymbal sustain/i); // the crash/ride reading
+ expect(mixed.detail).toMatch(/nothing to open/i); // the kick reading
+ expect(mixed.detail.indexOf('pedal')).toBeLessThan(mixed.detail.indexOf('let the cymbal sustain'));
+ // An unknown piece id can't invent a reading.
+ expect(drumGlyphLegend(['CB']).find((g) => g.char === 'o').name).toBe('Open');
+ });
+
it('has playing instructions for every kit piece', () => {
// The sheet's legend prints `technique` for whatever pieces a chart uses, so
// a tenth piece added without one would render a blank row.