Don't set TimeFXRequest done to true too early; it must only be set after Editor...
[ardour.git] / libs / ardour / rb_effect.cc
index 805782807ae37198c1c7279efad4f5d7f2949227..f3adaec22c36269393a889cf09c0faeebb2d7c10 100644 (file)
 #include "pbd/error.h"
 #include "rubberband/RubberBandStretcher.h"
 
-#include "ardour/types.h"
-#include "ardour/stretch.h"
+#include "ardour/audioregion.h"
+#include "ardour/audiosource.h"
 #include "ardour/pitch.h"
-#include "ardour/audiofilesource.h"
+#include "ardour/progress.h"
 #include "ardour/session.h"
-#include "ardour/audioregion.h"
+#include "ardour/stretch.h"
+#include "ardour/types.h"
 
 #include "i18n.h"
 
@@ -52,7 +53,7 @@ RBEffect::RBEffect (Session& s, TimeFXRequest& req)
        , tsr (req)
 
 {
-       tsr.progress = 0.0f;
+
 }
 
 RBEffect::~RBEffect ()
@@ -60,7 +61,7 @@ RBEffect::~RBEffect ()
 }
 
 int
-RBEffect::run (boost::shared_ptr<Region> r, Progress*)
+RBEffect::run (boost::shared_ptr<Region> r, Progress* progress)
 {
        boost::shared_ptr<AudioRegion> region = boost::dynamic_pointer_cast<AudioRegion> (r);
 
@@ -81,7 +82,7 @@ RBEffect::run (boost::shared_ptr<Region> r, Progress*)
        framepos_t pos = 0;
        framecnt_t avail = 0;
        boost::shared_ptr<AudioRegion> result;
-       
+
        cerr << "RBEffect: source region: position = " << region->position()
             << ", start = " << region->start()
             << ", length = " << region->length()
@@ -160,7 +161,7 @@ RBEffect::run (boost::shared_ptr<Region> r, Progress*)
                (session.frame_rate(), channels,
                 (RubberBandStretcher::Options) tsr.opts, stretch, shift);
 
-       tsr.progress = 0.0f;
+       progress->set_progress (0);
        tsr.done = false;
 
        stretcher.setExpectedInputDuration(read_duration);
@@ -238,7 +239,7 @@ RBEffect::run (boost::shared_ptr<Region> r, Progress*)
                        pos += this_read;
                        done += this_read;
 
-                       tsr.progress = ((float) done / read_duration) * 0.25;
+                       progress->set_progress (((float) done / read_duration) * 0.25);
 
                        stretcher.study(buffers, this_read, pos == read_duration);
                }
@@ -279,7 +280,7 @@ RBEffect::run (boost::shared_ptr<Region> r, Progress*)
                        pos += this_read;
                        done += this_read;
 
-                       tsr.progress = 0.25 + ((float) done / read_duration) * 0.75;
+                       progress->set_progress (0.25 + ((float) done / read_duration) * 0.75);
 
                        stretcher.process(buffers, this_read, pos == read_duration);
 
@@ -355,7 +356,10 @@ RBEffect::run (boost::shared_ptr<Region> r, Progress*)
                                          stretch,
                                          shift);
                (*x)->set_master_sources (region->master_sources());
-               (*x)->set_length( (*x)->length() * stretch, this);
+               /* multiply the old (possibly previously stretched) region length by the extra
+                  stretch this time around to get its new length
+               */
+               (*x)->set_length ((*x)->length() * tsr.time_fraction);
        }
 
        /* stretch region gain envelope */
@@ -384,8 +388,6 @@ RBEffect::run (boost::shared_ptr<Region> r, Progress*)
                }
        }
 
-       tsr.done = true;
-
        return ret;
 }