Fix #166016: Wrong slur on grace note after

This commit is contained in:
lasconic 2018-01-12 16:03:30 +01:00
parent ec85457cc1
commit 249d1e1299
3 changed files with 34 additions and 2 deletions

View file

@ -1518,5 +1518,35 @@ void ChordRest::removeMarkings(bool /* keepTremolo */)
qDeleteAll(lyrics());
}
//---------------------------------------------------------
// isBefore
//---------------------------------------------------------
bool ChordRest::isBefore(ChordRest* o)
{
if (!o)
return true;
if (this == o)
return true;
int otick = o->tick();
int t = tick();
if (t == otick) { // At least one of the chord is a grace, order the grace notes
bool oGraceAfter = o->isGraceAfter();
bool graceAfter = isGraceAfter();
bool oGrace = o->isGrace();
bool grace = isGrace();
// normal note are initialized at graceIndex 0 and graceIndex is 0 based
int oGraceIndex = oGrace ? toChord(o)->graceIndex() + 1 : 0;
int graceIndex = grace ? toChord(this)->graceIndex() + 1 : 0;
if (oGrace)
oGraceIndex = toChord(o->parent())->graceNotes().size() - oGraceIndex;
if (grace)
graceIndex = toChord(parent())->graceNotes().size() - graceIndex;
otick = otick + (oGraceAfter ? 1 : -1) * oGraceIndex;
t = t + (graceAfter ? 1 : -1) * graceIndex;
}
return t < otick;
}
}

View file

@ -187,6 +187,8 @@ class ChordRest : public DurationElement {
bool isFullMeasureRest() const { return _durationType == TDuration::DurationType::V_MEASURE; }
virtual void removeMarkings(bool keepTremolo = false);
bool isBefore(ChordRest*);
};

View file

@ -3097,9 +3097,9 @@ void ScoreView::addSlur()
if (!e->isChordRest())
continue;
ChordRest* cr = toChordRest(e);
if (!cr1 || cr1->tick() > cr->tick())
if (!cr1 || cr->isBefore(cr1))
cr1 = cr;
if (!cr2 || cr2->tick() < cr->tick() || (cr1 && cr1->parent() == cr))
if (!cr2 || cr2->isBefore(cr))
cr2 = cr;
}
if (cr1 == cr2)