Skip to content

Commit

Permalink
get segment
Browse files Browse the repository at this point in the history
  • Loading branch information
rettinghaus committed Nov 9, 2024
1 parent 4cff629 commit c5e9b58
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
57 changes: 42 additions & 15 deletions src/importexport/mei/internal/meiimporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "meiimporter.h"

#include "engraving/dom/anchors.h"
#include "engraving/dom/arpeggio.h"
#include "engraving/dom/articulation.h"
#include "engraving/dom/barline.h"
Expand Down Expand Up @@ -470,8 +471,8 @@ EngravingItem* MeiImporter::addAnnotation(const libmei::Element& meiElement, Mea

Spanner* MeiImporter::addSpanner(const libmei::Element& meiElement, Measure* measure, pugi::xml_node node)
{
ChordRest* chordRest = this->findStart(meiElement, measure);
if (!chordRest) {
Segment* segment = this->findSegment(meiElement, measure);
if (!segment) {
return nullptr;
}

Expand All @@ -480,29 +481,28 @@ Spanner* MeiImporter::addSpanner(const libmei::Element& meiElement, Measure* mea
if (meiElement.m_name == "dir") {
ElementType elementType = Convert::elementTypeForDirWithExt(meiElement);
switch (elementType) {
case (ElementType::HAIRPIN): item = Factory::createHairpin(
chordRest->segment());
case (ElementType::HAIRPIN): item = Factory::createHairpin(segment);
break;
default:
item = Factory::createTextLine(chordRest->segment());
item = Factory::createTextLine(segment);
}
} else if (meiElement.m_name == "hairpin") {
item = Factory::createHairpin(chordRest->segment());
item = Factory::createHairpin(segment);
} else if (meiElement.m_name == "octave") {
item = Factory::createOttava(chordRest->segment());
item = Factory::createOttava(segment);
} else if (meiElement.m_name == "pedal") {
item = Factory::createPedal(chordRest->segment());
item = Factory::createPedal(segment);
} else if (meiElement.m_name == "slur") {
item = Factory::createSlur(chordRest->segment());
item = Factory::createSlur(segment);
} else {
return nullptr;
}
m_uids->reg(item, meiElement.m_xmlId);

item->setTick(chordRest->tick());
item->setStartElement(chordRest);
item->setTrack(chordRest->track());
item->setTrack2(chordRest->track());
item->setTick(segment->tick());
//item->setStartElement(chordRest);
item->setTrack(segment->track());
item->setTrack2(segment->track());

m_score->addElement(item);

Expand Down Expand Up @@ -600,9 +600,9 @@ ChordRest* MeiImporter::findStart(const libmei::Element& meiElement, Measure* me
// If no @tstamp (invalid), put it on 1.0;
double tstampValue = timestampLogAtt->HasTstamp() ? timestampLogAtt->GetTstamp() : 1.0;
Fraction tstampFraction = Convert::tstampToFraction(tstampValue, measure->timesig());
int staffIdx = (staffIdentAtt->HasStaff() && staffIdentAtt->GetStaff().size() > 0) ? this->getStaffIndex(
const int staffIdx = (staffIdentAtt->HasStaff() && staffIdentAtt->GetStaff().size() > 0) ? this->getStaffIndex(
staffIdentAtt->GetStaff().at(0)) : 0;
int layer = (layerIdentAtt->HasLayer()) ? this->getVoiceIndex(staffIdx, layerIdentAtt->GetLayer()) : 0;
const int layer = (layerIdentAtt->HasLayer()) ? this->getVoiceIndex(staffIdx, layerIdentAtt->GetLayer()) : 0;

chordRest = measure->findChordRest(measure->tick() + tstampFraction, staffIdx * VOICES + layer);
if (!chordRest) {
Expand All @@ -614,6 +614,33 @@ ChordRest* MeiImporter::findStart(const libmei::Element& meiElement, Measure* me
return chordRest;
}

Segment* MeiImporter::findSegment(const libmei::Element& meiElement, Measure* measure)
{
ChordRest* chordRest = findStart(meiElement, measure);
if (!chordRest) {
const libmei::AttTimestampLog* timestampLogAtt = dynamic_cast<const libmei::AttTimestampLog*>(&meiElement);
const libmei::AttStaffIdent* staffIdentAtt = dynamic_cast<const libmei::AttStaffIdent*>(&meiElement);
const libmei::AttLayerIdent* layerIdentAtt = dynamic_cast<const libmei::AttLayerIdent*>(&meiElement);

IF_ASSERT_FAILED(timestampLogAtt && staffIdentAtt && layerIdentAtt) {
return nullptr;
}

double tstampValue = timestampLogAtt->HasTstamp() ? timestampLogAtt->GetTstamp() : 1.0;
Fraction tstampFraction = Convert::tstampToFraction(tstampValue, measure->timesig());
const int staffIdx = (staffIdentAtt->HasStaff() && staffIdentAtt->GetStaff().size() > 0) ? this->getStaffIndex(
staffIdentAtt->GetStaff().at(0)) : 0;
const int layer = (layerIdentAtt->HasLayer()) ? this->getVoiceIndex(staffIdx, layerIdentAtt->GetLayer()) : 0;

TimeTickAnchor* anchor = EditTimeTickAnchors::createTimeTickAnchor(measure, tstampFraction, staffIdx);
// Convert::logs.push_back(String("Could not find element corresponding to @tstamp '%1'").arg(timestampLogAtt->GetTstamp()));
EditTimeTickAnchors::updateLayout(measure);
return anchor->segment();
}

return chordRest->segment();
}

/**
* Look for the ChordRest for an MEI element with @endid.
* Do a lookup in the m_endIdChordRests map with the @endid value to retrieve the ChordRest to which the annotation points to.
Expand Down
1 change: 1 addition & 0 deletions src/importexport/mei/internal/meiimporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class MeiImporter
engraving::ChordRest* findEnd(pugi::xml_node controlNode, const engraving::ChordRest* startChordRest);
engraving::Note* findStartNote(const libmei::Element& meiElement);
engraving::Note* findEndNote(pugi::xml_node controlNode);
engraving::Segment* findSegment(const libmei::Element& meiElement, engraving::Measure* measure);
const std::list<engraving::ChordRest*> findPlistChordRests(pugi::xml_node controlNode);
void clearGraceNotes();
bool hasLyricsToExtend(engraving::track_idx_t track, int no);
Expand Down

0 comments on commit c5e9b58

Please sign in to comment.