rework peakfile handling:
authorRobin Gareus <robin@gareus.org>
Wed, 9 Sep 2015 22:48:10 +0000 (00:48 +0200)
committerRobin Gareus <robin@gareus.org>
Wed, 9 Sep 2015 22:55:58 +0000 (00:55 +0200)
- copy old peak-files to new (do not require re-calc)
- keep old peak-files (for now, backwards compat)
- fix cleanup-sources to remove *new* peak-file
- include channel-number in hash (like it was done before)

see also 624f76b

TODO: add Session > Cleanup > remove/re-create peaks

libs/ardour/ardour/audio_playlist_source.h
libs/ardour/ardour/audiofilesource.h
libs/ardour/ardour/audiosource.h
libs/ardour/ardour/session.h
libs/ardour/audio_playlist_source.cc
libs/ardour/audiofilesource.cc
libs/ardour/audiosource.cc
libs/ardour/session.cc
libs/ardour/session_state.cc

index 85f29bd79a226ceefa861a5a1321caca5d3f0123..a11749f46c78bf337b5b23ea0d8bd196307ccb73 100644 (file)
@@ -37,7 +37,7 @@ public:
        virtual ~AudioPlaylistSource ();
 
        bool empty() const;
-       std::string construct_peak_filepath (const std::string& audio_path) const;
+       std::string construct_peak_filepath (const std::string& audio_path, bool oldformat = false) const;
        uint32_t   n_channels() const;
        bool clamped_at_unity () const { return false; }
 
index 10c47d86586b2d9ccd4ceac59244bb8db6bc27f9..786d1628e8fc34dad9adb148a59bc8ccd0c05e84 100644 (file)
@@ -39,7 +39,7 @@ class LIBARDOUR_API AudioFileSource : public AudioSource, public FileSource {
 public:
        virtual ~AudioFileSource ();
 
-       std::string construct_peak_filepath (const std::string& audio_filepath) const;
+       std::string construct_peak_filepath (const std::string& audio_filepath, bool oldformat = false) const;
 
        static void set_peak_dir (const std::string& dir) { peak_dir = dir; }
 
index 0c66cdf0e91a058b9c9cb5a8ca38ade36055191e..ad56c8834f48676cee837bd1dc1c3a70e9dcaff0 100644 (file)
@@ -136,7 +136,7 @@ class LIBARDOUR_API AudioSource : virtual public Source,
 
        virtual framecnt_t read_unlocked (Sample *dst, framepos_t start, framecnt_t cnt) const = 0;
        virtual framecnt_t write_unlocked (Sample *dst, framecnt_t cnt) = 0;
-       virtual std::string construct_peak_filepath(const std::string& audio_filepath) const = 0;
+       virtual std::string construct_peak_filepath(const std::string& audio_filepath, bool oldformat = false) const = 0;
 
        virtual int read_peaks_with_fpp (PeakData *peaks,
                                         framecnt_t npeaks, framepos_t start, framecnt_t cnt,
index 102cb4917ee7ea1930b0f38bde0367f472cfa47e..51d3798d1c6fd7ad2994f3ae761d019008161919 100644 (file)
@@ -210,7 +210,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        std::string plugins_dir () const;     ///< Plugin state
        std::string externals_dir () const;   ///< Links to external files
 
-       std::string construct_peak_filepath (const std::string&) const;
+       std::string construct_peak_filepath (const std::string&, bool oldformat = false) const;
 
        bool audio_source_name_is_unique (const std::string& name);
        std::string format_audio_source_name (const std::string& legalized_base, uint32_t nchan, uint32_t chan, bool destructive, bool take_required, uint32_t cnt, bool related_exists);
index 82917aaa7a16619e5a4b36c52dbf15a83ff01b98..e9925852b8a62fe848a6cccc163b1749b3387613 100644 (file)
@@ -217,7 +217,7 @@ AudioPlaylistSource::setup_peakfile ()
 }
 
 string
-AudioPlaylistSource::construct_peak_filepath (const string& /*audio_path_IGNORED*/) const
+AudioPlaylistSource::construct_peak_filepath (const string& /*audio_path_IGNORED*/, bool /* oldformat IGNORED*/) const
 {
        return _peak_path;
 }
index 45ec162f094ec6fcb8dac21af8497b67d77b7198..0c921dae8d0c12952168c3986f0b748a611b79fc 100644 (file)
@@ -164,9 +164,17 @@ AudioFileSource::init (const string& pathstr, bool must_exist)
 }
 
 string
-AudioFileSource::construct_peak_filepath (const string& audio_path) const
+AudioFileSource::construct_peak_filepath (const string& audio_path, bool oldformat) const
 {
-       return _session.construct_peak_filepath (audio_path);
+       string base;
+       if (oldformat) {
+               base = audio_path.substr (0, audio_path.find_last_of ('.'));
+       } else {
+               base = audio_path;
+       }
+       base += '%';
+       base += (char) ('A' + _channel);
+       return _session.construct_peak_filepath (base, oldformat);
 }
 
 bool
index 62a632e435096426ab603dd1bdd342b5187ec53f..c79cbbbe26e1b13ef7ba44b29999352fdfc2bc0e 100644 (file)
@@ -50,6 +50,7 @@
 #include <glibmm/fileutils.h>
 #include <glibmm/miscutils.h>
 
+#include "pbd/file_utils.h"
 #include "pbd/scoped_file_descriptor.h"
 #include "pbd/xml++.h"
 
@@ -242,6 +243,16 @@ AudioSource::initialize_peakfile (const string& audio_path)
 
        _peakpath = construct_peak_filepath (audio_path);
 
+       if (!empty() && !Glib::file_test (_peakpath.c_str(), Glib::FILE_TEST_EXISTS)) {
+               string oldpeak = construct_peak_filepath (audio_path, true);
+               DEBUG_TRACE(DEBUG::Peaks, string_compose ("Looking for old peak file %1 for Audio file %2\n", oldpeak, audio_path));
+               if (Glib::file_test (oldpeak.c_str(), Glib::FILE_TEST_EXISTS)) {
+                       // TODO use hard-link if possible
+                       DEBUG_TRACE(DEBUG::Peaks, string_compose ("Copy old peakfile %1 to %2\n", oldpeak, _peakpath));
+                       PBD::copy_file (oldpeak, _peakpath);
+               }
+       }
+
        DEBUG_TRACE(DEBUG::Peaks, string_compose ("Initialize Peakfile %1 for Audio file %2\n", _peakpath, audio_path));
 
        if (g_stat (_peakpath.c_str(), &statbuf)) {
index f8bd39fe3395f539965be710154b0977c018084b..30ab5e1660cfe353f5c243a7e1942139480e2768 100644 (file)
@@ -4363,8 +4363,18 @@ Session::count_sources_by_origin (const string& path)
        return cnt;
 }
 
+static string
+peak_file_helper (const string& peak_path, const string& file_path, const string& file_base, bool hash) {
+       if (hash) {
+               std::string checksum = Glib::Checksum::compute_checksum(Glib::Checksum::CHECKSUM_SHA1, file_path + G_DIR_SEPARATOR + file_base);
+               return Glib::build_filename (peak_path, checksum + peakfile_suffix);
+       } else {
+               return Glib::build_filename (peak_path, file_base + peakfile_suffix);
+       }
+}
+
 string
-Session::construct_peak_filepath (const string& filepath) const
+Session::construct_peak_filepath (const string& filepath, bool oldformat) const
 {
        string interchange_dir_string = string (interchange_dir_name) + G_DIR_SEPARATOR;
 
@@ -4397,24 +4407,25 @@ Session::construct_peak_filepath (const string& filepath) const
 
                if (in_another_session) {
                        SessionDirectory sd (session_path);
-                       return Glib::build_filename (sd.peak_path(), Glib::path_get_basename (filepath) + peakfile_suffix);
+                       return peak_file_helper (sd.peak_path(), "", Glib::path_get_basename (filepath), !oldformat);
                }
        }
 
+       /* 1) if file belongs to this session
+        * it may be a relative path (interchange/...)
+        * or just basename (session_state, remove source)
+        * -> just use the basename
+        */
        std::string filename = Glib::path_get_basename (filepath);
        std::string path;
-       /* file is within our session: just use the filename for checksumming and leave path empty */
 
+       /* 2) if the file is outside our session dir:
+        * (imported but not copied) add the path for check-summming */
        if (filepath.find (interchange_dir_string) == string::npos) {
-               /* the file is outside our session: add the filepath for checksummming */
                path = Glib::path_get_dirname (filepath);
        }
        
-       string::size_type suffix = filename.find_last_of ('.');
-
-       std::string checksum = Glib::Checksum::compute_checksum(Glib::Checksum::CHECKSUM_SHA1, path + G_DIR_SEPARATOR + filename);
-
-       return Glib::build_filename (_session_dir->peak_path(), checksum + peakfile_suffix);
+       return peak_file_helper (_session_dir->peak_path(), path, Glib::path_get_basename (filepath), !oldformat);
 }
 
 string
index 0562d1801ce6643a3f91801291a7d406da496227..bb4a8265ef393e9182d5b1c16aa439f00a533ac3 100644 (file)
@@ -3047,7 +3047,7 @@ Session::cleanup_sources (CleanupReport& rep)
                /* see if there an easy to find peakfile for this file, and remove it.
                 */
 
-                string base = basename_nosuffix (*x);
+                string base = Glib::path_get_basename (*x);
                 base += "%A"; /* this is what we add for the channel suffix of all native files,
                                  or for the first channel of embedded files. it will miss
                                  some peakfiles for other channels