From d25742b28f33336d122c477f7302d4942d49b0cb Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 22 Aug 2009 19:45:40 +0000 Subject: [PATCH] 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 --- gtk2_ardour/editor.cc | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 7080798118..ec351be787 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -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::iterator i; + vector::iterator prev = region_boundary_cache.end (); + vector::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;