Skip to content

Commit

Permalink
allow key signatures to use accidental cutouts
Browse files Browse the repository at this point in the history
fix codestyle

refactor for codestyle
  • Loading branch information
Nick-Mazuk committed Nov 30, 2021
1 parent 7ca796b commit 8bae5cd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 52 deletions.
82 changes: 31 additions & 51 deletions src/engraving/libmscore/keysig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,30 @@ 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();
// 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, isAscending ? SmuflAnchorId::cutOutSW : SmuflAnchorId::cutOutNW);
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,66 +261,28 @@ void KeySig::layout()

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

// add prefixed naturals, if any
qreal accidentalGap = score()->styleS(Sid::accidentalDistance).val();
// width is divided by mag() to get the staff-scaling-independent width of the symbols
qreal sharpWidth = symWidth(SymId::accidentalSharp) / score()->spatium() / mag() + accidentalGap;
qreal flatWidth = symWidth(SymId::accidentalFlat) / score()->spatium() / mag() + accidentalGap;
qreal naturalWidth = symWidth(SymId::accidentalNatural) / score()->spatium() / mag() + accidentalGap;

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 += naturalWidth;
addLayout(SymId::accidentalNatural, lines[i + coffset]);
}
}
}
// add accidentals

switch (t1) {
case 7: addLayout(SymId::accidentalSharp, xo + 6.0 * sharpWidth, lines[6]);
// fall through
case 6: addLayout(SymId::accidentalSharp, xo + 5.0 * sharpWidth, lines[5]);
// fall through
case 5: addLayout(SymId::accidentalSharp, xo + 4.0 * sharpWidth, lines[4]);
// fall through
case 4: addLayout(SymId::accidentalSharp, xo + 3.0 * sharpWidth, lines[3]);
// fall through
case 3: addLayout(SymId::accidentalSharp, xo + 2.0 * sharpWidth, lines[2]);
// fall through
case 2: addLayout(SymId::accidentalSharp, xo + 1.0 * sharpWidth, lines[1]);
// fall through
case 1: addLayout(SymId::accidentalSharp, xo, lines[0]);
break;
case -7: addLayout(SymId::accidentalFlat, xo + 6.0 * flatWidth, lines[13]);
// fall through
case -6: addLayout(SymId::accidentalFlat, xo + 5.0 * flatWidth, lines[12]);
// fall through
case -5: addLayout(SymId::accidentalFlat, xo + 4.0 * flatWidth, lines[11]);
// fall through
case -4: addLayout(SymId::accidentalFlat, xo + 3.0 * flatWidth, lines[10]);
// fall through
case -3: addLayout(SymId::accidentalFlat, xo + 2.0 * flatWidth, lines[9]);
// fall through
case -2: addLayout(SymId::accidentalFlat, xo + 1.0 * flatWidth, 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) {
qreal accidentalWidth = (t1 > 0 ? sharpWidth : flatWidth);
xo += qAbs(t1) * accidentalWidth; // skip accidentals
for (int i = 0; i < 7; ++i) {
if (naturals & (1 << i)) {
addLayout(SymId::accidentalNatural, xo, lines[i + coffset]);
xo += naturalWidth;
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
1 change: 1 addition & 0 deletions src/engraving/style/styledef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ 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.22) },

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

0 comments on commit 8bae5cd

Please sign in to comment.