remove offset from process callback tree. some breakage may have occured. yes, really.
[ardour.git] / libs / ardour / panner.cc
index fe0a792b6bde3c4b15f915650179bde56967aace..a00edfdd3f468730cab0e63a96a5158d8459c402 100644 (file)
 
 #include <glibmm.h>
 
-#include <pbd/error.h>
-#include <pbd/failed_constructor.h>
-#include <pbd/xml++.h>
-#include <pbd/enumwriter.h>
+#include "pbd/error.h"
+#include "pbd/failed_constructor.h"
+#include "pbd/xml++.h"
+#include "pbd/enumwriter.h"
 
-#include <ardour/session.h>
-#include <ardour/panner.h>
-#include <ardour/utils.h>
+#include "evoral/Curve.hpp"
 
-#include <ardour/runtime_functions.h>
-#include <ardour/buffer_set.h>
+#include "ardour/session.h"
+#include "ardour/panner.h"
+#include "ardour/utils.h"
+#include "ardour/audio_buffer.h"
+
+#include "ardour/runtime_functions.h"
+#include "ardour/buffer_set.h"
+#include "ardour/audio_buffer.h"
 
 #include "i18n.h"
 
-#include <pbd/mathfix.h>
+#include "pbd/mathfix.h"
 
 using namespace std;
 using namespace ARDOUR;
@@ -78,7 +82,7 @@ StreamPanner::StreamPanner (Panner& p, Evoral::Parameter param)
        _muted = false;
 
        _control = boost::dynamic_pointer_cast<AutomationControl>( parent.control( param, true ) );
-
+       
        x = 0.5;
        y = 0.5;
        z = 0.5;
@@ -496,7 +500,7 @@ EqualPowerStereoPanner::set_state (const XMLNode& node)
 
        for (XMLNodeConstIterator iter = node.children().begin(); iter != node.children().end(); ++iter) {
 
-               if ((*iter)->name() == X_("controllable")) {
+               if ((*iter)->name() == X_("Controllable")) {
                        if ((prop = (*iter)->property("name")) != 0 && prop->value() == "panner") {
                                _control->set_state (**iter);
                        }
@@ -749,10 +753,14 @@ Panner::reset (uint32_t nouts, uint32_t npans)
 {
        uint32_t n;
        bool changed = false;
+       bool do_not_and_did_not_need_panning = ((nouts < 2) && (outputs.size() < 2));
 
-       //configure_io( ChanCount( DataType::AUDIO, nout ), ChanCount( DataType::AUDIO, nin ) )
-       
-       if (nouts < 2 || (nouts == outputs.size() && npans == _streampanners.size())) {
+       /* if new and old config don't need panning, or if 
+          the config hasn't changed, we're done.
+       */
+
+       if (do_not_and_did_not_need_panning || 
+           ((nouts == outputs.size()) && (npans == _streampanners.size()))) {
                return;
        } 
 
@@ -770,19 +778,25 @@ Panner::reset (uint32_t nouts, uint32_t npans)
                changed = true;
        }
 
+       if (nouts < 2) {
+               /* no need for panning with less than 2 outputs */
+               goto send_changed;
+       }
+
        switch (nouts) {
        case 0:
+               /* XXX: this can never happen */
                break;
 
        case 1:
+               /* XXX: this can never happen */
                fatal << _("programming error:")
                      << X_("Panner::reset() called with a single output")
                      << endmsg;
                /*NOTREACHED*/
                break;
 
-       case 2:
-               /* line */
+       case 2: // line
                outputs.push_back (Output (0, 0));
                outputs.push_back (Output (1.0, 0));
 
@@ -871,6 +885,7 @@ Panner::reset (uint32_t nouts, uint32_t npans)
                }
        }
 
+  send_changed:
        if (changed) {
                Changed (); /* EMIT SIGNAL */
        }
@@ -882,7 +897,7 @@ void
 Panner::remove (uint32_t which)
 {
        vector<StreamPanner*>::iterator i;
-       for (i = _streampanners.begin(); i != _streampanners.end() && which; ++i, --which);
+       for (i = _streampanners.begin(); i != _streampanners.end() && which; ++i, --which) {}
 
        if (i != _streampanners.end()) {
                delete *i;
@@ -890,6 +905,8 @@ Panner::remove (uint32_t which)
        }
 }
 
+
+/** Remove all our StreamPanners */
 void
 Panner::clear_panners ()
 {
@@ -1051,7 +1068,7 @@ Panner::set_state (const XMLNode& node)
                                                
                                                /* note that we assume that all the stream panners
                                                   are of the same type. pretty good
-                                                  assumption, but its still an assumption.
+                                                  assumption, but it's still an assumption.
                                                */
                                                
                                                sp = pan_plugins[i].factory (*this, Evoral::Parameter(PanAutomation, 0, num_panners));
@@ -1081,7 +1098,7 @@ Panner::set_state (const XMLNode& node)
                }       
        }
 
-       reset(num_panners, outputs.size());
+       reset (outputs.size (), num_panners);
        /* don't try to do old-school automation loading if it wasn't marked as existing */
 
        if ((prop = node.property (X_("automation")))) {
@@ -1250,7 +1267,7 @@ Panner::set_position (float xpos, float ypos, float zpos, StreamPanner& orig)
 }
 
 void
-Panner::distribute_no_automation (BufferSet& inbufs, BufferSet& outbufs, nframes_t nframes, nframes_t offset, gain_t gain_coeff)
+Panner::distribute_no_automation (BufferSet& inbufs, BufferSet& outbufs, nframes_t nframes, gain_t gain_coeff)
 {
        if (outbufs.count().n_audio() == 0) {
                // Don't want to lose audio...
@@ -1271,37 +1288,37 @@ Panner::distribute_no_automation (BufferSet& inbufs, BufferSet& outbufs, nframes
 
                        /* only one output, and gain was zero, so make it silent */
 
-                       dst.silence(offset);
+                       dst.silence (nframes);
                        
                } else if (gain_coeff == 1.0f){
 
                        /* mix all buffers into the output */
 
                        // copy the first
-                       dst.read_from(inbufs.get_audio(0), nframes, offset);
+                       dst.read_from(inbufs.get_audio(0), nframes);
                        
                        // accumulate starting with the second
-            if (inbufs.count().n_audio() > 0) {
-                BufferSet::audio_iterator i = inbufs.audio_begin();
-                for (++i; i != inbufs.audio_end(); ++i) {
-                    dst.accumulate_from(*i, nframes, offset);
-                }
-            }
+                       if (inbufs.count().n_audio() > 0) {
+                               BufferSet::audio_iterator i = inbufs.audio_begin();
+                               for (++i; i != inbufs.audio_end(); ++i) {
+                                       dst.accumulate_from(*i, nframes);
+                               }
+                       }
 
                } else {
 
                        /* mix all buffers into the output, scaling them all by the gain */
 
                        // copy the first
-                       dst.read_from(inbufs.get_audio(0), nframes, offset);
+                       dst.read_from(inbufs.get_audio(0), nframes);
                        
                        // accumulate (with gain) starting with the second
-            if (inbufs.count().n_audio() > 0) {
-                       BufferSet::audio_iterator i = inbufs.audio_begin();
-                           for (++i; i != inbufs.audio_end(); ++i) {
-                               dst.accumulate_with_gain_from(*i, nframes, offset, gain_coeff);
-                       }
-            }
+                       if (inbufs.count().n_audio() > 0) {
+                               BufferSet::audio_iterator i = inbufs.audio_begin();
+                               for (++i; i != inbufs.audio_end(); ++i) {
+                                       dst.accumulate_with_gain_from(*i, nframes, gain_coeff);
+                               }
+                       }
 
                }
 
@@ -1310,7 +1327,7 @@ Panner::distribute_no_automation (BufferSet& inbufs, BufferSet& outbufs, nframes
        
        /* the terrible silence ... */
        for (BufferSet::audio_iterator i = outbufs.audio_begin(); i != outbufs.audio_end(); ++i) {
-               i->silence(nframes, offset);
+               i->silence(nframes);
        }
 
        BufferSet::audio_iterator i = inbufs.audio_begin();
@@ -1321,7 +1338,7 @@ Panner::distribute_no_automation (BufferSet& inbufs, BufferSet& outbufs, nframes
 }
 
 void
-Panner::run_out_of_place (BufferSet& inbufs, BufferSet& outbufs, nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset)
+Panner::run_out_of_place (BufferSet& inbufs, BufferSet& outbufs, nframes_t start_frame, nframes_t end_frame, nframes_t nframes)
 {      
        if (outbufs.count().n_audio() == 0) {
                // Failing to deliver audio we were asked to deliver is a bug
@@ -1343,7 +1360,7 @@ Panner::run_out_of_place (BufferSet& inbufs, BufferSet& outbufs, nframes_t start
                        gain_coeff = speed_quietning;
                }
 
-               distribute_no_automation(inbufs, outbufs, nframes, offset, gain_coeff);
+               distribute_no_automation(inbufs, outbufs, nframes, gain_coeff);
                return;
        }
 
@@ -1356,12 +1373,12 @@ Panner::run_out_of_place (BufferSet& inbufs, BufferSet& outbufs, nframes_t start
                // FIXME: apply gain automation?
 
                // copy the first
-               dst.read_from(inbufs.get_audio(0), nframes, offset);
+               dst.read_from(inbufs.get_audio(0), nframes);
 
                // accumulate starting with the second
                BufferSet::audio_iterator i = inbufs.audio_begin();
                for (++i; i != inbufs.audio_end(); ++i) {
-                       dst.accumulate_from(*i, nframes, offset);
+                       dst.accumulate_from(*i, nframes);
                }
 
                return;
@@ -1372,7 +1389,7 @@ Panner::run_out_of_place (BufferSet& inbufs, BufferSet& outbufs, nframes_t start
        
        /* the terrible silence ... */
        for (BufferSet::audio_iterator i = outbufs.audio_begin(); i != outbufs.audio_end(); ++i) {
-               i->silence(nframes, offset);
+               i->silence(nframes);
        }
 
        BufferSet::audio_iterator i = inbufs.audio_begin();