Skip to content

Commit

Permalink
fixed calculation of chord symbol duration
Browse files Browse the repository at this point in the history
The actual distance between the current chord symbol and the next one may be shorter
than the duration of the current chord symbol segment. This situation occurs, for example,
when we have a measure with a whole rest, and one chord symbol is added to the whole rest segment
and the others are added to the time tick segments. Thus, the whole rest segment lasts for the measure duration,
while the time tick segments last only part of it
  • Loading branch information
RomanPudashkin committed Feb 20, 2025
1 parent 685584c commit 304e1a4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
19 changes: 15 additions & 4 deletions src/engraving/dom/harmony.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,9 +849,14 @@ Fraction Harmony::ticksTillNext(int utick, bool stopAtMeasureEnd) const
{
Segment* seg = getParentSeg();
Fraction duration = seg->ticks();
Segment* cur = seg->next();
auto rsIt = score()->repeatList().findRepeatSegmentFromUTick(utick);

const RepeatList& repeats = score()->repeatList();
auto rsIt = repeats.findRepeatSegmentFromUTick(utick);
if (rsIt == repeats.cend()) {
return duration;
}

Segment* cur = seg->next();
Measure const* currentMeasure = seg->measure();
Measure const* endMeasure = (stopAtMeasureEnd) ? currentMeasure : (*rsIt)->lastMeasure();
Harmony const* nextHarmony = nullptr;
Expand Down Expand Up @@ -892,9 +897,9 @@ Fraction Harmony::ticksTillNext(int utick, bool stopAtMeasureEnd) const
// End of repeatSegment or search boundary reached
if (stopAtMeasureEnd) {
break;
} else {
} else if (!nextHarmony) {
// move to next RepeatSegment
if (++rsIt != score()->repeatList().end()) {
if (++rsIt != repeats.end()) {
currentMeasure = (*rsIt)->firstMeasure();
endMeasure = (*rsIt)->lastMeasure();
cur = currentMeasure->first();
Expand All @@ -903,6 +908,12 @@ Fraction Harmony::ticksTillNext(int utick, bool stopAtMeasureEnd) const
}
} while ((nextHarmony == nullptr) && (cur != nullptr));

if (nextHarmony && rsIt != repeats.end()) {
int tickOffset = (*rsIt)->utick - (*rsIt)->tick;
int nextHarmonyUtick = nextHarmony->tick().ticks() + tickOffset;
duration = Fraction::fromTicks(nextHarmonyUtick - utick);
}

return duration;
}

Expand Down
12 changes: 8 additions & 4 deletions src/engraving/dom/repeatlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,14 @@ int RepeatList::utime2utick(double secs) const
///
std::vector<RepeatSegment*>::const_iterator RepeatList::findRepeatSegmentFromUTick(int utick) const
{
return std::lower_bound(this->cbegin(), this->cend(), utick, [](RepeatSegment const* rs, int utick) {
// Skip RS where endtick is less than us
return utick > (rs->utick + rs->len());
});
for (auto it = cbegin(); it != cend(); ++it) {
const RepeatSegment* seg = *it;
if (utick >= seg->utick && utick < seg->utick + seg->len()) {
return it;
}
}

return cend();
}

//---------------------------------------------------------
Expand Down

0 comments on commit 304e1a4

Please sign in to comment.