Skip to content

Commit

Permalink
Merge pull request #9237 from cbjeukendrup/stemlength
Browse files Browse the repository at this point in the history
Fix #8952: Simplify/unify stem layout code and let it take SMuFL anchors of flag into account
  • Loading branch information
RomanPudashkin committed Sep 24, 2021
2 parents 9e741b1 + 3935642 commit 96a916e
Show file tree
Hide file tree
Showing 15 changed files with 282 additions and 457 deletions.
2 changes: 1 addition & 1 deletion src/engraving/layout/layoutchords.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ void LayoutChords::layoutChords3(const MStyle& style, std::vector<Note*>& notes,
if (chord->stem()) {
chord->stem()->layout();
if (chord->hook()) {
chord->hook()->rypos() = chord->stem()->hookPos().y();
chord->hook()->rypos() = chord->stem()->flagPosition().y();
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/engraving/layout/layoutmeasure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,14 +705,14 @@ void LayoutMeasure::getNextMeasure(const LayoutOptions& options, LayoutContext&
if (drumset) {
layoutDrumsetChord(c, drumset, st, score->spatium());
}
c->layoutStem1();
c->layoutStem();
}
if (drumset) {
layoutDrumsetChord(chord, drumset, st, score->spatium());
}
chord->computeUp();
chord->layoutStem1(); // create stems needed to calculate spacing
// stem direction can change later during beam processing
chord->layoutStem(); // create stems needed to calculate spacing
// stem direction can change later during beam processing

// if there is a two-note tremolo attached, and it is too steep,
// extend stem of one of the chords (if not cross-staff)
Expand All @@ -726,8 +726,8 @@ void LayoutMeasure::getNextMeasure(const LayoutOptions& options, LayoutContext&
chord->tremolo(),
stem1->p2().y(),
stem2->p2().y());
stem1->setLen(extendedLen.first);
stem2->setLen(extendedLen.second);
stem1->setBaseLength(extendedLen.first);
stem2->setBaseLength(extendedLen.second);
}
}
}
Expand Down
40 changes: 21 additions & 19 deletions src/engraving/libmscore/beam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,9 @@ void Beam::layout1()
}
for (ChordRest* cr : qAsConst(_elements)) {
cr->setUp(_up);
cr->layoutStem1();
if (cr->isChord()) {
toChord(cr)->layoutStem();
}
}
} else {
//PITCHED STAVES (and TAB's with stems through staves)
Expand Down Expand Up @@ -470,7 +472,9 @@ void Beam::layout1()
if (!_cross || !staffMove) {
if (cr->up() != _up) {
cr->setUp(_up);
cr->layoutStem1();
if (cr->isChord()) {
toChord(cr)->layoutStem();
}
}
}
}
Expand Down Expand Up @@ -542,7 +546,7 @@ void Beam::layoutGraceNotes()
for (ChordRest* cr : qAsConst(_elements)) {
cr->setUp(_up);
if (cr->isChord()) {
toChord(cr)->layoutStem1(); /* create stems needed to calculate horizontal spacing */
toChord(cr)->layoutStem(); /* create stems needed to calculate horizontal spacing */
}
}
}
Expand Down Expand Up @@ -1872,29 +1876,32 @@ void Beam::layout2(std::vector<ChordRest*> crl, SpannerSegmentType, int frag)
}
}

qreal stemWidth = (cr1->isChord() && toChord(cr1)->stem()) ? toChord(cr1)->stem()->lineWidthMag() : 0.0;
qreal x2 = cr1->stemPosX() + cr1->pageX() - _pagePos.x();
qreal stemWidth = (cr1->isChord() && toChord(cr1)->stem()) ? toChord(cr1)->stem()->lineWidthMag() : 0.0;
qreal x2 = cr1->stemPosX() + cr1->pageX() - _pagePos.x();
qreal x3;

if ((chordRestEndGroupIndex - currentChordRestIndex) > 1) {
ChordRest* chordRest2 = crl[chordRestEndGroupIndex - 1];
// create segment
x3 = chordRest2->stemPosX() + chordRest2->pageX() - _pagePos.x();

qreal stemWidth2
= (chordRest2->isChord() && toChord(chordRest2)->stem()) ? toChord(chordRest2)->stem()->lineWidthMag() : 0.0;

if (tab) {
x2 -= stemWidth * 0.5;
x3 += stemWidth * 0.5;
x3 += stemWidth2 * 0.5;
} else {
if (cr1->up()) {
x2 -= stemWidth;
}
if (!chordRest2->up()) {
x3 += (chordRest2->isChord() && toChord(chordRest2)->stem()) ? toChord(chordRest2)->stem()->lineWidthMag() : 0.0;
x3 += stemWidth2;
}
}
} else {
// create broken segment
if (cr1->type() == ElementType::REST) {
if (cr1->isRest()) {
continue;
}

Expand Down Expand Up @@ -2040,9 +2047,9 @@ void Beam::layout2(std::vector<ChordRest*> crl, SpannerSegmentType, int frag)
}

PointF stemPos(c->stemPosX() + c->pagePos().x(), c->stemPos().y());
qreal x2 = stemPos.x() - _pagePos.x();
qreal y1 = (x2 - x1) * slope + py1 + _pagePos.y();
qreal y2 = stemPos.y();
qreal x2 = stemPos.x() - _pagePos.x();
qreal y1 = (x2 - x1) * slope + py1 + _pagePos.y();
qreal y2 = stemPos.y();
// qreal fuzz = _spatium * .1;
qreal fuzz = _spatium * .4; // something is wrong

Expand All @@ -2066,14 +2073,9 @@ void Beam::layout2(std::vector<ChordRest*> crl, SpannerSegmentType, int frag)

Stem* stem = c->stem();
if (stem) {
bool useTablature = staff() && staff()->isTabStaff(cr->tick());
qreal sw2 = useTablature ? 0.f : stem->lineWidthMag() * .5;
if (c->up()) {
sw2 = -sw2;
}
stem->rxpos() = c->stemPosX() + sw2;
qreal l = y2 - (by + _pagePos.y());
stem->setLen(l);
stem->rxpos() = c->stemPosX();
qreal l = y2 - (by + _pagePos.y());
stem->setBaseLength(l);

StemSlash* stemSlash = c->stemSlash();
if (stemSlash) {
Expand Down

0 comments on commit 96a916e

Please sign in to comment.