Skip to content

Commit

Permalink
further improvements to accidental / ledger line avoidance
Browse files Browse the repository at this point in the history
A recent improvement to this algorithm allowed accidentals
to avoid ledger lines in a number of cases where it didn't before.
However, it was a little overly aggressive and avoided ledger lines
in a few case where it wasn't necessary.
In particular, in cases where the accidental is actually
further from the staff than thre last "left note"
(note on the left side of a downsteam)
and could potentially have been tucked in closer.

This change detects that situation -
where the bottom of an accidental above the staff
is above the top of highest extended ledger line
(above the staff; conversely for below the staff).
In these cases, we do *not* add extra horizontal space.

This fixes the slight regression a few of the vtests
after the previous improvement -
allowing the accidentals to move closer to the stem
as they wetre before that recent change.
  • Loading branch information
MarcSabatella authored and vpereverzev committed Dec 14, 2020
1 parent de79bd8 commit 01eaed2
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions libmscore/layout.cpp
Expand Up @@ -773,6 +773,7 @@ static QPair<qreal, qreal> layoutAccidental(AcEl* me, AcEl* above, AcEl* below,

// extra space for ledger lines
qreal ledgerAdjust = 0.0;
qreal ledgerVerticalClear = 0.0;
bool ledgerAbove = chord->upNote()->line() <= -2;
bool ledgerBelow = chord->downNote()->line() >= staff->lines(tick) * 2;
if (ledgerAbove || ledgerBelow) {
Expand All @@ -783,6 +784,7 @@ static QPair<qreal, qreal> layoutAccidental(AcEl* me, AcEl* above, AcEl* below,
qreal lds = staff->lineDistance(tick) * sp;
if ((ledgerAbove && me->top + lds <= pnd) || (ledgerBelow && staff->lines(tick) * lds - me->bottom <= pnd)) {
ledgerAdjust = -acc->score()->styleS(Sid::ledgerLineLength).val() * sp;
ledgerVerticalClear = acc->score()->styleS(Sid::ledgerLineWidth).val() * 0.5 * sp;
lx = qMin(lx, ledgerAdjust);
}
}
Expand All @@ -792,12 +794,22 @@ static QPair<qreal, qreal> layoutAccidental(AcEl* me, AcEl* above, AcEl* below,
for (int i = 0; i < lns; ++i) {
Note* ln = leftNotes[i];
int lnLine = ln->line();
qreal lnLedgerAdjust = 0.0;
if (lnLine <= -2 || lnLine >= staff->lines(tick) * 2)
lnLedgerAdjust = ledgerAdjust;
qreal lnTop = (lnLine - 1) * 0.5 * sp;
qreal lnBottom = lnTop + sp;
if (me->top - lnBottom <= pnd && lnTop - me->bottom <= pnd) {
qreal lnLedgerAdjust = 0.0;
if (lnLine <= -2 || lnLine >= staff->lines(tick) * 2) {
// left note has a ledger line we probably need to clear horizontally as well
// except for accidentals that clear the last extended ledger line vertically
// in these cases, the accidental may tuck closer
Note* lastLnNote = lnLine < 0 ? leftNotes[0] : leftNotes[lns - 1];
int lastLnLine = lastLnNote->line();
qreal ledgerY = (lastLnLine / 2) * sp;
if (me->line < 0 && ledgerY - me->bottom < ledgerVerticalClear)
lnLedgerAdjust = ledgerAdjust;
else if (me->line > 0 && me->top - ledgerY < ledgerVerticalClear)
lnLedgerAdjust = ledgerAdjust;
}
// undercut note above if possible
if (lnBottom - me->top <= me->ascent - pnd)
lx = qMin(lx, ln->x() + ln->chord()->x() + lnLedgerAdjust + me->rightClear);
Expand Down

0 comments on commit 01eaed2

Please sign in to comment.