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

Prevent too large <backup> values in PartStaffExporter #1375

Merged
merged 1 commit into from
Aug 15, 2022
Merged
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
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