Fix setting of loop region start/end at the same time. Fixes #3314.
authorCarl Hetherington <carl@carlh.net>
Thu, 15 Jul 2010 00:24:50 +0000 (00:24 +0000)
committerCarl Hetherington <carl@carlh.net>
Thu, 15 Jul 2010 00:24:50 +0000 (00:24 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@7418 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/location.h
libs/ardour/location.cc

index 3f3eaf4fc8cde97cedb7fd8eac95a8e7873f7409..24387cdaef4b2aeafb702749df6a93cb8a58a0c9 100644 (file)
@@ -80,8 +80,8 @@ class Location : public PBD::StatefulDestructible
        nframes64_t end() const { return _end; }
        nframes64_t length() const { return _end - _start; }
 
-       int set_start (nframes64_t s);
-       int set_end (nframes64_t e);
+       int set_start (nframes64_t s, bool force = false);
+       int set_end (nframes64_t e, bool force = false);
        int set (nframes64_t start, nframes64_t end);
 
        int move_to (nframes64_t pos);
index 93b6b5c5fa1591f692e77bdf6f6545e2382c8f6c..3f62d8949d255b103bc0c0d387b875839ef0df7c 100644 (file)
@@ -82,15 +82,21 @@ Location::operator= (const Location& other)
        return this;
 }
 
+/** Set start position.
+ *  @param s New start.
+ *  @param force true to force setting, even if the given new start is after the current end.
+ */
 int
-Location::set_start (nframes64_t s)
+Location::set_start (nframes64_t s, bool force)
 {
        if (_locked) {
                return -1;
        }
 
-       if (((is_auto_punch() || is_auto_loop()) && s >= _end) || (!is_mark() && s > _end)) {
-               return -1;
+       if (!force) {
+               if (((is_auto_punch() || is_auto_loop()) && s >= _end) || (!is_mark() && s > _end)) {
+                       return -1;
+               }
        }
 
        if (is_mark()) {
@@ -115,15 +121,21 @@ Location::set_start (nframes64_t s)
        return 0;
 }
 
+/** Set end position.
+ *  @param s New end.
+ *  @param force true to force setting, even if the given new start is after the current end.
+ */
 int
-Location::set_end (nframes64_t e)
+Location::set_end (nframes64_t e, bool force)
 {
        if (_locked) {
                return -1;
        }
 
-       if (((is_auto_punch() || is_auto_loop()) && e <= _start) || e < _start) {
-               return -1;
+       if (!force) {
+               if (((is_auto_punch() || is_auto_loop()) && e <= _start) || e < _start) {
+                       return -1;
+               }
        }
        
        if (is_mark()) {
@@ -151,8 +163,14 @@ Location::set_end (nframes64_t e)
 int
 Location::set (nframes64_t start, nframes64_t end)
 {
-       int const s = set_start (start);
-       int const e = set_end (end);
+       /* check validity */
+       if (((is_auto_punch() || is_auto_loop()) && start >= end) || (!is_mark() && start > end)) {
+               return -1;
+       }
+
+       /* now we know these values are ok, so force-set them */
+       int const s = set_start (start, true);
+       int const e = set_end (end, true);
 
        return (s == 0 && e == 0) ? 0 : -1;
 }