major fixes to automation editing
[ardour.git] / libs / ardour / source.cc
index 0d32ea4a216ec6134dbb93281819747bd24ec8c5..74ca0afcd4bb932fe36605762cd43a7d7fe85f43 100644 (file)
@@ -34,6 +34,7 @@
 #include <pbd/pthread_utils.h>
 
 #include <ardour/source.h>
+#include <ardour/playlist.h>
 
 #include "i18n.h"
 
@@ -42,18 +43,19 @@ using std::max;
 
 using namespace ARDOUR;
 
-Source::Source (string name)
+Source::Source (Session& s, string name)
+       : _session (s)
 {
        _name = name;
-       _id = ARDOUR::new_id();
-       _use_cnt = 0;
        _timestamp = 0;
+       _in_use = 0;
 }
 
-Source::Source (const XMLNode& node) 
+Source::Source (Session& s, const XMLNode& node) 
+       : _session (s)
 {
-       _use_cnt = 0;
        _timestamp = 0;
+       _in_use = 0;
 
        if (set_state (node)) {
                throw failed_constructor();
@@ -62,6 +64,7 @@ Source::Source (const XMLNode& node)
 
 Source::~Source ()
 {
+       notify_callbacks ();
 }
 
 XMLNode&
@@ -71,7 +74,7 @@ Source::get_state ()
        char buf[64];
 
        node->add_property ("name", _name);
-       snprintf (buf, sizeof(buf)-1, "%" PRIu64, _id);
+       _id.print (buf, sizeof (buf));
        node->add_property ("id", buf);
 
        if (_timestamp != 0) {
@@ -94,7 +97,7 @@ Source::set_state (const XMLNode& node)
        }
        
        if ((prop = node.property ("id")) != 0) {
-               sscanf (prop->value().c_str(), "%" PRIu64, &_id);
+               _id = prop->value ();
        } else {
                return -1;
        }
@@ -107,14 +110,23 @@ Source::set_state (const XMLNode& node)
 }
 
 void
-Source::use ()
+Source::add_playlist (Playlist* pl)
 {
-       _use_cnt++;
+       _playlists.insert (pl);
 }
 
 void
-Source::release ()
+Source::remove_playlist (Playlist* pl)
 {
-       if (_use_cnt) --_use_cnt;
+       std::set<Playlist*>::iterator x;
+
+       if ((x = _playlists.find (pl)) != _playlists.end()) {
+               _playlists.erase (x);
+       }
 }
 
+uint32_t
+Source::used () const
+{
+       return _playlists.size();
+}