Optimize automation-event process splitting
[ardour.git] / libs / ardour / pannable.cc
index fb890a5e341d409c5fc4c847adece87113e926d4..09a63cca3f83fa77f6b9ef1d3fe6b2e64ad6532d 100644 (file)
@@ -18,9 +18,9 @@
 */
 
 #include "pbd/error.h"
-#include "pbd/convert.h"
 #include "pbd/compose.h"
 
+#include "ardour/boost_debug.h"
 #include "ardour/debug.h"
 #include "ardour/automation_control.h"
 #include "ardour/automation_list.h"
@@ -28,8 +28,9 @@
 #include "ardour/panner.h"
 #include "ardour/pan_controllable.h"
 #include "ardour/session.h"
+#include "ardour/value_as_string.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace PBD;
@@ -44,10 +45,11 @@ Pannable::Pannable (Session& s)
        , pan_frontback_control (new PanControllable (s, "", this, PanFrontBackAutomation))
        , pan_lfe_control (new PanControllable (s, "", this, PanLFEAutomation))
        , _auto_state (Off)
-       , _auto_style (Absolute)
        , _has_state (false)
        , _responding_to_control_auto_state_change (0)
 {
+       //boost_debug_shared_ptr_mark_interesting (this, "pannable");
+
        add_control (pan_azimuth_control);
        add_control (pan_elevation_control);
        add_control (pan_width_control);
@@ -104,6 +106,12 @@ Pannable::set_panner (boost::shared_ptr<Panner> p)
 void
 Pannable::value_changed ()
 {
+       if (!has_state ()) {
+               // prevent the GUI from resetting panners
+               // e.g. when switching to aux-sends and back.
+               _has_state = true;
+       }
+
        _session.set_dirty ();
 }
 
@@ -127,26 +135,6 @@ Pannable::set_automation_state (AutoState state)
        }
 }
 
-void
-Pannable::set_automation_style (AutoStyle style)
-{
-       if (style != _auto_style) {
-               _auto_style = style;
-
-               const Controls& c (controls());
-
-               for (Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
-                       boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl>(ci->second);
-                       if (ac) {
-                               ac->alist()->set_automation_style (style);
-                       }
-               }
-
-               session().set_dirty ();
-               automation_style_changed ();
-       }
-}
-
 void
 Pannable::start_touch (double when)
 {
@@ -162,14 +150,14 @@ Pannable::start_touch (double when)
 }
 
 void
-Pannable::stop_touch (bool mark, double when)
+Pannable::stop_touch (double when)
 {
        const Controls& c (controls());
 
        for (Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
                boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl>(ci->second);
                if (ac) {
-                       ac->alist()->stop_touch (mark, when);
+                       ac->alist()->stop_touch (when);
                }
        }
        g_atomic_int_set (&_touching, 0);
@@ -178,11 +166,11 @@ Pannable::stop_touch (bool mark, double when)
 XMLNode&
 Pannable::get_state ()
 {
-       return state (true);
+       return state ();
 }
 
 XMLNode&
-Pannable::state (bool full)
+Pannable::state ()
 {
        XMLNode* node = new XMLNode (X_("Pannable"));
 
@@ -210,21 +198,21 @@ Pannable::set_state (const XMLNode& root, int version)
 
        for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
                if ((*niter)->name() == Controllable::xml_node_name) {
-                       const XMLProperty* prop = (*niter)->property (X_("name"));
+                       std::string control_name;
 
-                       if (!prop) {
+                       if (!(*niter)->get_property (X_("name"), control_name)) {
                                continue;
                        }
 
-                       if (prop->value() == pan_azimuth_control->name()) {
+                       if (control_name == pan_azimuth_control->name()) {
                                pan_azimuth_control->set_state (**niter, version);
-                       } else if (prop->value() == pan_width_control->name()) {
+                       } else if (control_name == pan_width_control->name()) {
                                pan_width_control->set_state (**niter, version);
-                       } else if (prop->value() == pan_elevation_control->name()) {
+                       } else if (control_name == pan_elevation_control->name()) {
                                pan_elevation_control->set_state (**niter, version);
-                       } else if (prop->value() == pan_frontback_control->name()) {
+                       } else if (control_name == pan_frontback_control->name()) {
                                pan_frontback_control->set_state (**niter, version);
-                       } else if (prop->value() == pan_lfe_control->name()) {
+                       } else if (control_name == pan_lfe_control->name()) {
                                pan_lfe_control->set_state (**niter, version);
                        }
 
@@ -232,34 +220,28 @@ Pannable::set_state (const XMLNode& root, int version)
                        set_automation_xml_state (**niter, PanAzimuthAutomation);
 
                } else {
-                       const XMLProperty* prop;
-
                        /* old school (alpha1-6) XML info */
 
-                       if ((*niter)->name() == pan_azimuth_control->name()) {
-                               prop = (*niter)->property (X_("value"));
-                               if (prop) {
-                                       pan_azimuth_control->set_value (atof (prop->value()));
+                       float val;
+                       if ((*niter)->name() == X_("azimuth")) {
+                               if ((*niter)->get_property (X_("value"), val)) {
+                                       pan_azimuth_control->set_value (val, Controllable::NoGroup);
                                }
-                       } else if ((*niter)->name() == pan_width_control->name()) {
-                               prop = (*niter)->property (X_("value"));
-                               if (prop) {
-                                       pan_width_control->set_value (atof (prop->value()));
+                       } else if ((*niter)->name() == X_("width")) {
+                               if ((*niter)->get_property (X_("value"), val)) {
+                                       pan_width_control->set_value (val, Controllable::NoGroup);
                                }
-                       } else if ((*niter)->name() == pan_elevation_control->name()) {
-                               prop = (*niter)->property (X_("value"));
-                               if (prop) {
-                                       pan_elevation_control->set_value (atof (prop->value()));
+                       } else if ((*niter)->name() == X_("elevation")) {
+                               if ((*niter)->get_property (X_("value"), val)) {
+                                       pan_elevation_control->set_value (val, Controllable::NoGroup);
                                }
-                       } else if ((*niter)->name() == pan_frontback_control->name()) {
-                               prop = (*niter)->property (X_("value"));
-                               if (prop) {
-                                       pan_frontback_control->set_value (atof (prop->value()));
+                       } else if ((*niter)->name() == X_("frontback")) {
+                               if ((*niter)->get_property (X_("value"), val)) {
+                                       pan_frontback_control->set_value (val, Controllable::NoGroup);
                                }
-                       } else if ((*niter)->name() == pan_lfe_control->name()) {
-                               prop = (*niter)->property (X_("value"));
-                               if (prop) {
-                                       pan_lfe_control->set_value (atof (prop->value()));
+                       } else if ((*niter)->name() == X_("lfe")) {
+                               if ((*niter)->get_property (X_("value"), val)) {
+                                       pan_lfe_control->set_value (val, Controllable::NoGroup);
                                }
                        }
                }
@@ -271,7 +253,7 @@ Pannable::set_state (const XMLNode& root, int version)
 }
 
 string
-Pannable::value_as_string (boost::shared_ptr<AutomationControl> ac) const
+Pannable::value_as_string (boost::shared_ptr<const AutomationControl> ac) const
 {
        boost::shared_ptr<Panner> p = panner ();
 
@@ -279,5 +261,5 @@ Pannable::value_as_string (boost::shared_ptr<AutomationControl> ac) const
                return p->value_as_string (ac);
        }
 
-       return Automatable::value_as_string (ac);
+       return ARDOUR::value_as_string(ac->desc(), ac->get_value());
 }