Fix remainder of bug 1605 so that when snapping to region starts / ends, the crossover between the current snap and the next one happens halfway between the two.

git-svn-id: svn://localhost/ardour2/branches/3.0@5568 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Carl Hetherington 2009-08-22 19:45:40 +00:00
parent 970a3a7292
commit d25742b28f
1 changed files with 14 additions and 12 deletions

View File

@ -2684,26 +2684,28 @@ Editor::snap_to_internal (nframes64_t& start, int32_t direction, bool for_mark)
case SnapToRegionSync:
case SnapToRegionBoundary:
if (!region_boundary_cache.empty()) {
vector<nframes64_t>::iterator i;
vector<nframes64_t>::iterator prev = region_boundary_cache.end ();
vector<nframes64_t>::iterator next = region_boundary_cache.end ();
if (direction > 0) {
i = std::upper_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
next = std::upper_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
} else {
i = std::lower_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
next = std::lower_bound (region_boundary_cache.begin(), region_boundary_cache.end(), start);
}
if (i != region_boundary_cache.end()) {
if (next != region_boundary_cache.begin ()) {
prev = next;
prev--;
}
/* lower bound doesn't quite to the right thing for our purposes */
if (direction < 0 && i != region_boundary_cache.begin()) {
--i;
}
start = *i;
nframes64_t const p = (prev == region_boundary_cache.end()) ? region_boundary_cache.front () : *prev;
nframes64_t const n = (next == region_boundary_cache.end()) ? region_boundary_cache.back () : *next;
if (start > (p + n) / 2) {
start = n;
} else {
start = region_boundary_cache.back();
start = p;
}
}
break;