Skip to content

Commit

Permalink
Calculate beam position with BeamLayout methods
Browse files Browse the repository at this point in the history
  • Loading branch information
miiizen committed Sep 27, 2024
1 parent 058263c commit 40fc85a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/engraving/rendering/score/chordlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1274,16 +1274,11 @@ bool ChordLayout::isChordPosBelowBeam(Chord* item, Beam* beam)

Note* baseNote = item->up() ? item->downNote() : item->upNote();
double noteY = baseNote->pagePos().y();
double noteX = item->stemPosX() + item->pagePos().x();

PointF base = beam->pagePos();
const BeamFragment* fragment = beam->beamFragments().front();
double startY = fragment->py1[beam->directionIdx()] + base.y();
double endY = fragment->py2[beam->directionIdx()] + base.y();
double startX = beam->startAnchor().x();
double endX = beam->endAnchor().x();
PointF startAnchor(startX, startY);
PointF endAnchor(endX, endY);
ChordRest* startCR = beam->elements().front();
ChordRest* endCR = beam->elements().back();
PointF startAnchor = BeamLayout::chordBeamAnchor(beam, startCR, ChordBeamAnchorType::Start);
PointF endAnchor = BeamLayout::chordBeamAnchor(beam, endCR, ChordBeamAnchorType::End);

if (item == beam->elements().front()) {
return noteY > startAnchor.y();
Expand All @@ -1293,7 +1288,11 @@ bool ChordLayout::isChordPosBelowBeam(Chord* item, Beam* beam)
return noteY > endAnchor.y();
}

double proportionAlongX = muse::RealIsEqual(startX, endX) ? 0.0 : (noteX - startAnchor.x()) / (endAnchor.x() - startAnchor.x());
PointF noteAnchor = BeamLayout::chordBeamAnchor(beam, item, ChordBeamAnchorType::Middle);
double noteX = noteAnchor.x();

double proportionAlongX
= muse::RealIsEqual(startAnchor.x(), endAnchor.x()) ? 0.0 : (noteX - startAnchor.x()) / (endAnchor.x() - startAnchor.x());
double desiredY = proportionAlongX * (endAnchor.y() - startAnchor.y()) + startAnchor.y();
return noteY > desiredY;
}
Expand Down
Binary file added vtest/scores/beams-29.mscz
Binary file not shown.

0 comments on commit 40fc85a

Please sign in to comment.