Use PBD::sys::operator/ instead of PBD::sys::path::operator/= in ARDOUR::SessionDirectory
[ardour.git] / libs / ardour / panner.cc
index 2690ac868dbe929a73e690131c28326ed3e50e78..3e57037d6fb66a449425fab092a2d42c14500ee5 100644 (file)
@@ -69,13 +69,15 @@ static double direct_pan_to_control (pan_t val) {
        return val;
 }
 
-StreamPanner::StreamPanner (Panner& p)
-       : parent (p),
-         _control (X_("panner"), *this)
+StreamPanner::StreamPanner (Panner& p, Parameter param)
+       : parent (p)
+       , _control (new PanControllable(p.session(), X_("panner"), *this, param))
 {
+       assert(param.type() != NullAutomation);
+
        _muted = false;
 
-       parent.session().add_controllable (&_control);
+       parent.session().add_controllable (_control);
 
        x = 0.5;
        y = 0.5;
@@ -132,7 +134,7 @@ StreamPanner::set_position (float xpos, bool link_call)
                x = xpos;
                update ();
                Changed ();
-               _control.Changed ();
+               _control->Changed ();
        }
 }
 
@@ -189,8 +191,8 @@ StreamPanner::add_state (XMLNode& node)
 
 /*---------------------------------------------------------------------- */
 
-BaseStereoPanner::BaseStereoPanner (Panner& p)
-       : StreamPanner (p), _automation (0.0, 1.0, 0.5)
+BaseStereoPanner::BaseStereoPanner (Panner& p, Parameter param)
+       : StreamPanner (p, param)
 {
 }
 
@@ -198,50 +200,13 @@ BaseStereoPanner::~BaseStereoPanner ()
 {
 }
 
-void
-BaseStereoPanner::snapshot (nframes_t now)
-{
-       if (_automation.automation_state() == Write || _automation.automation_state() == Touch) {
-               _automation.rt_add (now, x);
-       }
-}
-
-void
-BaseStereoPanner::transport_stopped (nframes_t frame)
-{
-       _automation.reposition_for_rt_add (frame);
-
-       if (_automation.automation_state() != Off) {
-               set_position (_automation.eval (frame));
-       }
-}
-
-void
-BaseStereoPanner::set_automation_style (AutoStyle style)
-{
-       _automation.set_automation_style (style);
-}
-
-void
-BaseStereoPanner::set_automation_state (AutoState state)
-{
-       if (state != _automation.automation_state()) {
-
-               _automation.set_automation_state (state);
-               
-               if (state != Off) {
-                       set_position (_automation.eval (parent.session().transport_frame()));
-               }
-       }
-}
-
 int
 BaseStereoPanner::load (istream& in, string path, uint32_t& linecnt)
 {
        char line[128];
        LocaleGuard lg (X_("POSIX"));
        
-       _automation.clear ();
+       _control->list()->clear ();
 
        while (in.getline (line, sizeof (line), '\n')) {
                nframes_t when;
@@ -258,12 +223,12 @@ BaseStereoPanner::load (istream& in, string path, uint32_t& linecnt)
                        continue;
                }
 
-               _automation.fast_simple_add (when, value);
+               _control->list()->fast_simple_add (when, value);
        }
 
        /* now that we are done loading */
 
-       _automation.StateChanged ();
+       _control->list()->StateChanged ();
 
        return 0;
 }
@@ -271,7 +236,7 @@ BaseStereoPanner::load (istream& in, string path, uint32_t& linecnt)
 void
 BaseStereoPanner::distribute (AudioBuffer& srcbuf, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes)
 {
-       assert(obufs.count().get(DataType::AUDIO) == 2);
+       assert(obufs.count().n_audio() == 2);
 
        pan_t delta;
        Sample* dst;
@@ -383,8 +348,8 @@ BaseStereoPanner::distribute (AudioBuffer& srcbuf, BufferSet& obufs, gain_t gain
 
 /*---------------------------------------------------------------------- */
 
-EqualPowerStereoPanner::EqualPowerStereoPanner (Panner& p)
-       : BaseStereoPanner (p)
+EqualPowerStereoPanner::EqualPowerStereoPanner (Panner& p, Parameter param)
+       : BaseStereoPanner (p, param)
 {
        update ();
 
@@ -423,6 +388,7 @@ EqualPowerStereoPanner::update ()
        desired_right = panR * (scale * panR + 1.0f - scale);
 
        effective_x = x;
+       _control->set_value(x);
 }
 
 void
@@ -430,7 +396,7 @@ EqualPowerStereoPanner::distribute_automated (AudioBuffer& srcbuf, BufferSet& ob
                                              nframes_t start, nframes_t end, nframes_t nframes,
                                              pan_t** buffers)
 {
-       assert(obufs.count().get(DataType::AUDIO) == 2);
+       assert(obufs.count().n_audio() == 2);
 
        Sample* dst;
        pan_t* pbuf;
@@ -438,7 +404,7 @@ EqualPowerStereoPanner::distribute_automated (AudioBuffer& srcbuf, BufferSet& ob
 
        /* fetch positional data */
 
-       if (!_automation.rt_safe_get_vector (start, end, buffers[0], nframes)) {
+       if (!_control->list()->curve().rt_safe_get_vector (start, end, buffers[0], nframes)) {
                /* fallback */
                if (!_muted) {
                        distribute (srcbuf, obufs, 1.0, nframes);
@@ -448,8 +414,10 @@ EqualPowerStereoPanner::distribute_automated (AudioBuffer& srcbuf, BufferSet& ob
 
        /* store effective pan position. do this even if we are muted */
 
-       if (nframes > 0) 
+       if (nframes > 0) {
                effective_x = buffers[0][nframes-1];
+               _control->set_value(effective_x); // signal, update UI
+       }
 
        if (_muted) {
                return;
@@ -495,9 +463,9 @@ EqualPowerStereoPanner::distribute_automated (AudioBuffer& srcbuf, BufferSet& ob
 }
 
 StreamPanner*
-EqualPowerStereoPanner::factory (Panner& parent)
+EqualPowerStereoPanner::factory (Panner& parent, Parameter param)
 {
-       return new EqualPowerStereoPanner (parent);
+       return new EqualPowerStereoPanner (parent, param);
 }
 
 XMLNode&
@@ -518,12 +486,12 @@ EqualPowerStereoPanner::state (bool full_state)
        root->add_property (X_("type"), EqualPowerStereoPanner::name);
 
        XMLNode* autonode = new XMLNode (X_("Automation"));
-       autonode->add_child_nocopy (_automation.state (full_state));
+       autonode->add_child_nocopy (_control->list()->state (full_state));
        root->add_child_nocopy (*autonode);
 
        StreamPanner::add_state (*root);
 
-       root->add_child_nocopy (_control.get_state ());
+       root->add_child_nocopy (_control->get_state ());
 
        return *root;
 }
@@ -546,15 +514,15 @@ EqualPowerStereoPanner::set_state (const XMLNode& node)
 
                if ((*iter)->name() == X_("controllable")) {
                        if ((prop = (*iter)->property("name")) != 0 && prop->value() == "panner") {
-                               _control.set_state (**iter);
+                               _control->set_state (**iter);
                        }
 
                } else if ((*iter)->name() == X_("Automation")) {
 
-                       _automation.set_state (*((*iter)->children().front()));
+                       _control->list()->set_state (*((*iter)->children().front()));
 
-                       if (_automation.automation_state() != Off) {
-                               set_position (_automation.eval (parent.session().transport_frame()));
+                       if (_control->list()->automation_state() != Off) {
+                               set_position (_control->list()->eval (parent.session().transport_frame()));
                        }
                }
        }
@@ -564,8 +532,8 @@ EqualPowerStereoPanner::set_state (const XMLNode& node)
 
 /*----------------------------------------------------------------------*/
 
-Multi2dPanner::Multi2dPanner (Panner& p)
-       : StreamPanner (p), _automation (0.0, 1.0, 0.5) // XXX useless
+Multi2dPanner::Multi2dPanner (Panner& p, Parameter param)
+       : StreamPanner (p, param)
 {
        update ();
 }
@@ -574,30 +542,6 @@ Multi2dPanner::~Multi2dPanner ()
 {
 }
 
-void
-Multi2dPanner::snapshot (nframes_t now)
-{
-       // how?
-}
-
-void
-Multi2dPanner::transport_stopped (nframes_t frame)
-{
-       //what?
-}
-
-void
-Multi2dPanner::set_automation_style (AutoStyle style)
-{
-       //what?
-}
-
-void
-Multi2dPanner::set_automation_state (AutoState state)
-{
-       // what?
-}
-
 void
 Multi2dPanner::update ()
 {
@@ -628,6 +572,7 @@ Multi2dPanner::update ()
        }
 
        effective_x = x;
+       _control->set_value(x);
 }
 
 void
@@ -705,9 +650,9 @@ Multi2dPanner::distribute_automated (AudioBuffer& src, BufferSet& obufs,
 }
 
 StreamPanner*
-Multi2dPanner::factory (Panner& p)
+Multi2dPanner::factory (Panner& p, Parameter param)
 {
-       return new Multi2dPanner (p);
+       return new Multi2dPanner (p, param);
 }
 
 int
@@ -855,7 +800,7 @@ Panner::reset (uint32_t nouts, uint32_t npans)
                outputs.push_back (Output (1.0, 0));
 
                for (n = 0; n < npans; ++n) {
-                       push_back (new EqualPowerStereoPanner (*this));
+                       push_back (new EqualPowerStereoPanner (*this, Parameter(PanAutomation, n)));
                }
                break;
 
@@ -865,7 +810,7 @@ Panner::reset (uint32_t nouts, uint32_t npans)
                outputs.push_back (Output  (1.0, 1.0));
 
                for (n = 0; n < npans; ++n) {
-                       push_back (new Multi2dPanner (*this));
+                       push_back (new Multi2dPanner (*this, Parameter(PanAutomation, n)));
                }
 
                break; 
@@ -877,7 +822,7 @@ Panner::reset (uint32_t nouts, uint32_t npans)
                outputs.push_back (Output  (0, 1.0));
 
                for (n = 0; n < npans; ++n) {
-                       push_back (new Multi2dPanner (*this));
+                       push_back (new Multi2dPanner (*this, Parameter(PanAutomation, n)));
                }
 
                break;  
@@ -890,7 +835,7 @@ Panner::reset (uint32_t nouts, uint32_t npans)
                outputs.push_back (Output  (0.5, 0.75));
 
                for (n = 0; n < npans; ++n) {
-                       push_back (new Multi2dPanner (*this));
+                       push_back (new Multi2dPanner (*this, Parameter(PanAutomation, n)));
                }
 
                break;
@@ -902,7 +847,7 @@ Panner::reset (uint32_t nouts, uint32_t npans)
                }
 
                for (n = 0; n < npans; ++n) {
-                       push_back (new Multi2dPanner (*this));
+                       push_back (new Multi2dPanner (*this, Parameter(PanAutomation, n)));
                }
 
                break;
@@ -930,10 +875,10 @@ Panner::reset (uint32_t nouts, uint32_t npans)
                if (changed || ((left == 0.5) && (right == 0.5))) {
                
                        front()->set_position (0.0);
-                       front()->automation().reset_default (0.0);
+                       front()->pan_control()->list()->reset_default (0.0);
                        
                        back()->set_position (1.0);
-                       back()->automation().reset_default (1.0);
+                       back()->pan_control()->list()->reset_default (1.0);
                        
                        changed = true;
                }
@@ -972,7 +917,7 @@ void
 Panner::set_automation_style (AutoStyle style)
 {
        for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
-               (*i)->set_automation_style (style);
+               (*i)->pan_control()->list()->set_automation_style (style);
        }
        _session.set_dirty ();
 }      
@@ -981,7 +926,7 @@ void
 Panner::set_automation_state (AutoState state)
 {
        for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
-               (*i)->set_automation_state (state);
+               (*i)->pan_control()->list()->set_automation_state (state);
        }
        _session.set_dirty ();
 }      
@@ -990,7 +935,7 @@ AutoState
 Panner::automation_state () const
 {
        if (!empty()) {
-               return front()->automation().automation_state ();
+               return front()->pan_control()->list()->automation_state ();
        } else {
                return Off;
        }
@@ -1000,7 +945,7 @@ AutoStyle
 Panner::automation_style () const
 {
        if (!empty()) {
-               return front()->automation().automation_style ();
+               return front()->pan_control()->list()->automation_style ();
        } else {
                return Absolute;
        }
@@ -1010,7 +955,7 @@ void
 Panner::transport_stopped (nframes_t frame)
 {
        for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
-               (*i)->transport_stopped (frame);
+               (*i)->pan_control()->list()->reposition_for_rt_add (frame);
        }
 }      
 
@@ -1018,7 +963,9 @@ void
 Panner::snapshot (nframes_t now)
 {
        for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
-               (*i)->snapshot (now);
+               boost::shared_ptr<AutomationList> list = (*i)->pan_control()->list();
+               if (list->automation_write())
+                       list->rt_add(now, (*i)->pan_control()->get_value());
        }
 }      
 
@@ -1026,7 +973,7 @@ void
 Panner::clear_automation ()
 {
        for (vector<StreamPanner*>::iterator i = begin(); i != end(); ++i) {
-               (*i)->automation().clear ();
+               (*i)->pan_control()->list()->clear ();
        }
        _session.set_dirty ();
 }      
@@ -1034,7 +981,7 @@ Panner::clear_automation ()
 struct PanPlugins {
     string name;
     uint32_t nouts;
-    StreamPanner* (*factory)(Panner&);
+    StreamPanner* (*factory)(Panner&, Parameter);
 };
 
 PanPlugins pan_plugins[] = {
@@ -1136,7 +1083,7 @@ Panner::set_state (const XMLNode& node)
                                                   assumption, but its still an assumption.
                                                */
                                                
-                                               sp = pan_plugins[i].factory (*this);
+                                               sp = pan_plugins[i].factory (*this, Parameter(PanAutomation, 0));
                                                
                                                if (sp->set_state (**niter) == 0) {
                                                        push_back (sp);
@@ -1181,7 +1128,7 @@ bool
 Panner::touching () const
 {
        for (vector<StreamPanner*>::const_iterator i = begin(); i != end(); ++i) {
-               if ((*i)->automation().touching ()) {
+               if ((*i)->pan_control()->list()->touching ()) {
                        return true;
                }
        }
@@ -1335,9 +1282,9 @@ 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)
 {
-       if (outbufs.count().get(DataType::AUDIO) == 0) {
+       if (outbufs.count().n_audio() == 0) {
                // Don't want to lose audio...
-               assert(inbufs.count().get(DataType::AUDIO) == 0);
+               assert(inbufs.count().n_audio() == 0);
                return;
        }
 
@@ -1346,7 +1293,7 @@ Panner::distribute_no_automation (BufferSet& inbufs, BufferSet& outbufs, nframes
        assert(!empty());
 
        
-       if (outbufs.count().get(DataType::AUDIO) == 1) {
+       if (outbufs.count().n_audio() == 1) {
 
                AudioBuffer& dst = outbufs.get_audio(0);
 
@@ -1402,9 +1349,9 @@ Panner::distribute_no_automation (BufferSet& inbufs, BufferSet& outbufs, nframes
 void
 Panner::distribute (BufferSet& inbufs, BufferSet& outbufs, nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset)
 {      
-       if (outbufs.count().get(DataType::AUDIO) == 0) {
+       if (outbufs.count().n_audio() == 0) {
                // Failing to deliver audio we were asked to deliver is a bug
-               assert(inbufs.count().get(DataType::AUDIO) == 0);
+               assert(inbufs.count().n_audio() == 0);
                return;
        }
 
@@ -1428,7 +1375,7 @@ Panner::distribute (BufferSet& inbufs, BufferSet& outbufs, nframes_t start_frame
 
        // Otherwise.. let the automation flow, baby
        
-       if (outbufs.count().get(DataType::AUDIO) == 1) {
+       if (outbufs.count().n_audio() == 1) {
 
                AudioBuffer& dst = outbufs.get_audio(0);
 
@@ -1447,7 +1394,7 @@ Panner::distribute (BufferSet& inbufs, BufferSet& outbufs, nframes_t start_frame
        }
 
        // More than 1 output, we should have 1 panner for each input
-       assert(size() == inbufs.count().get(DataType::AUDIO));
+       assert(size() == inbufs.count().n_audio());
        
        /* the terrible silence ... */
        for (BufferSet::audio_iterator i = outbufs.audio_begin(); i != outbufs.audio_end(); ++i) {