fix crash when copy'ing latent plugins
[ardour.git] / libs / ardour / session_playlists.cc
index b586ab196ebd318d65f09d9951fe86fa815664ac..95982b6158932bfc0f0c842f7af7d79cebc2ebef 100644 (file)
@@ -23,7 +23,7 @@
 #include "ardour/playlist_factory.h"
 #include "ardour/session_playlists.h"
 #include "ardour/track.h"
-#include "i18n.h"
+#include "pbd/i18n.h"
 #include "pbd/compose.h"
 #include "pbd/xml++.h"
 
@@ -244,7 +244,6 @@ SessionPlaylists::destroy_region (boost::shared_ptr<Region> r)
        }
 }
 
-
 void
 SessionPlaylists::find_equivalent_playlist_regions (boost::shared_ptr<Region> region, vector<boost::shared_ptr<Region> >& result)
 {
@@ -260,6 +259,10 @@ SessionPlaylists::source_use_count (boost::shared_ptr<const Source> src) const
 {
        uint32_t count = 0;
 
+       /* XXXX this can go wildly wrong in the presence of circular references
+        * between compound regions.
+        */
+
        for (List::const_iterator p = playlists.begin(); p != playlists.end(); ++p) {
                 if ((*p)->uses_source (src)) {
                         ++count;
@@ -333,15 +336,39 @@ SessionPlaylists::maybe_delete_unused (boost::function<int(boost::shared_ptr<Pla
 {
        vector<boost::shared_ptr<Playlist> > playlists_tbd;
 
+       bool delete_remaining = false;
+       bool keep_remaining = false;
+
        for (List::iterator x = unused_playlists.begin(); x != unused_playlists.end(); ++x) {
 
+               if (keep_remaining) {
+                       break;
+               }
+
+               if (delete_remaining) {
+                       playlists_tbd.push_back (*x);
+                       continue;
+               }
+
                int status = ask (*x);
 
                switch (status) {
                case -1:
+                       // abort
                        return true;
 
-               case 0:
+               case -2:
+                       // keep this and all later
+                       keep_remaining = true;
+                       break;
+
+               case 2:
+                       // delete this and all later
+                       delete_remaining = true;
+                       // no break;
+
+               case 1:
+                       // delete this
                        playlists_tbd.push_back (*x);
                        break;
 
@@ -465,7 +492,7 @@ SessionPlaylists::playlists_for_track (boost::shared_ptr<Track> tr) const
 {
        vector<boost::shared_ptr<Playlist> > pl;
        get (pl);
-       
+
        vector<boost::shared_ptr<Playlist> > pl_tr;
 
        for (vector<boost::shared_ptr<Playlist> >::iterator i = pl.begin(); i != pl.end(); ++i) {
@@ -476,3 +503,19 @@ SessionPlaylists::playlists_for_track (boost::shared_ptr<Track> tr) const
 
        return pl_tr;
 }
+
+void
+SessionPlaylists::foreach (boost::function<void(boost::shared_ptr<const Playlist>)> functor)
+{
+       Glib::Threads::Mutex::Lock lm (lock);
+       for (List::iterator i = playlists.begin(); i != playlists.end(); i++) {
+               if (!(*i)->hidden()) {
+                       functor (*i);
+               }
+       }
+       for (List::iterator i = unused_playlists.begin(); i != unused_playlists.end(); i++) {
+               if (!(*i)->hidden()) {
+                       functor (*i);
+               }
+       }
+}