You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Duration, Velocity, TimeSignature, Interval, Note and Tempo accept whitespace and '+' that ToString never prints: Duration.Parse(" 1 / 4 "), Note.Parse("C4: 1/4 :v 64 ") #471
#307 changed Pitch.TryParse to parse the octave with NumberStyles.AllowLeadingSign only. The comment at Pitch.cs:~89-93 explains why: whitespace or '+' "would parse to a pitch that prints back differently".
The sibling Music value types still use NumberStyles.Integer, which allows leading and trailing whitespace and a leading sign:
File
What it uses
Duration.cs:113-114
NumberStyles.Integer | AllowLeadingSign for numerator and denominator
Velocity.cs:68
NumberStyles.Integer
TimeSignature.cs:76-77
NumberStyles.Integer
Interval.cs:61
NumberStyles.Integer | AllowLeadingSign
Tempo.cs:92
NumberStyles.Float, which also allows surrounding whitespace; the beat goes through Duration.TryParse
Note, Rest, ChordEvent and Progression cells inherit the same leniency.
Pitch.TryParse("C 4") and Pitch.TryParse("C+4") return false, so the Music types disagree about whether to accept a non-canonical spelling.
Suggested fix / acceptance criteria
Parse integer fields with NumberStyles.None.
Where a sign is meaningful (Interval semitones, and a negative Duration numerator if that is kept), allow a leading - and reject a leading +. Reuse the same helper as Pitch.
In Tempo, reject whitespace before or after the BPM.
Tests: every input above returns false, and X.Parse(x.ToString()) == x still holds.
Related but distinct: #434 (the Duration.TryParse overflow on "-2147483648/-1").
Fixed by #487 (commit 47dffbb, now on main). The commit cites this issue inline as "(#471)" rather than with a "Fixes" keyword, so GitHub didn't close it. Closing by hand.
Activity
matt-edmondson commentedon Oct 18, 2026
Triage
ToString. The issue is consistency withPitch(Pitch.TryParse("C1073741823") succeeds as C-1: octave arithmetic wraps, and "C 4 " is accepted too #307), not wrong results.Semantics.Musicvalue parsers (Duration,Velocity,TimeSignature,Interval,Tempo). Owner: @matt-edmondsonDuration.TryParseoverflow) touches the same code and could share a PR. No open PR covers it.Pitch's strict integer helper, use it in each type, and add the rejection tests listed in the issue.Generated by Claude Code
matt-edmondson commentedon Oct 29, 2026
Fixed by #487 (commit 47dffbb, now on
main). The commit cites this issue inline as "(#471)" rather than with a "Fixes" keyword, so GitHub didn't close it. Closing by hand.Generated by Claude Code