Skip to content

Commit

Permalink
Export hidden tempo text to MusicXML.
Browse files Browse the repository at this point in the history
Hidden tempo text is now exported as a <sound tempo="XX"/> element
without a container <direction> element.

This is now in line with the way MuseScore imports <sound> elements,
see: #7171
  • Loading branch information
matangover authored and vpereverzev committed Mar 10, 2021
1 parent ad17918 commit 4a06420
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 249 deletions.
15 changes: 10 additions & 5 deletions importexport/musicxml/exportxml.cpp
Expand Up @@ -3954,17 +3954,22 @@ void ExportMusicXml::tempoText(TempoText const* const text, int staff)
qPrintable(text->xmlText()));
*/
_attr.doAttr(_xml, false);
_xml.stag(QString("direction placement=\"%1\"").arg((text->placement() ==Placement::BELOW ) ? "below" : "above"));
wordsMetrome(_xml, _score, text, offset);
if (text->visible()) {
_xml.stag(QString("direction placement=\"%1\"").arg((text->placement() ==Placement::BELOW ) ? "below" : "above"));
wordsMetrome(_xml, _score, text, offset);

if (staff)
_xml.tag("staff", staff);
}

if (staff)
_xml.tag("staff", staff);
// Format tempo with maximum 2 decimal places, because in some MuseScore files tempo is stored
// imprecisely and this could cause rounding errors (e.g. 92 BPM would be saved as 91.9998).
qreal bpm = text->tempo() * 60.0;
qreal bpmRounded = round(bpm * 100) / 100;
_xml.tagE(QString("sound tempo=\"%1\"").arg(QString::number(bpmRounded)));
_xml.etag();

if (text->visible())
_xml.etag();
}

//---------------------------------------------------------
Expand Down
42 changes: 39 additions & 3 deletions mtest/musicxml/io/testSound1.xml
@@ -1,9 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 2.0 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 3.1 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="3.1">
<identification>
<encoding>
<software>MuseScore 0.7.0</software>
<encoding-date>2007-09-10</encoding-date>
<supports element="accidental" type="yes"/>
<supports element="beam" type="yes"/>
<supports element="print" attribute="new-page" type="no"/>
<supports element="print" attribute="new-system" type="no"/>
<supports element="stem" type="yes"/>
</encoding>
</identification>
<part-list>
<score-part id="P1">
<part-name>Music</part-name>
<score-instrument id="P1-I1">
<instrument-name></instrument-name>
</score-instrument>
<midi-device id="P1-I1" port="1"></midi-device>
<midi-instrument id="P1-I1">
<midi-channel>1</midi-channel>
<midi-program>1</midi-program>
<volume>78.7402</volume>
<pan>0</pan>
</midi-instrument>
</score-part>
</part-list>
<part id="P1">
Expand All @@ -12,7 +33,6 @@
<divisions>1</divisions>
<key>
<fifths>0</fifths>
<mode>major</mode>
</key>
<time>
<beats>4</beats>
Expand All @@ -23,38 +43,46 @@
<line>2</line>
</clef>
</attributes>
<sound tempo="60"/>
<sound tempo="60"/>
<note>
<pitch>
<step>C</step>
<octave>4</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>quarter</type>
<stem>up</stem>
</note>
<note>
<pitch>
<step>D</step>
<octave>4</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>quarter</type>
<stem>up</stem>
</note>
<note>
<pitch>
<step>E</step>
<octave>4</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>quarter</type>
<stem>up</stem>
</note>
<note>
<pitch>
<step>F</step>
<octave>4</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>quarter</type>
<stem>up</stem>
</note>
</measure>
<measure number="2">
Expand All @@ -64,31 +92,39 @@
<octave>4</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>quarter</type>
<stem>up</stem>
</note>
<note>
<pitch>
<step>F</step>
<octave>4</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>quarter</type>
<stem>up</stem>
</note>
<note>
<pitch>
<step>E</step>
<octave>4</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>quarter</type>
<stem>up</stem>
</note>
<note>
<pitch>
<step>D</step>
<octave>4</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>quarter</type>
<stem>up</stem>
</note>
</measure>
<measure number="3">
Expand Down
150 changes: 0 additions & 150 deletions mtest/musicxml/io/testSound1_ref.xml

This file was deleted.

10 changes: 1 addition & 9 deletions mtest/musicxml/io/testSound2_ref.xml
Expand Up @@ -43,15 +43,7 @@
<line>2</line>
</clef>
</attributes>
<direction placement="above">
<direction-type>
<metronome parentheses="no">
<beat-unit>quarter</beat-unit>
<per-minute>60</per-minute>
</metronome>
</direction-type>
<sound tempo="60"/>
</direction>
<sound tempo="60"/>
<note>
<pitch>
<step>C</step>
Expand Down

0 comments on commit 4a06420

Please sign in to comment.