Skip to content

Commit

Permalink
Merge pull request #4344 from dmitrio95/278770-fileformat
Browse files Browse the repository at this point in the history
fix #278770: score writing issues
  • Loading branch information
anatoly-os committed Dec 10, 2018
2 parents fc70693 + 38bb6ad commit 4661bf4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
25 changes: 20 additions & 5 deletions libmscore/scoreElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,18 +604,33 @@ void LinkedElements::setLid(Score* score, int id)

//---------------------------------------------------------
// mainElement
// Returns "main" linked element which is expected to
// be written to the file prior to others.
//---------------------------------------------------------

ScoreElement* LinkedElements::mainElement()
{
if (isEmpty())
return nullptr;
MasterScore* ms = at(0)->masterScore();
for (ScoreElement* se : *this) {
if (se->score() == ms)
return se;
}
return front();
const bool elements = at(0)->isElement();
return *std::min_element(begin(), end(), [ms, elements](ScoreElement* s1, ScoreElement* s2) {
if (s1->score() == ms && s2->score() != ms)
return true;
if (elements) {
if (s1->score() != s2->score())
return false;
// Now we compare either two elements from master score
// or two elements from excerpt.
Element* e1 = toElement(s1);
Element* e2 = toElement(s2);
if (e1->track() < e2->track())
return true;
if (e1->track() == e2->track() && e1->tick() < e2->tick())
return true;
}
return false;
});
}

//---------------------------------------------------------
Expand Down
20 changes: 4 additions & 16 deletions libmscore/spanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SpannerWriter : public ConnectorInfoWriter {
public:
SpannerWriter(XmlWriter& xml, const Element* current, const Spanner* spanner, int track, Fraction frac, bool start);

static void fillSpannerPosition(Location& l, const Element* endpoint, int tick, bool clipboardmode);
static void fillSpannerPosition(Location& l, const MeasureBase* endpoint, int tick, bool clipboardmode);
};

//---------------------------------------------------------
Expand Down Expand Up @@ -1219,31 +1219,19 @@ void Spanner::readSpanner(XmlReader& e, Score* current, int track)
// SpannerWriter::fillSpannerPosition
//---------------------------------------------------------

void SpannerWriter::fillSpannerPosition(Location& l, const Element* endpoint, int tick, bool clipboardmode)
void SpannerWriter::fillSpannerPosition(Location& l, const MeasureBase* m, int tick, bool clipboardmode)
{
if (clipboardmode) {
l.setMeasure(0);
l.setFrac(Fraction::fromTicks(tick));
}
else {
const MeasureBase* m = toMeasureBase(endpoint->findMeasure());
if (!m) {
qWarning("fillSpannerPosition: couldn't find spanner's endpoint's measure");
l.setMeasure(0);
l.setFrac(Fraction::fromTicks(tick));
return;
}
// It may happen (hairpins!) that the spanner's end element is
// situated in the end of one measure but its end tick is in the
// beginning of the next measure. So we are to correct the found
// measure a bit.
while (tick >= m->endTick()) {
const MeasureBase* next = m->next();
if (next)
m = next;
else
break;
}
l.setMeasure(m->measureIndex());
l.setFrac(Fraction::fromTicks(tick - m->tick()));
}
Expand All @@ -1268,12 +1256,12 @@ SpannerWriter::SpannerWriter(XmlWriter& xml, const Element* current, const Spann
// elements and will try to obtain this info from the spanner itself.
if (!start) {
_prevLoc.setTrack(sp->track());
fillSpannerPosition(_prevLoc, sp->startElement(), sp->tick(), clipboardmode);
fillSpannerPosition(_prevLoc, sp->score()->tick2measure(sp->tick()), sp->tick(), clipboardmode);
}
else {
const int track2 = (sp->track2() != -1) ? sp->track2() : sp->track();
_nextLoc.setTrack(track2);
fillSpannerPosition(_nextLoc, sp->endElement(), sp->tick2(), clipboardmode);
fillSpannerPosition(_nextLoc, sp->score()->tick2measure(sp->tick2()), sp->tick2(), clipboardmode);
}
}
else {
Expand Down

0 comments on commit 4661bf4

Please sign in to comment.