summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2015-09-10 00:48:10 +0200
committerRobin Gareus <robin@gareus.org>2015-09-10 00:55:58 +0200
commit390ea007c5b6b647e33c924b3429bf49ae83b1ca (patch)
tree774a07a6132c8c211de95e43a53484be5007ddbf
parent78ff3c05a3f5c5d532162b45bdd8857bc402011e (diff)
rework peakfile handling:
- 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
-rw-r--r--libs/ardour/ardour/audio_playlist_source.h2
-rw-r--r--libs/ardour/ardour/audiofilesource.h2
-rw-r--r--libs/ardour/ardour/audiosource.h2
-rw-r--r--libs/ardour/ardour/session.h2
-rw-r--r--libs/ardour/audio_playlist_source.cc2
-rw-r--r--libs/ardour/audiofilesource.cc12
-rw-r--r--libs/ardour/audiosource.cc11
-rw-r--r--libs/ardour/session.cc29
-rw-r--r--libs/ardour/session_state.cc2
9 files changed, 47 insertions, 17 deletions
diff --git a/libs/ardour/ardour/audio_playlist_source.h b/libs/ardour/ardour/audio_playlist_source.h
index 85f29bd79a..a11749f46c 100644
--- a/libs/ardour/ardour/audio_playlist_source.h
+++ b/libs/ardour/ardour/audio_playlist_source.h
@@ -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; }
diff --git a/libs/ardour/ardour/audiofilesource.h b/libs/ardour/ardour/audiofilesource.h
index 10c47d8658..786d1628e8 100644
--- a/libs/ardour/ardour/audiofilesource.h
+++ b/libs/ardour/ardour/audiofilesource.h
@@ -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; }
diff --git a/libs/ardour/ardour/audiosource.h b/libs/ardour/ardour/audiosource.h
index 0c66cdf0e9..ad56c8834f 100644
--- a/libs/ardour/ardour/audiosource.h
+++ b/libs/ardour/ardour/audiosource.h
@@ -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,
diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h
index 102cb4917e..51d3798d1c 100644
--- a/libs/ardour/ardour/session.h
+++ b/libs/ardour/ardour/session.h
@@ -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);
diff --git a/libs/ardour/audio_playlist_source.cc b/libs/ardour/audio_playlist_source.cc
index 82917aaa7a..e9925852b8 100644
--- a/libs/ardour/audio_playlist_source.cc
+++ b/libs/ardour/audio_playlist_source.cc
@@ -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;
}
diff --git a/libs/ardour/audiofilesource.cc b/libs/ardour/audiofilesource.cc
index 45ec162f09..0c921dae8d 100644
--- a/libs/ardour/audiofilesource.cc
+++ b/libs/ardour/audiofilesource.cc
@@ -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
diff --git a/libs/ardour/audiosource.cc b/libs/ardour/audiosource.cc
index 62a632e435..c79cbbbe26 100644
--- a/libs/ardour/audiosource.cc
+++ b/libs/ardour/audiosource.cc
@@ -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)) {
diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc
index f8bd39fe33..30ab5e1660 100644
--- a/libs/ardour/session.cc
+++ b/libs/ardour/session.cc
@@ -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
diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc
index 0562d1801c..bb4a8265ef 100644
--- a/libs/ardour/session_state.cc
+++ b/libs/ardour/session_state.cc
@@ -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