Skip to content

Tell a negative octave from a flat in removeRedundantPitches - #2027

Open
float3 wants to merge 2 commits into
cuthbertLab:masterfrom
float3:fix-redundant-pitches-negative-octave
Open

Tell a negative octave from a flat in removeRedundantPitches#2027
float3 wants to merge 2 commits into
cuthbertLab:masterfrom
float3:fix-redundant-pitches-negative-octave

Conversation

@float3

@float3 float3 commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Pitch.nameWithOctave spells both B-flat in octave 1 and B-natural in octave -1 as 'B-1', because the '-' is the flat sign and the minus sign both. removeRedundantPitches compared pitches by that string, so the second read as a repeat of the first and was thrown away.

Revised after review: _removePitchByRedundantAttribute now has the special knowledge of 'nameWithOctave' itself and compares by name and octave in its place. Its signature is unchanged, no tuple form is exposed, and both call sites and the pitch-class and pitch-name reductions are exactly as they were.

While rewriting it I noticed the earlier version had a second problem, so this one also pins it: the octave is compared together with octaveIsImplicit, so a pitch given no octave stays distinct from one placed in the default octave. nameWithOctave already made that distinction ('C' against 'C4'), and since v11 Pitch.octave returns 4 for both, comparing the octave alone would have quietly merged them. There is a doctest and a test case for it.

The docstring documented the old behaviour as a known bug ("doesn't seem a bug worth squashing at this moment"); it now documents what the method does, and test_chord carries a regression test.

@coveralls

coveralls commented Sep 7, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 93.348%. remained the same — float3:fix-redundant-pitches-negative-octave into cuthbertLab:master

@mscuthbert

Copy link
Copy Markdown
Member

I would rather have removeByRedunantPitches have special knowledge of 'nameWithOctave' and substitute 'nameWithOctave' with a special routine (either as a tuple or not) -- make the equivalence not something users have to think about.

Based on that, do not demonstrate ('name', 'octave') as the usage of a tuple in the docs -- I was trying to figure out some other usage of the tuple form -- but i can't think of one -- everything i tried ('pitchClass', 'octave') had an equivalent single attribute like ps -- so unless there's another good use for tuple form, do not expose that. Complexity reduction is a direction we're trying to go with -- this is the opposite. :-) Thanks!

`Pitch.nameWithOctave` spells both B-flat in octave 1 and B-natural in
octave -1 as 'B-1', because the '-' is the flat sign and the minus sign
both. `removeRedundantPitches` compared pitches by that string, so the
second read as a repeat of the first and was thrown away.

`_removePitchByRedundantAttribute` now knows that 'nameWithOctave' is the
ambiguous one and compares by name and octave in its place. Its signature
is unchanged and nothing new is exposed: the pitch-class and pitch-name
reductions, and both call sites, are exactly as they were.

The octave is compared together with `octaveIsImplicit`, so a pitch given
no octave stays distinct from one placed in the default octave, which is
what `nameWithOctave` ('C' against 'C4') already did.

The docstring documented the old behaviour as a known bug ("doesn't seem a
bug worth squashing at this moment"); it now documents what the method
does, and test_chord carries a regression test.
@float3
float3 force-pushed the fix-redundant-pitches-negative-octave branch from 6b1d83f to c304528 Compare September 8, 2026 00:24
Remove docs that overemphasize this bug fix compared to the routine's work as a whole.
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.

3 participants