Move panner bypass state up to the PannerShell so that it is preserved even when...
[ardour.git] / libs / ardour / panner_shell.cc
index c6cbbe36abdcd0b28f6667cc08efdc6e311faaa5..c3ca2b4694ff2f3735257a0f6b3c0f19d62f2c0e 100644 (file)
@@ -33,6 +33,7 @@
 #include <glibmm.h>
 
 #include "pbd/cartesian.h"
+#include "pbd/boost_debug.h"
 #include "pbd/convert.h"
 #include "pbd/error.h"
 #include "pbd/failed_constructor.h"
@@ -45,6 +46,7 @@
 #include "ardour/audio_buffer.h"
 #include "ardour/automatable.h"
 #include "ardour/buffer_set.h"
+#include "ardour/debug.h"
 #include "ardour/pannable.h"
 #include "ardour/panner.h"
 #include "ardour/panner_manager.h"
@@ -63,62 +65,74 @@ using namespace PBD;
 
 PannerShell::PannerShell (string name, Session& s, boost::shared_ptr<Pannable> p)
        : SessionObject (s, name)
-        , _pannable (p)
+       , _pannable (p)
+       , _bypassed (false)
 {
        set_name (name);
 }
 
 PannerShell::~PannerShell ()
 {
+       DEBUG_TRACE(DEBUG::Destruction, string_compose ("panner shell for %1 destructor, pannable is %2\n", _name, _pannable));
 }
 
 void
 PannerShell::configure_io (ChanCount in, ChanCount out)
 {
-        uint32_t nouts = out.n_audio();
-        uint32_t nins = in.n_audio();
+       uint32_t nouts = out.n_audio();
+       uint32_t nins = in.n_audio();
 
        /* if new and old config don't need panning, or if
           the config hasn't changed, we're done.
        */
 
-       if (_panner && _panner->in().n_audio() == nins && _panner->out().n_audio() == nouts) {
-                return;
+       if (_panner && (_panner->in().n_audio() == nins) && (_panner->out().n_audio() == nouts)) {
+               return;
        }
 
        if (nouts < 2 || nins == 0) {
                /* no need for panning with less than 2 outputs or no inputs */
                if (_panner) {
-                        _panner.reset ();
+                       _panner.reset ();
                        Changed (); /* EMIT SIGNAL */
                }
                return;
        }
 
-        PannerInfo* pi = PannerManager::instance().select_panner (in, out);
+       PannerInfo* pi = PannerManager::instance().select_panner (in, out);
+       if (!pi) {
+               cerr << "No panner found: check that panners are being discovered correctly during startup.\n";
+               assert (pi);
+       }
 
-        if (pi == 0) {
-                abort ();
-        }
+       boost::shared_ptr<Speakers> speakers = _session.get_speakers ();
 
-        _panner.reset (pi->descriptor.factory (_pannable, _session.get_speakers()));
+       if (nouts != speakers->size()) {
+               /* hmm, output count doesn't match session speaker count so
+                  create a new speaker set.
+               */
+               Speakers* s = new Speakers ();
+               s->setup_default_speakers (nouts);
+               speakers.reset (s);
+       }
 
-        Changed (); /* EMIT SIGNAL */
-}
+       Panner* p = pi->descriptor.factory (_pannable, speakers);
+       boost_debug_shared_ptr_mark_interesting (p, "Panner");
+       _panner.reset (p);
+       _panner->configure_io (in, out);
 
-XMLNode&
-PannerShell::get_state (void)
-{
-       return state (true);
+       Changed (); /* EMIT SIGNAL */
 }
 
 XMLNode&
-PannerShell::state (bool full)
+PannerShell::get_state ()
 {
        XMLNode* node = new XMLNode ("PannerShell");
 
-        if (_panner) {
-               node->add_child_nocopy (_panner->state (full));
+       node->add_property (X_("bypassed"), _bypassed ? X_("yes") : X_("no"));
+
+       if (_panner) {
+               node->add_child_nocopy (_panner->get_state ());
        }
 
        return *node;
@@ -132,7 +146,11 @@ PannerShell::set_state (const XMLNode& node, int version)
        const XMLProperty *prop;
        LocaleGuard lg (X_("POSIX"));
 
-        _panner.reset ();
+       if ((prop = node.property (X_("bypassed"))) != 0) {
+               set_bypassed (string_is_affirmative (prop->value ()));
+       }
+
+       _panner.reset ();
 
        for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
 
@@ -140,8 +158,8 @@ PannerShell::set_state (const XMLNode& node, int version)
 
                        if ((prop = (*niter)->property (X_("type")))) {
 
-                                list<PannerInfo*>::iterator p;
-                                PannerManager& pm (PannerManager::instance());
+                               list<PannerInfo*>::iterator p;
+                               PannerManager& pm (PannerManager::instance());
 
                                for (p = pm.panner_info.begin(); p != pm.panner_info.end(); ++p) {
                                        if (prop->value() == (*p)->descriptor.name) {
@@ -150,12 +168,12 @@ PannerShell::set_state (const XMLNode& node, int version)
                                                   are of the same type. pretty good
                                                   assumption, but it's still an assumption.
                                                */
-                                                        
-                                                _panner.reset ((*p)->descriptor.factory (_pannable, _session.get_speakers ()));
-                                                
+
+                                               _panner.reset ((*p)->descriptor.factory (_pannable, _session.get_speakers ()));
+
                                                if (_panner->set_state (**niter, version) == 0) {
-                                                        return -1;
-                                                }
+                                                       return -1;
+                                               }
 
                                                break;
                                        }
@@ -163,7 +181,7 @@ PannerShell::set_state (const XMLNode& node, int version)
 
                                if (p == pm.panner_info.end()) {
                                        error << string_compose (_("Unknown panner plugin \"%1\" found in pan state - ignored"),
-                                                         prop->value())
+                                                                prop->value())
                                              << endmsg;
                                }
 
@@ -190,7 +208,7 @@ PannerShell::distribute_no_automation (BufferSet& inbufs, BufferSet& outbufs, pf
 
        if (outbufs.count().n_audio() == 1) {
 
-                /* just one output: no real panning going on */
+               /* just one output: no real panning going on */
 
                AudioBuffer& dst = outbufs.get_audio(0);
 
@@ -235,19 +253,19 @@ PannerShell::distribute_no_automation (BufferSet& inbufs, BufferSet& outbufs, pf
                return;
        }
 
-        /* multiple outputs ... we must have a panner */
+       /* multiple outputs ... we must have a panner */
 
-        assert (_panner);
+       assert (_panner);
 
        /* setup silent buffers so that we can mix into the outbuffers (slightly suboptimal -
-           better to copy the first set of data then mix after that, but hey, its 2011)
-         */
+          better to copy the first set of data then mix after that, but hey, its 2011)
+       */
 
        for (BufferSet::audio_iterator b = outbufs.audio_begin(); b != outbufs.audio_end(); ++b) {
                (*b).silence (nframes);
        }
 
-        _panner->distribute (inbufs, outbufs, gain_coeff, nframes);
+       _panner->distribute (inbufs, outbufs, gain_coeff, nframes);
 }
 
 void
@@ -261,7 +279,7 @@ PannerShell::run (BufferSet& inbufs, BufferSet& outbufs, framepos_t start_frame,
 
        if (outbufs.count().n_audio() == 1) {
 
-                /* one output only: no panner */
+               /* one output only: no panner */
 
                AudioBuffer& dst = outbufs.get_audio(0);
 
@@ -281,7 +299,7 @@ PannerShell::run (BufferSet& inbufs, BufferSet& outbufs, framepos_t start_frame,
 
        // More than 1 output
 
-        AutoState as = _panner->automation_state ();
+       AutoState as = _panner->automation_state ();
 
        // If we shouldn't play automation defer to distribute_no_automation
 
@@ -289,7 +307,7 @@ PannerShell::run (BufferSet& inbufs, BufferSet& outbufs, framepos_t start_frame,
 
                // Speed quietning
                gain_t gain_coeff = 1.0;
-                
+
                if (fabsf(_session.transport_speed()) > 1.5f && Config->get_quieten_at_speed ()) {
                        gain_coeff = speed_quietning;
                }
@@ -298,14 +316,30 @@ PannerShell::run (BufferSet& inbufs, BufferSet& outbufs, framepos_t start_frame,
 
        } else {
 
-                /* setup the terrible silence so that we can mix into the outbuffers (slightly suboptimal -
-                   better to copy the first set of data then mix after that, but hey, its 2011)
-                */
-                for (BufferSet::audio_iterator i = outbufs.audio_begin(); i != outbufs.audio_end(); ++i) {
-                        i->silence(nframes);
-                }
-                
-                _panner->distribute_automated (inbufs, outbufs, start_frame, end_frame, nframes, _session.pan_automation_buffer());
-        }
+               /* setup the terrible silence so that we can mix into the outbuffers (slightly suboptimal -
+                  better to copy the first set of data then mix after that, but hey, its 2011)
+               */
+               for (BufferSet::audio_iterator i = outbufs.audio_begin(); i != outbufs.audio_end(); ++i) {
+                       i->silence(nframes);
+               }
+
+               _panner->distribute_automated (inbufs, outbufs, start_frame, end_frame, nframes, _session.pan_automation_buffer());
+       }
+}
+
+void
+PannerShell::set_bypassed (bool yn)
+{
+       if (yn == _bypassed) {
+               return;
+       }
+       
+       _bypassed = yn;
+       Changed (); /* EMIT SIGNAL */
 }
 
+bool
+PannerShell::bypassed () const
+{
+       return _bypassed;
+}