Skip to content

Commit

Permalink
[engraving] moved ChordRest up to LayoutData
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkorsukov committed Dec 6, 2023
1 parent 34fb37b commit abbfd95
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 178 deletions.
39 changes: 20 additions & 19 deletions src/engraving/dom/chord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ double Chord::stemPosX() const
if (staffType && staffType->isTabStaff()) {
return staffType->chordStemPosX(this) * spatium();
}
return m_up ? noteHeadWidth() : 0.0;
return ldata()->up ? noteHeadWidth() : 0.0;
}

//! Returns page coordinates
Expand All @@ -524,7 +524,7 @@ PointF Chord::stemPos() const
return pagePos() + staffType->chordStemPos(this) * spatium();
}

if (m_up) {
if (ldata()->up) {
const Note* downNote = this->downNote();
double nhw = m_notes.size() == 1 ? downNote->bboxRightPos() : noteHeadWidth();
return pagePos() + PointF(nhw, downNote->pos().y());
Expand All @@ -544,7 +544,7 @@ PointF Chord::stemPosBeam() const
return pagePos() + st->chordStemPosBeam(this) * spatium();
}

if (m_up) {
if (ldata()->up) {
double nhw = noteHeadWidth();
return pagePos() + PointF(nhw, upNote()->pos().y());
}
Expand Down Expand Up @@ -1148,25 +1148,25 @@ int Chord::calcMinStemLength()

int outsideStaffOffset = 0;
if (!staff()->isTabStaff(tick())) {
Note* lineNote = m_up ? upNote() : downNote();
Note* lineNote = ldata()->up ? upNote() : downNote();
if (lineNote->line() == INVALID_LINE) {
lineNote->updateLine();
}

int line = lineNote->line();
line *= 2; // convert to quarter spaces

if (!m_up && line < -2) {
if (!ldata()->up && line < -2) {
outsideStaffOffset = -line;
} else if (m_up && line > staff()->lines(tick()) * 4) {
} else if (ldata()->up && line > staff()->lines(tick()) * 4) {
outsideStaffOffset = line - (staff()->lines(tick()) * 4) + 4;
}
}
minStemLength += (outSidePadding + std::max(noteSidePadding, outsideStaffOffset));

if (m_hook) {
bool straightFlags = style().styleB(Sid::useStraightNoteFlags);
double smuflAnchor = m_hook->smuflAnchor().y() * (m_up ? 1 : -1);
double smuflAnchor = m_hook->smuflAnchor().y() * (ldata()->up ? 1 : -1);
int hookOffset = floor((m_hook->height() / intrinsicMag() + smuflAnchor) / _spatium * 4) - (straightFlags ? 0 : 2);
// some fonts have hooks that extend very far down (making the height of the hook very large)
// so we constrain to a reasonable maximum for hook length
Expand Down Expand Up @@ -1199,7 +1199,7 @@ int Chord::calcMinStemLength()
// for 4+ beams, there are a few situations where we need to lengthen the stem by 1
int noteLine = line();
int staffLines = staff()->lines(tick());
bool noteInStaff = (m_up && noteLine > 0) || (!m_up && noteLine < (staffLines - 1) * 2);
bool noteInStaff = (ldata()->up && noteLine > 0) || (!ldata()->up && noteLine < (staffLines - 1) * 2);
if (beamCount >= 4 && noteInStaff) {
newMinStemLength++;
}
Expand Down Expand Up @@ -1366,7 +1366,7 @@ double Chord::calcDefaultStemLength()
}
// extraHeight represents the extra vertical distance between notehead and stem start
// eg. slashed noteheads etc
double extraHeight = (m_up ? upNote()->stemUpSE().y() : downNote()->stemDownNW().y()) / intrinsicMag() / _spatium;
double extraHeight = (ldata()->up ? upNote()->stemUpSE().y() : downNote()->stemDownNW().y()) / intrinsicMag() / _spatium;
int shortestStem = style().styleB(Sid::useWideBeams) ? 12 : (style().styleD(Sid::shortestStem) + abs(extraHeight)) * 4;
int quarterSpacesPerLine = std::floor(lineDistance * 2);
int chordHeight = (downLine() - upLine()) * quarterSpacesPerLine; // convert to quarter spaces
Expand All @@ -1379,8 +1379,9 @@ double Chord::calcDefaultStemLength()
int shortStemStart = style().styleI(Sid::shortStemStartLocation) * quarterSpacesPerLine + 1;
bool useWideBeams = style().styleB(Sid::useWideBeams);
int beamCount = ((m_tremolo && m_tremolo->twoNotes()) ? m_tremolo->lines() : 0) + (m_beam ? beams() : 0);
int middleLine
= minStaffOverlap(m_up, staffLineCount, beamCount, !!m_hook, useWideBeams ? 4 : 3, useWideBeams, !(isGrace() || isSmall()));
int middleLine = minStaffOverlap(ldata()->up, staffLineCount,
beamCount, !!m_hook, useWideBeams ? 4 : 3,
useWideBeams, !(isGrace() || isSmall()));
if (up()) {
int stemEndPosition = upLine() * quarterSpacesPerLine - defaultStemLength;
double stemEndPositionMag = (double)upLine() * quarterSpacesPerLine - (defaultStemLength * intrinsicMag());
Expand Down Expand Up @@ -1422,11 +1423,11 @@ double Chord::calcDefaultStemLength()

double finalStemLength = (chordHeight / 4.0 * _spatium) + ((stemLength / 4.0 * _spatium) * intrinsicMag());
double extraLength = 0.;
Note* startNote = m_up ? downNote() : upNote();
Note* startNote = ldata()->up ? downNote() : upNote();
if (!startNote->fixed()) {
// when the chord's magnitude is < 1, the stem length with mag can find itself below the middle line.
// in those cases, we have to add the extra amount to it to bring it to a minimum.
double upValue = m_up ? -1. : 1.;
double upValue = ldata()->up ? -1. : 1.;
double stemStart = startNote->ldata()->pos().y();
double stemEndMag = stemStart + (finalStemLength * upValue);
double topLine = 0.0;
Expand All @@ -1437,23 +1438,23 @@ double Chord::calcDefaultStemLength()
if (RealIsEqualOrMore(lineDistance / _spatium, 1.0)) {
// need to extend to middle line, or to opposite line if staff is < 2sp tall
if (bottomLine < 2 * _spatium) {
target = m_up ? topLine : bottomLine;
target = ldata()->up ? topLine : bottomLine;
} else {
double twoSpIn = m_up ? bottomLine - (2 * _spatium) : topLine + (2 * _spatium);
double twoSpIn = ldata()->up ? bottomLine - (2 * _spatium) : topLine + (2 * _spatium);
target = RealIsEqual(lineDistance / _spatium, 1.0) ? midLine : twoSpIn;
}
} else {
// need to extend to second line in staff, or to opposite line if staff has < 3 lines
if (staffLineCount < 3) {
target = m_up ? topLine : bottomLine;
target = ldata()->up ? topLine : bottomLine;
} else {
target = m_up ? bottomLine - (2 * lineDistance) : topLine + (2 * lineDistance);
target = ldata()->up ? bottomLine - (2 * lineDistance) : topLine + (2 * lineDistance);
}
}
extraLength = 0.0;
if (m_up && stemEndMag > target) {
if (ldata()->up && stemEndMag > target) {
extraLength = stemEndMag - target;
} else if (!m_up && stemEndMag < target) {
} else if (!ldata()->up && stemEndMag < target) {
extraLength = target - stemEndMag;
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/engraving/dom/chordrest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ ChordRest::ChordRest(const ElementType& type, Segment* parent)
m_staffMove = 0;
m_beam = 0;
m_tabDur = 0;
m_up = true;
m_beamMode = BeamMode::AUTO;
m_isSmall = false;
m_melismaEnd = false;
Expand All @@ -87,7 +86,6 @@ ChordRest::ChordRest(const ChordRest& cr, bool link)
// simply copied from another CR

m_beamMode = cr.m_beamMode;
m_up = cr.m_up;
m_isSmall = cr.m_isSmall;
m_melismaEnd = cr.m_melismaEnd;
m_crossMeasure = cr.m_crossMeasure;
Expand Down Expand Up @@ -604,8 +602,6 @@ void ChordRest::removeDeleteBeam(bool beamed)
void ChordRest::computeUp()
{
UNREACHABLE;
m_usesAutoUp = false;
m_up = true;
}

//---------------------------------------------------------
Expand Down
19 changes: 11 additions & 8 deletions src/engraving/dom/chordrest.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,14 @@ class ChordRest : public DurationElement
virtual double downPos() const = 0;

int line(bool up) const { return up ? upLine() : downLine(); }
int line() const { return m_up ? upLine() : downLine(); }
int line() const { return ldata()->up ? upLine() : downLine(); }
virtual int upLine() const = 0;
virtual int downLine() const = 0;
virtual mu::PointF stemPos() const = 0;
virtual double stemPosX() const = 0;
virtual mu::PointF stemPosBeam() const = 0;
virtual double rightEdge() const = 0;

void setUp(bool val) { m_up = val; }
bool up() const { return m_up; }
bool usesAutoUp() const { return m_usesAutoUp; }
void setUsesAutoUp(bool val) { m_usesAutoUp = val; }

bool isSmall() const { return m_isSmall; }
void setSmall(bool val) { m_isSmall = val; }
void undoSetSmall(bool val);
Expand Down Expand Up @@ -202,6 +197,16 @@ class ChordRest : public DurationElement
TabDurationSymbol* tabDur() const { return m_tabDur; }
void setTabDur(TabDurationSymbol* s) { m_tabDur = s; }

struct LayoutData : public DurationElement::LayoutData {
ld_field<bool> up = { "[ChordRest] up", true }; // actual stem direction
};
DECLARE_LAYOUTDATA_METHODS(ChordRest)

//! DEPRECATED ------
void setUp(bool val) { mutldata()->up = val; }
bool up() const { return ldata()->up; }
//! -----------------

protected:

void addEl(EngravingItem* e) { m_el.push_back(e); }
Expand All @@ -214,8 +219,6 @@ class ChordRest : public DurationElement
Beam* m_beam = nullptr;
BeamSegment* m_beamlet = nullptr;
BeamMode m_beamMode = BeamMode::INVALID;
bool m_up = false; // actual stem direction
bool m_usesAutoUp = false;
bool m_isSmall = false;
bool m_melismaEnd = false;

Expand Down
4 changes: 2 additions & 2 deletions src/engraving/dom/rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ PointF Rest::stemPos() const
PointF Rest::stemPosBeam() const
{
PointF p(pagePos());
if (m_up) {
if (ldata()->up) {
p.ry() += ldata()->bbox().top() + spatium() * 1.5;
} else {
p.ry() += ldata()->bbox().bottom() - spatium() * 1.5;
Expand All @@ -688,7 +688,7 @@ PointF Rest::stemPosBeam() const

double Rest::stemPosX() const
{
if (m_up) {
if (ldata()->up) {
return ldata()->bbox().right();
} else {
return ldata()->bbox().left();
Expand Down
Loading

0 comments on commit abbfd95

Please sign in to comment.