Revert my revision 6996, which was wrong. Sources need to stay around in the session...
[ardour.git] / libs / ardour / audiosource.cc
index 2657ba94ad22695dfacaab30a7dc6992fafe9fcf..d8dd58844f8c45f44f7348b8c7b6734e79d77317 100644 (file)
@@ -148,8 +148,17 @@ AudioSource::update_length (sframes_t pos, sframes_t cnt)
   PEAK FILE STUFF
  ***********************************************************************/
 
+/** Checks to see if peaks are ready.  If so, we return true.  If not, we return false, and
+ *  things are set up so that doThisWhenReady is called when the peaks are ready.
+ *  A new PBD::ScopedConnection is created for the associated connection and written to
+ *  *connect_here_if_not.
+ *
+ *  @param doThisWhenReady Function to call when peaks are ready (if they are not already).
+ *  @param connect_here_if_not Address to write new ScopedConnection to.
+ *  @param event_loop Event loop for doThisWhenReady to be called in.
+ */
 bool
-AudioSource::peaks_ready (boost::function<void()> doThisWhenReady, Connection& connect_here_if_not, EventLoop* event_loop) const
+AudioSource::peaks_ready (boost::function<void()> doThisWhenReady, ScopedConnection** connect_here_if_not, EventLoop* event_loop) const
 {
        bool ret;
        Glib::Mutex::Lock lm (_peaks_ready_lock);
@@ -159,7 +168,8 @@ AudioSource::peaks_ready (boost::function<void()> doThisWhenReady, Connection& c
        */
 
        if (!(ret = _peaks_built)) {
-               PeaksReady.connect (connect_here_if_not, doThisWhenReady, event_loop);
+               *connect_here_if_not = new ScopedConnection;
+               PeaksReady.connect (**connect_here_if_not, MISSING_INVALIDATOR, doThisWhenReady, event_loop);
        }
 
        return ret;
@@ -548,22 +558,30 @@ AudioSource::read_peaks_with_fpp (PeakData *peaks, framecnt_t npeaks, framepos_t
 
                                to_read = min (chunksize, (framecnt_t)(_length - current_frame));
 
-                               if (to_read == 0) {
-                                       /* XXX ARGH .. out by one error ... need to figure out why this happens
-                                          and fix it rather than do this band-aid move.
-                                       */
-                                       zero_fill = npeaks - nvisual_peaks;
-                                       npeaks -= zero_fill;
-                                       break;
-                               }
-
-                               if ((frames_read = read_unlocked (raw_staging, current_frame, to_read)) == 0) {
-                                       error << string_compose(_("AudioSource[%1]: peak read - cannot read %2 samples at offset %3 of %4 (%5)"),
-                                                               _name, to_read, current_frame, _length, strerror (errno))
-                                             << endmsg;
-                                       goto out;
-                               }
+                               if (current_frame >= _length) {
 
+                                        /* hmm, error condition - we've reached the end of the file
+                                           without generating all the peak data. cook up a zero-filled
+                                           data buffer and then use it. this is simpler than
+                                           adjusting zero_fill and npeaks and then breaking out of
+                                           this loop early
+                                       */
+                                        
+                                        memset (raw_staging, 0, sizeof (Sample) * chunksize);
+                                        
+                                } else {
+                                        
+                                        to_read = min (chunksize, (_length - current_frame));
+                                        
+                                        
+                                        if ((frames_read = read_unlocked (raw_staging, current_frame, to_read)) == 0) {
+                                                error << string_compose(_("AudioSource[%1]: peak read - cannot read %2 samples at offset %3 of %4 (%5)"),
+                                                                        _name, to_read, current_frame, _length, strerror (errno))
+                                                      << endmsg;
+                                                goto out;
+                                        }
+                                }
+                                
                                i = 0;
                        }