Fixes case where audiofiles used wrong peakfiles
authorMathias Buhr <napcode@apparatus.de>
Sat, 29 Aug 2015 11:48:05 +0000 (13:48 +0200)
committerMathias Buhr <mathias.buhr@citrix.com>
Thu, 3 Sep 2015 07:54:23 +0000 (09:54 +0200)
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/file_source.cc
libs/ardour/session.cc
libs/ardour/session_state.cc

index ad278bad0dfb227d2f2548ab31f6b0ae7aebfc8a..85f29bd79a226ceefa861a5a1321caca5d3f0123 100644 (file)
@@ -37,7 +37,7 @@ public:
        virtual ~AudioPlaylistSource ();
 
        bool empty() const;
-       std::string generate_peak_path (const std::string& audio_path);
+       std::string construct_peak_filepath (const std::string& audio_path) const;
        uint32_t   n_channels() const;
        bool clamped_at_unity () const { return false; }
 
index 45b465c27ff91223f3fbc5e5f54e00daf2d37796..da4f9aaea5e520e1d2d086f2aaf45eb24fc8ce72 100644 (file)
@@ -39,7 +39,7 @@ class LIBARDOUR_API AudioFileSource : public AudioSource, public FileSource {
 public:
        virtual ~AudioFileSource ();
 
-       std::string generate_peak_path (const std::string& audio_path);
+       std::string construct_peak_filepath (const std::string& audio_filepath) const;
        std::string find_broken_peakfile (const std::string& missing_peak_path,
                                          const std::string& audio_path);
 
index 6503aa7f733dd8a2df9d3befb3600c147a4baa88..4c6463e5b3d92f1fdc3ecf9f70ff1d48cac57511 100644 (file)
@@ -136,9 +136,9 @@ 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 generate_peak_path(const std::string& audio_path) = 0;
+       virtual std::string construct_peak_filepath(const std::string& audio_filepath) const = 0;
        virtual std::string find_broken_peakfile (std::string /* missing_peak_path */,
-                                                 std::string audio_path) { return generate_peak_path (audio_path); }
+                                                 std::string audio_path) { return construct_peak_filepath (audio_path); }
 
        virtual int read_peaks_with_fpp (PeakData *peaks,
                                         framecnt_t npeaks, framepos_t start, framecnt_t cnt,
index 1ab53606eec9b62b6e27ad702fdc50caff7026f2..2e223beba7b1a4d6c7ec975b8ff28c914111f627 100644 (file)
@@ -198,7 +198,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 peak_path (const std::string&) const;
+       std::string construct_peak_filepath (const std::string&) 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 9415065b8f4a404de0f6b0aa607c5dde821e80e7..82917aaa7a16619e5a4b36c52dbf15a83ff01b98 100644 (file)
@@ -217,7 +217,7 @@ AudioPlaylistSource::setup_peakfile ()
 }
 
 string
-AudioPlaylistSource::generate_peak_path (const string& /*audio_path_IGNORED*/)
+AudioPlaylistSource::construct_peak_filepath (const string& /*audio_path_IGNORED*/) const
 {
        return _peak_path;
 }
index 0fd7ec9ec3448f4ae069dcb317f29244ea763e95..a6942e678b8a1cd30571f75fd52861f9700a8c3a 100644 (file)
@@ -164,26 +164,9 @@ AudioFileSource::init (const string& pathstr, bool must_exist)
 }
 
 string
-AudioFileSource::generate_peak_path (const string& audio_path)
+AudioFileSource::construct_peak_filepath (const string& audio_path) const
 {
-       string base;
-
-       string::size_type suffix = audio_path.find_last_of ('.');
-
-       if (suffix != string::npos) {
-               base = audio_path.substr (0, suffix);
-       } else {
-               warning << string_compose (_("Odd audio file path: %1"), audio_path) << endmsg;
-               base = audio_path;
-       }
-
-       base += '%';
-       base += (char) ('A' + _channel);
-
-       /* pass in the name/path of the source, with no audio file type suffix
-        */
-       
-       return _session.peak_path (base);
+       return _session.construct_peak_filepath (audio_path);
 }
 
 string
@@ -230,7 +213,7 @@ AudioFileSource::find_broken_peakfile (const string& peak_path, const string& au
 string
 AudioFileSource::broken_peak_path (const string& audio_path)
 {
-       return _session.peak_path (basename_nosuffix (audio_path));
+       return _session.construct_peak_filepath (basename_nosuffix (audio_path));
 }
 
 string
index 51c17b5905e79a29f213e7ca0f8e13d68489e787..01a030914db36a924d24d7cdbbc4d1970eff7dab 100644 (file)
@@ -239,7 +239,7 @@ AudioSource::initialize_peakfile (const string& audio_path)
 {
        GStatBuf statbuf;
 
-       _peakpath = generate_peak_path (audio_path);
+       _peakpath = construct_peak_filepath (audio_path);
 
        DEBUG_TRACE(DEBUG::Peaks, string_compose ("Initialize Peakfile %1 for Audio file %2\n", _peakpath, audio_path));
 
index 507f0df49c84647144cc616cfa4b1c8b4ec430d8..43763cf2f955276e24c793d2dfedf378312cdf7b 100644 (file)
@@ -58,7 +58,7 @@ FileSource::FileSource (Session& session, DataType type, const string& path, con
        , _path (path)
        , _file_is_new (!origin.empty()) // if origin is left unspecified (empty string) then file must exist
        , _channel (0)
-        , _origin (origin)
+       , _origin (origin)
 {
        set_within_session_from_path (path);
 }
@@ -148,9 +148,9 @@ FileSource::set_state (const XMLNode& node, int /*version*/)
                _channel = 0;
        }
 
-        if ((prop = node.property (X_("origin"))) != 0) {
-                _origin = prop->value();
-        }
+       if ((prop = node.property (X_("origin"))) != 0) {
+               _origin = prop->value();
+       }
 
        return 0;
 }
index ad97781c8923a1253a76d02a8dbcbe416b964c35..d382077827cd6e779f8591c18a4a3245a513aeca 100644 (file)
 
 #include "i18n.h"
 
+#include <glibmm/checksum.h>
+
 namespace ARDOUR {
 class MidiSource;
 class Processor;
@@ -4362,19 +4364,20 @@ Session::count_sources_by_origin (const string& path)
 }
 
 string
-Session::peak_path (const string& base) const
+Session::construct_peak_filepath (const string& filepath) const
 {
-       if (Glib::path_is_absolute (base)) {
+       string interchange_dir_string = string (interchange_dir_name) + G_DIR_SEPARATOR;
+
+       if (Glib::path_is_absolute (filepath)) {
 
                /* rip the session dir from the audiofile source */
 
                string session_path;
-               string interchange_dir_string = string (interchange_dir_name) + G_DIR_SEPARATOR;
                bool in_another_session = true;
                
-               if (base.find (interchange_dir_string) != string::npos) {
+               if (filepath.find (interchange_dir_string) != string::npos) {
                
-                       session_path = Glib::path_get_dirname (base); /* now ends in audiofiles */
+                       session_path = Glib::path_get_dirname (filepath); /* now ends in audiofiles */
                        session_path = Glib::path_get_dirname (session_path); /* now ends in session name */
                        session_path = Glib::path_get_dirname (session_path); /* now ends in interchange */
                        session_path = Glib::path_get_dirname (session_path); /* now has session path */
@@ -4394,12 +4397,32 @@ Session::peak_path (const string& base) const
 
                if (in_another_session) {
                        SessionDirectory sd (session_path);
-                       return Glib::build_filename (sd.peak_path(), Glib::path_get_basename (base) + peakfile_suffix);
+                       return Glib::build_filename (sd.peak_path(), Glib::path_get_basename (filepath) + peakfile_suffix);
                }
        }
 
-       std::string basename = Glib::path_get_basename (base);
-       return Glib::build_filename (_session_dir->peak_path(), basename + peakfile_suffix);
+       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 */
+
+       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 filename_unsuffixed;
+       if (suffix != string::npos) {
+               filename_unsuffixed = filename.substr (0, suffix);
+       } else {
+               warning << string_compose (_("Odd audio file path: %1"), filepath) << endmsg;
+               filename_unsuffixed = filename;
+       }
+
+       std::string checksum = "_" + Glib::Checksum::compute_checksum(Glib::Checksum::CHECKSUM_MD5, path + G_DIR_SEPARATOR + filename);
+
+       return Glib::build_filename (_session_dir->peak_path(), filename_unsuffixed + checksum + peakfile_suffix);
 }
 
 string
index 2880b2c3681907a25383e3011ca880924a080178..0562d1801ce6643a3f91801291a7d406da496227 100644 (file)
@@ -3052,7 +3052,7 @@ Session::cleanup_sources (CleanupReport& rep)
                                  or for the first channel of embedded files. it will miss
                                  some peakfiles for other channels
                               */
-               string peakpath = peak_path (base);
+               string peakpath = construct_peak_filepath (base);
 
                if (Glib::file_test (peakpath.c_str(), Glib::FILE_TEST_EXISTS)) {
                        if (::g_unlink (peakpath.c_str()) != 0) {