Skip to content

Commit

Permalink
Merge pull request #1299 from cuthbertLab/cautionary-accidental-in-chord
Browse files Browse the repository at this point in the history
Make cautionaryPitchClass=True work with chords
  • Loading branch information
mscuthbert authored May 15, 2022
2 parents f351234 + fd70c64 commit 3f76b17
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
8 changes: 8 additions & 0 deletions music21/pitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5060,6 +5060,14 @@ def set_displayStatus(newDisplayStatus: bool):
and cautionaryNotImmediateRepeat is False
and pPastInMeasure is False):
set_displayStatus(True)

# Avoid making early, incorrect assumptions if this pitch is part of a chord.
# pPast might include this note itself, in which case we should not say
# "natural already in past usage". (Filtering out the current note from pPast
# when calling this method is not sufficient, because there could be repetitions.)
elif (self._client is not None and self._client._chordAttached is not None):
continue

# other cases: already natural in past usage, do not need
# natural again (and not in key sig)
else:
Expand Down
3 changes: 2 additions & 1 deletion music21/stream/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6367,6 +6367,7 @@ def makeAccidentals(

Changed in v.6: does not return anything if inPlace is True.
Changed in v.7: default inPlace is False
Changed in v.8: altered unisons in Chords now supply clarifying naturals.

All arguments are keyword only.
'''
Expand Down Expand Up @@ -6452,6 +6453,7 @@ def makeAccidentals(
# when reading a chord, this will apply an accidental
# if pitches in the chord suggest an accidental
seenPitchNames = set()
pitchPast += e.pitches

for n in list(e):
p = n.pitch
Expand All @@ -6477,7 +6479,6 @@ def makeAccidentals(
for pName in seenPitchNames:
tiePitchSet.add(pName)

pitchPast += e.pitches
else:
tiePitchSet.clear()

Expand Down
6 changes: 3 additions & 3 deletions music21/stream/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2609,9 +2609,9 @@ def testMakeAccidentalsA(self):
s.makeAccidentals(inPlace=True)

self.assertTrue(n2.pitch.accidental.displayStatus)
# both a's in the chord now have naturals but are hidden
self.assertIsNone(c1.pitches[1].accidental)
# self.assertTrue(c1.pitches[2].accidental.displayStatus)
# Both A-naturals in the chord show accidentals
self.assertTrue(c1.pitches[1].accidental.displayStatus)
self.assertTrue(c1.pitches[2].accidental.displayStatus)

# not getting a natural here because of chord tones
# self.assertTrue(n3.pitch.accidental.displayStatus)
Expand Down

0 comments on commit 3f76b17

Please sign in to comment.