Tell a negative octave from a flat in removeRedundantPitches - #2027
Conversation
|
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 |
`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.
6b1d83f to
c304528
Compare
Remove docs that overemphasize this bug fix compared to the routine's work as a whole.
The example had been changed to B-natural in octave -1 against B-natural in octave 1. Those spell 'B-1' and 'B1', which do not look alike, so the example no longer showed what it says it shows, and the two `>>> c3` lines expected `<music21.chord.Chord B-1 B-1>` where the chord actually reprs as `<music21.chord.Chord B-1 B1>`. Back to B-flat in octave 1 against B-natural in octave -1, which is the pair that collides: both spell 'B-1', the chord really does repr as two of them, and the wording about `.nameWithOctave`s looking identical is true again. Kept the shape of the example as it was rewritten. Also drops the whitespace from two blank lines, which ruff was failing on.
|
is this what you had in mind? |
Restore phrasing
Nope! My bug was floating space -- i wanted the rest of my changes kept. We generally create chords from lowest to highest so p1 should be octave -1 and p2 be octave 1. And I didn't want extra information about octave -1 in the docs -- human attention is valuable so we try not to draw attention where it doesn't need to be. |
Pitch.nameWithOctavespells 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.removeRedundantPitchescompared pitches by that string, so the second read as a repeat of the first and was thrown away.Revised after review:
_removePitchByRedundantAttributenow 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.nameWithOctavealready made that distinction ('C'against'C4'), and since v11Pitch.octavereturns 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_chordcarries a regression test.