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

Avoid writing empty <movement-title /> and <creator /> tags when title and author have no defaults #1248

Merged
merged 3 commits into from
May 13, 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
29 changes: 24 additions & 5 deletions music21/musicxml/m21ToXml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2228,6 +2228,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 @@ -2243,7 +2258,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 @@ -2421,14 +2436,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