Skip to content

Commit

Permalink
Add ability to guess tie attachment point for different noteheads
Browse files Browse the repository at this point in the history
Also, cleaned up some comments and renamed some functions to make them easier to understand
  • Loading branch information
asattely committed Nov 17, 2021
1 parent 0ba7c08 commit 3211f22
Show file tree
Hide file tree
Showing 4 changed files with 305 additions and 167 deletions.
41 changes: 41 additions & 0 deletions src/engraving/libmscore/note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,47 @@ qreal Note::headBodyWidth() const
return headWidth() + 2 * bboxXShift();
}

//---------------------------------------------------------
// outsideTieAttachX
//
// returns the X-position for tie attachment for this particular notehead
//---------------------------------------------------------
qreal Note::outsideTieAttachX(bool up) const
{
qreal xo = symSmuflAnchor(noteHead(), SmuflAnchorId::opticalCenter).x() * mag();
if (xo > 0) {
return x() + xo;
}
// no optical center, try for average of cutouts
if (up) {
qreal xNE = symSmuflAnchor(noteHead(), SmuflAnchorId::cutOutNE).x();
qreal xNW = symSmuflAnchor(noteHead(), SmuflAnchorId::cutOutNW).x();
xo = ((xNE + xNW) / 2) * mag();
if (xNE < xNW) {
// musejazz is busted
xo = 0;
}
} else {
qreal xSE = symSmuflAnchor(noteHead(), SmuflAnchorId::cutOutSE).x();
qreal xSW = symSmuflAnchor(noteHead(), SmuflAnchorId::cutOutSW).x();
xo = ((xSE + xSW) / 2) * mag();
if (xSE < xSW) {
xo = 0;
}
}
if (xo > 0) {
return x() + xo;
}
// no cutout information, is the notehead a slash?
if (_headGroup == NoteHead::Group::HEAD_SLASH) {
xo = up ? symSmuflAnchor(noteHead(), SmuflAnchorId::stemUpSE).x() : symSmuflAnchor(noteHead(), SmuflAnchorId::stemDownNW).x();
xo += spatium() * 0.13 * (chord()->up() ? mag() : -mag());
return x() + xo;
}
// no cutout, not a slash head, default to middle of notehead
return x() + ((headWidth() / 2) * mag());
}

void Note::updateHeadGroup(const NoteHead::Group headGroup)
{
NoteHead::Group group = headGroup;
Expand Down
1 change: 1 addition & 0 deletions src/engraving/libmscore/note.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ class Note final : public EngravingItem
qreal noteheadCenterX() const;
qreal bboxRightPos() const;
qreal headBodyWidth() const;
qreal outsideTieAttachX(bool up) const;

NoteHead::Scheme headScheme() const { return _headScheme; }
void updateHeadGroup(const NoteHead::Group headGroup);
Expand Down
Loading

0 comments on commit 3211f22

Please sign in to comment.