From 26fac461ce73e50455ca41d2dd6d80941b7d6c06 Mon Sep 17 00:00:00 2001 From: Michael Scott Asato Cuthbert Date: Fri, 9 Oct 2026 17:04:20 -1000 Subject: [PATCH] Pitch.transpose(inPlace=True) takes the transposed microtone, even none The in-place copy-back took the transposed copy's microtone only when it was not None, so a microtone the transposition removed stayed: C4(+50c) up a ChromaticInterval(0.5) in place gave C#4(+50c), while the transposed copy is C#4. AI-assisted (Claude) --- music21/pitch.py | 5 ++--- music21/test/test_pitch.py | 7 +++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/music21/pitch.py b/music21/pitch.py index ea41aa794..a50d9e0b3 100644 --- a/music21/pitch.py +++ b/music21/pitch.py @@ -4726,9 +4726,8 @@ def transpose( # set fundamental self.fundamental = p.fundamental self.spellingIsInferred = p.spellingIsInferred - # deepcopy _microtone if present (not thru microtone property to detect None) - if p._microtone is not None: - self._microtone = copy.deepcopy(p._microtone) + # deepcopy _microtone (not thru microtone property to detect None) + self._microtone = copy.deepcopy(p._microtone) return None # -------------------------------------------------------------------------- diff --git a/music21/test/test_pitch.py b/music21/test/test_pitch.py index 81d1e7fcb..006e6dc8e 100644 --- a/music21/test/test_pitch.py +++ b/music21/test/test_pitch.py @@ -19,6 +19,7 @@ from music21 import converter from music21 import corpus from music21 import editorial +from music21 import interval from music21 import key from music21 import note from music21 import pitch @@ -801,6 +802,12 @@ def testLowNotes(self): self.assertEqual(lowC.name, 'C') self.assertEqual(lowC.octave, -1) + def testTransposeInPlaceReplacesMicrotone(self): + p = Pitch('C4') + p.microtone = 50 + p.transpose(interval.ChromaticInterval(0.5), inPlace=True) + self.assertEqual(str(p), 'C#4') + def testQuarterToneA(self): p1 = Pitch('D#~') # environLocal.printDebug([p1, p1.accidental])