Skip to content

Commit

Permalink
Merge branch 'update-fb-examples-solutions' into tsv-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mscuthbert committed Jun 14, 2024
2 parents d4fb6e4 780dc46 commit d1ae529
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
8 changes: 3 additions & 5 deletions music21/figuredBass/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 67,7 @@ def exampleA():
>>> fbRealization2 = fbLine.realize(fbRules)
>>> fbRealization2.keyboardStyleOutput = False
>>> fbRealization2.getNumSolutions()
3713168
3564440
>>> #_DOCS_SHOW fbRealization2.generateRandomRealization().show()
.. image:: images/figuredBass/fbExamples_sol2A.*
Expand Down Expand Up @@ -111,7 111,6 @@ def exampleD():
figured bass, and fbLine is realized again. Voice overlap can be seen in the fourth
measure.
>>> fbRules.forbidVoiceOverlap = False
>>> fbRealization2 = fbLine.realize(fbRules)
>>> fbRealization2.getNumSolutions()
Expand All @@ -124,12 123,11 @@ def exampleD():
Now, the restriction on voice overlap is reset, but the restriction on the upper parts
being within a perfect octave of each other is removed. fbLine is realized again.
>>> fbRules.forbidVoiceOverlap = True
>>> fbRules.upperPartsMaxSemitoneSeparation = None
>>> fbRealization3 = fbLine.realize(fbRules)
>>> fbRealization3.getNumSolutions()
29629539
27445876
>>> fbRealization3.keyboardStyleOutput = False
>>> #_DOCS_SHOW fbRealization3.generateRandomRealization().show()
Expand Down Expand Up @@ -177,7 175,7 @@ def exampleB():
>>> fbRules.forbidIncompletePossibilities = False
>>> fbRealization2 = fbLine.realize(fbRules)
>>> fbRealization2.getNumSolutions()
188974
159373
>>> #_DOCS_SHOW fbRealization2.generateRandomRealization().show()
.. image:: images/figuredBass/fbExamples_sol2B.*
Expand Down
27 changes: 20 additions & 7 deletions music21/musicxml/xmlToM21.py
Original file line number Diff line number Diff line change
Expand Up @@ -6202,7 6202,7 @@ def parseMeasureNumbers(self, mNumRaw=None):
def updateVoiceInformation(self):
# noinspection PyShadowingNames
'''
Finds all the "voice" information in <note> tags and updates the set of
Finds all the "voice" information in <note> and <forward> tags and updates the set of
`.voiceIndices` to be a set of all the voice texts, and if there is
more than one voice in the measure, sets `.useVoices` to True
and creates a voice for each.
Expand Down Expand Up @@ -6231,14 6231,27 @@ def updateVoiceInformation(self):
2
>>> list(MP.stream.getElementsByClass(stream.Voice))
[<music21.stream.Voice 1>, <music21.stream.Voice 2>]
>>> MP = musicxml.xmlToM21.MeasureParser()
>>> MP.mxMeasure = ET.fromstring('<measure><note><voice>1</voice></note>'
... '<forward><voice>2</voice></forward></measure>')
>>> MP.updateVoiceInformation()
>>> sorted(list(MP.voiceIndices))
['1', '2']
>>> MP.useVoices
True
>>> len(MP.stream)
2
>>> list(MP.stream.getElementsByClass(stream.Voice))
[<music21.stream.Voice 1>, <music21.stream.Voice 2>]
'''
mxm = self.mxMeasure
for mxn in mxm.findall('note'):
voice = mxn.find('voice')
if vIndex := strippedText(voice):
self.voiceIndices.add(vIndex)
# it is a set, so no need to check if already there
# additional time < 1 sec per ten million ops.
for tagSearch in ('note', 'forward'):
for mxn in mxm.findall(tagSearch):
voice = mxn.find('voice')
if vIndex := strippedText(voice):
self.voiceIndices.add(vIndex)
# it is a set, so no need to check if already there
# additional time < 1 sec per ten million ops.

if len(self.voiceIndices) > 1:
for vIndex in sorted(self.voiceIndices):
Expand Down
2 changes: 1 addition & 1 deletion music21/stream/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 490,7 @@ def __call__(self, e, iterator=None):
if not hasattr(iterator, 'iteratorStartOffsetInHierarchy'):
raise FilterException('Can only run OffsetHierarchyFilter on a RecursiveIterator')

offset = s.elementOffset(e) iterator.iteratorStartOffsetInHierarchy
offset = opFrac(s.elementOffset(e) iterator.iteratorStartOffsetInHierarchy)
return self.isElementOffsetInRange(e, offset, stopAfterEnd=False)


Expand Down

0 comments on commit d1ae529

Please sign in to comment.