Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use accidental width to space key signatures #9389

Merged
merged 3 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 36 additions & 54 deletions src/engraving/libmscore/keysig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,35 @@ qreal KeySig::mag() const
// add
//---------------------------------------------------------

void KeySig::addLayout(SymId sym, qreal x, int line)
void KeySig::addLayout(SymId sym, int line)
{
qreal stepDistance = staff() ? staff()->lineDistance(tick()) * 0.5 : 0.5;
KeySym ks;
ks.sym = sym;
ks.spos = PointF(x, qreal(line) * stepDistance);
ks.sym = sym;
qreal x = 0.0;
qreal y = qreal(line) * stepDistance;
if (_sig.keySymbols().size() > 0) {
KeySym& previous = _sig.keySymbols().back();
qreal accidentalGap = score()->styleS(Sid::keysigAccidentalDistance).val();
if (previous.sym != sym) {
accidentalGap *= 2;
} else if (previous.sym == SymId::accidentalNatural && sym == SymId::accidentalNatural) {
accidentalGap = score()->styleS(Sid::keysigNaturalDistance).val();
}
// width is divided by mag() to get the staff-scaling-independent width of the symbols
qreal previousWidth = symWidth(previous.sym) / score()->spatium() / mag();
x = previous.spos.x() + previousWidth + accidentalGap;
bool isAscending = y < previous.spos.y();
SmuflAnchorId currentCutout = isAscending ? SmuflAnchorId::cutOutSW : SmuflAnchorId::cutOutNW;
SmuflAnchorId previousCutout = isAscending ? SmuflAnchorId::cutOutNE : SmuflAnchorId::cutOutSE;
PointF cutout = symSmuflAnchor(sym, currentCutout);
qreal currentCutoutY = y * spatium() + cutout.y();
qreal previousCoutoutY = previous.spos.y() * spatium() + symSmuflAnchor(previous.sym, previousCutout).y();
if ((isAscending && currentCutoutY < previousCoutoutY) || (!isAscending && currentCutoutY > previousCoutoutY)) {
x -= cutout.x() / spatium();
}
}
ks.spos = PointF(x, y);
_sig.keySymbols().append(ks);
}

Expand Down Expand Up @@ -243,69 +266,28 @@ void KeySig::layout()

const signed char* lines = ClefInfo::lines(clef);

// add prefixed naturals, if any

qreal xo = 0.0;
if (prefixNaturals) {
for (int i = 0; i < 7; ++i) {
if (naturals & (1 << i)) {
addLayout(SymId::accidentalNatural, xo, lines[i + coffset]);
xo += 1.0;
addLayout(SymId::accidentalNatural, lines[i + coffset]);
}
}
}
// add accidentals
static const qreal sspread = 1.0;
static const qreal fspread = 1.0;

switch (t1) {
case 7: addLayout(SymId::accidentalSharp, xo + 6.0 * sspread, lines[6]);
// fall through
case 6: addLayout(SymId::accidentalSharp, xo + 5.0 * sspread, lines[5]);
// fall through
case 5: addLayout(SymId::accidentalSharp, xo + 4.0 * sspread, lines[4]);
// fall through
case 4: addLayout(SymId::accidentalSharp, xo + 3.0 * sspread, lines[3]);
// fall through
case 3: addLayout(SymId::accidentalSharp, xo + 2.0 * sspread, lines[2]);
// fall through
case 2: addLayout(SymId::accidentalSharp, xo + 1.0 * sspread, lines[1]);
// fall through
case 1: addLayout(SymId::accidentalSharp, xo, lines[0]);
break;
case -7: addLayout(SymId::accidentalFlat, xo + 6.0 * fspread, lines[13]);
// fall through
case -6: addLayout(SymId::accidentalFlat, xo + 5.0 * fspread, lines[12]);
// fall through
case -5: addLayout(SymId::accidentalFlat, xo + 4.0 * fspread, lines[11]);
// fall through
case -4: addLayout(SymId::accidentalFlat, xo + 3.0 * fspread, lines[10]);
// fall through
case -3: addLayout(SymId::accidentalFlat, xo + 2.0 * fspread, lines[9]);
// fall through
case -2: addLayout(SymId::accidentalFlat, xo + 1.0 * fspread, lines[8]);
// fall through
case -1: addLayout(SymId::accidentalFlat, xo, lines[7]);
case 0:
break;
default:
if (abs(t1) <= 7) {
SymId symbol = t1 > 0 ? SymId::accidentalSharp : SymId::accidentalFlat;
int lineIndexOffset = t1 > 0 ? 0 : 7;
for (int i = 0; i < abs(t1); ++i) {
addLayout(symbol, lines[lineIndexOffset + i]);
}
} else {
qDebug("illegal t1 key %d", t1);
break;
}

// add suffixed naturals, if any
if (suffixNaturals) {
xo += qAbs(t1); // skip accidentals
if (t1 > 0) { // after sharps, add a little more space
xo += 0.15;
// if last sharp (t1) is above next natural (t1+1)...
if (lines[t1] < lines[t1 + 1]) {
xo += 0.2; // ... add more space
}
}
for (int i = 0; i < 7; ++i) {
if (naturals & (1 << i)) {
addLayout(SymId::accidentalNatural, xo, lines[i + coffset]);
xo += 1.0;
addLayout(SymId::accidentalNatural, lines[i + coffset]);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/libmscore/keysig.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class KeySig final : public EngravingItem
KeySig(Segment* = 0);
KeySig(const KeySig&);

void addLayout(SymId sym, qreal x, int y);
void addLayout(SymId sym, int y);

public:

Expand Down
2 changes: 2 additions & 0 deletions src/engraving/style/styledef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ const std::array<StyleDef::StyleValue, size_t(Sid::STYLES)> StyleDef::styleValue
{ Sid::accidentalNoteDistance, "accidentalNoteDistance", Spatium(0.25) },
{ Sid::bracketedAccidentalPadding, "bracketedAccidentalPadding", Spatium(0.175) }, // Padding inside parentheses for bracketed accidentals
{ Sid::alignAccidentalsLeft, "alignAccidentalsLeft", false }, // When laid out in columns, whether accidentals align left or right. Musescore <= 3.5 uses left alignment.
{ Sid::keysigAccidentalDistance, "keysigAccidentalDistance", Spatium(0.3) },
{ Sid::keysigNaturalDistance, "keysigNaturalDistance", Spatium(0.4) },

{ Sid::beamWidth, "beamWidth", Spatium(0.5) }, // was 0.48
{ Sid::beamDistance, "beamDistance", PropertyValue(0.5) },
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/style/styledef.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ enum class Sid {
accidentalNoteDistance,
bracketedAccidentalPadding,
alignAccidentalsLeft,
keysigAccidentalDistance,
keysigNaturalDistance,
beamWidth,
beamDistance,
beamMinLen,
Expand Down