better handling of the inverse-push of solo-by-upstream. still not quite right, but...
[ardour.git] / libs / ardour / location.cc
index ec2059a41f24e2962bc6903e99c850c28111a33b..f855cb75cffff6c67248eaf0befb18d3461b714d 100644 (file)
@@ -89,32 +89,27 @@ Location::set_start (nframes64_t s)
                return -1;
        }
 
+       if (((is_auto_punch() || is_auto_loop()) && s >= _end) || (!is_mark() && s > _end)) {
+               return -1;
+       }
+
        if (is_mark()) {
                if (_start != s) {
-
                        _start = s;
                        _end = s;
-
-                       start_changed(this); /* EMIT SIGNAL */
-                       end_changed(this); /* EMIT SIGNAL */
-
+                       start_changed (this); /* EMIT SIGNAL */
+                       end_changed (this); /* EMIT SIGNAL */
                }
                return 0;
        }
        
-       if (is_session_range()) {
-               start_changed (this); /* EMIT SIGNAL */
-               Session::StartTimeChanged (); /* EMIT SIGNAL */
-               AudioFileSource::set_header_position_offset (s);
-       }
-
-       if (((is_auto_punch() || is_auto_loop()) && s >= _end) || s > _end) {
-               return -1;
-       }
-
        if (s != _start) {
                _start = s;
-               start_changed(this); /* EMIT SIGNAL */
+               start_changed (this); /* EMIT SIGNAL */
+               if (is_session_range ()) {
+                       Session::StartTimeChanged (); /* EMIT SIGNAL */
+                       AudioFileSource::set_header_position_offset (s);
+               }
        }
 
        return 0;
@@ -127,56 +122,39 @@ Location::set_end (nframes64_t e)
                return -1;
        }
 
+       if (((is_auto_punch() || is_auto_loop()) && e <= _start) || e < _start) {
+               return -1;
+       }
+       
        if (is_mark()) {
                if (_start != e) {
                        _start = e;
                        _end = e;
-                       start_changed(this); /* EMIT SIGNAL */
-                       end_changed(this); /* EMIT SIGNAL */
+                       start_changed (this); /* EMIT SIGNAL */
+                       end_changed (this); /* EMIT SIGNAL */
                }
                return 0;
        }
 
-       if (is_session_range()) {
+       if (e != _end) {
                _end = e;
-               end_changed (this); /* EMIT SIGNAL */
-               Session::EndTimeChanged (); /* EMIT SIGNAL */
-       }
+               end_changed(this); /* EMIT SIGNAL */
 
-       if (((is_auto_punch() || is_auto_loop()) && e <= _start) || e < _start) {
-               return -1;
+               if (is_session_range()) {
+                       Session::EndTimeChanged (); /* EMIT SIGNAL */
+               }
        }
 
-       if (e != _end) {
-               _end = e;
-                end_changed(this); /* EMIT SIGNAL */
-       }
        return 0;
 }
 
 int
 Location::set (nframes64_t start, nframes64_t end)
 {
-       if (_locked) {
-               return -1;
-       }
+       int const s = set_start (start);
+       int const e = set_end (end);
 
-       if (is_mark() && start != end) {
-               return -1;
-       } else if (((is_auto_punch() || is_auto_loop()) && start >= end) || (start > end)) {
-               return -1;
-       }
-
-       if (_start != start) {
-               _start = start;
-               start_changed(this); /* EMIT SIGNAL */
-       }
-
-       if (_end != end) {
-               _end = end;
-               end_changed(this); /* EMIT SIGNAL */
-       }
-       return 0;
+       return (s == 0 && e == 0) ? 0 : -1;
 }
 
 int
@@ -220,14 +198,6 @@ Location::set_cd (bool yn, void *src)
        }
 }
 
-void
-Location::set_is_session_range (bool yn, void *src)
-{
-       if (set_flag_internal (yn, IsSessionRange)) {
-                FlagsChanged (this, src); /* EMIT SIGNAL */
-       }
-}
-
 void
 Location::set_is_range_marker (bool yn, void *src)
 {
@@ -655,7 +625,7 @@ Locations::get_state ()
 }
 
 int
-Locations::set_state (const XMLNode& node, int /*version*/)
+Locations::set_state (const XMLNode& node, int version)
 {
        if (node.name() != "Locations") {
                error << _("incorrect XML mode passed to Locations::set_state") << endmsg;
@@ -667,6 +637,12 @@ Locations::set_state (const XMLNode& node, int /*version*/)
        locations.clear ();
        current_location = 0;
 
+       Location* session_range_location = 0;
+       if (version < 3000) {
+               session_range_location = new Location (0, 0, _("session"), Location::IsSessionRange);
+               locations.push_back (session_range_location);
+       }
+
        {
                Glib::Mutex::Lock lm (lock);
 
@@ -676,7 +652,39 @@ Locations::set_state (const XMLNode& node, int /*version*/)
                        try {
 
                                Location *loc = new Location (**niter);
-                               locations.push_back (loc);
+
+                               bool add = true;
+
+                               if (version < 3000) {
+                                       /* look for old-style IsStart / IsEnd properties in this location;
+                                          if they are present, update the session_range_location accordingly
+                                       */
+                                       XMLProperty const * prop = (*niter)->property ("flags");
+                                       if (prop) {
+                                               string v = prop->value ();
+                                               while (1) {
+                                                       string::size_type const c = v.find_first_of (',');
+                                                       string const s = v.substr (0, c);
+                                                       if (s == X_("IsStart")) {
+                                                               session_range_location->set_start (loc->start());
+                                                               add = false;
+                                                       } else if (s == X_("IsEnd")) {
+                                                               session_range_location->set_end (loc->start());
+                                                               add = false;
+                                                       }
+
+                                                       if (c == string::npos) {
+                                                               break;
+                                                       }
+
+                                                       v = v.substr (c + 1);
+                                               }
+                                       }
+                               }
+
+                               if (add) {
+                                       locations.push_back (loc);
+                               }
                        }
 
                        catch (failed_constructor& err) {
@@ -685,7 +693,6 @@ Locations::set_state (const XMLNode& node, int /*version*/)
                }
 
                if (locations.size()) {
-
                        current_location = locations.front();
                } else {
                        current_location = 0;