Skip to content

Commit

Permalink
add support for spanning trills
Browse files Browse the repository at this point in the history
  • Loading branch information
rettinghaus committed Dec 9, 2024
1 parent e089df9 commit 42786cb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
29 changes: 28 additions & 1 deletion src/importexport/mei/internal/meiexporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include "engraving/dom/text.h"
#include "engraving/dom/tie.h"
#include "engraving/dom/timesig.h"
#include "engraving/dom/trill.h"
#include "engraving/dom/tuplet.h"
#include "engraving/dom/volta.h"

Expand Down Expand Up @@ -837,6 +838,8 @@ bool MeiExporter::writeMeasure(const Measure* measure, int& measureN, bool& isFi
success = success && this->writeTempo(dynamic_cast<const TempoText*>(controlEvent.first), controlEvent.second);
} else if (controlEvent.first->isTie()) {
success = success && this->writeTie(dynamic_cast<const Tie*>(controlEvent.first), controlEvent.second);
} else if (controlEvent.first->isTrill()) {
success = success && this->writeTrill(dynamic_cast<const Trill*>(controlEvent.first), controlEvent.second);
}
}
m_startingControlEventList.clear();
Expand Down Expand Up @@ -2032,6 +2035,30 @@ bool MeiExporter::writeTie(const Tie* tie, const std::string& startid)
return true;
}

/**
* Write a trill.
*/

bool MeiExporter::writeTrill(const Trill* trill, const std::string& startid)
{
IF_ASSERT_FAILED(trill) {
return false;
}

pugi::xml_node trillNode = m_currentNode.append_child();
libmei::Trill meiTrill = Convert::trillToMEI(trill->ornament());
Convert::colorlineToMEI(trill, meiTrill);
meiTrill.SetExtender(libmei::BOOLEAN_true);
meiTrill.SetStartid(startid);

meiTrill.Write(trillNode, this->getXmlIdFor(trill, 't'));

// Add the node to the map of open control events
this->addNodeToOpenControlEvents(trillNode, trill, startid);

return true;
}

//---------------------------------------------------------
// write MEI attribute classes
//---------------------------------------------------------
Expand Down Expand Up @@ -2157,7 +2184,7 @@ void MeiExporter::fillControlEventMap(const std::string& xmlId, const ChordRest*
auto spanners = smap.findOverlapping(chordRest->tick().ticks(), chordRest->tick().ticks());
for (auto interval : spanners) {
Spanner* spanner = interval.value;
if (spanner && (spanner->isHairpin() || spanner->isOttava() || spanner->isPedal() || spanner->isSlur())) {
if (spanner && (spanner->isHairpin() || spanner->isOttava() || spanner->isPedal() || spanner->isSlur() || spanner->isTrill())) {
if (spanner->startCR() == chordRest) {
m_startingControlEventList.push_back(std::make_pair(spanner, "#" + xmlId));
} else if (spanner->endCR() == chordRest) {
Expand Down
2 changes: 2 additions & 0 deletions src/importexport/mei/internal/meiexporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Rest;
class Score;
class Staff;
class TremoloSingleChord;
class Trill;
class Tuplet;
class VBox;
}
Expand Down Expand Up @@ -143,6 +144,7 @@ class MeiExporter
bool writeSlur(const engraving::Slur* slur, const std::string& startid);
bool writeTempo(const engraving::TempoText* tempoText, const std::string& startid);
bool writeTie(const engraving::Tie* tie, const std::string& startid);
bool writeTrill(const engraving::Trill* trill, const std::string& startid);

/**
* Methods for writing specific MEI attribute classes within elements
Expand Down
17 changes: 15 additions & 2 deletions src/importexport/mei/internal/meiimporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,8 @@ Spanner* MeiImporter::addSpanner(const libmei::Element& meiElement, Measure* mea
item = Factory::createPedal(chordRest->segment());
} else if (meiElement.m_name == "slur") {
item = Factory::createSlur(chordRest->segment());
} else if (meiElement.m_name == "trill") {
item = Factory::createTrill(chordRest->segment());
} else {
return nullptr;
}
Expand Down Expand Up @@ -2885,6 +2887,17 @@ bool MeiImporter::readTrill(pugi::xml_node trillNode, Measure* measure)
return true;
}

if (meiTrill.HasEndid()) {
Trill* trill = static_cast<Trill*>(this->addSpanner(meiTrill, measure, trillNode));
if (trill) {
// move ornament to spanner
ornament->parentItem()->remove(ornament);
trill->setOrnament(ornament);
// @color
Convert::colorlineFromMEI(trill, meiTrill);
}
}

Convert::OrnamStruct ornamSt = Convert::trillFromMEI(ornament, meiTrill, warning);
this->setOrnamentAccid(ornament, ornamSt);

Expand Down Expand Up @@ -3286,10 +3299,10 @@ void MeiImporter::addSpannerEnds()
spannerMapEntry.first->setTick2(chordRest->tick());
spannerMapEntry.first->setEndElement(chordRest);
spannerMapEntry.first->setTrack2(chordRest->track());
if (spannerMapEntry.first->isOttava()) {
if (spannerMapEntry.first->isOttava() || spannerMapEntry.first->isTrill()) {
// Set the tick2 to include the duration of the ChordRest
spannerMapEntry.first->setTick2(chordRest->tick() + chordRest->ticks());
// Special handling of ottava
// Special handling of ottavas
if (spannerMapEntry.first->isOttava()) {
Ottava* ottava = toOttava(spannerMapEntry.first);
// Make the staff fill the pitch offsets accordingly since we use Note::ppitch in export
Expand Down

0 comments on commit 42786cb

Please sign in to comment.