Skip to content

Commit c12538d

Browse files
gregchapman-devTimFelixBeyer
authored andcommitted
Proposed solution for PR cuthbertLab#1636. Note that I had to check md['software'] as it was being constructed, instead of afterward, because Metadata() actually adds a software item for the music21 version that read the file, and I don't want to be confused by that.
1 parent 177bc53 commit c12538d

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

music21/musicxml/xmlToM21.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ def __init__(self):
767767
self.parts = []
768768

769769
self.musicXmlVersion = defaults.musicxmlVersion
770+
self.wasWrittenByFinale = False
770771

771772
def scoreFromFile(self, filename):
772773
'''
@@ -1364,9 +1365,17 @@ def processEncoding(self, encoding: ET.Element, md: metadata.Metadata) -> None:
13641365
# TODO: encoder (text + type = role) multiple
13651366
# TODO: encoding date multiple
13661367
# TODO: encoding-description (string) multiple
1368+
finaleFound: bool = False
1369+
nonFinaleFound: bool = False
13671370
for software in encoding.findall('software'):
13681371
if softwareText := strippedText(software):
1372+
if 'Finale' in softwareText:
1373+
finaleFound = True
1374+
else:
1375+
nonFinaleFound = True
13691376
md.add('software', softwareText)
1377+
if finaleFound and not nonFinaleFound:
1378+
self.wasWrittenByFinale = True
13701379

13711380
for supports in encoding.findall('supports'):
13721381
# todo: element: required
@@ -2668,8 +2677,20 @@ def xmlForward(self, mxObj: ET.Element):
26682677
mxDuration = mxObj.find('duration')
26692678
if durationText := strippedText(mxDuration):
26702679
change = opFrac(float(durationText) / self.divisions)
2680+
2681+
if self.parent.parent.wasWrittenByFinale:
2682+
# Create hidden rest (in other words, a spacer)
2683+
# old Finale documents close incomplete final measures with <forward>
2684+
# this will be removed afterward by removeEndForwardRest()
2685+
r = note.Rest(quarterLength=change)
2686+
r.style.hideObjectOnPrint = True
2687+
self.addToStaffReference(mxObj, r)
2688+
self.insertInMeasureOrVoice(mxObj, r)
2689+
# xmlToNote() sets None
2690+
self.endedWithForwardTag = r
2691+
26712692
# Allow overfilled measures for now -- TODO(someday): warn?
2672-
self.offsetMeasureNote = opFrac(self.offsetMeasureNote + change)
2693+
self.offsetMeasureNote = opFrac(self.offsetMeasureNote + change) # xmlToNote() sets None
26732694

26742695
def xmlPrint(self, mxPrint: ET.Element):
26752696
'''

0 commit comments

Comments
 (0)