Skip to content

feat(music): type-safe factories and canonical round-trip ToString/Parse#113

Merged
matt-edmondson merged 22 commits into
mainfrom
feat/music-type-safe-factories
Jul 2, 2026
Merged

feat(music): type-safe factories and canonical round-trip ToString/Parse#113
matt-edmondson merged 22 commits into
mainfrom
feat/music-type-safe-factories

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Summary

Gives Semantics.Music compiler-enforced construction and round-trippable text. Implements the docs/superpowers/plans/2026-07-02-music-type-safe-factories.md plan (20 tasks, TDD, one commit each).

  • New NoteLetter / Accidental value-backed enums (underlying value = natural pitch class / semitone offset) and typed factories: PitchClass.Create(NoteLetter, Accidental), Pitch.Create(NoteLetter, Accidental, octave).
  • Canonical ToString() + Parse/TryParse on every in-scope type (PitchClass, Pitch, Interval, Duration, TimeSignature, Velocity, Tempo, Scale, Key, Chord, ChordEvent, Note, Rest, Form, Progression, Section, Arrangement), with a tested Parse(x.ToString()) == x round-trip. Parse throws FormatException; TryParse(string?, out T?) never throws.
  • Renames to the BCL convention: Pitch.FromName/Mode.FromNameParse/TryParse; Form.FromPatternParse/TryParse.
  • Shared internal Notation scanner dedupes the note-letter/accidental parsing across Pitch, Chord, and roman-numeral parsing.

Breaking changes

  • Progression.Parse(string) format changed. The bar-delimited lead-sheet parser ("C | Am | F | G") is replaced by the chart-style format ("4/4 Dm7 / G7 / | Cmaj7 / / /"): a leading time signature is now required, and beat slashes carry duration. All in-repo call sites migrated. (Decision made during implementation; the plan had not accounted for the pre-existing analysis-layer parser.)
  • Structural value equality added to Form, Progression, and Arrangement (Section gets it transitively) so Parse(x.ToString()) == x holds — these records previously compared their list members by reference.

Suggest tagging the merge commit [major] (or [minor] if the changed Progression.Parse from the recent analysis layer is considered not-yet-stable API).

Test plan

  • 1037/1037 tests pass; clean multi-target build (net8.0net10.0 + netstandard2.0/netstandard2.1), 0 warnings.
  • New round-trip suites for the chord corpus and the three chart-style aggregates; new/merged tests for every type.

🤖 Generated with Claude Code

…e ToString/Parse/TryParse + structural equality; migrate call sites
…tive complexity and remove always-true check (SonarQube S3776/S2583)
@sonarqubecloud

sonarqubecloud Bot commented Jul 2, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
2 Security Hotspots
C Security Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@matt-edmondson matt-edmondson merged commit 08cdbee into main Jul 2, 2026
5 of 6 checks passed
@matt-edmondson matt-edmondson deleted the feat/music-type-safe-factories branch July 2, 2026 13:13
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.

1 participant