Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few leadsheet-related fixes #1708

Merged
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
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'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also be searching in <direction> tags? They're the only other thing that can contain a voice tag. But maybe unnecessary.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

return self.isElementOffsetInRange(e, offset, stopAfterEnd=False)


Expand Down
Loading