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; }
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; }
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,
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);
}
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;
}
}
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
#include <glibmm/fileutils.h>
#include <glibmm/miscutils.h>
+#include "pbd/file_utils.h"
#include "pbd/scoped_file_descriptor.h"
#include "pbd/xml++.h"
_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)) {
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;
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
/* 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