minor but important fix for the wrap-buffer case in a recording audio diskstream
[ardour.git] / libs / ardour / crossfade.cc
index 302b19399e7d34fcc10ecf2b4f6f0544a2db698d..dc8d3e3c526f2ec6c2332bb2f9f6ccb13d73e5a0 100644 (file)
@@ -17,9 +17,6 @@
 
 */
 
-
-#include "pbd/stacktrace.h"
-
 #include "ardour/debug.h"
 #include "ardour/types.h"
 #include "ardour/crossfade.h"
@@ -152,7 +149,7 @@ Crossfade::Crossfade (const Playlist& playlist, XMLNode const & node)
                */
                r = RegionFactory::region_by_id (id);
        }
-       
+
        if (!r) {
                error << string_compose (_("Crossfade: no \"in\" region %1 found in playlist %2 nor in region map"), id, playlist.name())
                      << endmsg;
@@ -175,7 +172,7 @@ Crossfade::Crossfade (const Playlist& playlist, XMLNode const & node)
        if (!r) {
                r = RegionFactory::region_by_id (id2);
        }
-       
+
        if (!r) {
                error << string_compose (_("Crossfade: no \"out\" region %1 found in playlist %2 nor in region map"), id2, playlist.name())
                      << endmsg;
@@ -239,7 +236,7 @@ Crossfade::initialize ()
         for (SourceList::iterator i = _sources.begin(); i != _sources.end(); ++i) {
                 (*i)->inc_use_count ();
         }
-        
+
        _master_sources = _in->master_sources();
        _master_sources.insert(_master_sources.end(), _out->master_sources().begin(), _out->master_sources().end());
 
@@ -317,8 +314,8 @@ Crossfade::read_raw_internal (Sample* buf, framecnt_t start, framecnt_t cnt, int
        Sample* mixdown = new Sample[cnt];
        float* gain = new float[cnt];
        framecnt_t ret;
-       
-       ret = read_at (buf, mixdown, gain, start, cnt, channel, cnt);
+
+       ret = read_at (buf, mixdown, gain, start, cnt, channel);
 
        delete [] mixdown;
        delete [] gain;
@@ -328,8 +325,7 @@ Crossfade::read_raw_internal (Sample* buf, framecnt_t start, framecnt_t cnt, int
 
 framecnt_t
 Crossfade::read_at (Sample *buf, Sample *mixdown_buffer,
-                   float *gain_buffer, framepos_t start, framecnt_t cnt, uint32_t chan_n,
-                   framecnt_t read_frames, framecnt_t skip_frames) const
+                   float *gain_buffer, framepos_t start, framecnt_t cnt, uint32_t chan_n) const
 {
        frameoffset_t offset;
        framecnt_t to_write;
@@ -371,8 +367,8 @@ Crossfade::read_at (Sample *buf, Sample *mixdown_buffer,
                memset (crossfade_buffer_in, 0, sizeof (Sample) * to_write);
        }
 
-       _out->read_at (crossfade_buffer_out, mixdown_buffer, gain_buffer, start, to_write, chan_n, read_frames, skip_frames);
-       _in->read_at (crossfade_buffer_in, mixdown_buffer, gain_buffer, start, to_write, chan_n, read_frames, skip_frames);
+       _out->read_at (crossfade_buffer_out, mixdown_buffer, gain_buffer, start, to_write, chan_n);
+       _in->read_at (crossfade_buffer_in, mixdown_buffer, gain_buffer, start, to_write, chan_n);
 
        float* fiv = new float[to_write];
        float* fov = new float[to_write];
@@ -441,7 +437,7 @@ Crossfade::refresh ()
                Invalidated (shared_from_this());
                return false;
        }
-        
+
         /* regions must cannot be identically sized and placed */
 
         if (_in->position() == _out->position() && _in->length() == _out->length()) {
@@ -590,8 +586,8 @@ Crossfade::compute (boost::shared_ptr<AudioRegion> a, boost::shared_ptr<AudioReg
                        } else {
                                _position = top->last_frame() - short_xfade_length;
                        }
-
-                       _length = min (short_xfade_length, top->length());
+                       
+                       set_xfade_length (min (short_xfade_length, top->length()));
                        _follow_overlap = false;
                        _anchor_point = EndOfIn;
                        _active = true;
@@ -625,7 +621,7 @@ Crossfade::compute (boost::shared_ptr<AudioRegion> a, boost::shared_ptr<AudioReg
                        _in = top;
                        _out = bottom;
                        _position = top->first_frame();
-                       _length = min (short_xfade_length, top->length());
+                       set_xfade_length (min (short_xfade_length, top->length()));
                        _follow_overlap = false;
                        _anchor_point = StartOfIn;
                        _active = true;
@@ -674,11 +670,11 @@ Crossfade::compute (boost::shared_ptr<AudioRegion> a, boost::shared_ptr<AudioReg
 
                        if (model == FullCrossfade) {
                                _position = bottom->first_frame(); // "{"
-                               _length = _out->first_frame() + _out->length() - _in->first_frame();
+                               set_xfade_length (_out->first_frame() + _out->length() - _in->first_frame());
                                /* leave active alone */
                                _follow_overlap = true;
                        } else {
-                               _length = min (short_xfade_length, top->length());
+                               set_xfade_length (min (short_xfade_length, top->length()));
                                _position = top->last_frame() - _length;  // "]" - length
                                _active = true;
                                _follow_overlap = false;
@@ -698,11 +694,11 @@ Crossfade::compute (boost::shared_ptr<AudioRegion> a, boost::shared_ptr<AudioReg
                        _anchor_point = StartOfIn;
 
                        if (model == FullCrossfade) {
-                               _length = _out->first_frame() + _out->length() - _in->first_frame();
+                               set_xfade_length (_out->first_frame() + _out->length() - _in->first_frame());
                                /* leave active alone */
                                _follow_overlap = true;
                        } else {
-                               _length = min (short_xfade_length, top->length());
+                               set_xfade_length (min (short_xfade_length, top->length()));
                                _active = true;
                                _follow_overlap = false;
 
@@ -979,7 +975,7 @@ Crossfade::set_xfade_length (framecnt_t len)
        _length = len;
 
        PropertyChanged (PropertyChange (Properties::length));
-       
+
        return len;
 }