Skip to content

Extract repeated chord-note retrieval into getChordPitchClasses utility#257

Merged
JWWade merged 2 commits intodevelopfrom
copilot/issue-e7-02-extract-chord-note-util
Mar 17, 2026
Merged

Extract repeated chord-note retrieval into getChordPitchClasses utility#257
JWWade merged 2 commits intodevelopfrom
copilot/issue-e7-02-extract-chord-note-util

Conversation

Copy link
Contributor

Copilot AI commented Mar 17, 2026

Five files duplicated the same conditional to resolve pitch classes from a Chord — a maintenance hazard whenever a new chord variant is added. This replaces all occurrences with a single canonical utility.

New utility

client/src/features/chord/utils/getChordPitchClasses.ts

export function getChordPitchClasses(chord: Chord): number[] {
  if (Array.isArray(chord.customNotes)) return chord.customNotes;
  return getChordNoteIndices(chord.root, chord.quality);
}

Re-exported from a new client/src/features/chord/utils/index.ts. Uses Array.isArray directly (rather than importing isCustomChord from current-chord/utils) to avoid a cross-feature circular dependency.

Call-site updates

  • CurrentChordPanel.tsx, ChordTile.tsx, midiBuilder.ts — replaced inline ternary with getChordPitchClasses(chord); dropped now-unused getChordNoteIndices imports.
  • pairMetrics.ts — removed the local getChordPitchClasses (which returned Set<number> and duplicated the same logic); now imports from @/features/chord/utils and wraps with new Set(...) where set semantics are needed.
  • pairMetrics.test.ts — import updated to the canonical location; assertions updated from Set to number[] to match the new return type.
Original prompt

This section details on the original issue you should resolve

<issue_title>ISSUE-E7-02 — Extract Repeated Chord-Note Retrieval into a Shared Utility</issue_title>
<issue_description># 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:

  1. Check isCustomChord(chord) and return chord.customNotes if true.
  2. 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

  • getChordPitchClasses(chord: Chord): number[] exists in client/src/features/chord/utils/.
  • No file outside getChordPitchClasses.ts contains the pattern isCustomChord(chord) ? chord.customNotes.
  • All existing tests pass.
  • npm run lint passes with --max-warnings=0.
  • npm run build succeeds with no TypeScript errors.

Verification Commands

cd client
npm run lint
npm run build
npm test
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Copilot AI changed the title [WIP] [ISSUE-E7-02] Extract repeated chord-note retrieval into a shared utility Extract repeated chord-note retrieval into getChordPitchClasses utility Mar 17, 2026
Copilot AI requested a review from JWWade March 17, 2026 04:41
@JWWade JWWade marked this pull request as ready for review March 17, 2026 04:42
@JWWade JWWade merged commit 0feff28 into develop Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ISSUE-E7-02 — Extract Repeated Chord-Note Retrieval into a Shared Utility

2 participants