summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2007-01-05 20:47:56 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2007-01-05 20:47:56 +0000
commit87a5518eb1e2bbdf7e6bffed20d153cfa1eac87d (patch)
treec11e7d9423fb812a9aeda6e097fb2cef54dca224 /libs
parent443126d148692e9828fea091e942c2a58a77a30b (diff)
actually fix cleanup design, plus buglet that used the wrong directory to store files in when cleaned up
git-svn-id: svn://localhost/ardour2/trunk@1276 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r--libs/ardour/ardour/session.h1
-rw-r--r--libs/ardour/audio_diskstream.cc4
-rw-r--r--libs/ardour/audiofilesource.cc8
-rw-r--r--libs/ardour/session.cc9
-rw-r--r--libs/ardour/session_state.cc112
5 files changed, 24 insertions, 110 deletions
diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h
index 03e50d152d..e550575ab1 100644
--- a/libs/ardour/ardour/session.h
+++ b/libs/ardour/ardour/session.h
@@ -575,7 +575,6 @@ class Session : public PBD::StatefulDestructible
void add_source (boost::shared_ptr<Source>);
void remove_source (boost::weak_ptr<Source>);
- int cleanup_audio_file_source (boost::shared_ptr<AudioFileSource>);
struct cleanup_report {
vector<string> paths;
diff --git a/libs/ardour/audio_diskstream.cc b/libs/ardour/audio_diskstream.cc
index ef3173e87b..44d5c19ab1 100644
--- a/libs/ardour/audio_diskstream.cc
+++ b/libs/ardour/audio_diskstream.cc
@@ -1630,7 +1630,7 @@ AudioDiskstream::finish_capture (bool rec_monitors_input)
void
AudioDiskstream::set_record_enabled (bool yn)
{
- if (!recordable() || !_session.record_enabling_legal()) {
+ if (!recordable() || !_session.record_enabling_legal() || _io->n_inputs() == 0) {
return;
}
@@ -1927,7 +1927,7 @@ AudioDiskstream::reset_write_sources (bool mark_write_complete, bool force)
}
capturing_sources.clear ();
-
+
for (chan = channels.begin(), n = 0; chan != channels.end(); ++chan, ++n) {
if (!destructive()) {
diff --git a/libs/ardour/audiofilesource.cc b/libs/ardour/audiofilesource.cc
index 1915957f3d..95fc0d2766 100644
--- a/libs/ardour/audiofilesource.cc
+++ b/libs/ardour/audiofilesource.cc
@@ -285,9 +285,11 @@ AudioFileSource::move_to_trash (const string trash_dir_name)
stick it in the `trash_dir_name' directory
on whichever filesystem it was already on.
*/
-
+
newpath = Glib::path_get_dirname (_path);
- newpath = Glib::path_get_dirname (newpath);
+ newpath = Glib::path_get_dirname (newpath);
+
+ cerr << "from " << _path << " dead dir looks like " << newpath << endl;
newpath += '/';
newpath += trash_dir_name;
@@ -511,7 +513,7 @@ AudioFileSource::set_name (string newname, bool destructive)
}
if (rename (oldpath.c_str(), newpath.c_str()) != 0) {
- error << string_compose (_("cannot rename audio file for %1 to %2"), _name, newpath) << endmsg;
+ error << string_compose (_("cannot rename audio file %1 to %2"), _name, newpath) << endmsg;
return -1;
}
diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc
index 4d8a77613c..1a965327be 100644
--- a/libs/ardour/session.cc
+++ b/libs/ardour/session.cc
@@ -3080,19 +3080,16 @@ Session::remove_playlist (boost::weak_ptr<Playlist> weak_playlist)
{
Glib::Mutex::Lock lm (playlist_lock);
- cerr << "removing playlist: " << playlist->name() << endl;
PlaylistList::iterator i;
i = find (playlists.begin(), playlists.end(), playlist);
if (i != playlists.end()) {
- cerr << "\tfound it in used playlist\n";
playlists.erase (i);
}
i = find (unused_playlists.begin(), unused_playlists.end(), playlist);
if (i != unused_playlists.end()) {
- cerr << "\tfound it in unused playlist\n";
unused_playlists.erase (i);
}
@@ -3640,12 +3637,6 @@ Session::route_name_unique (string n) const
return true;
}
-int
-Session::cleanup_audio_file_source (boost::shared_ptr<AudioFileSource> fs)
-{
- return fs->move_to_trash (dead_sound_dir_name);
-}
-
uint32_t
Session::n_playlists () const
{
diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc
index 9d5733b122..28d4a44174 100644
--- a/libs/ardour/session_state.cc
+++ b/libs/ardour/session_state.cc
@@ -2457,9 +2457,7 @@ struct RegionCounter {
int
Session::cleanup_sources (Session::cleanup_report& rep)
{
- typedef map<boost::shared_ptr<Source>, RegionCounter> SourceRegionMap;
- SourceRegionMap dead_sources;
-
+ vector<boost::shared_ptr<Source> > dead_sources;
vector<boost::shared_ptr<Playlist> > playlists_tbd;
PathScanner scanner;
string sound_path;
@@ -2505,104 +2503,26 @@ Session::cleanup_sources (Session::cleanup_report& rep)
playlists_tbd.clear ();
- /* step 2: find all un-referenced sources */
+ /* step 2: find all un-used sources */
rep.paths.clear ();
rep.space = 0;
- for (AudioSourceList::iterator i = audio_sources.begin(); i != audio_sources.end(); ++i) {
+ for (AudioSourceList::iterator i = audio_sources.begin(); i != audio_sources.end(); ) {
- /* we expect the use_count() to be at least 2: one for the shared_ptr<> in the sources
- list and one for the iterator. if its used by 1 region, we'd expect a value of 3.
-
- do not bother with files that are zero size, otherwise we remove the current "nascent"
- capture files.
- */
-
- if (i->second.use_count() <= 3 && i->second->length() > 0) {
-
- pair<boost::shared_ptr<Source>, RegionCounter> newpair;
-
- newpair.first = i->second;
- newpair.second.iter = i;
-
- dead_sources.insert (newpair);
- }
- }
-
- /* Search the region list to find out the state of the supposedly unreferenced regions
- */
-
- for (SourceRegionMap::iterator i = dead_sources.begin(); i != dead_sources.end();++i) {
-
- for (AudioRegionList::iterator r = audio_regions.begin(); r != audio_regions.end(); ++r) {
-
- boost::shared_ptr<AudioRegion> ar = r->second;
-
- for (uint32_t n = 0; n < ar->n_channels(); ++n) {
-
- if (ar->source (n) == i->first) {
-
- /* this region uses this source */
-
- i->second.region = ar;
- i->second.count++;
-
- if (i->second.count > 1) {
- break;
- }
- }
- }
- }
- }
-
- /* next, get rid of all regions in the region list that use any dead sources
- in case the sources themselves don't go away (they might be referenced in
- other snapshots).
-
- this is also where we remove the apparently unused sources from our source
- list. this doesn't rename them or delete them, but it means they are
- potential candidates for renaming after we find all soundfiles
- and scan for use across all snapshots (including this one).
- */
-
- for (SourceRegionMap::iterator i = dead_sources.begin(); i != dead_sources.end(); ) {
-
- SourceRegionMap::iterator tmp;
+ AudioSourceList::iterator tmp;
tmp = i;
++tmp;
- if (i->second.count == 0) {
-
- /* no regions use this source */
-
- /* remove this source from our own list to avoid us
- adding it to the list of all sources below
- */
-
- audio_sources.erase (i->second.iter);
-
- } else if (i->second.count == 1) {
-
- /* the use_count for the source was 3. this means that there is only reference to it in addition to the source
- list and an iterator used to traverse that list. since there is a single region using the source, that
- must be the extra reference. this implies that its a whole-file region
- with no children, so remove the region and the source.
- */
-
- remove_region (i->second.region);
-
- /* remove this source from our own list to avoid us
- adding it to the list of all sources below
- */
-
- audio_sources.erase (i->second.iter);
+ /* do not bother with files that are zero size, otherwise we remove the current "nascent"
+ capture files.
+ */
- } else {
- /* more than one region uses this source, do not remove it */
- dead_sources.erase (i);
- }
+ if (!i->second->used() && i->second->length() > 0) {
+ dead_sources.push_back (i->second);
+ i->second->GoingAway();
+ }
i = tmp;
}
@@ -2663,7 +2583,6 @@ Session::cleanup_sources (Session::cleanup_report& rep)
used = true;
break;
}
-
}
if (!used) {
@@ -2697,6 +2616,12 @@ Session::cleanup_sources (Session::cleanup_report& rep)
newpath += '/';
newpath += dead_sound_dir_name;
+
+ if (g_mkdir_with_parents (newpath.c_str(), 0755) < 0) {
+ error << string_compose(_("Session: cannot create session peakfile dir \"%1\" (%2)"), newpath, strerror (errno)) << endmsg;
+ return -1;
+ }
+
newpath += '/';
newpath += Glib::path_get_basename ((*x));
@@ -2736,7 +2661,6 @@ Session::cleanup_sources (Session::cleanup_report& rep)
<< endmsg;
goto out;
}
-
/* see if there an easy to find peakfile for this file, and remove it.
*/
@@ -2934,8 +2858,6 @@ Session::save_history (string snapshot_name)
return -1;
}
- cerr << "actually writing history\n";
-
if (!tree.write (xml_path))
{
error << string_compose (_("history could not be saved to %1"), xml_path) << endmsg;