Skip to content

Commit

Permalink
Fix crash in export of flattened piano music (#877)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls authored Feb 24, 2021
1 parent c79932c commit 41ca487
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions music21/musicxml/partStaffExporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,16 @@ def joinableGroups(self) -> List[StaffGroup]:
staffGroups = self.stream.getElementsByClass('StaffGroup')
joinableGroups: List[StaffGroup] = []
# Joinable groups must consist of only PartStaffs with Measures
# and exist in self.stream
for sg in staffGroups:
if len(sg) <= 1:
continue
if not all(stream.PartStaff in p.classSet for p in sg):
continue
if not all(p.getElementsByClass('Measure') for p in sg):
continue
if not all(p in self.stream for p in sg):
continue
joinableGroups.append(sg)

# Deduplicate joinable groups (ex: bracket and brace enclose same PartStaffs)
Expand Down Expand Up @@ -846,6 +849,19 @@ def testJoinPartStaffsE(self):
self.assertEqual({staff.text for staff in m2tag.findall('note/staff')}, {'2'})
self.assertEqual({staff.text for staff in m3tag.findall('note/staff')}, {'1'})

def testJoinPartStaffsF(self):
'''
Flattening the score will leave StaffGroup spanners with parts no longer in the stream.
'''
from music21 import corpus
from music21 import musicxml
sch = corpus.parse('schoenberg/opus19', 2)

SX = musicxml.m21ToXml.ScoreExporter(sch.flat)
SX.scorePreliminaries()
SX.parsePartlikeScore()
# Previously, an exception was raised by getRootForPartStaff()
SX.joinPartStaffs()


if __name__ == '__main__':
Expand Down

0 comments on commit 41ca487

Please sign in to comment.