Skip to content

Commit

Permalink
Merge pull request #1708 from gregchapman-dev/gregc/moreLeadSheetFixes
Browse files Browse the repository at this point in the history
A few leadsheet-related fixes
  • Loading branch information
mscuthbert authored Jun 13, 2024
2 parents 3fae7a1 + 57ed01f commit 4716deb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
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 4716deb

Please sign in to comment.