2 Copyright (C) 2002 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <sigc++/bind.h>
27 #include <ardour/parameter.h>
28 #include <ardour/automation_list.h>
29 #include <evoral/Curve.hpp>
30 #include <pbd/stacktrace.h>
31 #include <pbd/enumwriter.h>
36 using namespace ARDOUR;
40 sigc::signal<void,AutomationList *> AutomationList::AutomationListCreated;
43 static void dumpit (const AutomationList& al, string prefix = "")
45 cerr << prefix << &al << endl;
46 for (AutomationList::const_iterator i = al.const_begin(); i != al.const_end(); ++i) {
47 cerr << prefix << '\t' << (*i)->when << ',' << (*i)->value << endl;
53 /* XXX: min_val max_val redundant? (param.min() param.max()) */
54 AutomationList::AutomationList (Parameter id)
61 assert(_parameter.type() != NullAutomation);
62 AutomationListCreated(this);
65 AutomationList::AutomationList (const AutomationList& other)
68 _state = other._state;
69 _touching = other._touching;
71 assert(_parameter.type() != NullAutomation);
72 AutomationListCreated(this);
75 AutomationList::AutomationList (const AutomationList& other, double start, double end)
78 _style = other._style;
79 _state = other._state;
80 _touching = other._touching;
82 assert(_parameter.type() != NullAutomation);
83 AutomationListCreated(this);
86 /** \a id is used for legacy sessions where the type is not present
87 * in or below the <AutomationList> node. It is used if \a id is non-null.
89 AutomationList::AutomationList (const XMLNode& node, Parameter id)
101 assert(_parameter.type() != NullAutomation);
102 AutomationListCreated(this);
105 AutomationList::~AutomationList()
110 boost::shared_ptr<Evoral::ControlList>
111 AutomationList::create(Evoral::Parameter id)
113 return boost::shared_ptr<Evoral::ControlList>(new AutomationList(id));
117 AutomationList::operator== (const AutomationList& other)
119 return _events == other._events;
123 AutomationList::operator= (const AutomationList& other)
125 if (this != &other) {
129 for (const_iterator i = other._events.begin(); i != other._events.end(); ++i) {
130 _events.push_back (new ControlEvent (**i));
133 _min_yval = other._min_yval;
134 _max_yval = other._max_yval;
135 _max_xval = other._max_xval;
136 _default_value = other._default_value;
139 maybe_signal_changed ();
146 AutomationList::maybe_signal_changed ()
148 ControlList::maybe_signal_changed ();
151 StateChanged (); /* EMIT SIGNAL */
156 AutomationList::set_automation_state (AutoState s)
160 automation_state_changed (); /* EMIT SIGNAL */
165 AutomationList::set_automation_style (AutoStyle s)
169 automation_style_changed (); /* EMIT SIGNAL */
174 AutomationList::start_touch ()
181 AutomationList::stop_touch ()
188 AutomationList::freeze ()
194 AutomationList::thaw ()
198 if (_changed_when_thawed) {
199 StateChanged(); /* EMIT SIGNAL */
204 AutomationList::mark_dirty () const
206 ControlList::mark_dirty ();
207 Dirty (); /* EMIT SIGNAL */
211 AutomationList::get_state ()
217 AutomationList::state (bool full)
219 XMLNode* root = new XMLNode (X_("AutomationList"));
221 LocaleGuard lg (X_("POSIX"));
223 root->add_property ("automation-id", _parameter.symbol());
225 root->add_property ("id", _id.to_s());
227 snprintf (buf, sizeof (buf), "%.12g", _default_value);
228 root->add_property ("default", buf);
229 snprintf (buf, sizeof (buf), "%.12g", _min_yval);
230 root->add_property ("min_yval", buf);
231 snprintf (buf, sizeof (buf), "%.12g", _max_yval);
232 root->add_property ("max_yval", buf);
233 snprintf (buf, sizeof (buf), "%.12g", _max_xval);
234 root->add_property ("max_xval", buf);
236 root->add_property ("interpolation-style", enum_2_string (_interpolation));
239 root->add_property ("state", auto_state_to_string (_state));
241 /* never save anything but Off for automation state to a template */
242 root->add_property ("state", auto_state_to_string (Off));
245 root->add_property ("style", auto_style_to_string (_style));
247 if (!_events.empty()) {
248 root->add_child_nocopy (serialize_events());
255 AutomationList::serialize_events ()
257 XMLNode* node = new XMLNode (X_("events"));
260 for (iterator xx = _events.begin(); xx != _events.end(); ++xx) {
261 str << (double) (*xx)->when;
263 str <<(double) (*xx)->value;
267 /* XML is a bit wierd */
269 XMLNode* content_node = new XMLNode (X_("foo")); /* it gets renamed by libxml when we set content */
270 content_node->set_content (str.str());
272 node->add_child_nocopy (*content_node);
278 AutomationList::deserialize_events (const XMLNode& node)
280 if (node.children().empty()) {
284 XMLNode* content_node = node.children().front();
286 if (content_node->content().empty()) {
293 stringstream str (content_node->content());
309 fast_simple_add (x, y);
314 error << _("automation list: cannot load coordinates from XML, all points ignored") << endmsg;
317 reposition_for_rt_add (0);
318 maybe_signal_changed ();
327 AutomationList::set_state (const XMLNode& node)
329 XMLNodeList nlist = node.children();
331 XMLNodeIterator niter;
332 const XMLProperty* prop;
334 if (node.name() == X_("events")) {
335 /* partial state setting*/
336 return deserialize_events (node);
339 if (node.name() == X_("Envelope") || node.name() == X_("FadeOut") || node.name() == X_("FadeIn")) {
341 if ((nsos = node.child (X_("AutomationList")))) {
342 /* new school in old school clothing */
343 return set_state (*nsos);
348 const XMLNodeList& elist = node.children();
349 XMLNodeConstIterator i;
357 for (i = elist.begin(); i != elist.end(); ++i) {
359 if ((prop = (*i)->property ("x")) == 0) {
360 error << _("automation list: no x-coordinate stored for control point (point ignored)") << endmsg;
363 x = atoi (prop->value().c_str());
365 if ((prop = (*i)->property ("y")) == 0) {
366 error << _("automation list: no y-coordinate stored for control point (point ignored)") << endmsg;
369 y = atof (prop->value().c_str());
371 fast_simple_add (x, y);
379 if (node.name() != X_("AutomationList") ) {
380 error << string_compose (_("AutomationList: passed XML node called %1, not \"AutomationList\" - ignored"), node.name()) << endmsg;
384 if ((prop = node.property ("id")) != 0) {
385 _id = prop->value ();
386 /* update session AL list */
387 AutomationListCreated(this);
390 if ((prop = node.property (X_("automation-id"))) != 0){
391 _parameter = Parameter(prop->value());
393 warning << "Legacy session: automation list has no automation-id property.";
396 if ((prop = node.property (X_("interpolation-style"))) != 0) {
397 _interpolation = (InterpolationStyle)string_2_enum(prop->value(), _interpolation);
399 _interpolation = Linear;
402 if ((prop = node.property (X_("default"))) != 0){
403 _default_value = atof (prop->value().c_str());
405 _default_value = 0.0;
408 if ((prop = node.property (X_("style"))) != 0) {
409 _style = string_to_auto_style (prop->value());
414 if ((prop = node.property (X_("state"))) != 0) {
415 _state = string_to_auto_state (prop->value());
420 if ((prop = node.property (X_("min_yval"))) != 0) {
421 _min_yval = atof (prop->value ().c_str());
426 if ((prop = node.property (X_("max_yval"))) != 0) {
427 _max_yval = atof (prop->value ().c_str());
432 if ((prop = node.property (X_("max_xval"))) != 0) {
433 _max_xval = atof (prop->value ().c_str());
435 _max_xval = 0; // means "no limit ;
438 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
439 if ((*niter)->name() == X_("events")) {
440 deserialize_events (*(*niter));