Skip to content

Commit

Permalink
Merge pull request #1437 from gregchapman-dev/gregc/writeTempoText
Browse files Browse the repository at this point in the history
Write TempoText to MusicXML...
  • Loading branch information
mscuthbert authored Sep 24, 2022
2 parents 5b1bd49 + 9d796ef commit 038f495
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions music21/musicxml/m21ToXml.py
Original file line number Diff line number Diff line change
Expand Up @@ -3107,6 +3107,7 @@ class MeasureExporter(XMLExporterBase):
('Dynamic', 'dynamicToXml'),
('Segno', 'segnoToXml'),
('Coda', 'codaToXml'),
('TempoText', 'tempoIndicationToXml'),
('MetronomeMark', 'tempoIndicationToXml'),
('MetricModulation', 'tempoIndicationToXml'),
('TextExpression', 'textExpressionToXml'),
Expand Down Expand Up @@ -5828,6 +5829,18 @@ def tempoIndicationToXml(self, ti):
</direction-type>
<sound tempo="60" />
</direction>
This is the case of a TempoText.
>>> tt = tempo.TempoText('Andante')
>>> mxDirection = MEX.tempoIndicationToXml(tt)
>>> MEX.dump(mxDirection)
<direction>
<direction-type>
<words default-y="45" enclosure="none" font-weight="bold">Andante</words>
</direction-type>
</direction>
'''
# if writing just a sound tag, place an empty words tag in a
# direction type and then follow with sound declaration
Expand All @@ -5838,6 +5851,13 @@ def tempoIndicationToXml(self, ti):
hideNumber = [] # hide the number after equal, e.g., quarter=120, hide 120
# store the last value necessary as a sounding tag in bpm
soundingQuarterBPM = False

# handle TempoText simply by exporting its textExpression.
if isinstance(ti, tempo.TempoText):
te = ti.getTextExpression()
te.offset = ti.offset
return self.textExpressionToXml(te)

if isinstance(ti, tempo.MetronomeMark):
# will not show a number of implicit
if ti.numberImplicit or ti.number is None:
Expand Down

0 comments on commit 038f495

Please sign in to comment.