logic rearrangement to avoid unnecessary call to Route::monitoring_state() in instrum...
[ardour.git] / libs / ardour / location.cc
index e780923da6b0db168e9739452882f86bab76c1fe..4482876973bd74d54866adb0f6f0d90f5b2aaee6 100644 (file)
@@ -1,19 +1,19 @@
 /*
-  Copyright (C) 2000 Paul Davis
+    Copyright (C) 2000 Paul Davis
 
-  This program is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
 
-  This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
 
-  You should have received a copy of the GNU General Public License
-  along with this program; if not, write to the Free Software
-  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
 */
 
@@ -58,7 +58,6 @@ Location::Location (Session& s)
        , _flags (Flags (0))
        , _locked (false)
        , _position_lock_style (AudioTime)
-       , _block_change_notifications (false)
 {
        assert (_start >= 0);
        assert (_end >= 0);
@@ -73,7 +72,7 @@ Location::Location (Session& s, framepos_t sample_start, framepos_t sample_end,
        , _flags (bits)
        , _locked (false)
        , _position_lock_style (s.config.get_glue_new_markers_to_bars_and_beats() ? MusicTime : AudioTime)
-       , _block_change_notifications (false)
+
 {
        recompute_bbt_from_frames ();
 
@@ -91,7 +90,7 @@ Location::Location (const Location& other)
        , _bbt_end (other._bbt_end)
        , _flags (other._flags)
        , _position_lock_style (other._position_lock_style)
-       , _block_change_notifications (false)
+
 {
        /* copy is not locked even if original was */
 
@@ -105,6 +104,7 @@ Location::Location (const Location& other)
 
 Location::Location (Session& s, const XMLNode& node)
        : SessionHandleRef (s)
+       , _flags (Flags (0))
        , _position_lock_style (AudioTime)
 {
        /* Note: _position_lock_style is initialised above in case set_state doesn't set it
@@ -408,12 +408,9 @@ Location::set (framepos_t s, framepos_t e, bool allow_bbt_recompute)
 
        if (start_change && end_change) {
                changed (this);
-            
-               if (!_block_change_notifications) {
-                       Changed ();
-               }
+               Changed ();
        }
-        
+
        return 0;
 }
 
@@ -434,10 +431,7 @@ Location::move_to (framepos_t pos)
                recompute_bbt_from_frames ();
 
                changed (this); /* EMIT SIGNAL */
-        
-               if (!_block_change_notifications) {
-                       Changed (); /* EMIT SIGNAL */
-               }
+               Changed (); /* EMIT SIGNAL */
        }
 
        assert (_start >= 0);
@@ -652,8 +646,13 @@ Location::set_state (const XMLNode& node, int version)
                return -1;
        }
 
+       Flags old_flags (_flags);
        _flags = Flags (string_2_enum (prop->value(), _flags));
 
+       if (old_flags != _flags) {
+               FlagsChanged ();
+       }
+
        if ((prop = node.property ("locked")) != 0) {
                _locked = string_is_affirmative (prop->value());
        } else {
@@ -697,10 +696,7 @@ Location::set_state (const XMLNode& node, int version)
        recompute_bbt_from_frames ();
 
        changed (this); /* EMIT SIGNAL */
-    
-       if (!_block_change_notifications) {
-               Changed (); /* EMIT SIGNAL */
-       }
+       Changed (); /* EMIT SIGNAL */
 
        assert (_start >= 0);
        assert (_end >= 0);
@@ -764,9 +760,13 @@ Location::unlock ()
 void
 Location::set_scene_change (boost::shared_ptr<SceneChange>  sc)
 {
-       _scene_change = sc;
-
-       scene_changed (); /* EMIT SIGNAL */
+        if (_scene_change != sc) {
+                _scene_change = sc;
+                _session.set_dirty ();
+                
+                scene_changed (); /* EMIT SIGNAL */
+                SceneChangeChanged (); /* EMIT SIGNAL */
+        }
 }
 
 /*---------------------------------------------------------------------- */
@@ -829,8 +829,12 @@ Locations::next_available_name(string& result,string base)
                        const string& temp ((*i)->name());
                         
                        if (!temp.find (base,0)) {
-
-                               if ((suffix = atoi (temp.substr(l,3))) != 0) {
+                               /* grab what comes after the "base" as if it was
+                                  a number, and assuming that works OK,
+                                  store it in "taken" so that we know it
+                                  has been used.
+                               */
+                                if ((suffix = atoi (temp.substr(l))) != 0) {
                                        taken.insert (make_pair (suffix,true));
                                }
                        }
@@ -1083,9 +1087,7 @@ Locations::set_state (const XMLNode& node, int version)
                                        loc = *i;
                     
                                        // changed locations will be updated by Locations::changed signal
-                                       loc->set_block_change_notifications (true);
                                        loc->set_state (**niter, version);
-                                       loc->set_block_change_notifications (false);
                                } else {
                                        loc = new Location (_session, **niter);
                                }
@@ -1129,6 +1131,30 @@ Locations::set_state (const XMLNode& node, int version)
                        }
                }
 
+               /* We may have some unused locations in the old list. */
+               for (LocationList::iterator i = locations.begin(); i != locations.end(); ) {
+                       LocationList::iterator tmp = i;
+                       ++tmp;
+
+                       LocationList::iterator n = new_locations.begin();
+                       bool found = false;
+
+                       while (n != new_locations.end ()) {
+                               if ((*i)->id() == (*n)->id()) {
+                                       found = true;
+                                       break;
+                               }
+                               ++n;
+                       }
+
+                       if (!found) {
+                               delete *i;
+                               locations.erase (i);
+                       }
+
+                       i = tmp;
+               }
+
                locations = new_locations;
 
                if (locations.size()) {