Fixes case where audiofiles used wrong peakfiles

This commit is contained in:
Mathias Buhr 2015-08-29 13:48:05 +02:00 committed by Mathias Buhr
parent 95b144ee58
commit 624f76b229
10 changed files with 46 additions and 40 deletions

View file

@ -37,7 +37,7 @@ public:
virtual ~AudioPlaylistSource (); virtual ~AudioPlaylistSource ();
bool empty() const; 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; uint32_t n_channels() const;
bool clamped_at_unity () const { return false; } bool clamped_at_unity () const { return false; }

View file

@ -39,7 +39,7 @@ class LIBARDOUR_API AudioFileSource : public AudioSource, public FileSource {
public: public:
virtual ~AudioFileSource (); 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, std::string find_broken_peakfile (const std::string& missing_peak_path,
const std::string& audio_path); const std::string& audio_path);

View 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 read_unlocked (Sample *dst, framepos_t start, framecnt_t cnt) const = 0;
virtual framecnt_t write_unlocked (Sample *dst, framecnt_t cnt) = 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 */, 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, virtual int read_peaks_with_fpp (PeakData *peaks,
framecnt_t npeaks, framepos_t start, framecnt_t cnt, framecnt_t npeaks, framepos_t start, framecnt_t cnt,

View file

@ -198,7 +198,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
std::string plugins_dir () const; ///< Plugin state std::string plugins_dir () const; ///< Plugin state
std::string externals_dir () const; ///< Links to external files 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); 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); 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 string
AudioPlaylistSource::generate_peak_path (const string& /*audio_path_IGNORED*/) AudioPlaylistSource::construct_peak_filepath (const string& /*audio_path_IGNORED*/) const
{ {
return _peak_path; return _peak_path;
} }

View file

@ -164,26 +164,9 @@ AudioFileSource::init (const string& pathstr, bool must_exist)
} }
string string
AudioFileSource::generate_peak_path (const string& audio_path) AudioFileSource::construct_peak_filepath (const string& audio_path) const
{ {
string base; return _session.construct_peak_filepath (audio_path);
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);
} }
string string
@ -230,7 +213,7 @@ AudioFileSource::find_broken_peakfile (const string& peak_path, const string& au
string string
AudioFileSource::broken_peak_path (const string& audio_path) 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 string

View file

@ -239,7 +239,7 @@ AudioSource::initialize_peakfile (const string& audio_path)
{ {
GStatBuf statbuf; 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)); DEBUG_TRACE(DEBUG::Peaks, string_compose ("Initialize Peakfile %1 for Audio file %2\n", _peakpath, audio_path));

View file

@ -107,6 +107,8 @@
#include "i18n.h" #include "i18n.h"
#include <glibmm/checksum.h>
namespace ARDOUR { namespace ARDOUR {
class MidiSource; class MidiSource;
class Processor; class Processor;
@ -4362,19 +4364,20 @@ Session::count_sources_by_origin (const string& path)
} }
string 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 */ /* rip the session dir from the audiofile source */
string session_path; string session_path;
string interchange_dir_string = string (interchange_dir_name) + G_DIR_SEPARATOR;
bool in_another_session = true; 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 session name */
session_path = Glib::path_get_dirname (session_path); /* now ends in interchange */ session_path = Glib::path_get_dirname (session_path); /* now ends in interchange */
session_path = Glib::path_get_dirname (session_path); /* now has session path */ 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) { if (in_another_session) {
SessionDirectory sd (session_path); 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); std::string filename = Glib::path_get_basename (filepath);
return Glib::build_filename (_session_dir->peak_path(), basename + peakfile_suffix); 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 string

View file

@ -3052,7 +3052,7 @@ Session::cleanup_sources (CleanupReport& rep)
or for the first channel of embedded files. it will miss or for the first channel of embedded files. it will miss
some peakfiles for other channels 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 (Glib::file_test (peakpath.c_str(), Glib::FILE_TEST_EXISTS)) {
if (::g_unlink (peakpath.c_str()) != 0) { if (::g_unlink (peakpath.c_str()) != 0) {