Add support for newly introduced class ARDOUR::DSPLoadCalculator (when building with...
[ardour.git] / libs / ardour / audiosource.cc
index 51c17b5905e79a29f213e7ca0f8e13d68489e787..c79cbbbe26e1b13ef7ba44b29999352fdfc2bc0e 100644 (file)
 #include <glibmm/fileutils.h>
 #include <glibmm/miscutils.h>
 
+#include "pbd/file_utils.h"
 #include "pbd/scoped_file_descriptor.h"
 #include "pbd/xml++.h"
 
 #include "ardour/audiosource.h"
 #include "ardour/rc_configuration.h"
 #include "ardour/runtime_functions.h"
+#include "ardour/session.h"
 
 #include "i18n.h"
 
@@ -239,16 +241,20 @@ AudioSource::initialize_peakfile (const string& audio_path)
 {
        GStatBuf statbuf;
 
-       _peakpath = generate_peak_path (audio_path);
-
-       DEBUG_TRACE(DEBUG::Peaks, string_compose ("Initialize Peakfile %1 for Audio file %2\n", _peakpath, audio_path));
-
-       /* if the peak file should be there, but isn't .... */
+       _peakpath = construct_peak_filepath (audio_path);
 
        if (!empty() && !Glib::file_test (_peakpath.c_str(), Glib::FILE_TEST_EXISTS)) {
-               _peakpath = find_broken_peakfile (_peakpath, audio_path);
+               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)) {
                if (errno != ENOENT) {
                        /* it exists in the peaks dir, but there is some kind of error */
@@ -744,12 +750,22 @@ AudioSource::build_peaks_from_scratch ()
                                goto out;
                        }
 
+                       lp.release(); // allow butler to refill buffers
+
+                       if (_session.deletion_in_progress()) {
+                               cerr << "peak file creation interrupted: " << _name << endmsg;
+                               done_with_peakfile_writes (false);
+                               goto out;
+                       }
+
                        if (compute_and_write_peaks (buf.get(), current_frame, frames_read, true, false, _FPP)) {
                                break;
                        }
 
                        current_frame += frames_read;
                        cnt -= frames_read;
+
+                       lp.acquire();
                }
 
                if (cnt == 0) {