Skip to content

feat(editor): enharmonic flat-key note spelling (4.16a follow-up) - #207

Merged
byrongamatos merged 3 commits into
mainfrom
feat/editor-flat-key-labels
Jul 11, 2026
Merged

feat(editor): enharmonic flat-key note spelling (4.16a follow-up)#207
byrongamatos merged 3 commits into
mainfrom
feat/editor-flat-key-labels

Conversation

@ChrisBeWithYou

@ChrisBeWithYou ChrisBeWithYou commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

What

Note names follow the song key's spelling convention (the 4.16a follow-up queued behind #200, which shared the draw.js region): with a flat key set, the editor writes Bb4, never A#4

  • Piano-roll note labels (the name chip on keys notes),
  • the add-note dialog's pitch readout,
  • the roll placement status messages (suggest-position refusals),
  • and Detect, which now announces the found key in its own spelling (Eb minor, never D# minor).

Sharp keys and no-key-set keep today's sharp names exactly. The C-octave row labels on the keyboard gutter are untouched (C is never enharmonic).

The convention

A key signature spells its accidentals one way, decided by the relative major's side of the circle of fifths — so every mode borrows its signature's spelling (D dorian → C major → sharps; G dorian → F major → flats; C minor → Eb major → flats). Flat majors: Db, Eb, F, Ab, Bb. F#/Gb stays sharp because the key picker's tonic list is sharp-named — the label must match the choice; the picker itself keeps sharp-named ids (stable localStorage values). chromatic and unknown scales default to sharps.

How

  • theory.js (pure): PIANO_NOTE_NAMES_FLAT, _keyPrefersFlatsPure(tonic, scale) (relative-major offset table, wrap-safe on out-of-range tonics), _noteNamesForKeyPure(key) (null/malformed → the sharp table, same ref).
  • keys.js: midiToNote(midi, names?) — optional table, defaulting to the historical sharp spelling so every existing call site is behavior-identical; editorKeyNoteNames() resolves the active S.editorKey's table for display call sites.
  • Display call sites in draw.js, add-note.js, main.js (_rollConfirmPosition), key-view.js (Detect status) pass the key-aware table. No wire/pack change anywhere — spelling is a view concern.

Tests

tests/flat_key_labels.test.mjs (9, real-import ESM; fails on main — the spelling exports don't exist there): flat-table shape, the full flat/sharp major split, minors + harmonic/melodic borrowing the relative signature, all seven modes + pentatonics/blues, chromatic/garbage/wrapping tonics, _noteNamesForKeyPure ref semantics, midiToNote default-unchanged + flat respelling, and editorKeyNoteNames following S.editorKey.

Full suite 102/102; ESLint clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EBQCHCNA81E9tHmSDHSe2Q

Summary by CodeRabbit

  • New Features

    • Updated note-name rendering across the piano roll, add-note dialogs, and roll-position confirmations to use the active song key’s sharp/flat enharmonic spelling.
    • Key detection and “Detected key” status now use theory-based key-signature tonic spelling for consistent minor/tonic names.
    • Added key-aware naming so chord/open-string readouts and detected tonics follow the editor’s spelling rules.
  • Tests

    • Added automated coverage for sharp/flat selection across major, minor, modes, and fallback/invalid key scenarios, plus regression checks (e.g., Bb-related flats).

Roll note labels, the add-note pitch readout, roll placement messages,
and the Detect announcement spell flats in flat keys (Bb4, never A#4),
via a pure relative-major preference table in theory.js. midiToNote
gains an optional names argument, defaulting to the historical sharp
table; the key picker stays sharp-named and F#/Gb spells sharp to
match it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EBQCHCNA81E9tHmSDHSe2Q
@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@byrongamatos, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 15 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8f9e5a53-6e55-4a37-82d9-f751b2484af0

📥 Commits

Reviewing files that changed from the base of the PR and between a8fc343 and 7158144.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • src/draw.js
  • src/key-view.js
  • src/keys.js
  • src/main.js
📝 Walkthrough

Walkthrough

Adds key-aware enharmonic note spelling, selecting flat or sharp names from the editor key and applying them to piano-roll labels, dialogs, chord and fretboard readouts, position confirmation, and detected-key output. Tests cover key preferences, fallbacks, MIDI conversion, and editor state changes.

Changes

Enharmonic note spelling

Layer / File(s) Summary
Key-aware naming contracts
src/theory.js, src/keys.js
Adds flat note names, key preference helpers, optional naming tables for midiToNote, and editorKeyNoteNames() with sharp spelling as the fallback.
Editor label integration
src/add-note.js, src/draw.js, src/fretboard-strip.js, src/key-view.js, src/main.js
Applies editor-key spelling to add-note labels, piano-roll and fretboard labels, position confirmation, chord readouts, and detected-key status text.
Spelling behavior validation and documentation
tests/flat_key_labels.test.mjs, CHANGELOG.md
Tests key-dependent spelling, fallback behavior, MIDI conversion, editor state updates, and Bb-major labels; documents the changes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Editor as Editor UI
  participant State as S.editorKey
  participant Names as editorKeyNoteNames
  participant MIDI as midiToNote
  Editor->>State: read active editor key
  State-->>Names: provide key
  Names->>MIDI: provide flat or sharp table
  MIDI-->>Editor: return key-spelled note label
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: editor note spelling now follows flat-key enharmonic rules.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/editor-flat-key-labels

Comment @coderabbitai help to get the list of available commands.

byrongamatos and others added 2 commits July 11, 2026 20:48
Two note-name surfaces still hard-coded the sharp table after 4.16a: the
fretboard strip's open-string labels (fretboard-strip.js) and the
chord-identification root name (main.js _identifyChordPure call). In a
flat key with accidental open strings (Eb tuning / capo) or a chord whose
root is a black key, they read A#/D#/C#m while the roll read Bb/Eb/Dbm.

Both now index the same key-aware table the roll uses
(_noteNamesForKeyPure(S.editorKey) / editorKeyNoteNames()), so spelling is
consistent everywhere. Chord readout is only root+suffix, so respelling
the root letter is the whole visible fix; full functional chord spelling
(accidentals on non-root tones) stays out of scope. Pure display only —
no pitch/chart mutation.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@byrongamatos
byrongamatos merged commit 17ef135 into main Jul 11, 2026
3 checks passed
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.

2 participants