Skip to content

Commit

Permalink
Add support for the sostenuto pedal signs to MusicXML import/export
Browse files Browse the repository at this point in the history
Backport of (the MusicXML part of) musescore#20219
  • Loading branch information
rettinghaus authored and Jojo-Schmitz committed Dec 4, 2023
1 parent 37908e0 commit a6cba54
Show file tree
Hide file tree
Showing 8 changed files with 1,655 additions and 943 deletions.
10 changes: 6 additions & 4 deletions importexport/musicxml/exportxml.cpp
Expand Up @@ -4774,15 +4774,16 @@ void ExportMusicXml::pedal(Pedal const* const pd, int staff, const Fraction& tic
break;
case HookType::NONE:
if (pd->beginText() == "") {
pedalType = "resume";
pedalType = pd->lineVisible() ? "resume" : "start";
break;
}
// FALLTHROUGH
default:
pedalType = "start";
}
signText = pd->beginText() == "" ? " sign=\"no\"" : " sign=\"yes\"";
signText += color2xml(pd);
signText = pd->beginText().isEmpty() ? " sign=\"no\"" : " sign=\"yes\"";
if (pd->beginText() == "<sym>keyboardPedalSost</sym>" || pd->beginText() == "<sym>keyboardPedalS</sym>")
pedalType = "sostenuto";
}
else {
if (!pd->endText().isEmpty() || pd->endHookType() == HookType::HOOK_90)
Expand All @@ -4791,11 +4792,12 @@ void ExportMusicXml::pedal(Pedal const* const pd, int staff, const Fraction& tic
pedalType = "discontinue";
// "change" type is handled only on the beginning of pedal lines

signText = pd->endText() == "" ? " sign=\"no\"" : " sign=\"yes\"";
signText = pd->endText().isEmpty() ? " sign=\"no\"" : " sign=\"yes\"";
}
QString pedalXml = QString("pedal type=\"%1\"").arg(pedalType);
pedalXml += lineText;
pedalXml += signText;
pedalXml += color2xml(pd);
pedalXml += positioningAttributes(pd, pd->tick() == tick);
_xml.tagE(pedalXml);
_xml.etag();
Expand Down
15 changes: 13 additions & 2 deletions importexport/musicxml/importmxmlpass2.cpp
Expand Up @@ -4150,7 +4150,7 @@ void MusicXMLParserDirection::pedal(const QString& type, const int /* number */,
sign = "no"; // MusicXML 2.0 compatibility
}
auto& spdesc = _pass2.getSpanner({ ElementType::PEDAL, number });
if (type == "start" || type == "resume") {
if (type == "start" || type == "resume" || type == "sostenuto") {
if (spdesc._isStarted && !spdesc._isStopped) {
// Previous pedal unterminated—likely an unrecorded "discontinue", so delete the line.
// TODO: if "change", create 0-length spanner rather than delete
Expand All @@ -4165,9 +4165,16 @@ void MusicXMLParserDirection::pedal(const QString& type, const int /* number */,
if (!p->lineVisible() || sign == "yes") {
p->setBeginText("<sym>keyboardPedalPed</sym>");
p->setContinueText("(<sym>keyboardPedalPed</sym>)");
if (type == "sostenuto") {
p->setBeginText("<sym>keyboardPedalSost</sym>");
p->setContinueText("(<sym>keyboardPedalSost</sym>)");
}
}
else
else {
p->setBeginText("");
p->setContinueText("");
p->setBeginHookType(type == "resume" ? HookType::NONE : HookType::HOOK_90);
}
p->setEndHookType(HookType::NONE);

if (color.isValid()/* && preferences.getBool(PREF_IMPORT_MUSICXML_IMPORTLAYOUT)*/)
Expand Down Expand Up @@ -4212,6 +4219,10 @@ void MusicXMLParserDirection::pedal(const QString& type, const int /* number */,

if (color.isValid()/* && preferences.getBool(PREF_IMPORT_MUSICXML_IMPORTLAYOUT)*/)
p->setLineColor(color);
if (sign == "no") {
p->setBeginText("");
p->setContinueText("");
}
starts.append(MusicXmlSpannerDesc(p, ElementType::PEDAL, number));
}
else if (type == "continue") {
Expand Down
4 changes: 2 additions & 2 deletions mtest/musicxml/io/testColorExport_ref.xml
Expand Up @@ -261,7 +261,7 @@
</note>
<direction placement="below">
<direction-type>
<pedal type="stop" line="yes" sign="no"/>
<pedal type="stop" line="yes" sign="no" color="#FF85FF"/>
</direction-type>
</direction>
<barline location="right">
Expand Down Expand Up @@ -421,7 +421,7 @@
</note>
<direction placement="below">
<direction-type>
<pedal type="stop" line="yes" sign="no"/>
<pedal type="stop" line="yes" sign="no" color="#0433FF"/>
</direction-type>
</direction>
<barline location="right">
Expand Down
4 changes: 2 additions & 2 deletions mtest/musicxml/io/testDirections1.xml
Expand Up @@ -102,7 +102,7 @@
<measure number="2">
<direction placement="above">
<direction-type>
<pedal type="start"/>
<pedal type="start" line="no" sign="yes"/>
</direction-type>
</direction>
<note>
Expand Down Expand Up @@ -132,7 +132,7 @@
</note>
<direction placement="below">
<direction-type>
<pedal type="start"/>
<pedal type="start" line="no" sign="yes"/>
</direction-type>
</direction>
<note>
Expand Down

0 comments on commit a6cba54

Please sign in to comment.