Merge with trunk R2978.
[ardour.git] / libs / ardour / source.cc
index db2147493aaf971e4ea353e8ed3fa4489a9b8568..a11e82f1e81b245e912ca9f3e2a1439ee2fbd71c 100644 (file)
@@ -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 <sys/stat.h>
@@ -43,20 +42,20 @@ using std::max;
 
 using namespace ARDOUR;
 
-Source::Source (Session& s, string name, DataType type)
-       : _session (s)
+Source::Source (Session& s, const string& name, DataType type)
+       : SessionObject(s, name)
        , _type(type)
 {
-       assert(_name.find("/") == string::npos);
+       // not true.. is this supposed to be an assertion?
+       //assert(_name.find("/") == string::npos);
 
-       _name = name;
        _timestamp = 0;
        _length = 0;
        _in_use = 0;
 }
 
 Source::Source (Session& s, const XMLNode& node) 
-       : _session (s)
+       : SessionObject(s, "unnamed source")
        , _type(DataType::AUDIO)
 {
        _timestamp = 0;
@@ -66,7 +65,6 @@ Source::Source (Session& s, const XMLNode& node)
        if (set_state (node) || _type == DataType::NIL) {
                throw failed_constructor();
        }
-       assert(_name.find("/") == string::npos);
 }
 
 Source::~Source ()
@@ -117,13 +115,15 @@ Source::set_state (const XMLNode& node)
        if ((prop = node.property ("timestamp")) != 0) {
                sscanf (prop->value().c_str(), "%ld", &_timestamp);
        }
-       assert(_name.find("/") == string::npos);
+       
+       // Don't think this is valid, absolute paths fail
+       //assert(_name.find("/") == string::npos);
 
        return 0;
 }
 
 void
-Source::update_length (jack_nframes_t pos, jack_nframes_t cnt)
+Source::update_length (nframes_t pos, nframes_t cnt)
 {
        if (pos + cnt > _length) {
                _length = pos+cnt;
@@ -133,7 +133,17 @@ Source::update_length (jack_nframes_t pos, jack_nframes_t cnt)
 void
 Source::add_playlist (boost::shared_ptr<Playlist> pl)
 {
-       _playlists.insert (pl);
+       std::pair<PlaylistMap::iterator,bool> res;
+       std::pair<boost::shared_ptr<Playlist>, 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<Playlist> (pl)));
 }
 
@@ -146,10 +156,15 @@ Source::remove_playlist (boost::weak_ptr<Playlist> wpl)
                return;
        }
 
-       std::set<boost::shared_ptr<Playlist> >::iterator x;
+       PlaylistMap::iterator x;
+       Glib::Mutex::Lock lm (playlist_lock);
 
        if ((x = _playlists.find (pl)) != _playlists.end()) {
-               _playlists.erase (x);
+               if (x->second > 1) {
+                       x->second--;
+               } else {
+                       _playlists.erase (x);
+               }
        }
 }