Skip to content

Commit

Permalink
Merge pull request #1248 from jacobtylerwalls/empty-defaults
Browse files Browse the repository at this point in the history
Avoid writing empty `<movement-title />` and `<creator />` tags when title and author have no defaults
  • Loading branch information
mscuthbert authored May 13, 2022
2 parents 33b37c4 + 1fcd518 commit 486b6cd
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions music21/musicxml/m21ToXml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2239,6 +2239,21 @@ def setIdentification(self):
</encoding>
</identification>
Overriding the default:
>>> defaults.author = "Batch Conversion March 2022"
>>> SX = musicxml.m21ToXml.ScoreExporter()
>>> mxIdentification = SX.setIdentification()
>>> SX.dump(mxIdentification)
<identification>
<creator type="composer">Batch Conversion March 2022</creator>
<encoding>
<encoding-date>20...-...-...</encoding-date>
<software>music21 v...</software>
</encoding>
</identification>
'''
if self.mxIdentification is not None:
mxId = self.mxIdentification
Expand All @@ -2254,7 +2269,7 @@ def setIdentification(self):
mxId.append(mxCreator)
foundOne = True

if foundOne is False:
if foundOne is False and defaults.author:
mxCreator = SubElement(mxId, 'creator')
mxCreator.set('type', 'composer')
mxCreator.text = defaults.author
Expand Down Expand Up @@ -2431,14 +2446,18 @@ def setTitles(self):

# musicxml often defaults to show only movement title
# if no movement title is found, get the .title attr
mxMovementTitle = SubElement(mxScoreHeader, 'movement-title')
movement_title = ''
if mdObj.movementName not in (None, ''):
mxMovementTitle.text = str(mdObj.movementName)
movement_title = str(mdObj.movementName)
else: # it is none
if mdObj.title is not None:
mxMovementTitle.text = str(mdObj.title)
movement_title = str(mdObj.title)
elif defaults.title:
movement_title = defaults.title
else:
mxMovementTitle.text = defaults.title
return
mxMovementTitle = SubElement(mxScoreHeader, 'movement-title')
mxMovementTitle.text = movement_title

def contributorToXmlCreator(self, c):
# noinspection SpellCheckingInspection, PyShadowingNames
Expand Down

0 comments on commit 486b6cd

Please sign in to comment.