From d47ce0609dfca0ce3bca4c81a63d53262efa2051 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Wed, 9 Mar 2022 08:59:02 -0500 Subject: [PATCH 1/3] Remove title and author defaults Avoid writing empty tags for movement-title and creator --- music21/defaults.py | 4 ++-- music21/musicxml/m21ToXml.py | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/music21/defaults.py b/music21/defaults.py index 4f55198a96..ec2830d63d 100644 --- a/music21/defaults.py +++ b/music21/defaults.py @@ -31,8 +31,8 @@ class DefaultsException(Exception): pass -title = 'Music21 Fragment' -author = 'Music21' +title = '' +author = '' software = 'music21 v.' + _version.__version__ # used in xml encoding source software musicxmlVersion = '3.1' diff --git a/music21/musicxml/m21ToXml.py b/music21/musicxml/m21ToXml.py index c8ae1f2fbe..114ee977fc 100644 --- a/music21/musicxml/m21ToXml.py +++ b/music21/musicxml/m21ToXml.py @@ -352,9 +352,7 @@ def parse(self, obj=None): PUBLIC "-//Recordare//DTD MusicXML ... Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd"> - Music21 Fragment - Music21 ... music21 v... @@ -2198,7 +2196,6 @@ def setIdentification(self): >>> mxIdentification = SX.setIdentification() >>> SX.dump(mxIdentification) - Music21 20...-...-... music21 v... @@ -2243,7 +2240,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 @@ -2421,14 +2418,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 From ae2f64f4f695c6fd877112a980b6aa3947a9a2a6 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Wed, 9 Mar 2022 09:21:48 -0500 Subject: [PATCH 2/3] Add coverage --- music21/musicxml/m21ToXml.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/music21/musicxml/m21ToXml.py b/music21/musicxml/m21ToXml.py index 114ee977fc..e79b62e75d 100644 --- a/music21/musicxml/m21ToXml.py +++ b/music21/musicxml/m21ToXml.py @@ -2225,6 +2225,21 @@ def setIdentification(self): + + Overriding the default: + + >>> defaults.author = "Batch Conversion March 2022" + >>> SX = musicxml.m21ToXml.ScoreExporter() + >>> mxIdentification = SX.setIdentification() + >>> SX.dump(mxIdentification) + + Batch Conversion March 2022 + + 20...-...-... + music21 v... + + + ''' if self.mxIdentification is not None: mxId = self.mxIdentification From 1fcd51885963e992f3058b261ae82311c6546179 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Tue, 19 Apr 2022 18:35:27 -0400 Subject: [PATCH 3/3] Restore defaults --- music21/defaults.py | 4 ++-- music21/musicxml/m21ToXml.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/music21/defaults.py b/music21/defaults.py index ec2830d63d..4f55198a96 100644 --- a/music21/defaults.py +++ b/music21/defaults.py @@ -31,8 +31,8 @@ class DefaultsException(Exception): pass -title = '' -author = '' +title = 'Music21 Fragment' +author = 'Music21' software = 'music21 v.' + _version.__version__ # used in xml encoding source software musicxmlVersion = '3.1' diff --git a/music21/musicxml/m21ToXml.py b/music21/musicxml/m21ToXml.py index e79b62e75d..c8ebf209bc 100644 --- a/music21/musicxml/m21ToXml.py +++ b/music21/musicxml/m21ToXml.py @@ -352,7 +352,9 @@ def parse(self, obj=None): PUBLIC "-//Recordare//DTD MusicXML ... Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd"> + Music21 Fragment + Music21 ... music21 v... @@ -2196,6 +2198,7 @@ def setIdentification(self): >>> mxIdentification = SX.setIdentification() >>> SX.dump(mxIdentification) + Music21 20...-...-... music21 v...