summaryrefslogtreecommitdiff
path: root/libs/ardour/session.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2010-06-23 20:14:07 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2010-06-23 20:14:07 +0000
commitf4401c59284258c6aa56707da64e3da32756329f (patch)
tree73679199ae43516347d607adad212c10612f7eb9 /libs/ardour/session.cc
parentcac03dbeb6ebdcd406385dd14a746cb8c51dd5f8 (diff)
midway snapshot of work done on managing Region & Source lifetimes correctly. may fix missing MIDI file bug ; save empty playlists because they may be referred to by the history file ; undo commands auto-delete when objects they refer to die (currently not commands built from XML deserialization); Sources now know how many regions are using them for something, meaning that we know if we can delete the files holding any data for the source
git-svn-id: svn://localhost/ardour2/branches/3.0@7291 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/session.cc')
-rw-r--r--libs/ardour/session.cc88
1 files changed, 52 insertions, 36 deletions
diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc
index 3d5430d259..91b1e2a0f9 100644
--- a/libs/ardour/session.cc
+++ b/libs/ardour/session.cc
@@ -1484,6 +1484,7 @@ Session::new_midi_track (TrackMode mode, RouteGroup* route_group, uint32_t how_m
auto_connect_route (track, existing_inputs, existing_outputs);
track->non_realtime_input_change();
+
if (route_group) {
route_group->add (track);
}
@@ -2483,46 +2484,58 @@ Session::find_whole_file_parent (boost::shared_ptr<Region const> child) const
}
int
-Session::destroy_region (boost::shared_ptr<Region> region)
+Session::destroy_sources (list<boost::shared_ptr<Source> > srcs)
{
- vector<boost::shared_ptr<Source> > srcs;
-
- {
- if (region->playlist()) {
- region->playlist()->destroy_region (region);
- }
+ set<boost::shared_ptr<Region> > relevant_regions;
- for (uint32_t n = 0; n < region->n_channels(); ++n) {
- srcs.push_back (region->source (n));
- }
+ for (list<boost::shared_ptr<Source> >::iterator s = srcs.begin(); s != srcs.end(); ++s) {
+ RegionFactory::get_regions_using_source (*s, relevant_regions);
}
- region->drop_references ();
+ cerr << "There are " << relevant_regions.size() << " using " << srcs.size() << " sources" << endl;
+
+ for (set<boost::shared_ptr<Region> >::iterator r = relevant_regions.begin(); r != relevant_regions.end(); ) {
+ set<boost::shared_ptr<Region> >::iterator tmp;
+
+ tmp = r;
+ ++tmp;
+
+ cerr << "Cleanup " << (*r)->name() << " UC = " << (*r).use_count() << endl;
- for (vector<boost::shared_ptr<Source> >::iterator i = srcs.begin(); i != srcs.end(); ++i) {
+ playlists->destroy_region (*r);
+ RegionFactory::map_remove (*r);
- (*i)->mark_for_remove ();
- (*i)->drop_references ();
+ (*r)->drop_sources ();
+ (*r)->drop_references ();
+
+ cerr << "\tdone UC = " << (*r).use_count() << endl;
+
+ relevant_regions.erase (r);
+
+ r = tmp;
+ }
+
+ for (list<boost::shared_ptr<Source> >::iterator s = srcs.begin(); s != srcs.end(); ) {
- cerr << "source was not used by any playlist\n";
- }
+ {
+ Glib::Mutex::Lock ls (source_lock);
+ /* remove from the main source list */
+ sources.erase ((*s)->id());
+ }
- return 0;
-}
+ (*s)->mark_for_remove ();
+ (*s)->drop_references ();
+
+ s = srcs.erase (s);
+ }
-int
-Session::destroy_regions (list<boost::shared_ptr<Region> > regions)
-{
- for (list<boost::shared_ptr<Region> >::iterator i = regions.begin(); i != regions.end(); ++i) {
- destroy_region (*i);
- }
return 0;
}
int
Session::remove_last_capture ()
{
- list<boost::shared_ptr<Region> > r;
+ list<boost::shared_ptr<Source> > srcs;
boost::shared_ptr<RouteList> rl = routes.reader ();
for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
@@ -2531,15 +2544,15 @@ Session::remove_last_capture ()
continue;
}
- list<boost::shared_ptr<Region> >& l = tr->last_capture_regions();
+ list<boost::shared_ptr<Source> >& l = tr->last_capture_sources();
if (!l.empty()) {
- r.insert (r.end(), l.begin(), l.end());
+ srcs.insert (srcs.end(), l.begin(), l.end());
l.clear ();
}
}
- destroy_regions (r);
+ destroy_sources (srcs);
save_state (_current_snapshot_name);
@@ -2563,16 +2576,19 @@ Session::add_source (boost::shared_ptr<Source> source)
}
if (result.second) {
- set_dirty();
- }
- boost::shared_ptr<AudioFileSource> afs;
+ /* yay, new source */
- if ((afs = boost::dynamic_pointer_cast<AudioFileSource>(source)) != 0) {
- if (Config->get_auto_analyse_audio()) {
- Analyser::queue_source_for_analysis (source, false);
- }
- }
+ set_dirty();
+
+ boost::shared_ptr<AudioFileSource> afs;
+
+ if ((afs = boost::dynamic_pointer_cast<AudioFileSource>(source)) != 0) {
+ if (Config->get_auto_analyse_audio()) {
+ Analyser::queue_source_for_analysis (source, false);
+ }
+ }
+ }
}
void