Skip to content

Commit

Permalink
fix #294121: navigation skips annotations entered out of order
Browse files Browse the repository at this point in the history
Annotations are appended to the annotation list as they are entered.
This means they won't necessarily be sorted by track,
if you enter them onto staves in any order but top down.
The result is the navitgation code skips all annotations for a staff
after the first annotation it encounters on a different staff.

This commit fixes the issue by continuing to loop through the annotations,
looking for more on the same staff.

anatoly-os: rewrite the improvement from #5308 using `find_if`

anatoly-os: Did refactoring using `find_if` to make the code cleaner. Initial idea and implementation are authored by @MarcSabatella.
  • Loading branch information
MarcSabatella authored and anatoly-os committed Oct 2, 2019
1 parent 7ca7ad4 commit 9149511
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions libmscore/segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1178,11 +1178,15 @@ Element* Segment::nextAnnotation(Element* e)
{
if (_annotations.empty() || e == _annotations.back())
return nullptr;
auto i = std::find(_annotations.begin(), _annotations.end(), e);
Element* next = *(i+1);
if (next && next->staffIdx() == e->staffIdx())
return next;
return nullptr;
auto ei = std::find(_annotations.begin(), _annotations.end(), e);
if (ei == _annotations.end())
return nullptr; // element not found

auto resIt = std::find_if(ei + 1, _annotations.end(), [e](Element* nextElem){
return nextElem && nextElem->staffIdx() == e->staffIdx();
});

return _annotations.end() == resIt ? nullptr : *resIt;
}

//---------------------------------------------------------
Expand All @@ -1194,11 +1198,15 @@ Element* Segment::prevAnnotation(Element* e)
{
if (e == _annotations.front())
return nullptr;
auto i = std::find(_annotations.begin(), _annotations.end(), e);
Element* prev = *(i-1);
if (prev && prev->staffIdx() == e->staffIdx())
return prev;
return nullptr;
auto reverseIt = std::find(_annotations.rbegin(), _annotations.rend(), e);
if (reverseIt == _annotations.rend())
return nullptr; // element not found

auto resIt = std::find_if(reverseIt + 1, _annotations.rend(), [e](Element* prevElem){
return prevElem && prevElem->staffIdx() == e->staffIdx();
});

return _annotations.rend() == resIt ? nullptr : *resIt;
}

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

0 comments on commit 9149511

Please sign in to comment.