X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fsource.cc;h=a11e82f1e81b245e912ca9f3e2a1439ee2fbd71c;hb=8ab17e96312f1a61c014c50687e15430d5ae786b;hp=0d32ea4a216ec6134dbb93281819747bd24ec8c5;hpb=7ff370e79895d7eb293e7214689b791bd98415fb;p=ardour.git diff --git a/libs/ardour/source.cc b/libs/ardour/source.cc index 0d32ea4a21..a11e82f1e8 100644 --- a/libs/ardour/source.cc +++ b/libs/ardour/source.cc @@ -15,7 +15,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #include @@ -34,6 +33,7 @@ #include #include +#include #include "i18n.h" @@ -42,26 +42,34 @@ using std::max; using namespace ARDOUR; -Source::Source (string name) +Source::Source (Session& s, const string& name, DataType type) + : SessionObject(s, name) + , _type(type) { - _name = name; - _id = ARDOUR::new_id(); - _use_cnt = 0; + // not true.. is this supposed to be an assertion? + //assert(_name.find("/") == string::npos); + _timestamp = 0; + _length = 0; + _in_use = 0; } -Source::Source (const XMLNode& node) +Source::Source (Session& s, const XMLNode& node) + : SessionObject(s, "unnamed source") + , _type(DataType::AUDIO) { - _use_cnt = 0; _timestamp = 0; + _length = 0; + _in_use = 0; - if (set_state (node)) { + if (set_state (node) || _type == DataType::NIL) { throw failed_constructor(); } } Source::~Source () { + notify_callbacks (); } XMLNode& @@ -71,7 +79,8 @@ Source::get_state () char buf[64]; node->add_property ("name", _name); - snprintf (buf, sizeof(buf)-1, "%" PRIu64, _id); + node->add_property ("type", _type.to_string()); + _id.print (buf, sizeof (buf)); node->add_property ("id", buf); if (_timestamp != 0) { @@ -94,27 +103,73 @@ 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; } + if ((prop = node.property ("type")) != 0) { + _type = DataType(prop->value()); + } + if ((prop = node.property ("timestamp")) != 0) { sscanf (prop->value().c_str(), "%ld", &_timestamp); } + + // Don't think this is valid, absolute paths fail + //assert(_name.find("/") == string::npos); return 0; } void -Source::use () +Source::update_length (nframes_t pos, nframes_t cnt) { - _use_cnt++; + if (pos + cnt > _length) { + _length = pos+cnt; + } } void -Source::release () +Source::add_playlist (boost::shared_ptr pl) { - if (_use_cnt) --_use_cnt; + std::pair res; + std::pair, 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 (pl))); } +void +Source::remove_playlist (boost::weak_ptr wpl) +{ + boost::shared_ptr 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(); +}