Skip to content

Commit

Permalink
Merge pull request #1521 from cuthbertLab/faster-accidental-from-int
Browse files Browse the repository at this point in the history
Tiny change to make .accidental
  • Loading branch information
mscuthbert authored Jan 30, 2023
2 parents b474fd4 + 829cdf0 commit 9afb3bc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions music21/pitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,6 @@ def inheritDisplay(self, other):
This is needed when transposing Pitches: we need to retain accidental display properties.
>>> a = pitch.Accidental('double-flat')
>>> a.displayType = 'always'
>>> b = pitch.Accidental('sharp')
Expand Down Expand Up @@ -2103,7 +2102,10 @@ def accidental(self, value: str | Accidental | None | int | float):
elif isinstance(value, str):
# int version is used in interval.py which cannot import Pitch directly
self._accidental = Accidental(value)
elif isinstance(value, (int, float)):
elif isinstance(value, int):
self._accidental = Accidental(value)
self._microtone = None
elif isinstance(value, float):
# check and add any microtones
alter, cents = _convertCentsToAlterAndCents(value * 100.0)
self._accidental = Accidental(alter)
Expand Down Expand Up @@ -3937,7 +3939,7 @@ def getHigherEnharmonic(self: PitchType, *, inPlace: bool = False) -> PitchType
>>> p4.getHigherEnharmonic()
Traceback (most recent call last):
music21.pitch.AccidentalException: -5.0 is not a supported accidental type
music21.pitch.AccidentalException: -5 is not a supported accidental type
Note that half accidentals (~ = half-sharp, ` = half-flat)
get converted to microtones:
Expand Down
2 changes: 1 addition & 1 deletion music21/test/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def testRepeatedTransposePitch(self):
]
)
with self.assertRaisesRegex(pitch.AccidentalException,
'5.0 is not a supported accidental type'):
'5 is not a supported accidental type'):
intv.transposePitch(p, maxAccidental=None)
p2 = intv.transposePitch(p)
self.assertEqual(p2.nameWithOctave, 'B-20')
Expand Down

0 comments on commit 9afb3bc

Please sign in to comment.