Switch to PBD control-math and prefer Controllable API
[ardour.git] / libs / ardour / automation_list.cc
index c397323767ee435c55c40f3ceb64cee87a1905da..fbeb98fa2678db49b7b84329f9110dd45f6e8ef2 100644 (file)
 #include <sstream>
 #include <algorithm>
 #include "ardour/automation_list.h"
+#include "ardour/beats_frames_converter.h"
 #include "ardour/event_type_map.h"
 #include "ardour/parameter_descriptor.h"
+#include "ardour/parameter_types.h"
 #include "ardour/evoral_types_convert.h"
 #include "ardour/types_convert.h"
 #include "evoral/Curve.hpp"
@@ -57,7 +59,6 @@ AutomationList::AutomationList (const Evoral::Parameter& id, const Evoral::Param
        , _before (0)
 {
        _state = Off;
-       _style = Absolute;
        g_atomic_int_set (&_touching, 0);
 
        create_curve_if_necessary();
@@ -71,7 +72,6 @@ AutomationList::AutomationList (const Evoral::Parameter& id)
        , _before (0)
 {
        _state = Off;
-       _style = Absolute;
        g_atomic_int_set (&_touching, 0);
 
        create_curve_if_necessary();
@@ -81,11 +81,10 @@ AutomationList::AutomationList (const Evoral::Parameter& id)
 }
 
 AutomationList::AutomationList (const AutomationList& other)
-       : StatefulDestructible()
-       , ControlList(other)
+       : ControlList(other)
+       , StatefulDestructible()
        , _before (0)
 {
-       _style = other._style;
        _state = other._state;
        g_atomic_int_set (&_touching, other.touching());
 
@@ -99,7 +98,6 @@ AutomationList::AutomationList (const AutomationList& other, double start, doubl
        : ControlList(other, start, end)
        , _before (0)
 {
-       _style = other._style;
        _state = other._state;
        g_atomic_int_set (&_touching, other.touching());
 
@@ -118,7 +116,6 @@ AutomationList::AutomationList (const XMLNode& node, Evoral::Parameter id)
 {
        g_atomic_int_set (&_touching, 0);
        _state = Off;
-       _style = Absolute;
 
        set_state (node, Stateful::loading_state_version);
 
@@ -171,7 +168,6 @@ AutomationList::operator= (const AutomationList& other)
 
                ControlList::operator= (other);
                _state = other._state;
-               _style = other._style;
                _touching = other._touching;
 
                mark_dirty ();
@@ -206,15 +202,6 @@ AutomationList::set_automation_state (AutoState s)
        }
 }
 
-void
-AutomationList::set_automation_style (AutoStyle s)
-{
-       if (s != _style) {
-               _style = s;
-               automation_style_changed (); /* EMIT SIGNAL */
-       }
-}
-
 void
 AutomationList::start_write_pass (double when)
 {
@@ -289,6 +276,31 @@ AutomationList::thaw ()
        }
 }
 
+bool
+AutomationList::paste (const ControlList& alist, double pos, DoubleBeatsFramesConverter const& bfc)
+{
+       AutomationType src_type = (AutomationType)alist.parameter().type();
+       AutomationType dst_type = (AutomationType)_parameter.type();
+
+       if (parameter_is_midi (src_type) == parameter_is_midi (dst_type)) {
+               return ControlList::paste (alist, pos);
+       }
+       bool to_frame = parameter_is_midi (src_type);
+
+       ControlList cl (alist);
+       cl.clear ();
+       for (const_iterator i = alist.begin ();i != alist.end (); ++i) {
+               double when = (*i)->when;
+               if (to_frame) {
+                       when = bfc.to ((*i)->when);
+               } else {
+                       when = bfc.from ((*i)->when);
+               }
+               cl.fast_simple_add (when, (*i)->value);
+       }
+       return ControlList::paste (cl, pos);
+}
+
 Command*
 AutomationList::memento_command (XMLNode* before, XMLNode* after)
 {
@@ -332,8 +344,6 @@ AutomationList::state (bool full)
                root->set_property ("state", Off);
        }
 
-       root->set_property ("style", _style);
-
        if (!_events.empty()) {
                root->add_child_nocopy (serialize_events());
        }
@@ -489,10 +499,6 @@ AutomationList::set_state (const XMLNode& node, int version)
                _default_value = 0.0;
        }
 
-       if (!node.get_property (X_("style"), _style)) {
-               _style = Absolute;
-       }
-
        if (node.get_property (X_("state"), _state)) {
                if (_state == Write) {
                        _state = Off;
@@ -537,7 +543,6 @@ AutomationList::operator!= (AutomationList const & other) const
        return (
                static_cast<ControlList const &> (*this) != static_cast<ControlList const &> (other) ||
                _state != other._state ||
-               _style != other._style ||
                _touching != other._touching
                );
 }