#include <pbd/pthread_utils.h>
#include <ardour/source.h>
+#include <ardour/playlist.h>
#include "i18n.h"
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();
Source::~Source ()
{
+ notify_callbacks ();
}
XMLNode&
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) {
}
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();
+}