Fix incorrectly saved un-used playlists
authorRobin Gareus <robin@gareus.org>
Tue, 19 Mar 2019 20:56:13 +0000 (21:56 +0100)
committerRobin Gareus <robin@gareus.org>
Tue, 19 Mar 2019 21:05:06 +0000 (22:05 +0100)
This addresses issues with session-cleanup and region-cleanup in
some sessions.

The root-cause why some unused playlists were saved in the session XML
under <Playlists> and not <UnusedPlaylists> is not known.

Early 6.0-pre did incorrect reference counting, but also older sessions
had this issue. Perhaps due to ambiguities of matching playlists
by name in 5.x or session-format changes 3.x .. 5.x.

libs/ardour/ardour/session_playlists.h
libs/ardour/session_playlists.cc
libs/ardour/session_state.cc

index 226680f6eb0f19ad7673fa1aeeef912f8219adc8..865ad9ed3961bd7a0afe70945f1c84830ab89ba3 100644 (file)
@@ -72,6 +72,7 @@ private:
        void remove (boost::shared_ptr<Playlist>);
        void remove_weak (boost::weak_ptr<Playlist>);
        void track (bool, boost::weak_ptr<Playlist>);
+       void update_tracking ();
 
        void find_equivalent_playlist_regions (boost::shared_ptr<Region>, std::vector<boost::shared_ptr<Region> >& result);
        void update_after_tempo_map_change ();
index d0468b981e14964ad7c653c411380c4961dd8026..4ee92d26496bbdc647c8b16ccabeb0a4ac87cf65 100644 (file)
@@ -111,6 +111,30 @@ SessionPlaylists::remove (boost::shared_ptr<Playlist> playlist)
        }
 }
 
+void
+SessionPlaylists::update_tracking ()
+{
+       /* This is intended to be called during session-load, after loading
+        * playlists and re-assigning them to tracks (refcnt is up to date).
+        * Check playlist refcnt, move unused playlist to unused_playlists
+        * array (which may be the case when loading old sessions)
+        */
+       for (List::iterator i = playlists.begin(); i != playlists.end(); ) {
+               if ((*i)->hidden () || (*i)->used ()) {
+                       ++i;
+                       continue;
+               }
+
+               warning << _("Session State: Unused playlist was listed as used.") << endmsg;
+
+               assert (unused_playlists.find (*i) == unused_playlists.end());
+               unused_playlists.insert (*i);
+
+               List::iterator rm = i;
+               ++i;
+                playlists.erase (rm);
+       }
+}
 
 void
 SessionPlaylists::track (bool inuse, boost::weak_ptr<Playlist> wpl)
index 8e08630471b206029d4431c61090ad409f64b21b..534bd4b9bb8f073ec3c38ce9b0657810eb9313a0 100644 (file)
@@ -1702,6 +1702,9 @@ Session::set_state (const XMLNode& node, int version)
                goto out;
        }
 
+       /* Now that we Tracks have been loaded and playlists are assigned */
+       _playlists->update_tracking ();
+
        /* Now that we have Routes and masters loaded, connect them if appropriate */
 
        Slavable::Assign (_vca_manager); /* EMIT SIGNAL */