From fd70c644a298d05cf32883434b841e8549b8e031 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Mon, 9 May 2022 13:06:10 -0400 Subject: [PATCH] Make cautionaryPitchClass=True work with chords --- music21/pitch.py | 8 ++++++++ music21/stream/base.py | 3 ++- music21/stream/tests.py | 6 +++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/music21/pitch.py b/music21/pitch.py index 250dc7235f..c23d38cd37 100644 --- a/music21/pitch.py +++ b/music21/pitch.py @@ -5039,6 +5039,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: diff --git a/music21/stream/base.py b/music21/stream/base.py index 961420a926..7e8d90544c 100644 --- a/music21/stream/base.py +++ b/music21/stream/base.py @@ -6368,6 +6368,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. ''' @@ -6453,6 +6454,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 @@ -6478,7 +6480,6 @@ def makeAccidentals( for pName in seenPitchNames: tiePitchSet.add(pName) - pitchPast += e.pitches else: tiePitchSet.clear() diff --git a/music21/stream/tests.py b/music21/stream/tests.py index 8066efae4b..0e220b71ca 100644 --- a/music21/stream/tests.py +++ b/music21/stream/tests.py @@ -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)