Skip to content

Commit

Permalink
Fix midmeasure clef export regression involving voices
Browse files Browse the repository at this point in the history
jacobtylerwalls committed Jul 3, 2022
1 parent 48a3fa6 commit e0266ab
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions music21/musicxml/m21ToXml.py
Original file line number Diff line number Diff line change
@@ -3113,8 +3113,8 @@ def parseFlatElements(self, m, *, backupAfterwards=False):
amountToMoveForward = int(round(divisions * (groupOffset
- self.offsetInMeasure)))
if amountToMoveForward > 0 and any(
isinstance(obj, note.GeneralNote) for obj in objGroup):
# gap in stream between GeneralNote objects: create <forward>
isinstance(obj, (note.GeneralNote, clef.Clef)) for obj in objGroup):
# gap in stream between GeneralNote/Clef objects: create <forward>
mxForward = Element('forward')
mxDuration = SubElement(mxForward, 'duration')
mxDuration.text = str(amountToMoveForward)
24 changes: 24 additions & 0 deletions music21/musicxml/testPrimitive.py
Original file line number Diff line number Diff line change
@@ -18236,6 +18236,30 @@ def testMidMeasureClefs2(self):
self.assertEqual([c.classes for c in new_clefs],
[c.classes for c in orig_clefs])

def testMidMeasureClefs3(self):
'''
Test midmeasure clef changes outside voices
'''
from music21 import clef
from music21 import note
from music21 import musicxml
from music21 import stream

v1 = stream.Voice()
v2 = stream.Voice()
quarter = note.Note()
v1.repeatAppend(quarter, 4)
v2.repeatAppend(quarter, 4)
m = stream.Measure([v1, v2])
m.insert(1.0, clef.BassClef())
p = stream.Part(m)
p.makeNotation(inPlace=True)

tree = musicxml.test_m21ToXml.Test().getET(p)
self.assertEqual(len(tree.findall('.//clef')), 1)
# One backup from the clef back to voice 1, then another back to voice 2
self.assertEqual(len(tree.findall('.//backup')), 2)

# ------------------------------------------------------------------------------


0 comments on commit e0266ab

Please sign in to comment.