extensive changes to PresentationInfo API
[ardour.git] / libs / ardour / st_stretch.cc
index 5adf8ad6d1fe2c4315ecfd4511da8f05778f2c9a..b031ee28f935c96dd892cf13c397a1ad8bee7f24 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2004-2007 Paul Davis 
+    Copyright (C) 2004-2007 Paul Davis
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -41,8 +41,8 @@ STStretch::STStretch (Session& s, TimeFXRequest& req)
 {
        float percentage;
 
-       /* the soundtouch code wants a *tempo* change percentage, which is 
-          of opposite sign to the length change.  
+       /* the soundtouch code wants a *tempo* change percentage, which is
+          of opposite sign to the length change.
        */
 
        percentage = -tsr.time_fraction;
@@ -52,11 +52,10 @@ STStretch::STStretch (Session& s, TimeFXRequest& req)
        st.setTempoChange (percentage);
        st.setPitchSemiTones (0);
        st.setRateChange (0);
-       
+
        st.setSetting(SETTING_USE_QUICKSEEK, tsr.quick_seek);
        st.setSetting(SETTING_USE_AA_FILTER, tsr.antialias);
 
-       tsr.progress = 0.0f;
 }
 
 STStretch::~STStretch ()
@@ -64,22 +63,22 @@ STStretch::~STStretch ()
 }
 
 int
-STStretch::run (boost::shared_ptr<Region> a_region)
+STStretch::run (boost::shared_ptr<Region> a_region, Progress* progress)
 {
        SourceList nsrcs;
-       nframes_t total_frames;
-       nframes_t done;
+       framecnt_t total_frames;
+       framecnt_t done;
        int ret = -1;
-       const nframes_t bufsize = 16384;
+       const framecnt_t bufsize = 16384;
        gain_t *gain_buffer = 0;
        Sample *buffer = 0;
        char suffix[32];
        string new_name;
        string::size_type at;
 
-       tsr.progress = 0.0f;
+       progress->set_progress (0);
        tsr.done = false;
-       
+
        boost::shared_ptr<AudioRegion> region = boost::dynamic_pointer_cast<AudioRegion>(a_region);
 
        total_frames = region->length() * region->n_channels();
@@ -88,11 +87,11 @@ STStretch::run (boost::shared_ptr<Region> a_region)
        /* the name doesn't need to be super-precise, but allow for 2 fractional
           digits just to disambiguate close but not identical stretches.
        */
-       
+
        snprintf (suffix, sizeof (suffix), "@%d", (int) floor (tsr.time_fraction * 100.0f));
 
        /* create new sources */
-       
+
        if (make_new_sources (region, nsrcs, suffix)) {
                goto out;
        }
@@ -108,33 +107,33 @@ STStretch::run (boost::shared_ptr<Region> a_region)
                        boost::shared_ptr<AudioSource> asrc
                                = boost::dynamic_pointer_cast<AudioSource>(nsrcs[i]);
 
-                       nframes_t pos = 0;
-                       nframes_t this_read = 0;
+                       framepos_t pos = 0;
+                       framecnt_t this_read = 0;
 
                        st.clear();
 
                        while (!tsr.cancel && pos < region->length()) {
-                               nframes_t this_time;
-                       
+                               framecnt_t this_time;
+
                                this_time = min (bufsize, region->length() - pos);
 
-                               /* read from the master (original) sources for the region, 
-                                  not the ones currently in use, in case it's already been 
-                                  subject to timefx.  
+                               /* read from the master (original) sources for the region,
+                                  not the ones currently in use, in case it's already been
+                                  subject to timefx.
                                */
 
                                if ((this_read = region->master_read_at (buffer, buffer, gain_buffer, pos + region->position(), this_time)) != this_time) {
                                        error << string_compose (_("tempoize: error reading data from %1"), asrc->name()) << endmsg;
                                        goto out;
                                }
-                       
+
                                pos += this_read;
                                done += this_read;
 
-                               tsr.progress = (float) done / total_frames;
-                               
+                               progress->set_progress ((float) done / total_frames);
+
                                st.putSamples (buffer, this_read);
-                       
+
                                while ((this_read = st.receiveSamples (buffer, bufsize)) > 0 && !tsr.cancel) {
                                        if (asrc->write (buffer, this_read) != this_read) {
                                                error << string_compose (_("error writing tempo-adjusted data to %1"), asrc->name()) << endmsg;
@@ -142,11 +141,11 @@ STStretch::run (boost::shared_ptr<Region> a_region)
                                        }
                                }
                        }
-               
+
                        if (!tsr.cancel) {
                                st.flush ();
                        }
-               
+
                        while (!tsr.cancel && (this_read = st.receiveSamples (buffer, bufsize)) > 0) {
                                if (asrc->write (buffer, this_read) != this_read) {
                                        error << string_compose (_("error writing tempo-adjusted data to %1"), asrc->name()) << endmsg;
@@ -177,18 +176,18 @@ STStretch::run (boost::shared_ptr<Region> a_region)
        /* now reset ancestral data for each new region */
 
        for (vector<boost::shared_ptr<Region> >::iterator x = results.begin(); x != results.end(); ++x) {
-               nframes64_t astart = (*x)->ancestral_start();
-               nframes64_t alength = (*x)->ancestral_length();
-               nframes_t start;
-               nframes_t length;
+               framepos_t astart = (*x)->ancestral_start();
+               framepos_t alength = (*x)->ancestral_length();
+               framepos_t start;
+               framecnt_t length;
 
-               // note: tsr.fraction is a percentage of original length. 100 = no change, 
+               // note: tsr.fraction is a percentage of original length. 100 = no change,
                // 50 is half as long, 200 is twice as long, etc.
 
                float stretch = (*x)->stretch() * (tsr.time_fraction/100.0);
 
-               start = (nframes_t) floor (astart + ((astart - (*x)->start()) / stretch));
-               length = (nframes_t) floor (alength / stretch);
+               start = (framepos_t) floor (astart + ((astart - (*x)->start()) / stretch));
+               length = (framecnt_t) floor (alength / stretch);
 
                (*x)->set_ancestral_data (start, length, stretch, (*x)->shift());
        }
@@ -203,8 +202,6 @@ STStretch::run (boost::shared_ptr<Region> a_region)
                        (*si)->mark_for_remove ();
                }
        }
-       
-       tsr.done = true;
 
        return ret;
 }