Fix remainder of bug 1605 so that when snapping to region starts / ends, the crossove...
authorCarl Hetherington <carl@carlh.net>
Sat, 22 Aug 2009 19:45:40 +0000 (19:45 +0000)
committerCarl Hetherington <carl@carlh.net>
Sat, 22 Aug 2009 19:45:40 +0000 (19:45 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@5568 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/editor.cc

index 7080798118ee6a85a80f0ede86458a7ca9e06a0e..ec351be787e33bfab7c7502ab148e2d64977d78c 100644 (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()) {
-
-                               /* lower bound doesn't quite to the right thing for our purposes */
-
-                               if (direction < 0 && i != region_boundary_cache.begin()) {
-                                       --i;
-                               }
+                       if (next != region_boundary_cache.begin ()) {
+                               prev = next;
+                               prev--;
+                       }
 
-                               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;