Merged with trunk R1283.
[ardour.git] / libs / ardour / source.cc
index d218e2cf9446442523aa28c1c97d526140b9c2c1..db2147493aaf971e4ea353e8ed3fa4489a9b8568 100644 (file)
@@ -34,6 +34,7 @@
 #include <pbd/pthread_utils.h>
 
 #include <ardour/source.h>
+#include <ardour/playlist.h>
 
 #include "i18n.h"
 
@@ -42,24 +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;
        _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)
 {
        _timestamp = 0;
        _length = 0;
+       _in_use = 0;
 
        if (set_state (node) || _type == DataType::NIL) {
                throw failed_constructor();
@@ -80,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) {
@@ -128,3 +130,31 @@ Source::update_length (jack_nframes_t pos, jack_nframes_t cnt)
        }
 }
 
+void
+Source::add_playlist (boost::shared_ptr<Playlist> pl)
+{
+       _playlists.insert (pl);
+       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;
+       }
+
+       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();
+}