Skip to content

Commit

Permalink
Re-layout whole spanner when change made to 1 segment
Browse files Browse the repository at this point in the history
  • Loading branch information
miiizen committed Nov 30, 2023
1 parent a09ceb5 commit 809534e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 32 deletions.
15 changes: 14 additions & 1 deletion src/engraving/dom/score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5601,6 +5601,19 @@ void Score::doLayoutRange(const Fraction& st, const Fraction& et)
{
TRACEFUNC;

Fraction start = st;
Fraction end = et;

auto spanners = score()->spannerMap().findOverlapping(st.ticks(), et.ticks());
for (auto interval : spanners) {
Spanner* spanner = interval.value;
if (!spanner->staff()->visible()) {
continue;
}
start = std::min(st, spanner->tick());
end = std::max(et, spanner->tick2());
}

m_engravingFont = engravingFonts()->fontByName(style().value(Sid::MusicalSymbolFont).value<String>().toStdString());
m_layoutOptions.noteHeadWidth = m_engravingFont->width(SymId::noteheadBlack, style().spatium() / SPATIUM20);

Expand All @@ -5614,7 +5627,7 @@ void Score::doLayoutRange(const Fraction& st, const Fraction& et)
this->updateVelo();
}

renderer()->layoutScore(this, st, et);
renderer()->layoutScore(this, start, end);

if (m_resetAutoplace) {
m_resetAutoplace = false;
Expand Down
52 changes: 22 additions & 30 deletions src/engraving/rendering/dev/slurtielayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1765,12 +1765,12 @@ double SlurTieLayout::defaultStemLengthEnd(Tremolo* tremolo)
tremolo->chord2()->defaultStemLength()).second;
}

bool SlurTieLayout::isDirectionMixture(Chord* c1, Chord* c2, LayoutContext& ctx)
bool SlurTieLayout::isDirectionMixture(const Chord* c1, const Chord* c2, LayoutContext& ctx)
{
if (c1->track() != c2->track()) {
return false;
}
bool up = c1->up();
const bool up = c1->up();
if (c2->isGrace() && c2->up() != up) {
return true;
}
Expand All @@ -1779,36 +1779,28 @@ bool SlurTieLayout::isDirectionMixture(Chord* c1, Chord* c2, LayoutContext& ctx)
return true;
}
}
track_idx_t track = c1->track();
for (Measure* m = c1->measure(); m; m = m->nextMeasure()) {
for (Segment* seg = m->first(); seg; seg = seg->next(SegmentType::ChordRest)) {
if (!seg || seg->tick() < c1->tick() || !seg->isChordRestType()) {
continue;
}
if (seg->tick() > c2->tick()) {
return false;
}
if ((c1->isGrace() || c2->isGraceBefore()) && seg->tick() >= c2->tick()) {
// if slur ends at a grace-note-before, we don't need to look at the main note
return false;
}
EngravingItem* e = seg->element(track);
if (!e || !e->isChord()) {
continue;
}
Chord* c = toChord(e);

if (!c->staff()->isDrumStaff(c->tick()) && c1->measure()->system() != m->system()) {
// This chord is on a different system and may not have been laid out yet
for (Note* note : c->notes()) {
note->updateLine(); // because chord direction is based on note lines
}
ChordLayout::computeUp(c, ctx);
const track_idx_t track = c1->track();
for (const Segment* seg = c1->segment(); seg && seg->tick() <= c2->tick(); seg = seg->next1(SegmentType::ChordRest)) {
if ((c1->isGrace() || c2->isGraceBefore()) && seg->tick() == c2->tick()) {
// if slur ends at a grace-note-before, we don't need to look at the main note
return false;
}
EngravingItem* e = seg->element(track);
if (!e || !e->isChord()) {
continue;
}
Chord* c = toChord(e);
const Measure* m = c->measure();
if (!c->staff()->isDrumStaff(c->tick()) && c1->measure()->system() != m->system()) {
// This chord is on a different system and may not have been laid out yet
for (Note* note : c->notes()) {
note->updateLine(); // because chord direction is based on note lines
}
ChordLayout::computeUp(c, ctx);
}

if (c->up() != up) {
return true;
}
if (c->up() != up) {
return true;
}
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/rendering/dev/slurtielayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class SlurTieLayout
static double defaultStemLengthStart(Tremolo* tremolo);
static double defaultStemLengthEnd(Tremolo* tremolo);

static bool isDirectionMixture(Chord* c1, Chord* c2, LayoutContext& ctx);
static bool isDirectionMixture(const Chord* c1, const Chord* c2, LayoutContext& ctx);

static void layoutSegment(SlurSegment* item, LayoutContext& ctx, const PointF& p1, const PointF& p2);
};
Expand Down

0 comments on commit 809534e

Please sign in to comment.