Skip to content

Commit

Permalink
Merge pull request #25870 from rettinghaus/xml/trueOrnam
Browse files Browse the repository at this point in the history
[MusicXML] import ornament as ornament
  • Loading branch information
miiizen authored Jan 8, 2025
2 parents 02047c3 + f3a8bc7 commit d1860d2
Show file tree
Hide file tree
Showing 4 changed files with 733 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1261,25 +1261,53 @@ static void addMordentToChord(const Notation& notation, ChordRest* cr)
if (articSym != SymId::noSym) {
const Color color = Color::fromString(notation.attribute(u"color"));
const String place = notation.attribute(u"placement");
Articulation* na = Factory::createArticulation(cr);
na->setSymId(articSym);
Ornament* mordent = Factory::createOrnament(cr);
mordent->setSymId(articSym);
if (place == u"above") {
na->setAnchor(ArticulationAnchor::TOP);
mordent->setAnchor(ArticulationAnchor::TOP);
} else if (place == u"below") {
na->setAnchor(ArticulationAnchor::BOTTOM);
mordent->setAnchor(ArticulationAnchor::BOTTOM);
} else {
na->setAnchor(ArticulationAnchor::AUTO);
mordent->setAnchor(ArticulationAnchor::AUTO);
}
if (color.isValid()) {
na->setColor(color);
mordent->setColor(color);
}
cr->add(na);
cr->add(mordent);
} else {
LOGD("unknown ornament: name '%s' long '%s' approach '%s' departure '%s'",
muPrintable(name), muPrintable(attrLong), muPrintable(attrAppr), muPrintable(attrDep)); // TODO
}
}

//---------------------------------------------------------
// addTurnToChord
//---------------------------------------------------------

/**
Add Turn to Chord.
*/

static void addTurnToChord(const Notation& notation, ChordRest* cr)
{
const SymId turnSym = notation.symId();
const Color color = Color::fromString(notation.attribute(u"color"));
const String place = notation.attribute(u"placement");
Ornament* turn = Factory::createOrnament(cr);
turn->setSymId(turnSym);
if (place == u"above") {
turn->setAnchor(ArticulationAnchor::TOP);
} else if (place == u"below") {
turn->setAnchor(ArticulationAnchor::BOTTOM);
} else {
turn->setAnchor(ArticulationAnchor::AUTO);
}
if (color.isValid()) {
turn->setColor(color);
}
cr->add(turn);
}

//---------------------------------------------------------
// addOtherOrnamentToChord
//---------------------------------------------------------
Expand All @@ -1297,12 +1325,12 @@ static void addOtherOrnamentToChord(const Notation& notation, ChordRest* cr)

if (sym != SymId::noSym) {
const Color color = Color::fromString(notation.attribute(u"color"));
Articulation* na = Factory::createArticulation(cr);
na->setSymId(sym);
Ornament* ornam = Factory::createOrnament(cr);
ornam->setSymId(sym);
if (color.isValid()) {
na->setColor(color);
ornam->setColor(color);
}
cr->add(na);
cr->add(ornam);
} else {
LOGD("unknown ornament: name '%s': '%s'.", muPrintable(name), muPrintable(symname));
}
Expand Down Expand Up @@ -8075,7 +8103,7 @@ void MusicXmlParserNotations::ornaments()
SymId id { SymId::noSym };
if (convertArticulationToSymId(String::fromAscii(m_e.name().ascii()), id)) {
Notation notation = Notation::notationWithAttributes(String::fromAscii(m_e.name().ascii()),
m_e.attributes(), u"articulations", id);
m_e.attributes(), u"ornaments", id);
m_notations.push_back(notation);
m_e.skipCurrentElement(); // skip but don't log
} else if (m_e.name() == "trill-mark") {
Expand Down Expand Up @@ -8816,6 +8844,8 @@ void MusicXmlParserNotations::addNotation(const Notation& notation, ChordRest* c
// Terminate tempo line
const InferredTempoLineStack& lines = m_pass2.getInferredTempoLine();
terminateInferredLine(std::vector<TextLineBase*>(lines.begin(), lines.end()), cr->tick(), cr->track());
} else if (notation.parent() == u"ornaments") {
addTurnToChord(notation, cr);
} else {
addArticulationToChord(notation, cr);
}
Expand Down
Loading

0 comments on commit d1860d2

Please sign in to comment.