2.X commits up to and including 7519
[ardour.git] / libs / ardour / session_playlists.cc
index 0d32ea75d74f0e07681af1806b3b9858a927e321..38c6744d06c2864aef3b59f4ad83f584c009551c 100644 (file)
@@ -43,6 +43,7 @@ SessionPlaylists::~SessionPlaylists ()
                ++tmp;
 
                DEBUG_TRACE(DEBUG::Destruction, string_compose ("Dropping for used playlist %1 ; pre-ref = %2\n", (*i)->name(), (*i).use_count()));
+               boost::shared_ptr<Playlist> keeper (*i);
                (*i)->drop_references ();
 
                i = tmp;
@@ -56,6 +57,7 @@ SessionPlaylists::~SessionPlaylists ()
                ++tmp;
 
                DEBUG_TRACE(DEBUG::Destruction, string_compose ("Dropping for unused playlist %1 ; pre-ref = %2\n", (*i)->name(), (*i).use_count()));
+               boost::shared_ptr<Playlist> keeper (*i);
                (*i)->drop_references ();
 
                i = tmp;
@@ -74,7 +76,7 @@ SessionPlaylists::add (boost::shared_ptr<Playlist> playlist)
 
        if (!existing) {
                playlists.insert (playlists.begin(), playlist);
-               playlist->InUse.connect (*this, boost::bind (&SessionPlaylists::track, this, _1, boost::weak_ptr<Playlist>(playlist)));
+               playlist->InUse.connect_same_thread (*this, boost::bind (&SessionPlaylists::track, this, _1, boost::weak_ptr<Playlist>(playlist)));
        }
 
        return existing;
@@ -165,6 +167,26 @@ SessionPlaylists::by_name (string name)
        return boost::shared_ptr<Playlist>();
 }
 
+boost::shared_ptr<Playlist>
+SessionPlaylists::by_id (const PBD::ID& id)
+{
+       Glib::Mutex::Lock lm (lock);
+
+       for (List::iterator i = playlists.begin(); i != playlists.end(); ++i) {
+               if ((*i)->id() == id) {
+                       return* i;
+               }
+       }
+       
+       for (List::iterator i = unused_playlists.begin(); i != unused_playlists.end(); ++i) {
+               if ((*i)->id() == id) {
+                       return* i;
+               }
+       }
+
+       return boost::shared_ptr<Playlist>();
+}
+
 void
 SessionPlaylists::unassigned (std::list<boost::shared_ptr<Playlist> > & list)
 {
@@ -197,6 +219,21 @@ SessionPlaylists::get (vector<boost::shared_ptr<Playlist> >& s)
        }
 }
 
+void
+SessionPlaylists::destroy_region (boost::shared_ptr<Region> r)
+{
+       Glib::Mutex::Lock lm (lock);
+
+       for (List::iterator i = playlists.begin(); i != playlists.end(); ++i) {
+                (*i)->destroy_region (r);
+       }
+       
+       for (List::iterator i = unused_playlists.begin(); i != unused_playlists.end(); ++i) {
+                (*i)->destroy_region (r);
+       }
+}
+
+
 void
 SessionPlaylists::find_equivalent_playlist_regions (boost::shared_ptr<Region> region, vector<boost::shared_ptr<Region> >& result)
 {
@@ -240,14 +277,12 @@ SessionPlaylists::add_state (XMLNode* node, bool full_state)
        XMLNode* child = node->add_child ("Playlists");
        for (List::iterator i = playlists.begin(); i != playlists.end(); ++i) {
                if (!(*i)->hidden()) {
-                       if (!(*i)->empty()) {
-                               if (full_state) {
-                                       child->add_child_nocopy ((*i)->get_state());
-                               } else {
-                                       child->add_child_nocopy ((*i)->get_template());
-                               }
-                       }
-               }
+                        if (full_state) {
+                                child->add_child_nocopy ((*i)->get_state());
+                        } else {
+                                child->add_child_nocopy ((*i)->get_template());
+                        }
+                }
        }
 
        child = node->add_child ("UnusedPlaylists");
@@ -291,6 +326,7 @@ SessionPlaylists::maybe_delete_unused (boost::function<int(boost::shared_ptr<Pla
        /* now delete any that were marked for deletion */
 
        for (vector<boost::shared_ptr<Playlist> >::iterator x = playlists_tbd.begin(); x != playlists_tbd.end(); ++x) {
+               boost::shared_ptr<Playlist> keeper (*x);
                (*x)->drop_references ();
        }