Skip to content

Commit

Permalink
Merge pull request #24438 from mike-spa/portStuff
Browse files Browse the repository at this point in the history
Port recent PRs
  • Loading branch information
RomanPudashkin authored Sep 4, 2024
2 parents 20d3734 + fb43aa1 commit d7bbd3e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 16 deletions.
7 changes: 7 additions & 0 deletions src/engraving/dom/engravingitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,13 @@ void EngravingItem::setPlacementBasedOnVoiceAssignment(DirectionV styledDirectio
startTick = tick();
length = toSpanner(this)->ticks();
} else if (const Segment* segment = toSegment(findAncestor(ElementType::SEGMENT))) {
if (segment && segment->isTimeTickType() && segment->measure() != measure) {
// Edge case: this is a TimeTick segment at the end of previous measure. Happens only
// when dynamic is anchorToEndOfPrevious. In this case look for preceding segment.
segment = segment->prev1ChordRestOrTimeTick();
assert(segment);
measure = segment->measure();
}
startTick = segment->tick();
length = segment->ticks();
} else if (measure) {
Expand Down
1 change: 1 addition & 0 deletions src/engraving/dom/stem.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class Stem final : public EngravingItem

struct LayoutData : public EngravingItem::LayoutData {
LineF line;
double beamCorrection = 0.0;
};
DECLARE_LAYOUTDATA_METHODS(Stem)

Expand Down
25 changes: 20 additions & 5 deletions src/engraving/rendering/dev/beamlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1338,22 +1338,37 @@ void BeamLayout::createBeamSegment(Beam* item, ChordRest* startCr, ChordRest* en
continue;
}

double _up = chord->up() ? -1.0 : 1.0;

if (level == 0) {
BeamTremoloLayout::extendStem(item->ldata(), chord, 0.0);
// HACK: extend the bounding box of the stem (NOT the stem itself) by half beam width.
// This way the bbox of the stem covers also the beam position. Hugely helps with all the collision checks.
chord->stem()->mutldata()->beamCorrection = _up * item->beamWidth() / 2;
} else {
int stemLengthAdjustmentSteps = computeStemLengthAdjustmentSteps(cr, cr == startCr || cr == endCr, b->above, frenchStyleBeams,
level, beamsAbove, beamsBelow);
if (stemLengthAdjustmentSteps != 0) {
bool isStartOrEnd = cr == startCr || cr == endCr;
int visualStemLengthAdjustmentSteps = computeStemLengthAdjustmentSteps(cr, isStartOrEnd, b->above, frenchStyleBeams,
level, beamsAbove, beamsBelow);
if (visualStemLengthAdjustmentSteps != 0) {
double grow = item->growLeft();
if (!muse::RealIsEqual(item->growLeft(), item->growRight())) {
double anchorX = BeamTremoloLayout::chordBeamAnchorX(item->ldata(), chord, ChordBeamAnchorType::Middle);
double proportionAlongX = (anchorX - item->startAnchor().x()) / (item->endAnchor().x() - item->startAnchor().x());
grow = proportionAlongX * (item->growRight() - item->growLeft()) + item->growLeft();
}

double stemLengthAdjustment = grow * stemLengthAdjustmentSteps * item->beamDist();
double visualStemLengthAdjustment = grow * visualStemLengthAdjustmentSteps * item->beamDist();

BeamTremoloLayout::extendStem(item->ldata(), chord, stemLengthAdjustment);
if (frenchStyleBeams) {
// Even if we visually shorten the stem, we need the 'original' length for collisions.
int bboxStemLengthAdjustmentSteps = computeStemLengthAdjustmentSteps(cr, isStartOrEnd, b->above,
/*frenchStyleBeams*/ false,
level, beamsAbove, beamsBelow);
chord->stem()->mutldata()->beamCorrection = _up * item->beamWidth() / 2 + _up * grow
* (bboxStemLengthAdjustmentSteps - visualStemLengthAdjustmentSteps)
* item->beamDist();
}
BeamTremoloLayout::extendStem(item->ldata(), chord, visualStemLengthAdjustment);
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/engraving/rendering/dev/tlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5245,11 +5245,8 @@ void TLayout::layoutStem(const Stem* item, Stem::LayoutData* ldata, const Layout
LineF line = LineF(lineX, y1, lineX, y2);
ldata->line = line;

// HACK: if there is a beam, extend the bounding box of the stem (NOT the stem itself) by half beam width.
// This way the bbox of the stem covers also the beam position. Hugely helps with all the collision checks.
double beamCorrection = (item->chord() && item->chord()->beam()) ? _up * conf.styleMM(Sid::beamWidth) * item->mag() / 2 : 0.0;
// compute line and bounding rectangle
RectF rect(line.p1(), line.p2() + PointF(0.0, beamCorrection));
RectF rect(line.p1(), line.p2() + PointF(0.0, ldata->beamCorrection));
ldata->setBbox(rect.normalized().adjusted(-lineWidthCorrection, 0, lineWidthCorrection, 0));
}

Expand Down
2 changes: 1 addition & 1 deletion src/engraving/rendering/paddingtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void PaddingTable::createTable(const MStyle& style)
table[ElementType::LEDGER_LINE][ElementType::TIMESIG]
= std::max(table[ElementType::NOTE][ElementType::TIMESIG] - ledgerLength / 2, ledgerPad);

table[ElementType::HOOK][ElementType::NOTE] = 0.5 * spatium;
table[ElementType::HOOK][ElementType::NOTE] = 0.35 * spatium;
table[ElementType::HOOK][ElementType::LEDGER_LINE]
= std::max(table[ElementType::HOOK][ElementType::NOTE] - ledgerLength, ledgerPad);
table[ElementType::HOOK][ElementType::ACCIDENTAL] = 0.35 * spatium;
Expand Down
12 changes: 6 additions & 6 deletions src/importexport/musicxml/tests/data/testLayout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@
</score-part>
</part-list>
<part id="P1">
<measure number="1" width="235.38">
<measure number="1" width="234.07">
<print>
<system-layout>
<system-margins>
<left-margin>50</left-margin>
<right-margin>743.65</right-margin>
<right-margin>744.96</right-margin>
</system-margins>
<top-system-distance>169.98</top-system-distance>
</system-layout>
Expand All @@ -110,7 +110,7 @@
<line>4</line>
</clef>
</attributes>
<note default-x="134.93" default-y="-10">
<note default-x="134.27" default-y="-10">
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
Expand Down Expand Up @@ -155,7 +155,7 @@
<stem>up</stem>
<staff>2</staff>
</note>
<note default-x="128.51" default-y="-110">
<note default-x="127.2" default-y="-110">
<pitch>
<step>G</step>
<octave>4</octave>
Expand All @@ -166,7 +166,7 @@
<stem>down</stem>
<staff>2</staff>
</note>
<note default-x="158.9" default-y="-135">
<note default-x="157.59" default-y="-135">
<pitch>
<step>B</step>
<octave>3</octave>
Expand All @@ -183,7 +183,7 @@
</direction-type>
<staff>2</staff>
</direction>
<note default-x="189.29" default-y="-125">
<note default-x="187.98" default-y="-125">
<pitch>
<step>D</step>
<octave>3</octave>
Expand Down
Binary file added vtest/scores/beams-french-style-2.mscz
Binary file not shown.

0 comments on commit d7bbd3e

Please sign in to comment.