13
0

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
This commit is contained in:
David Robillard 2009-10-26 17:24:08 +00:00
parent fa5aeb7892
commit 8d168bda87
12 changed files with 50 additions and 124 deletions

View File

@ -2564,7 +2564,7 @@ Editor::snap_to (nframes64_t& start, int32_t direction, bool for_mark)
}
void
Editor::timecode_snap_to_internal (nframes64_t& start, int32_t direction, bool for_mark)
Editor::timecode_snap_to_internal (nframes64_t& start, int32_t direction, bool /*for_mark*/)
{
const nframes64_t one_timecode_second = (nframes64_t)(rint(session->timecode_frames_per_second()) * session->frames_per_timecode_frame());
nframes64_t one_timecode_minute = (nframes64_t)(rint(session->timecode_frames_per_second()) * session->frames_per_timecode_frame() * 60);

View File

@ -109,6 +109,8 @@ class Playlist : public SessionObject,
boost::shared_ptr<Playlist> copy (std::list<AudioRange>&, bool result_is_hidden = true);
int paste (boost::shared_ptr<Playlist>, 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);

View File

@ -177,6 +177,7 @@ class Region
bool overlap_equivalent (boost::shared_ptr<const Region>) const;
bool region_list_equivalent (boost::shared_ptr<const Region>) const;
bool source_equivalent (boost::shared_ptr<const Region>) const;
bool uses_source (boost::shared_ptr<const Source>) const;
/* EDITING OPERATIONS */

View File

@ -642,6 +642,8 @@ class Session : public PBD::StatefulDestructible, public boost::noncopyable
void add_source (boost::shared_ptr<Source>);
void remove_source (boost::weak_ptr<Source>);
uint32_t source_use_count (boost::shared_ptr<const Source> src) const;
struct cleanup_report {
std::vector<std::string> paths;
int64_t space;

View File

@ -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<ARDOUR::Playlist>);
void remove_playlist (boost::weak_ptr<ARDOUR::Playlist>);
uint32_t used() const;
static sigc::signal<void,Source*> SourceCreated;
sigc::signal<void,boost::shared_ptr<Source> > Switched;
@ -123,9 +117,6 @@ class Source : public SessionObject, public boost::noncopyable
mutable Glib::Mutex _analysis_lock;
Glib::Mutex _playlist_lock;
typedef std::map<boost::shared_ptr<ARDOUR::Playlist>, uint32_t > PlaylistMap;
PlaylistMap _playlists;
private:
uint32_t _in_use;
void fix_writable_flags ();

View File

@ -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;
}

View File

@ -119,7 +119,7 @@ MidiPlaylist::read (MidiRingBuffer<nframes_t>& 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<nframes_t>& 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());

View File

@ -505,7 +505,7 @@ Playlist::add_region (boost::shared_ptr<Region> 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);
}

View File

@ -338,17 +338,6 @@ Region::Region (boost::shared_ptr<Source> src, const XMLNode& node)
Region::~Region ()
{
boost::shared_ptr<Playlist> 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<const Region> other, nframes_t /*offset*/,
void
Region::set_playlist (boost::weak_ptr<Playlist> wpl)
{
boost::shared_ptr<Playlist> old_playlist = (_playlist.lock());
boost::shared_ptr<Playlist> 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<Playlist> 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<const Region> other) const
return true;
}
bool
Region::uses_source (boost::shared_ptr<const Source> 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<Region> r;
boost::shared_ptr<Region const> grrr2 = boost::dynamic_pointer_cast<Region const> (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<Region> (r);
}
}

View File

@ -3004,6 +3004,23 @@ Session::remove_source (boost::weak_ptr<Source> src)
}
}
/** Return the number of playlists (not regions) that contain @a src */
uint32_t
Session::source_use_count (boost::shared_ptr<const Source> 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<Source>
Session::source_by_id (const PBD::ID& id)
{

View File

@ -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();
}

View File

@ -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<Playlist> 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)));
}
void
Source::remove_playlist (boost::weak_ptr<Playlist> wpl)
{
boost::shared_ptr<Playlist> 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
{