ISSUE-E7-02 — Extract Repeated Chord-Note Retrieval into a Shared Utility
Objective
Replace a copy-pasted conditional that retrieves pitch classes from a Chord value with a single reusable utility function, removing the duplication from at least five files.
Background
The following pattern appears verbatim (or near-verbatim) in multiple files across the codebase:
isCustomChord(chord) ? chord.customNotes : getChordNoteIndices(chord.root, chord.type)
Known locations (non-exhaustive):
client/src/features/current-chord/components/CurrentChordPanel.tsx
client/src/features/progression-sidebar/components/ChordTile.tsx
client/src/features/progression-sidebar/components/ProgressionSidebar.tsx
client/src/features/midi-export/utils/midiBuilder.ts
client/src/features/progression-sidebar/utils/pairMetrics.ts
Each duplicate is a maintenance hazard: introducing a new chord variant (e.g., quartal chords) requires hunting down and updating every occurrence. A single function eliminates that risk.
Proposed API
// client/src/features/chord/utils/getChordPitchClasses.ts
export function getChordPitchClasses(chord: Chord): number[]
The function should:
- Check
isCustomChord(chord) and return chord.customNotes if true.
- Otherwise call
getChordNoteIndices(chord.root, chord.type) and return the result.
Files To Add
client/src/features/chord/utils/getChordPitchClasses.ts — new utility function.
Files To Edit
client/src/features/chord/utils/index.ts — re-export getChordPitchClasses.
- All files listed in Known locations above — replace inline conditionals with a call to
getChordPitchClasses(chord).
Acceptance Criteria
Verification Commands
cd client
npm run lint
npm run build
npm test
ISSUE-E7-02 — Extract Repeated Chord-Note Retrieval into a Shared Utility
Objective
Replace a copy-pasted conditional that retrieves pitch classes from a
Chordvalue with a single reusable utility function, removing the duplication from at least five files.Background
The following pattern appears verbatim (or near-verbatim) in multiple files across the codebase:
Known locations (non-exhaustive):
client/src/features/current-chord/components/CurrentChordPanel.tsxclient/src/features/progression-sidebar/components/ChordTile.tsxclient/src/features/progression-sidebar/components/ProgressionSidebar.tsxclient/src/features/midi-export/utils/midiBuilder.tsclient/src/features/progression-sidebar/utils/pairMetrics.tsEach duplicate is a maintenance hazard: introducing a new chord variant (e.g., quartal chords) requires hunting down and updating every occurrence. A single function eliminates that risk.
Proposed API
The function should:
isCustomChord(chord)and returnchord.customNotesif true.getChordNoteIndices(chord.root, chord.type)and return the result.Files To Add
client/src/features/chord/utils/getChordPitchClasses.ts— new utility function.Files To Edit
client/src/features/chord/utils/index.ts— re-exportgetChordPitchClasses.getChordPitchClasses(chord).Acceptance Criteria
getChordPitchClasses(chord: Chord): number[]exists inclient/src/features/chord/utils/.getChordPitchClasses.tscontains the patternisCustomChord(chord) ? chord.customNotes.npm run lintpasses with--max-warnings=0.npm run buildsucceeds with no TypeScript errors.Verification Commands