Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
miiizen committed Aug 8, 2024
1 parent 8182c47 commit 211c648
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 26 deletions.
5 changes: 5 additions & 0 deletions src/engraving/dom/stem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ void Stem::setBaseLength(Millimetre baseLength)
m_baseLength = Millimetre(std::abs(baseLength.val()));
}

double Stem::lineWidthMag() const
{
return absoluteFromSpatium(m_lineWidth) * chord()->intrinsicMag();
}

void Stem::spatiumChanged(double oldValue, double newValue)
{
m_userLength = (m_userLength / oldValue) * newValue;
Expand Down
5 changes: 1 addition & 4 deletions src/engraving/dom/stem.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#define MU_ENGRAVING_STEM_H

#include "engravingitem.h"
#include "score.h"

namespace mu::engraving {
class Chord;
Expand Down Expand Up @@ -68,10 +67,8 @@ class Stem final : public EngravingItem
Millimetre userLength() const { return m_userLength; }
void setUserLength(Millimetre userLength) { m_userLength = userLength; }

double absoluteFromSpatium(const Spatium& sp) const override { return sp.val() * score()->style().spatium(); }

Spatium lineWidth() const { return m_lineWidth; }
double lineWidthMag() const { return absoluteFromSpatium(m_lineWidth) * mag(); }
double lineWidthMag() const;
void setLineWidth(Spatium lineWidth) { m_lineWidth = lineWidth; }

PointF flagPosition() const;
Expand Down
3 changes: 0 additions & 3 deletions src/engraving/dom/tuplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

#include "durationelement.h"
#include "property.h"
#include "score.h"
#include "types.h"

namespace mu::engraving {
Expand Down Expand Up @@ -88,8 +87,6 @@ class Tuplet final : public DurationElement
Spatium bracketWidth() const { return m_bracketWidth; }
void setBracketWidth(Spatium s) { m_bracketWidth = s; }

double absoluteFromSpatium(const Spatium& sp) const override { return sp.val() * score()->style().spatium(); }

const Fraction& ratio() const { return m_ratio; }
void setRatio(const Fraction& r) { m_ratio = r; }

Expand Down
2 changes: 1 addition & 1 deletion src/engraving/rendering/dev/beamtremololayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,7 @@ double BeamTremoloLayout::chordBeamAnchorX(const BeamBase::LayoutData* ldata, co
const Chord* chord = toChord(cr);
const Stem* stem = chord->stem();

double stemWidth = stem->absoluteFromSpatium(stem->lineWidth()) * chord->mag();
double stemWidth = stem->lineWidthMag();

switch (anchorType) {
case ChordBeamAnchorType::Start:
Expand Down
13 changes: 6 additions & 7 deletions src/engraving/rendering/dev/chordlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,7 @@ void ChordLayout::layoutChords1(LayoutContext& ctx, Segment* segment, staff_idx_
// align stems if present
if (topDownNote->chord()->stem() && bottomUpNote->chord()->stem()) {
const Stem* topDownStem = topDownNote->chord()->stem();
downOffset -= topDownStem->absoluteFromSpatium(topDownStem->lineWidth());
downOffset -= topDownStem->lineWidthMag();
} else if (topDownNote->chord()->durationType().headType() != NoteHeadType::HEAD_BREVIS
&& bottomUpNote->chord()->durationType().headType() != NoteHeadType::HEAD_BREVIS) {
// stemless notes should be aligned as is they were stemmed
Expand Down Expand Up @@ -1950,19 +1950,18 @@ void ChordLayout::layoutChords1(LayoutContext& ctx, Segment* segment, staff_idx_
if (const Stem* topDownStem = topDownNote->chord()->stem()) {
if (ledgerOverlapBelow) {
// Create space between stem and ledger line below staff
clearLeft += ledgerLen + ledgerGap + topDownStem->absoluteFromSpatium(topDownStem->lineWidth());
clearLeft += ledgerLen + ledgerGap + topDownStem->lineWidthMag();
} else {
clearLeft += topDownStem->absoluteFromSpatium(topDownStem->lineWidth()) + overlapPadding;
clearLeft += topDownStem->lineWidthMag() + overlapPadding;
}
}
if (const Stem* bottomUpStem = bottomUpNote->chord()->stem()) {
if (ledgerOverlapAbove) {
// Create space between stem and ledger line above staff
clearRight += maxDownWidth + ledgerLen + ledgerGap - maxUpWidth
+ bottomUpStem->absoluteFromSpatium(bottomUpStem->lineWidth());
+ bottomUpStem->lineWidthMag();
} else {
clearRight += bottomUpStem->absoluteFromSpatium(bottomUpStem->lineWidth())
+ std::max(maxDownWidth - maxUpWidth, 0.0) + overlapPadding;
clearRight += bottomUpStem->lineWidthMag() + std::max(maxDownWidth - maxUpWidth, 0.0) + overlapPadding;
}
} else {
downDots = 0; // no need to adjust for dots in this case
Expand Down Expand Up @@ -2485,7 +2484,7 @@ void ChordLayout::layoutChords3(const std::vector<Chord*>& chords,
double overlapMirror;
Stem* stem = chord->stem();
if (stem) {
overlapMirror = stem->absoluteFromSpatium(stem->lineWidth()) * chord->mag();
overlapMirror = stem->lineWidthMag();
} else if (chord->durationType().headType() == NoteHeadType::HEAD_WHOLE) {
overlapMirror = style.styleMM(Sid::stemWidth) * chord->mag();
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/rendering/dev/tdraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3163,7 +3163,7 @@ void TDraw::draw(const Tuplet* item, Painter* painter)
painter->translate(-pos);
}
if (item->hasBracket()) {
Pen pen(color, item->absoluteFromSpatium(item->bracketWidth()) * item->mag());
Pen pen(color, item->absoluteFromSpatium(item->bracketWidth()));
pen.setJoinStyle(PenJoinStyle::MiterJoin);
pen.setCapStyle(PenCapStyle::FlatCap);
painter->setPen(pen);
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/rendering/stable/beamtremololayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ double BeamTremoloLayout::chordBeamAnchorX(const BeamBase::LayoutData* ldata, co
const Chord* chord = toChord(cr);
const Stem* stem = chord->stem();

double stemWidth = stem->absoluteFromSpatium(stem->lineWidth()) * chord->mag();
double stemWidth = stem->lineWidthMag();

switch (anchorType) {
case ChordBeamAnchorType::Start:
Expand Down
14 changes: 6 additions & 8 deletions src/engraving/rendering/stable/chordlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1673,7 +1673,7 @@ void ChordLayout::layoutChords1(LayoutContext& ctx, Segment* segment, staff_idx_
// align stems if present
if (topDownNote->chord()->stem() && bottomUpNote->chord()->stem()) {
const Stem* topDownStem = topDownNote->chord()->stem();
downOffset -= topDownStem->absoluteFromSpatium(topDownStem->lineWidth());
downOffset -= topDownStem->lineWidthMag();
} else if (topDownNote->chord()->durationType().headType() != NoteHeadType::HEAD_BREVIS
&& bottomUpNote->chord()->durationType().headType() != NoteHeadType::HEAD_BREVIS) {
// stemless notes should be aligned as is they were stemmed
Expand Down Expand Up @@ -1877,19 +1877,17 @@ void ChordLayout::layoutChords1(LayoutContext& ctx, Segment* segment, staff_idx_
if (const Stem* topDownStem = topDownNote->chord()->stem()) {
if (ledgerOverlapBelow) {
// Create space between stem and ledger line below staff
clearLeft = ledgerLen + ledgerGap + topDownStem->absoluteFromSpatium(topDownStem->lineWidth());
clearLeft = ledgerLen + ledgerGap + topDownStem->lineWidthMag();
} else {
clearLeft = topDownStem->absoluteFromSpatium(topDownStem->lineWidth()) + 0.3 * sp;
clearLeft = topDownStem->lineWidthMag() + 0.3 * sp;
}
}
if (const Stem* bottomUpStem = bottomUpNote->chord()->stem()) {
if (ledgerOverlapAbove) {
// Create space between stem and ledger line above staff
clearRight = maxDownWidth + ledgerLen + ledgerGap - maxUpWidth + bottomUpStem->absoluteFromSpatium(
bottomUpStem->lineWidth());
clearRight = maxDownWidth + ledgerLen + ledgerGap - maxUpWidth + bottomUpStem->lineWidthMag();
} else {
clearRight = bottomUpStem->absoluteFromSpatium(bottomUpStem->lineWidth())
+ std::max(maxDownWidth - maxUpWidth, 0.0) + 0.3 * sp;
clearRight = bottomUpStem->lineWidthMag() + std::max(maxDownWidth - maxUpWidth, 0.0) + 0.3 * sp;
}
} else {
downDots = 0; // no need to adjust for dots in this case
Expand Down Expand Up @@ -2468,7 +2466,7 @@ void ChordLayout::layoutChords3(const MStyle& style, const std::vector<Chord*>&
double overlapMirror;
Stem* stem = chord->stem();
if (stem) {
overlapMirror = stem->absoluteFromSpatium(stem->lineWidth()) * chord->mag();
overlapMirror = stem->lineWidthMag();
} else if (chord->durationType().headType() == NoteHeadType::HEAD_WHOLE) {
overlapMirror = style.styleMM(Sid::stemWidth) * chord->mag();
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/rendering/stable/tdraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3063,7 +3063,7 @@ void TDraw::draw(const Tuplet* item, Painter* painter)
painter->translate(-pos);
}
if (item->hasBracket()) {
Pen pen(color, item->absoluteFromSpatium(item->bracketWidth()) * item->mag());
Pen pen(color, item->absoluteFromSpatium(item->bracketWidth()));
pen.setJoinStyle(PenJoinStyle::MiterJoin);
pen.setCapStyle(PenCapStyle::FlatCap);
painter->setPen(pen);
Expand Down

0 comments on commit 211c648

Please sign in to comment.