From 211c648936778dde1e001796c6e7ba1ccf93a151 Mon Sep 17 00:00:00 2001 From: James Mizen Date: Thu, 8 Aug 2024 09:46:58 +0100 Subject: [PATCH] Review changes --- src/engraving/dom/stem.cpp | 5 +++++ src/engraving/dom/stem.h | 5 +---- src/engraving/dom/tuplet.h | 3 --- src/engraving/rendering/dev/beamtremololayout.cpp | 2 +- src/engraving/rendering/dev/chordlayout.cpp | 13 ++++++------- src/engraving/rendering/dev/tdraw.cpp | 2 +- .../rendering/stable/beamtremololayout.cpp | 2 +- src/engraving/rendering/stable/chordlayout.cpp | 14 ++++++-------- src/engraving/rendering/stable/tdraw.cpp | 2 +- 9 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/engraving/dom/stem.cpp b/src/engraving/dom/stem.cpp index ce97952e8cd14..e330ae910feb0 100644 --- a/src/engraving/dom/stem.cpp +++ b/src/engraving/dom/stem.cpp @@ -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; diff --git a/src/engraving/dom/stem.h b/src/engraving/dom/stem.h index edf3d61a1fafa..5e05000b65ba7 100644 --- a/src/engraving/dom/stem.h +++ b/src/engraving/dom/stem.h @@ -24,7 +24,6 @@ #define MU_ENGRAVING_STEM_H #include "engravingitem.h" -#include "score.h" namespace mu::engraving { class Chord; @@ -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; diff --git a/src/engraving/dom/tuplet.h b/src/engraving/dom/tuplet.h index a7cd847c5c2fa..93467ea5c2e82 100644 --- a/src/engraving/dom/tuplet.h +++ b/src/engraving/dom/tuplet.h @@ -27,7 +27,6 @@ #include "durationelement.h" #include "property.h" -#include "score.h" #include "types.h" namespace mu::engraving { @@ -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; } diff --git a/src/engraving/rendering/dev/beamtremololayout.cpp b/src/engraving/rendering/dev/beamtremololayout.cpp index ddc93d1e82141..703c8543b71cc 100644 --- a/src/engraving/rendering/dev/beamtremololayout.cpp +++ b/src/engraving/rendering/dev/beamtremololayout.cpp @@ -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: diff --git a/src/engraving/rendering/dev/chordlayout.cpp b/src/engraving/rendering/dev/chordlayout.cpp index 6f6c6bfba680b..ae8e438fe517c 100644 --- a/src/engraving/rendering/dev/chordlayout.cpp +++ b/src/engraving/rendering/dev/chordlayout.cpp @@ -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 @@ -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 @@ -2485,7 +2484,7 @@ void ChordLayout::layoutChords3(const std::vector& 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 { diff --git a/src/engraving/rendering/dev/tdraw.cpp b/src/engraving/rendering/dev/tdraw.cpp index 18656af9677bf..4423104df4c89 100644 --- a/src/engraving/rendering/dev/tdraw.cpp +++ b/src/engraving/rendering/dev/tdraw.cpp @@ -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); diff --git a/src/engraving/rendering/stable/beamtremololayout.cpp b/src/engraving/rendering/stable/beamtremololayout.cpp index acfc0b6840db1..4ee60e01ae66c 100644 --- a/src/engraving/rendering/stable/beamtremololayout.cpp +++ b/src/engraving/rendering/stable/beamtremololayout.cpp @@ -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: diff --git a/src/engraving/rendering/stable/chordlayout.cpp b/src/engraving/rendering/stable/chordlayout.cpp index 4337a394f312b..43aad6766182b 100644 --- a/src/engraving/rendering/stable/chordlayout.cpp +++ b/src/engraving/rendering/stable/chordlayout.cpp @@ -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 @@ -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 @@ -2468,7 +2466,7 @@ void ChordLayout::layoutChords3(const MStyle& style, const std::vector& 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 { diff --git a/src/engraving/rendering/stable/tdraw.cpp b/src/engraving/rendering/stable/tdraw.cpp index 383930e19f812..019a86fd0aea6 100644 --- a/src/engraving/rendering/stable/tdraw.cpp +++ b/src/engraving/rendering/stable/tdraw.cpp @@ -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);