Skip to content

Commit

Permalink
Merge pull request #20213 from rettinghaus/xml/barlinefermata
Browse files Browse the repository at this point in the history
MusicXML: add missing import for fermatas on barlines
  • Loading branch information
cbjeukendrup committed Dec 5, 2023
2 parents ec87c59 + f14db85 commit 2be126e
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 252 deletions.
80 changes: 51 additions & 29 deletions src/importexport/musicxml/internal/musicxml/importmxmlpass2.cpp
Expand Up @@ -1244,6 +1244,34 @@ static bool convertArticulationToSymId(const QString& mxmlName, SymId& id)
}
}

//---------------------------------------------------------
// convertFermataToSymId
//---------------------------------------------------------

/**
Convert a MusicXML fermata name to a MuseScore fermata.
*/

static SymId convertFermataToSymId(const QString& mxmlName)
{
QMap<QString, SymId> map; // map MusicXML fermata name to MuseScore symbol
map["normal"] = SymId::fermataAbove;
map["angled"] = SymId::fermataShortAbove;
map["square"] = SymId::fermataLongAbove;
map["double-angled"] = SymId::fermataVeryShortAbove;
map["double-square"] = SymId::fermataVeryLongAbove;
map["double-dot"] = SymId::fermataLongHenzeAbove;
map["half-curve"] = SymId::fermataShortHenzeAbove;
map["curlew"] = SymId::curlewSign;

if (map.contains(mxmlName)) {
return map.value(mxmlName);
} else {
LOGD("unknown fermata %s", qPrintable(mxmlName));
}
return SymId::fermataAbove;
}

//---------------------------------------------------------
// convertNotehead
//---------------------------------------------------------
Expand Down Expand Up @@ -3902,6 +3930,21 @@ void MusicXMLParserPass2::barline(const QString& partId, Measure* measure, const
endingColor = _e.attributes().value("color").toString();
printEnding = _e.attributes().value("print-object").toString() != "no";
endingText = _e.readElementText();
} else if (_e.name() == "fermata") {
const QColor fermataColor = _e.attributes().value("color").toString();
const QString fermataType = _e.attributes().value("type").toString();
const auto segment = measure->getSegment(SegmentType::EndBarLine, tick);
const track_idx_t track = _pass1.trackForPart(partId);
Fermata* fermata = Factory::createFermata(segment);
fermata->setSymId(convertFermataToSymId(_e.readElementText()));
fermata->setTrack(track);
segment->add(fermata);
if (fermataColor.isValid()) {
fermata->setColor(fermataColor);
}
if (fermataType == "inverted") {
fermata->setPlacement(PlacementV::BELOW);
}
} else if (_e.name() == "repeat") {
repeat = _e.attributes().value("direction").toString();
count = _e.attributes().value("times").toString();
Expand Down Expand Up @@ -7040,32 +7083,11 @@ void MusicXMLParserPass2::stem(DirectionV& sd, bool& nost)
void MusicXMLParserNotations::fermata()
{
Notation notation = Notation::notationWithAttributes(_e.name().toString(), _e.attributes(), "notations");
const auto fermataText = _e.readElementText();

if (fermataText == "normal" || fermataText == "") {
notation.setSymId(SymId::fermataAbove);
} else if (fermataText == "angled") {
notation.setSymId(SymId::fermataShortAbove);
} else if (fermataText == "square") {
notation.setSymId(SymId::fermataLongAbove);
} else if (fermataText == "double-angled") {
notation.setSymId(SymId::fermataVeryShortAbove);
} else if (fermataText == "double-square") {
notation.setSymId(SymId::fermataVeryLongAbove);
} else if (fermataText == "double-dot") {
notation.setSymId(SymId::fermataLongHenzeAbove);
} else if (fermataText == "half-curve") {
notation.setSymId(SymId::fermataShortHenzeAbove);
} else if (fermataText == "curlew") {
notation.setSymId(SymId::curlewSign);
}
const QString fermataText = _e.readElementText();

if (notation.symId() != SymId::noSym) {
notation.setText(fermataText);
_notations.push_back(notation);
} else {
_logger->logError(QString("unknown fermata '%1'").arg(fermataText), &_e);
}
notation.setSymId(convertFermataToSymId(fermataText));
notation.setText(fermataText);
_notations.push_back(notation);
}

//---------------------------------------------------------
Expand All @@ -7078,10 +7100,10 @@ void MusicXMLParserNotations::fermata()

void MusicXMLParserNotations::tuplet()
{
QString tupletType = _e.attributes().value("type").toString();
QString tupletPlacement = _e.attributes().value("placement").toString();
QString tupletBracket = _e.attributes().value("bracket").toString();
QString tupletShowNumber = _e.attributes().value("show-number").toString();
const QString tupletType = _e.attributes().value("type").toString();
const QString tupletPlacement = _e.attributes().value("placement").toString();
const QString tupletBracket = _e.attributes().value("bracket").toString();
const QString tupletShowNumber = _e.attributes().value("show-number").toString();

// ignore possible children (currently not supported)
_e.skipCurrentElement();
Expand Down
135 changes: 0 additions & 135 deletions src/importexport/musicxml/tests/data/testBarlineFermatas.mscx

This file was deleted.

126 changes: 126 additions & 0 deletions src/importexport/musicxml/tests/data/testBarlineFermatas.xml
@@ -0,0 +1,126 @@
<?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>Fermatas on barlines</work-title>
</work>
<identification>
<creator type="composer">K. Rettinghaus</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></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>42</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>C</sign>
<line>3</line>
</clef>
</attributes>
<note>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
</note>
<barline location="right">
<fermata type="upright"/>
</barline>
</measure>
<measure number="2">
<note>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
</note>
<barline location="right">
<bar-style>light-light</bar-style>
<fermata type="inverted" color="#FF2600">angled</fermata>
</barline>
</measure>
<measure number="3">
<note>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
</note>
<barline location="right">
<fermata type="upright" color="#0096FF">square</fermata>
</barline>
</measure>
<measure number="4">
<note>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
</note>
<barline location="right">
<bar-style>light-light</bar-style>
<fermata type="upright">double-dot</fermata>
<fermata type="inverted">double-dot</fermata>
</barline>
</measure>
<measure number="5">
<note>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
</note>
<barline location="right">
<fermata type="upright">half-curve</fermata>
</barline>
</measure>
<measure number="6">
<note>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
</note>
<barline location="right">
<bar-style>dashed</bar-style>
<fermata type="upright" color="#24680B">double-square</fermata>
<fermata type="inverted" color="#F0A2CC">curlew</fermata>
</barline>
</measure>
<measure number="7">
<note>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
</note>
<barline location="right">
<bar-style>light-heavy</bar-style>
<fermata type="upright">double-angled</fermata>
</barline>
</measure>
</part>
</score-partwise>

0 comments on commit 2be126e

Please sign in to comment.