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
This commit is contained in:
Robin Gareus 2015-09-10 00:48:10 +02:00
parent 78ff3c05a3
commit 390ea007c5
9 changed files with 47 additions and 17 deletions

View 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; }

View 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; }

View 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,

View 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);

View 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;
}

View 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

View 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)) {

View 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

View 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