Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions music21/duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import fractions
from functools import lru_cache
import io
from math import inf, isnan
from math import inf, isnan, isfinite
import typing as t
import unittest

Expand Down Expand Up @@ -1173,7 +1173,7 @@ def _reprInternal(self):
return base_rep

def _checkFrozen(self):
if self.frozen is True:
if self.frozen:
raise TupletException(
'A frozen tuplet (or one attached to a duration) has immutable length.')

Expand Down Expand Up @@ -1797,7 +1797,7 @@ def __eq__(self, other):
return True

def _reprInternal(self):
if self.linked is True:
if self.linked:
return str(self.quarterLength)
else:
return f'unlinked type:{self.type} quarterLength:{self.quarterLength}'
Expand Down Expand Up @@ -1870,9 +1870,9 @@ def _setLinked(self, value: bool):
raise TypeError(f'Linked can only be True or False, not {value}')
if self._quarterLengthNeedsUpdating:
self._updateQuarterLength()
if value is False and self._linked is True:
if value is False and self._linked:
self._unlinkedType = self.type
elif value is True and self._linked is False:
elif value is True and not self._linked:
self._quarterLengthNeedsUpdating = True
self._componentsNeedUpdating = True

Expand Down Expand Up @@ -2290,7 +2290,7 @@ def getGraceDuration(

# create grace duration
gd: GraceDuration
if appoggiatura is True:
if appoggiatura:
gd = AppoggiaturaDuration()
else:
gd = GraceDuration()
Expand Down Expand Up @@ -2321,7 +2321,7 @@ def informClient(self) -> bool:
Returns False if there was no need to inform the client (like nothing has changed)
or if `.client` is None. Otherwise returns True.
'''
if self._quarterLengthNeedsUpdating is True:
if self._quarterLengthNeedsUpdating:
old_qtrLength = self._qtrLength
self._updateQuarterLength()
if self._qtrLength == old_qtrLength:
Expand Down Expand Up @@ -2511,7 +2511,7 @@ def _updateQuarterLength(self):

* Changed in v7: made private and faster.
'''
if self.linked is False:
if not self.linked:
return

if self._dotGroups == (0,) and not self.tuplets and len(self.components) == 1:
Expand Down Expand Up @@ -2712,7 +2712,7 @@ def dots(self, value: int):
if not common.isNum(value):
raise TypeError('only numeric dot values can be used with this method.')

# easter egg
# Easter egg
if value == inf:
self.type = nextLargerType(self.type)
self.dots = 0
Expand All @@ -2723,7 +2723,7 @@ def dots(self, value: int):
components[i] = durationTupleFromTypeDots(dt.type, value)
self._components = tuple(components)
self._quarterLengthNeedsUpdating = True
if self.linked is True:
if self.linked:
self.expressionIsInferred = False
self.informClient()

Expand Down Expand Up @@ -2921,13 +2921,18 @@ def _getQuarterLength(self) -> OffsetQL:
return self._qtrLength

def _setQuarterLength(self, value: OffsetQLIn):
if self.linked is False:
if not self.linked:
# linked durations get this check for free from opFrac below.
if not isfinite(value):
raise ValueError(
f'quarterLength must be a finite number, not {value!r}'
)
self._qtrLength = value
elif (self._qtrLength != value
or self._componentsNeedUpdating # skip a type update for next type check
or self.type == 'inexpressible'):
value = opFrac(value)
if value == 0.0 and self.linked is True:
if value == 0.0 and self.linked:
self.clear()
self._qtrLength = value
self.expressionIsInferred = True
Expand Down Expand Up @@ -3055,7 +3060,7 @@ def type(self) -> str:
>>> a.quarterLength
0.25
'''
if self.linked is False:
if not self.linked:
if self._unlinkedType is None: # pragma: no cover
raise DurationException(
'linked property setter failed to set _unlinkedType, please open a bug report'
Expand All @@ -3074,7 +3079,7 @@ def type(self, value: str):
if value not in ordinalTypeFromNum and value not in ('inexpressible', 'complex'):
raise ValueError(f'no such type exists: {value}')

if self.linked is True:
if self.linked:
nt = durationTupleFromTypeDots(value, self.dots)
self.components = (nt,)
self._quarterLengthNeedsUpdating = True
Expand Down Expand Up @@ -3347,12 +3352,12 @@ def findTupletGroups(self, incorporateGroupings: bool = False) -> list[list[note
tupletActive = False
for n in self.streamIn.notesAndRests:
if not n.duration.tuplets: # most common case first
if tupletActive is True:
if tupletActive:
self.allTupletGroups.append(currentTupletGroup)
currentTupletGroup = []
tupletActive = False
continue
if tupletActive is False:
if not tupletActive:
tupletActive = True
currentTupletGroup.append(n)
if incorporateGroupings and n.duration.tuplets[0].type == 'stop':
Expand Down
6 changes: 4 additions & 2 deletions music21/tinyNotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,8 @@ def durationType(self, element, search, pm, t, parent):
self.durationFound = True
typeNum = int(search.group(1))
if typeNum == 0:
# NOTE: using 0 to mean full-bar + fermata was never fully documented.
# it is considered deprecated.
if parent.stateDict['currentTimeSignature'] is not None:
element.duration = copy.deepcopy(
parent.stateDict['currentTimeSignature'].barDuration
Expand Down Expand Up @@ -1133,7 +1135,7 @@ def __init__(
self.modifierSquare = None
self.modifierUnderscore = LyricModifier

self.makeNotation = makeNotation
self.makeNotation: bool = makeNotation
self.raiseExceptions = raiseExceptions
# will be filled by self.setupRegularExpressions()
self._tokenMapRe: list[tuple[typing.Pattern, type]] = []
Expand Down Expand Up @@ -1408,7 +1410,7 @@ def postParse(self):

It currently runs `.makeMeasures()` on `.stream` unless `.makeNotation` is `False`.
'''
if self.makeNotation is not False:
if self.makeNotation:
self.stream.makeMeasures(inPlace=True)


Expand Down
Loading