actually fix cleanup design, plus buglet that used the wrong directory to store files...
authorPaul Davis <paul@linuxaudiosystems.com>
Fri, 5 Jan 2007 20:47:56 +0000 (20:47 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Fri, 5 Jan 2007 20:47:56 +0000 (20:47 +0000)
git-svn-id: svn://localhost/ardour2/trunk@1276 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/route_time_axis.cc
libs/ardour/ardour/session.h
libs/ardour/audio_diskstream.cc
libs/ardour/audiofilesource.cc
libs/ardour/session.cc
libs/ardour/session_state.cc

index 67a86b385fe0a8a453302ed2d21ead33c85feecd..84f752dc8a4b547e643458144829a733dc4c9278 100644 (file)
@@ -957,7 +957,6 @@ RouteTimeAxisView::use_new_playlist (bool prompt)
        if (name.length()) {
                ds->use_new_playlist ();
                ds->playlist()->set_name (name);
-               cerr << " installed new PL, UC = " << ds->playlist().use_count() << endl;
        }
 }
 
index 03e50d152dc5810fec33b07217e40af343bc9fa1..e550575ab1a3ff1f175b5ef18608474b9c684cd6 100644 (file)
@@ -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;
index ef3173e87b4624a5766e2b2cd77081ffc9e4208f..44d5c19ab1e787f90a1ddb832bfc1d104a81ff24 100644 (file)
@@ -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()) {
 
index 1915957f3dea18fec89390213e630bedc5bfe3d1..95fc0d27667f8a03e07e6d28c78398129ff0bced 100644 (file)
@@ -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;
        }
 
index 4d8a77613ca1d010a0624d3d34a9f4b12c23d9cd..1a965327beffe5e43cb7b7c80c68c320db91ec78 100644 (file)
@@ -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
 {
index 9d5733b122876399451a40b5419a8cc57c09d76f..28d4a44174bd9e8243c24981fc8f499ad394f268 100644 (file)
@@ -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;