Skip to content

Commit

Permalink
Segment-based horizontal spacing and lyrics spacing improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-spa committed Oct 11, 2024
1 parent 05934b3 commit 955469d
Show file tree
Hide file tree
Showing 20 changed files with 1,145 additions and 1,153 deletions.
106 changes: 43 additions & 63 deletions src/engraving/dom/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1970,6 +1970,14 @@ bool Measure::isFirstInSystem() const
return system()->firstMeasure() == this;
}

bool Measure::isLastInSystem() const
{
IF_ASSERT_FAILED(system()) {
return false;
}
return system()->lastMeasure() == this;
}

//---------------------------------------------------------
// isFirstInSection
//---------------------------------------------------------
Expand Down Expand Up @@ -3108,6 +3116,41 @@ EngravingItem* Measure::prevElementStaff(staff_idx_t staff)
return score()->firstElement();
}

bool Measure::hasCrossStaffOrModifiedBeams() const
{
for (const Segment& seg : m_segments) {
if (!seg.isChordRestType()) {
continue;
}
for (EngravingItem* e : seg.elist()) {
if (!e || !e->isChordRest()) {
continue;
}
if (toChordRest(e)->beam() && (toChordRest(e)->beam()->cross() || toChordRest(e)->beam()->userModified())) {
return true;
}
Chord* c = e->isChord() ? toChord(e) : nullptr;
if (c && c->tremoloTwoChord()) {
TremoloTwoChord* trem = c->tremoloTwoChord();
Chord* c1 = trem->chord1();
Chord* c2 = trem->chord2();
if (trem->userModified() || c1->staffMove() != c2->staffMove()) {
return true;
}
}
if (e->isChord() && !toChord(e)->graceNotes().empty()) {
for (Chord* grace : toChord(e)->graceNotes()) {
if (grace->beam() && (grace->beam()->cross() || grace->beam()->userModified())) {
return true;
}
}
}
}
}

return false;
}

//---------------------------------------------------------
// accessibleInfo
//---------------------------------------------------------
Expand Down Expand Up @@ -3244,34 +3287,6 @@ void Measure::setEndBarLineType(BarLineType val, track_idx_t track, bool visible
bl->setColor(color.isValid() ? color : curColor());
}

//---------------------------------------------------------
// basicStretch
//---------------------------------------------------------

double Measure::basicStretch() const
{
double stretch = userStretch() * style().styleD(Sid::measureSpacing);
if (stretch < 1.0) {
stretch = 1.0;
}
return stretch;
}

//---------------------------------------------------------
// basicWidth
//---------------------------------------------------------

double Measure::basicWidth() const
{
Segment* ls = last();
double w = (ls->x() + ls->width()) * basicStretch();
double minMeasureWidth = style().styleMM(Sid::minMeasureWidth);
if (w < minMeasureWidth) {
w = minMeasureWidth;
}
return w;
}

//---------------------------------------------------------
// checkHeader
//---------------------------------------------------------
Expand Down Expand Up @@ -3335,24 +3350,6 @@ bool Measure::canAddStringTunings(staff_idx_t staffIdx) const
return !alreadyHasStringTunings;
}

void Measure::stretchToTargetWidth(double targetWidth)
{
if (targetWidth < width()) {
return;
}
std::vector<Spring> springs;
for (Segment& s : m_segments) {
if (s.isChordRestType() && s.visible() && s.enabled() && !s.allElementsInvisible()) {
double springConst = 1 / s.stretch();
double width = s.width(LD_ACCESS::BAD) - s.widthOffset();
double preTension = width * springConst;
springs.emplace_back(springConst, width, preTension, &s);
}
}
Segment::stretchSegmentsToWidth(springs, targetWidth - width());
respaceSegments();
}

Fraction Measure::maxTicks() const
{
Segment* s = first();
Expand All @@ -3369,23 +3366,6 @@ Fraction Measure::maxTicks() const
return maxticks;
}

Fraction Measure::shortestChordRest() const
{
Fraction shortest = Fraction::max(); // Initializing at arbitrary high value
Fraction cur = Fraction::max();
Segment* s = first();
while (s) {
if (s->isChordRestType() && !s->allElementsInvisible()) {
cur = s->shortestChordRest();
if (cur < shortest) {
shortest = cur;
}
}
s = s->next();
}
return shortest;
}

void Measure::respaceSegments()
{
double x = 0.0;
Expand Down
24 changes: 4 additions & 20 deletions src/engraving/dom/measure.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,8 @@ class Measure final : public MeasureBase
double userStretch() const;
void setUserStretch(double v) { m_userStretch = v; }

void setLayoutStretch(double stretchCoeff) { m_layoutStretch = stretchCoeff; }
double layoutStretch() const { return m_layoutStretch; }

void computeTicks();
Fraction anacrusisOffset() const;
Fraction shortestChordRest() const;
Fraction maxTicks() const;

bool showsMeasureNumber();
Expand Down Expand Up @@ -287,6 +283,7 @@ class Measure final : public MeasureBase
bool isFinalMeasureOfSection() const;
bool isAnacrusis() const;
bool isFirstInSystem() const;
bool isLastInSystem() const;
bool isFirstInSection() const;

bool breakMultiMeasureRest() const { return m_breakMultiMeasureRest; }
Expand Down Expand Up @@ -333,6 +330,8 @@ class Measure final : public MeasureBase
EngravingItem* nextElementStaff(staff_idx_t staff);
EngravingItem* prevElementStaff(staff_idx_t staff);

bool hasCrossStaffOrModifiedBeams() const;

String accessibleInfo() const override;

#ifndef ENGRAVING_NO_ACCESSIBILITY
Expand All @@ -343,20 +342,10 @@ class Measure final : public MeasureBase
BarLineType endBarLineType() const;
bool endBarLineVisible() const;
void triggerLayout() const override;
double basicStretch() const;
double basicWidth() const;
void stretchToTargetWidth(double targetWidth);

void checkHeader();
void checkTrailer();

bool isWidthLocked() const { return m_isWidthLocked; }
// A measure is widthLocked if its width has been locked by the minMeasureWidth (or minMMRestWidth)
// parameter, meaning it can't be any narrower than it currently is.
void setWidthLocked(bool b) { m_isWidthLocked = b; }

double squeezableSpace() const { return m_squeezableSpace; }
void setSqueezableSpace(double val) { m_squeezableSpace = val; }

void respaceSegments();

bool canAddStringTunings(staff_idx_t staffIdx) const;
Expand All @@ -378,8 +367,6 @@ class Measure final : public MeasureBase

MStaff* mstaff(staff_idx_t staffIndex) const;

double m_squeezableSpace = 0.0;

std::vector<MStaff*> m_mstaves;
SegmentList m_segments;
Measure* m_mmRest = nullptr; // multi measure rest which replaces a measure range
Expand All @@ -399,9 +386,6 @@ class Measure final : public MeasureBase

MeasureNumberMode m_noMode = MeasureNumberMode::AUTO;
bool m_breakMultiMeasureRest = false;

double m_layoutStretch = 1.0;
bool m_isWidthLocked = false;
};
} // namespace mu::engraving
#endif
2 changes: 1 addition & 1 deletion src/engraving/dom/note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2684,7 +2684,7 @@ void Note::normalizeLeftDragDelta(Segment* seg, EditData& ed, NoteEditData* ned)
Segment* previous = seg->prev();

if (previous) {
double minDist = HorizontalSpacing::minHorizontalCollidingDistance(previous, seg, 1.0);
double minDist = HorizontalSpacing::minHorizontalDistance(previous, seg, 1.0);

double diff = (ed.pos.x()) - (previous->pageX() + minDist);

Expand Down
Loading

0 comments on commit 955469d

Please sign in to comment.