Skip to content

Commit

Permalink
Allow more flexibility for Spanners to compute start and end segment
Browse files Browse the repository at this point in the history
Start segment: if a segment is not found to the right of this tick, allow looking to the left.

End segment: system-line spanners should be allowed to terminate on segments that aren't necessarily ChordRest (for example, they can terminate on bar lines).
  • Loading branch information
mike-spa committed Aug 16, 2023
1 parent a31e3ca commit 0b5131f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/engraving/libmscore/score.h
Expand Up @@ -565,7 +565,7 @@ class Score : public EngravingObject
Segment* tick2segmentMM(const Fraction& tick, bool first, SegmentType st) const;
Segment* tick2segmentMM(const Fraction& tick) const;
Segment* tick2segmentMM(const Fraction& tick, bool first) const;
Segment* tick2leftSegment(const Fraction& tick, bool useMMrest = false) const;
Segment* tick2leftSegment(const Fraction& tick, bool useMMrest = false, bool anySegmentType = false) const;
Segment* tick2rightSegment(const Fraction& tick, bool useMMrest = false) const;
Segment* tick2leftSegmentMM(const Fraction& tick) { return tick2leftSegment(tick, /* useMMRest */ true); }

Expand Down
8 changes: 6 additions & 2 deletions src/engraving/libmscore/spanner.cpp
Expand Up @@ -987,7 +987,11 @@ ChordRest* Spanner::findEndCR() const
Segment* Spanner::startSegment() const
{
assert(score() != NULL);
return score()->tick2rightSegment(tick(), style().styleB(Sid::createMultiMeasureRests));
Segment* rightSegment = score()->tick2rightSegment(tick(), style().styleB(Sid::createMultiMeasureRests));
if (rightSegment) {
return rightSegment;
}
return score()->tick2leftSegment(tick(), style().styleB(Sid::createMultiMeasureRests));
}

//---------------------------------------------------------
Expand All @@ -996,7 +1000,7 @@ Segment* Spanner::startSegment() const

Segment* Spanner::endSegment() const
{
return score()->tick2leftSegment(tick2(), style().styleB(Sid::createMultiMeasureRests));
return score()->tick2leftSegment(tick2(), style().styleB(Sid::createMultiMeasureRests), systemFlag());
}

//---------------------------------------------------------
Expand Down
6 changes: 4 additions & 2 deletions src/engraving/libmscore/utils.cpp
Expand Up @@ -205,16 +205,18 @@ Segment* Score::tick2segment(const Fraction& tick, bool first) const
/// the first segment *before* this tick position
//---------------------------------------------------------

Segment* Score::tick2leftSegment(const Fraction& tick, bool useMMrest) const
Segment* Score::tick2leftSegment(const Fraction& tick, bool useMMrest, bool anySegmentType) const
{
Measure* m = useMMrest ? tick2measureMM(tick) : tick2measure(tick);
if (m == 0) {
LOGD("tick2leftSegment(): not found tick %d", tick.ticks());
return 0;
}

// loop over all segments
SegmentType segmentType = anySegmentType ? SegmentType::All : SegmentType::ChordRest;
Segment* ps = 0;
for (Segment* s = m->first(SegmentType::ChordRest); s; s = s->next(SegmentType::ChordRest)) {
for (Segment* s = m->first(segmentType); s; s = s->next(segmentType)) {
if (tick < s->tick()) {
return ps;
} else if (tick == s->tick()) {
Expand Down

0 comments on commit 0b5131f

Please sign in to comment.