Merged with trunk R1283.
[ardour.git] / libs / ardour / source.cc
index 0b15a8b5b8b7cdfb2c86ca53311e3e06bb94fd1f..db2147493aaf971e4ea353e8ed3fa4489a9b8568 100644 (file)
@@ -34,6 +34,7 @@
 #include <pbd/pthread_utils.h>
 
 #include <ardour/source.h>
+#include <ardour/playlist.h>
 
 #include "i18n.h"
 
@@ -42,26 +43,25 @@ using std::max;
 
 using namespace ARDOUR;
 
-sigc::signal<void,Source*> Source::SourceCreated;
-
-
-Source::Source (string name, DataType type)
-       : _type(type)
+Source::Source (Session& s, string name, DataType type)
+       : _session (s)
+       , _type(type)
 {
        assert(_name.find("/") == string::npos);
 
        _name = name;
-       _use_cnt = 0;
        _timestamp = 0;
        _length = 0;
+       _in_use = 0;
 }
 
-Source::Source (const XMLNode& node) 
-       : _type(DataType::AUDIO)
+Source::Source (Session& s, const XMLNode& node) 
+       : _session (s)
+       , _type(DataType::AUDIO)
 {
-       _use_cnt = 0;
        _timestamp = 0;
        _length = 0;
+       _in_use = 0;
 
        if (set_state (node) || _type == DataType::NIL) {
                throw failed_constructor();
@@ -71,6 +71,7 @@ Source::Source (const XMLNode& node)
 
 Source::~Source ()
 {
+       notify_callbacks ();
 }
 
 XMLNode&
@@ -81,7 +82,7 @@ Source::get_state ()
 
        node->add_property ("name", _name);
        node->add_property ("type", _type.to_string());
-       _id.print (buf);
+       _id.print (buf, sizeof (buf));
        node->add_property ("id", buf);
 
        if (_timestamp != 0) {
@@ -122,22 +123,38 @@ Source::set_state (const XMLNode& node)
 }
 
 void
-Source::use ()
+Source::update_length (jack_nframes_t pos, jack_nframes_t cnt)
 {
-       _use_cnt++;
+       if (pos + cnt > _length) {
+               _length = pos+cnt;
+       }
 }
 
 void
-Source::release ()
+Source::add_playlist (boost::shared_ptr<Playlist> pl)
 {
-       if (_use_cnt) --_use_cnt;
+       _playlists.insert (pl);
+       pl->GoingAway.connect (bind (mem_fun (*this, &Source::remove_playlist), boost::weak_ptr<Playlist> (pl)));
 }
 
 void
-Source::update_length (jack_nframes_t pos, jack_nframes_t cnt)
+Source::remove_playlist (boost::weak_ptr<Playlist> wpl)
 {
-       if (pos + cnt > _length) {
-               _length = pos+cnt;
+       boost::shared_ptr<Playlist> pl (wpl.lock());
+
+       if (!pl) {
+               return;
+       }
+
+       std::set<boost::shared_ptr<Playlist> >::iterator x;
+
+       if ((x = _playlists.find (pl)) != _playlists.end()) {
+               _playlists.erase (x);
        }
 }
 
+uint32_t
+Source::used () const
+{
+       return _playlists.size();
+}