From 8d168bda874ae05b142e122cb48407ee4e1b442d Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 26 Oct 2009 17:24:08 +0000 Subject: Remove cyclic Source->Playlist references (and with it all dependence on Playlist from Source and children and a bunch of finicky reference managing code). git-svn-id: svn://localhost/ardour2/branches/3.0@5925 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/playlist.h | 2 + libs/ardour/ardour/region.h | 1 + libs/ardour/ardour/session.h | 2 + libs/ardour/ardour/source.h | 11 +----- libs/ardour/audio_diskstream.cc | 2 +- libs/ardour/midi_playlist.cc | 4 +- libs/ardour/playlist.cc | 2 +- libs/ardour/region.cc | 82 +++++++++++------------------------------ libs/ardour/session.cc | 17 +++++++++ libs/ardour/session_state.cc | 2 +- libs/ardour/source.cc | 47 ----------------------- 11 files changed, 49 insertions(+), 123 deletions(-) (limited to 'libs') diff --git a/libs/ardour/ardour/playlist.h b/libs/ardour/ardour/playlist.h index aa661b8588..693b2de2dd 100644 --- a/libs/ardour/ardour/playlist.h +++ b/libs/ardour/ardour/playlist.h @@ -109,6 +109,8 @@ class Playlist : public SessionObject, boost::shared_ptr copy (std::list&, bool result_is_hidden = true); int paste (boost::shared_ptr, nframes_t position, float times); + const RegionList& region_list () const { return regions; } + RegionList* regions_at (nframes_t frame); RegionList* regions_touched (nframes_t start, nframes_t end); RegionList* regions_to_read (nframes_t start, nframes_t end); diff --git a/libs/ardour/ardour/region.h b/libs/ardour/ardour/region.h index c1c7ddd5e0..7bae98e573 100644 --- a/libs/ardour/ardour/region.h +++ b/libs/ardour/ardour/region.h @@ -177,6 +177,7 @@ class Region bool overlap_equivalent (boost::shared_ptr) const; bool region_list_equivalent (boost::shared_ptr) const; bool source_equivalent (boost::shared_ptr) const; + bool uses_source (boost::shared_ptr) const; /* EDITING OPERATIONS */ diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 024b866730..d850fb96d6 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -642,6 +642,8 @@ class Session : public PBD::StatefulDestructible, public boost::noncopyable void add_source (boost::shared_ptr); void remove_source (boost::weak_ptr); + uint32_t source_use_count (boost::shared_ptr src) const; + struct cleanup_report { std::vector paths; int64_t space; diff --git a/libs/ardour/ardour/source.h b/libs/ardour/ardour/source.h index 1ffca509fd..62aca91365 100644 --- a/libs/ardour/ardour/source.h +++ b/libs/ardour/ardour/source.h @@ -35,7 +35,6 @@ namespace ARDOUR { class Session; -class Playlist; class Source : public SessionObject, public boost::noncopyable { @@ -77,7 +76,7 @@ class Source : public SessionObject, public boost::noncopyable XMLNode& get_state (); int set_state (const XMLNode&, int version); - + bool destructive() const { return (_flags & Destructive); } bool writable () const { return (_flags & Writable); } virtual bool set_destructive (bool /*yn*/) { return false; } @@ -86,11 +85,6 @@ class Source : public SessionObject, public boost::noncopyable void use () { _in_use++; } void disuse () { if (_in_use) { _in_use--; } } - void add_playlist (boost::shared_ptr); - void remove_playlist (boost::weak_ptr); - - uint32_t used() const; - static sigc::signal SourceCreated; sigc::signal > Switched; @@ -123,9 +117,6 @@ class Source : public SessionObject, public boost::noncopyable mutable Glib::Mutex _analysis_lock; Glib::Mutex _playlist_lock; - typedef std::map, uint32_t > PlaylistMap; - PlaylistMap _playlists; - private: uint32_t _in_use; void fix_writable_flags (); diff --git a/libs/ardour/audio_diskstream.cc b/libs/ardour/audio_diskstream.cc index 70b4a6bf20..fbd10b92e3 100644 --- a/libs/ardour/audio_diskstream.cc +++ b/libs/ardour/audio_diskstream.cc @@ -2305,7 +2305,7 @@ AudioDiskstream::can_become_destructive (bool& requires_bounce) const assert (afirst); - if (afirst->source()->used() > 1) { + if (_session.source_use_count (afirst->source()) > 1) { requires_bounce = true; return false; } diff --git a/libs/ardour/midi_playlist.cc b/libs/ardour/midi_playlist.cc index 2d042ffb44..a1fb01a7bb 100644 --- a/libs/ardour/midi_playlist.cc +++ b/libs/ardour/midi_playlist.cc @@ -119,7 +119,7 @@ MidiPlaylist::read (MidiRingBuffer& dst, nframes_t start, nframes_t d on, and remove it from the list we are keeping around, because we don't need it anymore. - if the end of the region (where we want to theoretically resolve notes) + if the end of the region (where we want to theoretically resolve notes) is outside the current read range, then just do it at the start of this read range. */ @@ -128,7 +128,7 @@ MidiPlaylist::read (MidiRingBuffer& dst, nframes_t start, nframes_t d if (resolve_at >= end) { resolve_at = start; } - + tracker_info.push_back (TrackerInfo (t->second, resolve_at)); DEBUG_TRACE (DEBUG::MidiPlaylistIO, string_compose ("time to resolve & remove tracker for %1 @ %2\n", (*i)->name(), resolve_at)); note_cnt += (t->second->on()); diff --git a/libs/ardour/playlist.cc b/libs/ardour/playlist.cc index a072d4977b..f57093ea40 100644 --- a/libs/ardour/playlist.cc +++ b/libs/ardour/playlist.cc @@ -505,7 +505,7 @@ Playlist::add_region (boost::shared_ptr region, nframes_t position, floa nframes_t pos = position; - if(times == 1 && auto_partition){ + if (times == 1 && auto_partition){ partition(pos, (nframes_t) (pos + region->length()), true); } diff --git a/libs/ardour/region.cc b/libs/ardour/region.cc index a881d9f1ed..20c87fb1de 100644 --- a/libs/ardour/region.cc +++ b/libs/ardour/region.cc @@ -338,17 +338,6 @@ Region::Region (boost::shared_ptr src, const XMLNode& node) Region::~Region () { - boost::shared_ptr pl (playlist()); - - if (pl) { - for (SourceList::const_iterator i = _sources.begin(); i != _sources.end(); ++i) { - (*i)->remove_playlist (pl); - } - for (SourceList::const_iterator i = _master_sources.begin(); i != _master_sources.end(); ++i) { - (*i)->remove_playlist (pl); - } - } - notify_callbacks (); GoingAway (); /* EMIT SIGNAL */ } @@ -383,44 +372,7 @@ Region::copy_stuff (boost::shared_ptr other, nframes_t /*offset*/, void Region::set_playlist (boost::weak_ptr wpl) { - boost::shared_ptr old_playlist = (_playlist.lock()); - - boost::shared_ptr pl (wpl.lock()); - - if (old_playlist == pl) { - return; - } - - _playlist = pl; - - if (pl) { - if (old_playlist) { - for (SourceList::const_iterator i = _sources.begin(); i != _sources.end(); ++i) { - (*i)->remove_playlist (_playlist); - (*i)->add_playlist (pl); - } - for (SourceList::const_iterator i = _master_sources.begin(); i != _master_sources.end(); ++i) { - (*i)->remove_playlist (_playlist); - (*i)->add_playlist (pl); - } - } else { - for (SourceList::const_iterator i = _sources.begin(); i != _sources.end(); ++i) { - (*i)->add_playlist (pl); - } - for (SourceList::const_iterator i = _master_sources.begin(); i != _master_sources.end(); ++i) { - (*i)->add_playlist (pl); - } - } - } else { - if (old_playlist) { - for (SourceList::const_iterator i = _sources.begin(); i != _sources.end(); ++i) { - (*i)->remove_playlist (old_playlist); - } - for (SourceList::const_iterator i = _master_sources.begin(); i != _master_sources.end(); ++i) { - (*i)->remove_playlist (old_playlist); - } - } - } + _playlist = wpl.lock(); } bool @@ -487,7 +439,7 @@ Region::first_edit () if (_first_edit != EditChangesNothing && pl) { - _name = pl->session().new_region_name (_name); + _name = _session.new_region_name (_name); _first_edit = EditChangesNothing; send_change (ARDOUR::NameChanged); @@ -554,7 +506,7 @@ Region::set_position_lock_style (PositionLockStyle ps) _positional_lock_style = ps; if (_positional_lock_style == MusicTime) { - pl->session().tempo_map().bbt_time (_position, _bbt_time); + _session.tempo_map().bbt_time (_position, _bbt_time); } } @@ -568,13 +520,13 @@ Region::update_position_after_tempo_map_change () return; } - TempoMap& map (pl->session().tempo_map()); + TempoMap& map (_session.tempo_map()); nframes_t pos = map.frame_time (_bbt_time); set_position_internal (pos, false); } void -Region::set_position (nframes_t pos, void */*src*/) +Region::set_position (nframes_t pos, void* /*src*/) { if (!can_move()) { return; @@ -616,7 +568,7 @@ Region::set_position_internal (nframes_t pos, bool allow_bbt_recompute) } void -Region::set_position_on_top (nframes_t pos, void */*src*/) +Region::set_position_on_top (nframes_t pos, void* /*src*/) { if (_flags & Locked) { return; @@ -644,15 +596,12 @@ void Region::recompute_position_from_lock_style () { if (_positional_lock_style == MusicTime) { - boost::shared_ptr pl (playlist()); - if (pl) { - pl->session().tempo_map().bbt_time (_position, _bbt_time); - } + _session.tempo_map().bbt_time (_position, _bbt_time); } } void -Region::nudge_position (nframes64_t n, void */*src*/) +Region::nudge_position (nframes64_t n, void* /*src*/) { if (_flags & Locked) { return; @@ -691,7 +640,7 @@ Region::set_ancestral_data (nframes64_t s, nframes64_t l, float st, float sh) } void -Region::set_start (nframes_t pos, void */*src*/) +Region::set_start (nframes_t pos, void* /*src*/) { if (_flags & (Locked|PositionLocked)) { return; @@ -1515,6 +1464,17 @@ Region::source_equivalent (boost::shared_ptr other) const return true; } +bool +Region::uses_source (boost::shared_ptr source) const +{ + for (SourceList::const_iterator i = _sources.begin(); i != _sources.end(); ++i) { + if (*i == source) { + return true; + } + } + return false; +} + sframes_t Region::source_length(uint32_t n) const { @@ -1596,7 +1556,7 @@ Region::get_parent() const boost::shared_ptr r; boost::shared_ptr grrr2 = boost::dynamic_pointer_cast (shared_from_this()); - if (grrr2 && (r = pl->session().find_whole_file_parent (grrr2))) { + if (grrr2 && (r = _session.find_whole_file_parent (grrr2))) { return boost::static_pointer_cast (r); } } diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 1b054fd6fb..d9c83a3ff3 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -3004,6 +3004,23 @@ Session::remove_source (boost::weak_ptr src) } } +/** Return the number of playlists (not regions) that contain @a src */ +uint32_t +Session::source_use_count (boost::shared_ptr src) const +{ + uint32_t count = 0; + for (PlaylistList::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; + } + } + } + return count; +} + boost::shared_ptr Session::source_by_id (const PBD::ID& id) { diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 83cebbccbe..437699f1e9 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -2503,7 +2503,7 @@ Session::cleanup_sources (Session::cleanup_report& rep) capture files. */ - if (!i->second->used() && i->second->length(i->second->timeline_position()) > 0) { + if (!source_use_count(i->second) && i->second->length(i->second->timeline_position()) > 0) { dead_sources.push_back (i->second); i->second->GoingAway(); } diff --git a/libs/ardour/source.cc b/libs/ardour/source.cc index 4efd154dcd..0304bfea8a 100644 --- a/libs/ardour/source.cc +++ b/libs/ardour/source.cc @@ -36,7 +36,6 @@ #include "pbd/pthread_utils.h" #include "pbd/enumwriter.h" -#include "ardour/playlist.h" #include "ardour/session.h" #include "ardour/source.h" #include "ardour/transient_detector.h" @@ -149,52 +148,6 @@ Source::set_state (const XMLNode& node, int /*version*/) return 0; } -void -Source::add_playlist (boost::shared_ptr pl) -{ - 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(); -} - bool Source::has_been_analysed() const { -- cgit v1.2.3