assert() to help find some possible causes of #2991. Fix some confusion with GTK...
[ardour.git] / libs / ardour / source.cc
index 45cd1fb904e0536a99f791e9087b66c12af33424..239c3729c950cc570d492362c3cec3c207985602 100644 (file)
@@ -36,7 +36,7 @@
 #include "pbd/pthread_utils.h"
 #include "pbd/enumwriter.h"
 
-#include "ardour/playlist.h"
+#include "ardour/debug.h"
 #include "ardour/session.h"
 #include "ardour/source.h"
 #include "ardour/transient_detector.h"
@@ -54,7 +54,6 @@ Source::Source (Session& s, DataType type, const string& name, Flag flags)
 {
        _analysed = false;
        _timestamp = 0;
-       _in_use = 0;
        fix_writable_flags ();
 }
 
@@ -66,9 +65,8 @@ Source::Source (Session& s, const XMLNode& node)
 {
        _timestamp = 0;
        _analysed = false;
-       _in_use = 0;
 
-       if (set_state (node) || _type == DataType::NIL) {
+       if (set_state (node, Stateful::loading_state_version) || _type == DataType::NIL) {
                throw failed_constructor();
        }
 
@@ -77,10 +75,9 @@ Source::Source (Session& s, const XMLNode& node)
 
 Source::~Source ()
 {
-       notify_callbacks ();
+       DEBUG_TRACE (DEBUG::Destruction, string_compose ("Source %1 destructor %2\n", _name, this));
 }
 
-
 void
 Source::fix_writable_flags ()
 {
@@ -110,7 +107,7 @@ Source::get_state ()
 }
 
 int
-Source::set_state (const XMLNode& node)
+Source::set_state (const XMLNode& node, int /*version*/)
 {
        const XMLProperty* prop;
 
@@ -149,52 +146,6 @@ Source::set_state (const XMLNode& node)
        return 0;
 }
 
-void
-Source::add_playlist (boost::shared_ptr<Playlist> pl)
-{
-       std::pair<PlaylistMap::iterator,bool> res;
-       std::pair<boost::shared_ptr<Playlist>, uint32_t> newpair (pl, 1);
-       Glib::Mutex::Lock lm (_playlist_lock);
-
-       res = _playlists.insert (newpair);
-
-       if (!res.second) {
-               /* it already existed, bump count */
-               res.first->second++;
-       }
-
-       pl->GoingAway.connect (bind (
-                       mem_fun (*this, &Source::remove_playlist),
-                       boost::weak_ptr<Playlist> (pl)));
-}
-
-void
-Source::remove_playlist (boost::weak_ptr<Playlist> wpl)
-{
-       boost::shared_ptr<Playlist> pl (wpl.lock());
-
-       if (!pl) {
-               return;
-       }
-
-       PlaylistMap::iterator x;
-       Glib::Mutex::Lock lm (_playlist_lock);
-
-       if ((x = _playlists.find (pl)) != _playlists.end()) {
-               if (x->second > 1) {
-                       x->second--;
-               } else {
-                       _playlists.erase (x);
-               }
-       }
-}
-
-uint32_t
-Source::used () const
-{
-       return _playlists.size();
-}
-
 bool
 Source::has_been_analysed() const
 {
@@ -286,10 +237,12 @@ Source::check_for_analysis_data_on_disk ()
 void
 Source::mark_for_remove ()
 {
-       // This operation is not allowed for sources for destructive tracks or embedded files.
-       // Fortunately mark_for_remove() is never called for embedded files. This function
-       // must be fixed if that ever happens.
-       if (_flags & Destructive) {
+       // This operation is not allowed for sources for destructive tracks or out-of-session files.
+
+       /* XXX need a way to detect _within_session() condition here - move it from FileSource? 
+        */
+
+       if ((_flags & Destructive)) { 
                return;
        }