Fix stripable order for new strips & master-order
[ardour.git] / libs / ardour / automation_list.cc
index ff22dae5dab36bd61b9bb88c70b06f10ed5fb621..40c924d293a2aad23410d59f8688a038f893f773 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"
@@ -81,8 +83,8 @@ AutomationList::AutomationList (const Evoral::Parameter& id)
 }
 
 AutomationList::AutomationList (const AutomationList& other)
-       : StatefulDestructible()
-       , ControlList(other)
+       : ControlList(other)
+       , StatefulDestructible()
        , _before (0)
 {
        _style = other._style;
@@ -289,6 +291,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)
 {
@@ -347,12 +374,10 @@ AutomationList::serialize_events ()
        XMLNode* node = new XMLNode (X_("events"));
        stringstream str;
 
-       str.precision(15);  //10 digits is enough digits for 24 hours at 96kHz
-
        for (iterator xx = _events.begin(); xx != _events.end(); ++xx) {
-               str << (double) (*xx)->when;
+               str << PBD::to_string ((*xx)->when);
                str << ' ';
-               str <<(double) (*xx)->value;
+               str << PBD::to_string ((*xx)->value);
                str << '\n';
        }
 
@@ -384,17 +409,19 @@ AutomationList::deserialize_events (const XMLNode& node)
 
        stringstream str (content_node->content());
 
+       std::string x_str;
+       std::string y_str;
        double x;
        double y;
        bool ok = true;
 
        while (str) {
-               str >> x;
-               if (!str) {
+               str >> x_str;
+               if (!str || !PBD::string_to<double> (x_str, x)) {
                        break;
                }
-               str >> y;
-               if (!str) {
+               str >> y_str;
+               if (!str || !PBD::string_to<double> (y_str, y)) {
                        ok = false;
                        break;
                }