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

Read 'print-object' for directions and write for tempo #444

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
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
15 changes: 7 additions & 8 deletions importexport/musicxml/exportxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4512,6 +4512,8 @@ static void wordsMetronome(XmlWriter& xml, Score* s, TextBase const* const text,
QString tagName = QString("metronome parentheses=\"%1\"").arg(hasParen ? "yes" : "no");
tagName += color2xml(text);
tagName += positioningAttributes(text);
if (!text->visible())
tagName += " print-object=\"no\"";
xml.stag(tagName);
int len1 = 0;
TDuration dur;
Expand Down Expand Up @@ -4571,22 +4573,19 @@ void ExportMusicXml::tempoText(TempoText const* const text, int staff)
qPrintable(text->xmlText()));
*/
_attr.doAttr(_xml, false);
if (text->visible()) {
_xml.stag(QString("direction placement=\"%1\"").arg((text->placement() == Placement::BELOW ) ? "below" : "above"));
wordsMetronome(_xml, _score, text, offset);
_xml.stag(QString("direction placement=\"%1\"").arg((text->placement() == Placement::BELOW ) ? "below" : "above"));
wordsMetronome(_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)));

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

//---------------------------------------------------------
Expand Down
10 changes: 9 additions & 1 deletion importexport/musicxml/importmxmlpass2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3281,6 +3281,7 @@ void MusicXMLParserDirection::direction(const QString& partId,
if (tt->plainText().contains('='))
tt->setFollowText(true);
}
tt->setVisible(_visible);

addElemOffset(tt, track, placement(), measure, tick + _offset);
}
Expand Down Expand Up @@ -3351,6 +3352,8 @@ void MusicXMLParserDirection::direction(const QString& partId,
t->setPropertyFlags(Pid::COLOR, PropertyFlags::UNSTYLED);
}

t->setVisible(_visible);

QString wordsPlacement = placement();
// Case-based defaults
if (wordsPlacement.isEmpty()) {
Expand Down Expand Up @@ -3408,9 +3411,11 @@ void MusicXMLParserDirection::direction(const QString& partId,
dynaValue = 127;
else if (dynaValue < 0)
dynaValue = 0;
dyn->setVelocity( dynaValue );
dyn->setVelocity(dynaValue);
}

dyn->setVisible(_visible);

QString dynamicsPlacement = placement();
// Case-based defaults
if (dynamicsPlacement.isEmpty())
Expand Down Expand Up @@ -3499,6 +3504,7 @@ void MusicXMLParserDirection::direction(const QString& partId,
else
spannerPlacement = totalY() < 0 ? "above" : "below";
}
desc._sp->setVisible(_visible);
if (spdesc._isStopped) {
_pass2.addSpanner(desc);
// handleSpannerStart and handleSpannerStop must be called in order
Expand Down Expand Up @@ -3540,6 +3546,7 @@ void MusicXMLParserDirection::directionType(QList<MusicXmlSpannerDesc>& starts,
_hasDefaultY |= hasDefaultYCandidate;
_hasRelativeY |= hasRelativeYCandidate;
_isBold &= _e.attributes().value("font-weight").toString() == "bold";
_visible = _e.attributes().value("print-object").toString() != "no";
QString number = _e.attributes().value("number").toString();
int n = 0;
if (!number.isEmpty()) {
Expand Down Expand Up @@ -4233,6 +4240,7 @@ void MusicXMLParserDirection::handleRepeats(Measure* measure, const int track, c
measure = measure->prevMeasure();
else if (tb->tid() == Tid::REPEAT_LEFT && !closerToLeft && measure->nextMeasure())
measure = measure->nextMeasure();
tb->setVisible(_visible);
measure->add(tb);
}
}
Expand Down
1 change: 1 addition & 0 deletions importexport/musicxml/importmxmlpass2.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ class MusicXMLParserDirection {
double _tpoMetro; // tempo according to metronome
double _tpoSound; // tempo according to sound
bool _systemDirection = false;
bool _visible = true;
QList<Element*> _elems;
Fraction _offset;

Expand Down
84 changes: 84 additions & 0 deletions mtest/musicxml/io/testInvisibleDirection.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 4.0 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="4.0">
<work>
<work-title>Untitled score</work-title>
</work>
<identification>
<creator type="composer">Composer / arranger</creator>
<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>Flute</part-name>
<part-abbreviation>Fl.</part-abbreviation>
<score-instrument id="P1-I1">
<instrument-name>Flute</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>74</midi-program>
<volume>78.7402</volume>
<pan>0</pan>
</midi-instrument>
</score-part>
</part-list>
<part id="P1">
<measure number="1">
<attributes>
<divisions>1</divisions>
<key>
<fifths>0</fifths>
</key>
<time>
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<direction placement="above">
<direction-type>
<metronome parentheses="no" print-object="no">
<beat-unit>quarter</beat-unit>
<per-minute>64</per-minute>
</metronome>
</direction-type>
<sound tempo="64"/>
</direction>
<note>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
</note>
</measure>
<measure number="2">
<note>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
</note>
</measure>
<measure number="3">
<note>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
</note>
<barline location="right">
<bar-style>light-heavy</bar-style>
</barline>
</measure>
</part>
</score-partwise>
10 changes: 9 additions & 1 deletion mtest/musicxml/io/testSound1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@
<line>2</line>
</clef>
</attributes>
<sound tempo="60"/>
<direction placement="above">
<direction-type>
<metronome parentheses="no" print-object="no">
<beat-unit>quarter</beat-unit>
<per-minute>60</per-minute>
</metronome>
</direction-type>
<sound tempo="60"/>
</direction>
<note>
<pitch>
<step>C</step>
Expand Down
10 changes: 9 additions & 1 deletion mtest/musicxml/io/testSound2_ref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@
<line>2</line>
</clef>
</attributes>
<sound tempo="60"/>
<direction placement="above">
<direction-type>
<metronome parentheses="no" print-object="no">
<beat-unit>quarter</beat-unit>
<per-minute>60</per-minute>
</metronome>
</direction-type>
<sound tempo="60"/>
</direction>
<note>
<pitch>
<step>C</step>
Expand Down
90 changes: 81 additions & 9 deletions mtest/musicxml/io/testTempoOverlap_ref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,31 @@
<words>Direction words (empty) with sound tempo</words>
</direction-type>
</direction>
<sound tempo="81"/>
<direction placement="above">
<direction-type>
<metronome parentheses="no" print-object="no">
<beat-unit>quarter</beat-unit>
<per-minute>81</per-minute>
</metronome>
</direction-type>
<sound tempo="81"/>
</direction>
<note>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
</note>
</measure>
<measure number="9">
<sound tempo="82"/>
<direction placement="above">
<direction-type>
<metronome parentheses="no" print-object="no">
<beat-unit>quarter</beat-unit>
<per-minute>82</per-minute>
</metronome>
</direction-type>
<sound tempo="82"/>
</direction>
<note>
<rest measure="yes"/>
<duration>4</duration>
Expand All @@ -228,7 +244,15 @@
</measure>
<measure number="10">
<print new-system="yes"/>
<sound tempo="81"/>
<direction placement="above">
<direction-type>
<metronome parentheses="no" print-object="no">
<beat-unit>quarter</beat-unit>
<per-minute>81</per-minute>
</metronome>
</direction-type>
<sound tempo="81"/>
</direction>
<direction placement="above">
<direction-type>
<words>Voice</words>
Expand All @@ -246,23 +270,47 @@
</note>
</measure>
<measure number="11">
<sound tempo="82"/>
<direction placement="above">
<direction-type>
<metronome parentheses="no" print-object="no">
<beat-unit>quarter</beat-unit>
<per-minute>82</per-minute>
</metronome>
</direction-type>
<sound tempo="82"/>
</direction>
<note>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
</note>
</measure>
<measure number="12">
<sound tempo="83"/>
<direction placement="above">
<direction-type>
<metronome parentheses="no" print-object="no">
<beat-unit>quarter</beat-unit>
<per-minute>83</per-minute>
</metronome>
</direction-type>
<sound tempo="83"/>
</direction>
<note>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
</note>
</measure>
<measure number="13">
<sound tempo="84"/>
<direction placement="above">
<direction-type>
<metronome parentheses="no" print-object="no">
<beat-unit>quarter</beat-unit>
<per-minute>84</per-minute>
</metronome>
</direction-type>
<sound tempo="84"/>
</direction>
<note>
<rest measure="yes"/>
<duration>4</duration>
Expand All @@ -271,7 +319,15 @@
</measure>
<measure number="14">
<print new-system="yes"/>
<sound tempo="85"/>
<direction placement="above">
<direction-type>
<metronome parentheses="no" print-object="no">
<beat-unit>quarter</beat-unit>
<per-minute>85</per-minute>
</metronome>
</direction-type>
<sound tempo="85"/>
</direction>
<direction placement="above">
<direction-type>
<words>Voice</words>
Expand All @@ -284,15 +340,31 @@
</note>
</measure>
<measure number="15">
<sound tempo="86"/>
<direction placement="above">
<direction-type>
<metronome parentheses="no" print-object="no">
<beat-unit>quarter</beat-unit>
<per-minute>86</per-minute>
</metronome>
</direction-type>
<sound tempo="86"/>
</direction>
<note>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
</note>
</measure>
<measure number="16">
<sound tempo="87"/>
<direction placement="above">
<direction-type>
<metronome parentheses="no" print-object="no">
<beat-unit>quarter</beat-unit>
<per-minute>87</per-minute>
</metronome>
</direction-type>
<sound tempo="87"/>
</direction>
<direction placement="above">
<direction-type>
<words>Voice</words>
Expand Down
1 change: 1 addition & 0 deletions mtest/musicxml/io/tst_mxml_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ private slots:
void instrumentSound() { mxmlIoTestRef("testInstrumentSound"); }
void invalidLayout() { mxmlMscxExportTestRef("testInvalidLayout"); }
void invalidTimesig() { mxmlIoTestRef("testInvalidTimesig"); }
void invisibleDirection() { mxmlIoTest("testInvisibleDirection"); }
void invisibleElements() { mxmlIoTest("testInvisibleElements"); }
void invisibleNote() { mxmlMscxExportTestRef("testInvisibleNote"); }
void keysig1() { mxmlIoTest("testKeysig1"); }
Expand Down