X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fsession_playlists.cc;h=b2c4640880284bf0d83364fe0946265e383167b6;hb=5e1cfcc7ed557fc28ca8b362deceefa1967ab22b;hp=0d32ea75d74f0e07681af1806b3b9858a927e321;hpb=aae367b63c9b619db1e40f27dc334c6987219481;p=ardour.git diff --git a/libs/ardour/session_playlists.cc b/libs/ardour/session_playlists.cc index 0d32ea75d7..b2c4640880 100644 --- a/libs/ardour/session_playlists.cc +++ b/libs/ardour/session_playlists.cc @@ -18,15 +18,14 @@ */ #include -#include "pbd/xml++.h" -#include "pbd/compose.h" #include "ardour/debug.h" -#include "ardour/session_playlists.h" #include "ardour/playlist.h" -#include "ardour/region.h" #include "ardour/playlist_factory.h" -#include "ardour/session.h" +#include "ardour/session_playlists.h" +#include "ardour/track.h" #include "i18n.h" +#include "pbd/compose.h" +#include "pbd/xml++.h" using namespace std; using namespace PBD; @@ -35,7 +34,7 @@ using namespace ARDOUR; SessionPlaylists::~SessionPlaylists () { DEBUG_TRACE (DEBUG::Destruction, "delete playlists\n"); - + for (List::iterator i = playlists.begin(); i != playlists.end(); ) { SessionPlaylists::List::iterator tmp; @@ -43,6 +42,7 @@ SessionPlaylists::~SessionPlaylists () ++tmp; DEBUG_TRACE(DEBUG::Destruction, string_compose ("Dropping for used playlist %1 ; pre-ref = %2\n", (*i)->name(), (*i).use_count())); + boost::shared_ptr keeper (*i); (*i)->drop_references (); i = tmp; @@ -56,6 +56,7 @@ SessionPlaylists::~SessionPlaylists () ++tmp; DEBUG_TRACE(DEBUG::Destruction, string_compose ("Dropping for unused playlist %1 ; pre-ref = %2\n", (*i)->name(), (*i).use_count())); + boost::shared_ptr keeper (*i); (*i)->drop_references (); i = tmp; @@ -68,22 +69,34 @@ SessionPlaylists::~SessionPlaylists () bool SessionPlaylists::add (boost::shared_ptr playlist) { - Glib::Mutex::Lock lm (lock); + Glib::Threads::Mutex::Lock lm (lock); bool const existing = find (playlists.begin(), playlists.end(), playlist) != playlists.end(); if (!existing) { playlists.insert (playlists.begin(), playlist); - playlist->InUse.connect (*this, boost::bind (&SessionPlaylists::track, this, _1, boost::weak_ptr(playlist))); + playlist->InUse.connect_same_thread (*this, boost::bind (&SessionPlaylists::track, this, _1, boost::weak_ptr(playlist))); + playlist->DropReferences.connect_same_thread ( + *this, boost::bind (&SessionPlaylists::remove_weak, this, boost::weak_ptr (playlist)) + ); } return existing; } +void +SessionPlaylists::remove_weak (boost::weak_ptr playlist) +{ + boost::shared_ptr p = playlist.lock (); + if (p) { + remove (p); + } +} + void SessionPlaylists::remove (boost::shared_ptr playlist) { - Glib::Mutex::Lock lm (lock); + Glib::Threads::Mutex::Lock lm (lock); List::iterator i; @@ -97,7 +110,7 @@ SessionPlaylists::remove (boost::shared_ptr playlist) unused_playlists.erase (i); } } - + void SessionPlaylists::track (bool inuse, boost::weak_ptr wpl) @@ -116,7 +129,7 @@ SessionPlaylists::track (bool inuse, boost::weak_ptr wpl) } { - Glib::Mutex::Lock lm (lock); + Glib::Threads::Mutex::Lock lm (lock); if (!inuse) { @@ -141,21 +154,21 @@ SessionPlaylists::track (bool inuse, boost::weak_ptr wpl) uint32_t SessionPlaylists::n_playlists () const { - Glib::Mutex::Lock lm (lock); + Glib::Threads::Mutex::Lock lm (lock); return playlists.size(); } boost::shared_ptr SessionPlaylists::by_name (string name) { - Glib::Mutex::Lock lm (lock); + Glib::Threads::Mutex::Lock lm (lock); for (List::iterator i = playlists.begin(); i != playlists.end(); ++i) { if ((*i)->name() == name) { return* i; } } - + for (List::iterator i = unused_playlists.begin(); i != unused_playlists.end(); ++i) { if ((*i)->name() == name) { return* i; @@ -165,38 +178,73 @@ SessionPlaylists::by_name (string name) return boost::shared_ptr(); } +boost::shared_ptr +SessionPlaylists::by_id (const PBD::ID& id) +{ + Glib::Threads::Mutex::Lock lm (lock); + + for (List::iterator i = playlists.begin(); i != playlists.end(); ++i) { + if ((*i)->id() == id) { + return* i; + } + } + + for (List::iterator i = unused_playlists.begin(); i != unused_playlists.end(); ++i) { + if ((*i)->id() == id) { + return* i; + } + } + + return boost::shared_ptr(); +} + void SessionPlaylists::unassigned (std::list > & list) { - Glib::Mutex::Lock lm (lock); + Glib::Threads::Mutex::Lock lm (lock); for (List::iterator i = playlists.begin(); i != playlists.end(); ++i) { - if (!(*i)->get_orig_diskstream_id().to_s().compare ("0")) { + if (!(*i)->get_orig_track_id().to_s().compare ("0")) { list.push_back (*i); } } - + for (List::iterator i = unused_playlists.begin(); i != unused_playlists.end(); ++i) { - if (!(*i)->get_orig_diskstream_id().to_s().compare ("0")) { + if (!(*i)->get_orig_track_id().to_s().compare ("0")) { list.push_back (*i); } } } void -SessionPlaylists::get (vector >& s) +SessionPlaylists::get (vector >& s) const { - Glib::Mutex::Lock lm (lock); + Glib::Threads::Mutex::Lock lm (lock); for (List::iterator i = playlists.begin(); i != playlists.end(); ++i) { s.push_back (*i); } - + for (List::iterator i = unused_playlists.begin(); i != unused_playlists.end(); ++i) { s.push_back (*i); } } +void +SessionPlaylists::destroy_region (boost::shared_ptr r) +{ + Glib::Threads::Mutex::Lock lm (lock); + + for (List::iterator i = playlists.begin(); i != playlists.end(); ++i) { + (*i)->destroy_region (r); + } + + for (List::iterator i = unused_playlists.begin(); i != unused_playlists.end(); ++i) { + (*i)->destroy_region (r); + } +} + + void SessionPlaylists::find_equivalent_playlist_regions (boost::shared_ptr region, vector >& result) { @@ -204,23 +252,40 @@ SessionPlaylists::find_equivalent_playlist_regions (boost::shared_ptr re (*i)->get_region_list_equivalent_regions (region, result); } -/** Return the number of playlists (not regions) that contain @a src */ +/** Return the number of playlists (not regions) that contain @a src + * Important: this counts usage in both used and not-used playlists. + */ uint32_t SessionPlaylists::source_use_count (boost::shared_ptr src) const { uint32_t count = 0; + for (List::const_iterator p = playlists.begin(); p != playlists.end(); ++p) { - for (Playlist::RegionList::const_iterator r = (*p)->region_list().begin(); - r != (*p)->region_list().end(); ++r) { - if ((*r)->uses_source(src)) { - ++count; - break; - } - } + if ((*p)->uses_source (src)) { + ++count; + break; + } + } + + for (List::const_iterator p = unused_playlists.begin(); p != unused_playlists.end(); ++p) { + if ((*p)->uses_source (src)) { + ++count; + break; + } } + return count; } +void +SessionPlaylists::sync_all_regions_with_regions () +{ + Glib::Threads::Mutex::Lock lm (lock); + + for (List::const_iterator p = playlists.begin(); p != playlists.end(); ++p) { + (*p)->sync_all_regions_with_regions (); + } +} void SessionPlaylists::update_after_tempo_map_change () @@ -240,14 +305,12 @@ SessionPlaylists::add_state (XMLNode* node, bool full_state) XMLNode* child = node->add_child ("Playlists"); for (List::iterator i = playlists.begin(); i != playlists.end(); ++i) { if (!(*i)->hidden()) { - if (!(*i)->empty()) { - if (full_state) { - child->add_child_nocopy ((*i)->get_state()); - } else { - child->add_child_nocopy ((*i)->get_template()); - } - } - } + if (full_state) { + child->add_child_nocopy ((*i)->get_state()); + } else { + child->add_child_nocopy ((*i)->get_template()); + } + } } child = node->add_child ("UnusedPlaylists"); @@ -291,6 +354,7 @@ SessionPlaylists::maybe_delete_unused (boost::function >::iterator x = playlists_tbd.begin(); x != playlists_tbd.end(); ++x) { + boost::shared_ptr keeper (*x); (*x)->drop_references (); } @@ -354,3 +418,61 @@ SessionPlaylists::XMLPlaylistFactory (Session& session, const XMLNode& node) } } +boost::shared_ptr +SessionPlaylists::find_crossfade (const PBD::ID& id) +{ + Glib::Threads::Mutex::Lock lm (lock); + + boost::shared_ptr c; + + for (List::iterator i = playlists.begin(); i != playlists.end(); ++i) { + c = (*i)->find_crossfade (id); + if (c) { + return c; + } + } + + for (List::iterator i = unused_playlists.begin(); i != unused_playlists.end(); ++i) { + c = (*i)->find_crossfade (id); + if (c) { + return c; + } + } + + return boost::shared_ptr (); +} + +uint32_t +SessionPlaylists::region_use_count (boost::shared_ptr region) const +{ + Glib::Threads::Mutex::Lock lm (lock); + uint32_t cnt = 0; + + for (List::iterator i = playlists.begin(); i != playlists.end(); ++i) { + cnt += (*i)->region_use_count (region); + } + + for (List::iterator i = unused_playlists.begin(); i != unused_playlists.end(); ++i) { + cnt += (*i)->region_use_count (region); + } + + return cnt; +} + +/** @return list of Playlists that are associated with a track */ +vector > +SessionPlaylists::playlists_for_track (boost::shared_ptr tr) const +{ + vector > pl; + get (pl); + + vector > pl_tr; + + for (vector >::iterator i = pl.begin(); i != pl.end(); ++i) { + if (((*i)->get_orig_track_id() == tr->id()) || (tr->playlist()->id() == (*i)->id())) { + pl_tr.push_back (*i); + } + } + + return pl_tr; +}