Skip to content

Commit

Permalink
Merge pull request #1375 from jacobtylerwalls/too-large-backup
Browse files Browse the repository at this point in the history
Prevent too large `<backup>` values in PartStaffExporter
  • Loading branch information
mscuthbert authored Aug 15, 2022
2 parents d68cdd6 + 95ef0de commit cb04dd0
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion music21/musicxml/partStaffExporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,12 @@ def moveMeasureContents(measure: Element, otherMeasure: Element, staffNumber: in

# Create <backup>
amountToBackup: int = 0
for dur in otherMeasure.findall('note/duration'):
for note in otherMeasure.findall('note'):
if note.find('chord') is not None:
continue
dur = note.find('duration')
if dur is None:
continue
backupDurText = dur.text
if backupDurText is not None:
amountToBackup += int(backupDurText)
Expand Down Expand Up @@ -1067,6 +1072,23 @@ def testMeterChanges(self):
root = self.getET(s)
self.assertEqual(len(root.findall('part/measure/attributes/time')), 3)

def testBackupAmount(self):
'''Regression test for chord members causing too-large backup amounts.'''
from music21 import chord
from music21 import defaults
from music21 import layout

ps1 = stream.PartStaff(chord.Chord("C E G"))
ps2 = stream.PartStaff(chord.Chord("D F A"))
sg = layout.StaffGroup([ps1, ps2])
s = stream.Score([sg, ps1, ps2])

root = self.getET(s)
self.assertEqual(
root.findall('part/measure/backup/duration')[0].text,
str(defaults.divisionsPerQuarter)
)


if __name__ == '__main__':
import music21
Expand Down

0 comments on commit cb04dd0

Please sign in to comment.