Make stem export export from right before any processors.
[ardour.git] / libs / ardour / audiosource.cc
index a25e24ab7a4a6053559d8798c0531883eb4bfd06..b993a093b50b0eda3087bee4ac25154c4e08c9f9 100644 (file)
@@ -48,7 +48,6 @@
 using namespace std;
 using namespace ARDOUR;
 using namespace PBD;
-using Glib::ustring;
 
 bool AudioSource::_build_missing_peakfiles = false;
 
@@ -57,7 +56,7 @@ bool AudioSource::_build_peakfiles = false;
 
 #define _FPP 256
 
-AudioSource::AudioSource (Session& s, ustring name)
+AudioSource::AudioSource (Session& s, string name)
        : Source (s, DataType::AUDIO, name)
        , _length (0)
 {
@@ -166,10 +165,6 @@ AudioSource::peaks_ready (boost::function<void()> doThisWhenReady, ScopedConnect
        bool ret;
        Glib::Mutex::Lock lm (_peaks_ready_lock);
 
-       /* check to see if the peak data is ready. if not
-          connect the slot while still holding the lock.
-       */
-
        if (!(ret = _peaks_built)) {
                *connect_here_if_not = new ScopedConnection;
                PeaksReady.connect (**connect_here_if_not, MISSING_INVALIDATOR, doThisWhenReady, event_loop);
@@ -196,11 +191,11 @@ AudioSource::touch_peakfile ()
 }
 
 int
-AudioSource::rename_peakfile (ustring newpath)
+AudioSource::rename_peakfile (string newpath)
 {
        /* caller must hold _lock */
 
-       ustring oldpath = peakpath;
+       string oldpath = peakpath;
 
        if (access (oldpath.c_str(), F_OK) == 0) {
                if (rename (oldpath.c_str(), newpath.c_str()) != 0) {
@@ -215,7 +210,7 @@ AudioSource::rename_peakfile (ustring newpath)
 }
 
 int
-AudioSource::initialize_peakfile (bool newfile, ustring audio_path)
+AudioSource::initialize_peakfile (bool newfile, string audio_path)
 {
        struct stat statbuf;
 
@@ -243,7 +238,7 @@ AudioSource::initialize_peakfile (bool newfile, ustring audio_path)
 
                /* we found it in the peaks dir, so check it out */
 
-               if (statbuf.st_size == 0 || ((nframes_t) statbuf.st_size < ((length(_timeline_position) / _FPP) * sizeof (PeakData)))) {
+               if (statbuf.st_size == 0 || (statbuf.st_size < (off_t) ((length(_timeline_position) / _FPP) * sizeof (PeakData)))) {
                        // empty
                        _peaks_built = false;
                } else {
@@ -653,7 +648,7 @@ AudioSource::build_peaks_from_scratch ()
                        goto out;
                }
 
-               framepos_t current_frame = 0;
+               framecnt_t current_frame = 0;
                framecnt_t cnt = _length;
 
                _peaks_built = false;
@@ -684,13 +679,7 @@ AudioSource::build_peaks_from_scratch ()
                }
 
                done_with_peakfile_writes ((cnt == 0));
-       }
-
-       {
-               Glib::Mutex::Lock lm (_peaks_ready_lock);
-
-               if (_peaks_built) {
-                       PeaksReady (); /* EMIT SIGNAL */
+               if (cnt == 0) {
                        ret = 0;
                }
        }
@@ -724,22 +713,25 @@ AudioSource::done_with_peakfile_writes (bool done)
        }
 
        if (done) {
+               Glib::Mutex::Lock lm (_peaks_ready_lock);
                _peaks_built = true;
+               PeaksReady (); /* EMIT SIGNAL */
        }
 
        delete _peakfile_descriptor;
        _peakfile_descriptor = 0;
 }
 
+/** @param first_frame Offset from the source start of the first frame to process */
 int
-AudioSource::compute_and_write_peaks (Sample* buf, framepos_t first_frame, framecnt_t cnt,
+AudioSource::compute_and_write_peaks (Sample* buf, framecnt_t first_frame, framecnt_t cnt,
                                      bool force, bool intermediate_peaks_ready)
 {
        return compute_and_write_peaks (buf, first_frame, cnt, force, intermediate_peaks_ready, _FPP);
 }
 
 int
-AudioSource::compute_and_write_peaks (Sample* buf, framepos_t first_frame, framecnt_t cnt,
+AudioSource::compute_and_write_peaks (Sample* buf, framecnt_t first_frame, framecnt_t cnt,
                                      bool force, bool intermediate_peaks_ready, framecnt_t fpp)
 {
        Sample* buf2 = 0;
@@ -880,7 +872,7 @@ AudioSource::compute_and_write_peaks (Sample* buf, framepos_t first_frame, frame
                off_t target_length = blocksize * ((first_peak_byte + blocksize + 1) / blocksize);
 
                if (endpos < target_length) {
-                       ftruncate (_peakfile_fd, target_length);
+                       (void) ftruncate (_peakfile_fd, target_length);
                        /* error doesn't actually matter though, so continue on without testing */
                }
        }
@@ -923,7 +915,7 @@ AudioSource::truncate_peakfile ()
        off_t end = lseek (_peakfile_fd, 0, SEEK_END);
 
        if (end > _peak_byte_max) {
-               ftruncate (_peakfile_fd, _peak_byte_max);
+               (void) ftruncate (_peakfile_fd, _peak_byte_max);
        }
 }
 
@@ -945,3 +937,24 @@ AudioSource::available_peaks (double zoom_factor) const
        return (end/sizeof(PeakData)) * _FPP;
 }
 
+void
+AudioSource::dec_read_data_count (framecnt_t cnt)
+{
+        uint32_t val = cnt * sizeof (Sample);
+
+        if (val < _read_data_count) {
+                _read_data_count -= val;
+        } else { 
+                _read_data_count = 0;
+        }
+}
+
+void
+AudioSource::mark_streaming_write_completed ()
+{
+       Glib::Mutex::Lock lm (_peaks_ready_lock);
+
+       if (_peaks_built) {
+               PeaksReady (); /* EMIT SIGNAL */
+       }
+}