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
4 changes: 2 additions & 2 deletions documentation/docbuild/documenters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1564,13 +1564,13 @@ def getRstComposerWorksFormat(self, corpusWork):
# worksAreVirtual = corpusWork.virtual
# if worksAreVirtual:
# workTitle += ' (*virtual*)'
if isSingleWork is False:
if not isSingleWork:
result.append(workTitle)
result.append('')
procedure = self.getRstWorkFileDictFormat
# if worksAreVirtual:
# procedure = self.getRstVirtualWorkFileDictFormat
if isSingleWork is False:
if not isSingleWork:
for corpusFile in corpusWork.files:
result.extend(['- ' + procedure(corpusFile), ''])
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@
" if analyzedKey.mode != 'minor':\n",
" return False\n",
" lastChord = getLastChord(score)\n",
" if lastChord.isMinorTriad() is False:\n",
" if not lastChord.isMinorTriad():\n",
" return False\n",
" if lastChord.root().name != analyzedKey.tonic.name:\n",
" return False\n",
Expand Down
14 changes: 7 additions & 7 deletions music21/alpha/analysis/fixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class DeleteFixer(OMRMidiFixer):
def fix(self):
super().fix()
for (midiRef, omrRef, op) in self.changes:
if self.checkIfNoteInstance(midiRef, omrRef) is False:
if not self.checkIfNoteInstance(midiRef, omrRef):
continue
# if they are the same, don't bother to try changing it
# 3 is the number of noChange Ops
Expand Down Expand Up @@ -140,7 +140,7 @@ class EnharmonicFixer(OMRMidiFixer):
>>> fixer3.fix()
>>> omrNote3.pitch.accidental

TEST 4 (case 2-1) e.g MIDI = g#, ground truth = a-, OMR = an
TEST 4 (case 2-1) e.g. MIDI = g#, ground truth = a-, OMR = an

>>> midiNote4 = note.Note('G#4')
>>> omrNote4 = note.Note('An4')
Expand All @@ -156,7 +156,7 @@ class EnharmonicFixer(OMRMidiFixer):
>>> omrNote4.pitch.accidental
<music21.pitch.Accidental flat>

TEST 5 (case 2-2) e.g midi = g-, gt = f#, omr = fn
TEST 5 (case 2-2) e.g. midi = g-, gt = f#, omr = fn

>>> midiNote5 = note.Note('G-4')
>>> omrNote5 = note.Note('Fn4')
Expand Down Expand Up @@ -237,7 +237,7 @@ def fix(self):
for (midiRef, omrRef, op) in self.changes:
omrRef.style.color = 'black'
# if they're not notes, don't bother with rest
if self.checkIfNoteInstance(midiRef, omrRef) is False:
if not self.checkIfNoteInstance(midiRef, omrRef):
continue
# if they are the same, don't bother to try changing it
# 3 is the number of noChange Ops
Expand All @@ -253,15 +253,15 @@ def fix(self):
omrRef.pitch.accidental = None
else:
# case 2-1: midi note is sharp, omr note is one step higher and natural,
# should be a flat instead. e.g midi = g#, gt = a-, omr = an
# should be a flat instead. e.g. midi = g#, gt = a-, omr = an
# omr note has higher ps than midi-- on a higher
# line or space than midi note
if omrRef.pitch > midiRef.pitch:
if omrRef.pitch.transpose(interval.Interval(-1)
).isEnharmonic(midiRef.pitch):
omrRef.pitch.accidental = pitch.Accidental('flat')
# case 2-2: midi note is flat, omr note is one step lower and natural,
# should be a flat instead. e.g midi = g-, gt = f#, omr = fn
# should be a flat instead. e.g. midi = g-, gt = f#, omr = fn
# omr note has lower ps than midi-- on a higher line
# or space than midi note
elif omrRef.pitch < midiRef.pitch:
Expand Down Expand Up @@ -399,7 +399,7 @@ def addOrnament(self,
* show: True when note should be colored blue

Returns True if added successfully, or False if there was already an
ornament on the note and it wasn't added.
ornament on the note, and it wasn't added.
'''
if not any(isinstance(e, expressions.Ornament) for e in selectedNote.expressions):
selectedNote.expressions.append(ornament)
Expand Down
6 changes: 3 additions & 3 deletions music21/analysis/enharmonics.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def getAlterationScore(self, possibility):
Returns a score according to the number of sharps and flats in a possible spelling.
The score is the sum of the flats and sharps + 1, multiplied by the alterationPenalty.
'''
if self.ruleObject.alterationPenalty is False:
if not self.ruleObject.alterationPenalty:
return 1

joinedPossibility = ''.join([p.name for p in possibility])
Expand All @@ -114,7 +114,7 @@ def getMixSharpFlatsScore(self, possibility):
the score is given by the number of the lesser used accidental (sharps or flats)
multiplied by the mixSharpsFlatsPenalty.
'''
if self.ruleObject.mixSharpsFlatsPenalty is False:
if not self.ruleObject.mixSharpsFlatsPenalty:
return 1

joinedPossibility = ''.join([p.name for p in possibility])
Expand All @@ -128,7 +128,7 @@ def getAugDimScore(self, possibility):
Returns a score based on the number of augmented and diminished intervals between
successive pitches in the given spelling.
'''
if self.ruleObject.augDimPenalty is False:
if not self.ruleObject.augDimPenalty:
return 1

intervalStr = ''
Expand Down
10 changes: 5 additions & 5 deletions music21/analysis/neoRiemannian.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def L(c, raiseException=True):
transposeInterval = 'm2'
changingPitch = c.fifth
else:
if raiseException is True:
if raiseException:
raise LRPException('Cannot perform L on this chord: not a major or minor triad')
return c

Expand Down Expand Up @@ -134,7 +134,7 @@ def P(c, raiseException=True):
transposeInterval = 'A1'
changingPitch = c.third
else:
if raiseException is True:
if raiseException:
raise LRPException('Cannot perform P on this chord: not a Major or Minor triad')
return c

Expand Down Expand Up @@ -171,7 +171,7 @@ def R(c, raiseException=True):
transposeInterval = '-M2'
changingPitch = c.root()
else:
if raiseException is True:
if raiseException:
raise LRPException('Cannot perform R on this chord: not a Major or Minor triad')
return c

Expand Down Expand Up @@ -358,7 +358,7 @@ def LRP_combinations(c,
'''

if not c.isMajorTriad() and not c.isMinorTriad(): # First to avoid doing anything else if fail
if raiseException is True:
if raiseException:
raise LRPException(
f'Cannot perform transformations on chord {c}: not a major or minor triad')
return c
Expand Down Expand Up @@ -435,7 +435,7 @@ def completeHexatonic(c, simplifyEnharmonics=False, raiseException=True):
hexatonicList.append(lastChord)
return hexatonicList
else:
if raiseException is True:
if raiseException:
raise LRPException(
'Cannot perform transformations on this chord: not a major or minor triad')

Expand Down
4 changes: 2 additions & 2 deletions music21/analysis/reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ def testPartReductionB(self, show=False):
s.insert(0, p)
pCount += 1

if show is True:
if show:
s.show()

pr = analysis.reduction.PartReduction(s, normalize=False)
Expand All @@ -1140,7 +1140,7 @@ def testPartReductionB(self, show=False):

self._matchWeightedData(match, target)

if show is True:
if show:
p = graph.plot.Dolan(s, title='Dynamics')
p.run()

Expand Down
5 changes: 3 additions & 2 deletions music21/audioSearch/recording.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
default_recordChunkLength = 1024


def samplesFromRecording(seconds=10.0, storeFile=True,
def samplesFromRecording(seconds=10.0,
storeFile: bool|str = True,
recordFormat=None,
recordChannels=default_recordChannels,
recordSampleRate=default_recordSampleRate,
Expand Down Expand Up @@ -77,7 +78,7 @@ def samplesFromRecording(seconds=10.0, storeFile=True,
st.close()
p_audio.terminate()

if storeFile is not False:
if storeFile:
if isinstance(storeFile, str):
waveFilename = storeFile
else:
Expand Down
4 changes: 2 additions & 2 deletions music21/audioSearch/scoreFollower.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def repeatTranscription(self):
# print('3')
self.processing_time = time() - time_start
environLocal.printDebug('and even to here.')
if END_OF_SCORE is True:
if END_OF_SCORE:
exitType = 'endOfScore' # 'endOfScore'
return exitType

Expand Down Expand Up @@ -239,7 +239,7 @@ def silencePeriodDetection(self, notesList):
if i.name != 'rest':
onlyRests = False

if onlyRests is True:
if onlyRests:
self.silencePeriod = True
self.notesCounter = 0
self.silencePeriodCounter += 1
Expand Down
10 changes: 7 additions & 3 deletions music21/audioSearch/transcriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
environLocal = environment.Environment('audioSearch.transcriber')


def runTranscribe(show=True, plot=True, useMic=True,
seconds=20.0, useScale=None, saveFile=True): # pragma: no cover
def runTranscribe(show: bool = True,
plot: bool = True,
useMic: bool = True,
seconds: float = 20.0,
useScale=None,
saveFile: bool|str = True): # pragma: no cover
'''
runs all the methods to record from audio for `seconds` length (default 10.0)
and transcribe the resulting melody returning a music21.Score object
Expand Down Expand Up @@ -54,7 +58,7 @@ def runTranscribe(show=True, plot=True, useMic=True,
waveFilename = saveFile

# the rest of the score
if useMic is True:
if useMic:
freqFromAQList = audioSearchBase.getFrequenciesFromMicrophone(
length=seconds,
storeWaveFilename=str(waveFilename))
Expand Down
4 changes: 2 additions & 2 deletions music21/chord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4005,7 +4005,7 @@ def semiClosedPosition(
c2 = self.closedPosition(forceOctave=forceOctave,
inPlace=inPlace,
leaveRedundantPitches=leaveRedundantPitches)
if inPlace is True:
if inPlace:
c2 = self

# closedPosition() only returns None when inPlace=True, in which case c2
Expand All @@ -4028,7 +4028,7 @@ def semiClosedPosition(
c2.clearCache()
c2.sortAscending(inPlace=True)

if inPlace is False:
if not inPlace:
return c2

def semitonesFromChordStep(self, chordStep, testRoot=None):
Expand Down
6 changes: 3 additions & 3 deletions music21/converter/subConverters.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def parseFile(self,
loading the file and putting the data into parseData then there is no need
to implement this method. Just set self.readBinary to True | False.
'''
if self.readBinary is False:
if not self.readBinary:
import locale
with open(filePath, encoding=locale.getpreferredencoding()) as f:
dataStream = f.read()
Expand Down Expand Up @@ -289,7 +289,7 @@ def writeDataStream(self,
if fp is None:
fp = self.getTemporaryFile()

if self.readBinary is False:
if not self.readBinary:
writeFlags = 'w'
else:
writeFlags = 'wb'
Expand Down Expand Up @@ -330,7 +330,7 @@ def toData(
and return the object (str or bytes) returned.
'''
fp = self.write(obj, fmt=fmt, subformats=subformats, **keywords)
if self.readBinary is False:
if not self.readBinary:
readFlags = 'r'
else:
readFlags = 'rb'
Expand Down
1 change: 1 addition & 0 deletions music21/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import typing as t
from music21 import _version


# note: this module should not import any higher level modules
type StepName = t.Literal['C', 'D', 'E', 'F', 'G', 'A', 'B'] # restating so as not to import.

Expand Down
12 changes: 6 additions & 6 deletions music21/freezeThaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def __init__(self, streamObj=None, fastButUnsafe=False, topLevel=True, streamIds

self.subStreamFreezers = {} # this will keep track of sub freezers for spanners

if streamObj is not None and fastButUnsafe is False:
if streamObj is not None and not fastButUnsafe:
# deepcopy necessary because we mangle sites in the objects
# before serialization
self.stream = copy.deepcopy(streamObj)
Expand Down Expand Up @@ -267,7 +267,7 @@ def setupSerializationScaffold(self, streamObj=None):
# might not work when recurse yields
allEls = list(streamObj.recurse(restoreActiveSites=False))

if self.topLevel is True:
if self.topLevel:
self.findActiveStreamIdsInHierarchy(streamObj)

for el in allEls:
Expand Down Expand Up @@ -297,7 +297,7 @@ def setupSerializationScaffold(self, streamObj=None):
# removing seems to create problems for jsonPickle with Spanners
self.setupStoredElementOffsetTuples(streamObj)

if self.topLevel is True:
if self.topLevel:
self.recursiveClearSites(streamObj)

def removeStreamStatusClient(self, streamObj):
Expand Down Expand Up @@ -578,11 +578,11 @@ def findActiveStreamIdsInHierarchy(
includeSelf=True)
streamIds = [id(s) for s in streamsFoundGenerator]

if getSpanners is True:
if getSpanners:
spannerBundle = streamObj.spannerBundle
streamIds += spannerBundle.getSpannerStorageIds()

if getVariants is True:
if getVariants:
for el in streamObj.recurse(includeSelf=True).getElementsByClass(variant.Variant):
streamIds += self.findActiveStreamIdsInHierarchy(el._stream)

Expand Down Expand Up @@ -853,7 +853,7 @@ def restoreElementsFromTuples(self, streamObj):
streamObj.coreElementsChanged()

for subElement in streamObj:
if subElement.isStream is True:
if subElement.isStream:
# note that the elements may have already been restored
# if the spanner stores a part or something in the Stream
# for instance in a StaffGroup object
Expand Down
8 changes: 4 additions & 4 deletions music21/graph/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ class PitchAxis(Axis):

def __init__(self, client=None, axisName='x'):
super().__init__(client, axisName)
self.showOctaves = 'few'
self.showOctaves: bool|t.Literal['few'] = 'few'
self.showEnharmonic = True
self.blankLabelUnused = True
self.hideUnused = True
Expand Down Expand Up @@ -425,7 +425,7 @@ def unweightedSortHelper(x):
sub.append(accidentalLabelToUnicode(name))
label = '/'.join(sub)

if self.showOctaves is False:
if not self.showOctaves:
label = re.sub(r'\d', '', label)
elif self.showOctaves == 'few':
matchOctave = re.search(r'\d', label)
Expand All @@ -451,7 +451,7 @@ class PitchClassAxis(PitchAxis):
quantities: tuple[str, ...] = ('pitchClass', 'pitchclass', 'pc')

def __init__(self, client=None, axisName='x'):
self.showOctaves = False
self.showOctaves: bool|t.Literal['few'] = False
super().__init__(client, axisName)
self.minValue = 0
self.maxValue = 11
Expand Down Expand Up @@ -1129,7 +1129,7 @@ class QuarterLengthAxis(PositionAxis):

def __init__(self, client=None, axisName='x'):
super().__init__(client, axisName)
self.useLogScale = True
self.useLogScale: bool|int = True
self.useDurationNames = False

def extractOneElement(self, n, formatDict):
Expand Down
Loading
Loading