Skip to content

Twelve-bar-blues Form does not round-trip: Form.Parse(form.ToString()) != form #447

Closed

Description

@matt-edmondson

What's wrong

In Semantics.Music/Form.cs:

  • Form.Of(...) (about lines 85-86) sets Name = TwelveBarBlues based on the bar structure of the sections.
  • TryParse (about line 117) derives the name from the letter pattern alone.
  • ToString() (about line 123) returns only Pattern.
  • Equals / GetHashCode (about lines 37-41) include Name.

The name is therefore lost when the form is written out and differs when it is parsed back.

Reproduction

Take a one-section 12-bar blues arrangement: C7×4 | F7×2 | C7×2 | G7 | F7 | C7×2.

  • Form.Of(...) gives Pattern = "A", Name = TwelveBarBlues.
  • form.ToString() gives "A".
  • Form.Parse("A") gives Name = ThroughComposed.
  • Form.Parse(form.ToString()) == form is false.

Why it matters

The music type-safe-factories work promises a round trip for every type:

  • plan Task 16 requires Parse(x.ToString()) == x.
  • The design spec`` states that Form "already round-trips".

Anything that persists a Form as text and compares it later breaks for blues forms, for example caching or deduplicating analyses.

Suggested fix (needs a decision)

Pick one:

  • (a) Treat Name as derived. Exclude it from Equals/GetHashCode, and document that Parse names forms from the pattern only.
  • (b) Make the canonical text carry the name, for example A (TwelveBarBlues), and parse it back.

Acceptance criteria

  • A round-trip test for a twelve-bar-blues Form passes.
  • The chosen semantics are documented on Form.

Related: #384 (AABA naming should depend on section length) causes the same symptom for AABA forms, but it is a separate fix.

Activity

  1. matt-edmondson commented on Oct 18, 2026

    @matt-edmondson
    ContributorAuthor

    Triage

    • Category: Bug
    • Priority: Low. The round-trip promise breaks for twelve-bar-blues forms only, and the issue needs a design decision before work starts: (a) treat Name as derived and leave it out of equality, or (b) put the name in the canonical text.
    • Area / suggested assignment: Semantics.Music Form (Of, TryParse, ToString, equality). The owner of the music type-safe-factories plan should choose between (a) and (b).
    • Duplicates / related: Form names any AABA arrangement ThirtyTwoBarAABA regardless of section length, and NamedForm.VerseChorus can never be produced #384 (AABA naming) causes the same symptom but needs a separate fix. Option (a) would fix both symptoms at once. Not a duplicate.
    • In progress: No open PR references this issue.

    Generated by Claude Code

  2. matt-edmondson commented on Oct 29, 2026

    @matt-edmondson
    ContributorAuthor

    Fixed by #487 (commit 47dffbb, now on main). The commit cites this issue inline as "(#447)" rather than with a "Fixes" keyword, so GitHub didn't close it. Closing by hand.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions