Skip to content

Commit

Permalink
Fix MS #314800 Add Ledger Lines to Key Signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
sammik committed May 1, 2022
1 parent a623af3 commit 4ce902c
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/engraving/libmscore/keysig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void KeySig::layout()
accIdx = flat ? 13 - accIdx : accIdx;
int line = ClefInfo::lines(clef)[accIdx] + cd.octAlt * 7;
double xpos = _sig.keySymbols().size() * _sig.xstep() + cd.xAlt;
// if translated symbol if out of range, add key accidental followed by untranslated symbol
// if translated symbol is out of range, add key accidental followed by untranslated symbol
if (sym == SymId::noSym) {
KeySym ks;
ks.line = line;
Expand Down Expand Up @@ -369,10 +369,26 @@ void KeySig::draw(mu::draw::Painter* painter) const
painter->setPen(curColor());
qreal _spatium = spatium();
qreal step = _spatium * (staff() ? staff()->staffTypeForElement(this)->lineDistance().val() * 0.5 : 0.5);
qreal accidentalGap = score()->styleS(Sid::keysigAccidentalDistance).val();
int lines = staff() ? staff()->staffTypeForElement(this)->lines() : 5;
for (const KeySym& ks: _sig.keySymbols()) {
qreal x = ks.xPos * _spatium;
qreal y = ks.line * step;
drawSymbol(ks.sym, painter, PointF(x, y));
// draw ledger lines
qreal _symWidth = symWidth(ks.sym);
SymId ledgerLine = _symWidth < 30 ? SymId::legerLine : SymId::legerLineWide;
qreal _ledgerWidth = symWidth(ledgerLine);
x -= ((_ledgerWidth - _symWidth) / 2 - accidentalGap * _spatium);
int i = static_cast<int>(ks.line * 0.5);
while (i < 0) { // above staff
drawSymbol(ledgerLine, painter, PointF(x, (i * 2 * step)));
++i;
}
while (i >= lines) { // below staff
drawSymbol(ledgerLine, painter, PointF(x, (i * 2 * step)));
--i;
}
}
if (!explicitParent() && (isAtonal() || isCustom()) && _sig.keySymbols().empty()) {
// empty custom or atonal key signature - draw something for palette
Expand Down

0 comments on commit 4ce902c

Please sign in to comment.