fix bug in path_expand() when passed an empty string
[ardour.git] / libs / ardour / audiosource.cc
index d8640306463708c61bedeb64c23d08c546478686..360e4cd48ad493736bc4d25c174de6539ad74dc6 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)
 {
@@ -126,14 +125,20 @@ AudioSource::set_state (const XMLNode& node, int /*version*/)
        return 0;
 }
 
-sframes_t
-AudioSource::length (sframes_t /*pos*/) const
+bool
+AudioSource::empty () const
+{
+        return _length == 0;
+}
+
+framecnt_t
+AudioSource::length (framepos_t /*pos*/) const
 {
        return _length;
 }
 
 void
-AudioSource::update_length (sframes_t pos, sframes_t cnt)
+AudioSource::update_length (framepos_t pos, framecnt_t cnt)
 {
        if (pos + cnt > _length) {
                _length = pos + cnt;
@@ -160,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);
@@ -190,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) {
@@ -209,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;
 
@@ -678,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;
                }
        }
@@ -718,7 +713,9 @@ 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;
@@ -874,7 +871,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 */
                }
        }
@@ -917,7 +914,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);
        }
 }
 
@@ -939,3 +936,24 @@ AudioSource::available_peaks (double zoom_factor) const
        return (end/sizeof(PeakData)) * _FPP;
 }
 
+void
+AudioSource::dec_read_data_count (nframes_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 */
+       }
+}