Skip to content

Commit 086e55f

Browse files
authored
Merge pull request #180 from frescobaldi/fix-musicxml-iterate-part
Add more robust logic to find the last Bar in a ScorePart
2 parents ea3c0c4 + bd4964d commit 086e55f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

ly/musicxml/xml_objs.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ def iterate_partgroup(self, group):
9696

9797
def iterate_part(self, part):
9898
"""The part is iterated."""
99-
if part.barlist:
100-
last_bar = part.barlist[-1]
99+
last_bar = part.last_bar()
100+
if last_bar:
101101
last_bar_objs = last_bar.obj_list
102102
part.set_first_bar(self.divisions)
103103
self.musxml.create_part(part.name, part.abbr, part.midi)
@@ -458,6 +458,12 @@ def extract_global_to_section(self, name):
458458
section.barlist.append(section_bar)
459459
return section
460460

461+
def last_bar(self):
462+
"""Returns the last Bar object in the score, or None if the score is empty."""
463+
for obj in reversed(self.barlist):
464+
if isinstance(obj, Bar):
465+
return obj
466+
461467

462468
class Bar():
463469
""" Representing the bar/measure.

0 commit comments

Comments
 (0)