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_event.h>
29 #include <ardour/curve.h>
30 #include <pbd/stacktrace.h>
31 #include <pbd/enumwriter.h>
36 using namespace ARDOUR;
40 sigc::signal<void,AutomationList *> AutomationList::AutomationListCreated;
42 static bool sort_events_by_time (ControlEvent* a, ControlEvent* b)
44 return a->when < b->when;
48 static void dumpit (const AutomationList& al, string prefix = "")
50 cerr << prefix << &al << endl;
51 for (AutomationList::const_iterator i = al.const_begin(); i != al.const_end(); ++i) {
52 cerr << prefix << '\t' << (*i)->when << ',' << (*i)->value << endl;
58 AutomationList::AutomationList (Parameter id, double min_val, double max_val, double default_val)
60 , _interpolation(Linear)
61 , _curve(new Curve(*this))
65 _changed_when_thawed = false;
71 _max_xval = 0; // means "no limit"
72 _default_value = default_val;
73 _rt_insertion_point = _events.end();
74 _lookup_cache.left = -1;
75 _lookup_cache.range.first = _events.end();
76 _search_cache.left = -1;
77 _search_cache.range.first = _events.end();
78 _sort_pending = false;
80 assert(_parameter.type() != NullAutomation);
81 AutomationListCreated(this);
84 AutomationList::AutomationList (const AutomationList& other)
85 : _parameter(other._parameter)
86 , _interpolation(Linear)
87 , _curve(new Curve(*this))
90 _changed_when_thawed = false;
91 _style = other._style;
92 _min_yval = other._min_yval;
93 _max_yval = other._max_yval;
94 _max_xval = other._max_xval;
95 _default_value = other._default_value;
96 _state = other._state;
97 _touching = other._touching;
98 _rt_insertion_point = _events.end();
99 _lookup_cache.range.first = _events.end();
100 _search_cache.range.first = _events.end();
101 _sort_pending = false;
103 for (const_iterator i = other._events.begin(); i != other._events.end(); ++i) {
104 _events.push_back (new ControlEvent (**i));
108 assert(_parameter.type() != NullAutomation);
109 AutomationListCreated(this);
112 AutomationList::AutomationList (const AutomationList& other, double start, double end)
113 : _parameter(other._parameter)
114 , _interpolation(Linear)
115 , _curve(new Curve(*this))
118 _changed_when_thawed = false;
119 _style = other._style;
120 _min_yval = other._min_yval;
121 _max_yval = other._max_yval;
122 _max_xval = other._max_xval;
123 _default_value = other._default_value;
124 _state = other._state;
125 _touching = other._touching;
126 _rt_insertion_point = _events.end();
127 _lookup_cache.range.first = _events.end();
128 _search_cache.range.first = _events.end();
129 _sort_pending = false;
131 /* now grab the relevant points, and shift them back if necessary */
133 AutomationList* section = const_cast<AutomationList*>(&other)->copy (start, end);
135 if (!section->empty()) {
136 for (iterator i = section->begin(); i != section->end(); ++i) {
137 _events.push_back (new ControlEvent ((*i)->when, (*i)->value));
145 assert(_parameter.type() != NullAutomation);
146 AutomationListCreated(this);
149 /** \a id is used for legacy sessions where the type is not present
150 * in or below the <AutomationList> node. It is used if \a id is non-null.
152 AutomationList::AutomationList (const XMLNode& node, Parameter id)
153 : _interpolation(Linear)
154 , _curve(new Curve(*this))
157 _changed_when_thawed = false;
161 _max_xval = 0; // means "no limit"
164 _rt_insertion_point = _events.end();
165 _lookup_cache.range.first = _events.end();
166 _search_cache.range.first = _events.end();
167 _sort_pending = false;
174 assert(_parameter.type() != NullAutomation);
175 AutomationListCreated(this);
178 AutomationList::~AutomationList()
182 for (EventList::iterator x = _events.begin(); x != _events.end(); ++x) {
188 AutomationList::operator== (const AutomationList& other)
190 return _events == other._events;
194 AutomationList::operator= (const AutomationList& other)
196 if (this != &other) {
200 for (const_iterator i = other._events.begin(); i != other._events.end(); ++i) {
201 _events.push_back (new ControlEvent (**i));
204 _min_yval = other._min_yval;
205 _max_yval = other._max_yval;
206 _max_xval = other._max_xval;
207 _default_value = other._default_value;
210 maybe_signal_changed ();
217 AutomationList::maybe_signal_changed ()
222 _changed_when_thawed = true;
229 AutomationList::set_automation_state (AutoState s)
233 automation_state_changed (); /* EMIT SIGNAL */
238 AutomationList::set_automation_style (AutoStyle s)
242 automation_style_changed (); /* EMIT SIGNAL */
247 AutomationList::start_touch ()
254 AutomationList::stop_touch ()
261 AutomationList::clear ()
264 Glib::Mutex::Lock lm (_lock);
269 maybe_signal_changed ();
273 AutomationList::x_scale (double factor)
275 Glib::Mutex::Lock lm (_lock);
280 AutomationList::extend_to (double when)
282 Glib::Mutex::Lock lm (_lock);
283 if (_events.empty() || _events.back()->when == when) {
286 double factor = when / _events.back()->when;
291 void AutomationList::_x_scale (double factor)
293 for (iterator i = _events.begin(); i != _events.end(); ++i) {
294 (*i)->when = floor ((*i)->when * factor);
301 AutomationList::reposition_for_rt_add (double when)
303 _rt_insertion_point = _events.end();
307 AutomationList::rt_add (double when, double value)
309 /* this is for automation recording */
311 if ((_state & Touch) && !_touching) {
315 // cerr << "RT: alist @ " << this << " add " << value << " @ " << when << endl;
318 Glib::Mutex::Lock lm (_lock);
322 ControlEvent cp (when, 0.0);
325 if ((_rt_insertion_point != _events.end()) && ((*_rt_insertion_point)->when < when) ) {
327 /* we have a previous insertion point, so we should delete
328 everything between it and the position where we are going
329 to insert this point.
332 iterator after = _rt_insertion_point;
334 if (++after != _events.end()) {
335 iterator far = after;
337 while (far != _events.end()) {
338 if ((*far)->when > when) {
346 _rt_insertion_point = where;
348 if ((*where)->when == when) {
349 (*where)->value = value;
353 where = _events.erase (after, far);
362 iterator previous = _rt_insertion_point;
365 if (_rt_insertion_point != _events.begin() && (*_rt_insertion_point)->value == value && (*previous)->value == value) {
366 (*_rt_insertion_point)->when = when;
373 where = lower_bound (_events.begin(), _events.end(), &cp, cmp);
375 if (where != _events.end()) {
376 if ((*where)->when == when) {
377 (*where)->value = value;
384 _rt_insertion_point = _events.insert (where, new ControlEvent (when, value));
391 maybe_signal_changed ();
395 AutomationList::fast_simple_add (double when, double value)
397 /* to be used only for loading pre-sorted data from saved state */
398 _events.insert (_events.end(), new ControlEvent (when, value));
402 AutomationList::add (double when, double value)
404 /* this is for graphical editing */
407 Glib::Mutex::Lock lm (_lock);
409 ControlEvent cp (when, 0.0f);
411 iterator insertion_point;
413 for (insertion_point = lower_bound (_events.begin(), _events.end(), &cp, cmp); insertion_point != _events.end(); ++insertion_point) {
415 /* only one point allowed per time point */
417 if ((*insertion_point)->when == when) {
418 (*insertion_point)->value = value;
423 if ((*insertion_point)->when >= when) {
430 _events.insert (insertion_point, new ControlEvent (when, value));
431 reposition_for_rt_add (0);
438 maybe_signal_changed ();
442 AutomationList::erase (iterator i)
445 Glib::Mutex::Lock lm (_lock);
447 reposition_for_rt_add (0);
450 maybe_signal_changed ();
454 AutomationList::erase (iterator start, iterator end)
457 Glib::Mutex::Lock lm (_lock);
458 _events.erase (start, end);
459 reposition_for_rt_add (0);
462 maybe_signal_changed ();
466 AutomationList::reset_range (double start, double endt)
471 Glib::Mutex::Lock lm (_lock);
473 ControlEvent cp (start, 0.0f);
477 if ((s = lower_bound (_events.begin(), _events.end(), &cp, cmp)) != _events.end()) {
480 e = upper_bound (_events.begin(), _events.end(), &cp, cmp);
482 for (iterator i = s; i != e; ++i) {
483 (*i)->value = _default_value;
493 maybe_signal_changed ();
498 AutomationList::erase_range (double start, double endt)
503 Glib::Mutex::Lock lm (_lock);
505 ControlEvent cp (start, 0.0f);
509 if ((s = lower_bound (_events.begin(), _events.end(), &cp, cmp)) != _events.end()) {
511 e = upper_bound (_events.begin(), _events.end(), &cp, cmp);
512 _events.erase (s, e);
513 reposition_for_rt_add (0);
521 maybe_signal_changed ();
526 AutomationList::move_range (iterator start, iterator end, double xdelta, double ydelta)
528 /* note: we assume higher level logic is in place to avoid this
529 reordering the time-order of control events in the list. ie. all
530 points after end are later than (end)->when.
534 Glib::Mutex::Lock lm (_lock);
536 while (start != end) {
537 (*start)->when += xdelta;
538 (*start)->value += ydelta;
539 if (isnan ((*start)->value)) {
546 _events.sort (sort_events_by_time);
548 _sort_pending = true;
554 maybe_signal_changed ();
558 AutomationList::slide (iterator before, double distance)
561 Glib::Mutex::Lock lm (_lock);
563 if (before == _events.end()) {
567 while (before != _events.end()) {
568 (*before)->when += distance;
573 maybe_signal_changed ();
577 AutomationList::modify (iterator iter, double when, double val)
579 /* note: we assume higher level logic is in place to avoid this
580 reordering the time-order of control events in the list. ie. all
581 points after *iter are later than when.
585 Glib::Mutex::Lock lm (_lock);
587 (*iter)->when = when;
588 (*iter)->value = val;
595 _events.sort (sort_events_by_time);
597 _sort_pending = true;
603 maybe_signal_changed ();
606 std::pair<AutomationList::iterator,AutomationList::iterator>
607 AutomationList::control_points_adjacent (double xval)
609 Glib::Mutex::Lock lm (_lock);
612 ControlEvent cp (xval, 0.0f);
613 std::pair<iterator,iterator> ret;
615 ret.first = _events.end();
616 ret.second = _events.end();
618 for (i = lower_bound (_events.begin(), _events.end(), &cp, cmp); i != _events.end(); ++i) {
620 if (ret.first == _events.end()) {
621 if ((*i)->when >= xval) {
622 if (i != _events.begin()) {
631 if ((*i)->when > xval) {
641 AutomationList::freeze ()
647 AutomationList::thaw ()
650 PBD::stacktrace (cerr);
651 fatal << string_compose (_("programming error: %1"), X_("AutomationList::thaw() called while not frozen")) << endmsg;
660 Glib::Mutex::Lock lm (_lock);
663 _events.sort (sort_events_by_time);
664 _sort_pending = false;
668 if (_changed_when_thawed) {
669 StateChanged(); /* EMIT SIGNAL */
674 AutomationList::set_max_xval (double x)
680 AutomationList::mark_dirty ()
682 _lookup_cache.left = -1;
683 _search_cache.left = -1;
684 Dirty (); /* EMIT SIGNAL */
688 AutomationList::truncate_end (double last_coordinate)
691 Glib::Mutex::Lock lm (_lock);
692 ControlEvent cp (last_coordinate, 0);
693 list<ControlEvent*>::reverse_iterator i;
696 if (_events.empty()) {
700 if (last_coordinate == _events.back()->when) {
704 if (last_coordinate > _events.back()->when) {
709 iterator foo = _events.begin();
712 if (foo == _events.end()) {
714 } else if (++foo == _events.end()) {
721 /* less than 2 points: add a new point */
722 _events.push_back (new ControlEvent (last_coordinate, _events.back()->value));
725 /* more than 2 points: check to see if the last 2 values
726 are equal. if so, just move the position of the
727 last point. otherwise, add a new point.
730 iterator penultimate = _events.end();
731 --penultimate; /* points at last point */
732 --penultimate; /* points at the penultimate point */
734 if (_events.back()->value == (*penultimate)->value) {
735 _events.back()->when = last_coordinate;
737 _events.push_back (new ControlEvent (last_coordinate, _events.back()->value));
745 last_val = unlocked_eval (last_coordinate);
746 last_val = max ((double) _min_yval, last_val);
747 last_val = min ((double) _max_yval, last_val);
749 i = _events.rbegin();
751 /* make i point to the last control point */
755 /* now go backwards, removing control points that are
756 beyond the new last coordinate.
759 uint32_t sz = _events.size();
761 while (i != _events.rend() && sz > 2) {
762 list<ControlEvent*>::reverse_iterator tmp;
767 if ((*i)->when < last_coordinate) {
771 _events.erase (i.base());
777 _events.back()->when = last_coordinate;
778 _events.back()->value = last_val;
781 reposition_for_rt_add (0);
785 maybe_signal_changed ();
789 AutomationList::truncate_start (double overall_length)
792 Glib::Mutex::Lock lm (_lock);
794 double first_legal_value;
795 double first_legal_coordinate;
797 if (_events.empty()) {
798 fatal << _("programming error:")
799 << "AutomationList::truncate_start() called on an empty list"
805 if (overall_length == _events.back()->when) {
806 /* no change in overall length */
810 if (overall_length > _events.back()->when) {
812 /* growing at front: duplicate first point. shift all others */
814 double shift = overall_length - _events.back()->when;
817 for (np = 0, i = _events.begin(); i != _events.end(); ++i, ++np) {
823 /* less than 2 points: add a new point */
824 _events.push_front (new ControlEvent (0, _events.front()->value));
828 /* more than 2 points: check to see if the first 2 values
829 are equal. if so, just move the position of the
830 first point. otherwise, add a new point.
833 iterator second = _events.begin();
834 ++second; /* points at the second point */
836 if (_events.front()->value == (*second)->value) {
837 /* first segment is flat, just move start point back to zero */
838 _events.front()->when = 0;
840 /* leave non-flat segment in place, add a new leading point. */
841 _events.push_front (new ControlEvent (0, _events.front()->value));
847 /* shrinking at front */
849 first_legal_coordinate = _events.back()->when - overall_length;
850 first_legal_value = unlocked_eval (first_legal_coordinate);
851 first_legal_value = max (_min_yval, first_legal_value);
852 first_legal_value = min (_max_yval, first_legal_value);
854 /* remove all events earlier than the new "front" */
858 while (i != _events.end() && !_events.empty()) {
859 list<ControlEvent*>::iterator tmp;
864 if ((*i)->when > first_legal_coordinate) {
874 /* shift all remaining points left to keep their same
878 for (i = _events.begin(); i != _events.end(); ++i) {
879 (*i)->when -= first_legal_coordinate;
882 /* add a new point for the interpolated new value */
884 _events.push_front (new ControlEvent (0, first_legal_value));
887 reposition_for_rt_add (0);
892 maybe_signal_changed ();
896 AutomationList::unlocked_eval (double x) const
898 pair<EventList::iterator,EventList::iterator> range;
904 npoints = _events.size();
908 return _default_value;
911 if (x >= _events.front()->when) {
912 return _events.front()->value;
914 // return _default_value;
915 return _events.front()->value;
919 if (x >= _events.back()->when) {
920 return _events.back()->value;
921 } else if (x == _events.front()->when) {
922 return _events.front()->value;
923 } else if (x < _events.front()->when) {
924 // return _default_value;
925 return _events.front()->value;
928 lpos = _events.front()->when;
929 lval = _events.front()->value;
930 upos = _events.back()->when;
931 uval = _events.back()->value;
933 if (_interpolation == Discrete)
936 /* linear interpolation betweeen the two points
939 fraction = (double) (x - lpos) / (double) (upos - lpos);
940 return lval + (fraction * (uval - lval));
944 if (x >= _events.back()->when) {
945 return _events.back()->value;
946 } else if (x == _events.front()->when) {
947 return _events.front()->value;
948 } else if (x < _events.front()->when) {
949 // return _default_value;
950 return _events.front()->value;
953 return multipoint_eval (x);
959 AutomationList::multipoint_eval (double x) const
965 /* "Stepped" lookup (no interpolation) */
966 /* FIXME: no cache. significant? */
967 if (_interpolation == Discrete) {
968 const ControlEvent cp (x, 0);
970 EventList::const_iterator i = lower_bound (_events.begin(), _events.end(), &cp, cmp);
972 // shouldn't have made it to multipoint_eval
973 assert(i != _events.end());
975 if (i == _events.begin() || (*i)->when == x)
978 return (*(--i))->value;
981 /* Only do the range lookup if x is in a different range than last time
982 * this was called (or if the lookup cache has been marked "dirty" (left<0) */
983 if ((_lookup_cache.left < 0) ||
984 ((_lookup_cache.left > x) ||
985 (_lookup_cache.range.first == _events.end()) ||
986 ((*_lookup_cache.range.second)->when < x))) {
988 const ControlEvent cp (x, 0);
991 _lookup_cache.range = equal_range (_events.begin(), _events.end(), &cp, cmp);
994 pair<const_iterator,const_iterator> range = _lookup_cache.range;
996 if (range.first == range.second) {
998 /* x does not exist within the list as a control point */
1000 _lookup_cache.left = x;
1002 if (range.first != _events.begin()) {
1004 lpos = (*range.first)->when;
1005 lval = (*range.first)->value;
1007 /* we're before the first point */
1008 // return _default_value;
1009 return _events.front()->value;
1012 if (range.second == _events.end()) {
1013 /* we're after the last point */
1014 return _events.back()->value;
1017 upos = (*range.second)->when;
1018 uval = (*range.second)->value;
1020 /* linear interpolation betweeen the two points
1024 fraction = (double) (x - lpos) / (double) (upos - lpos);
1025 return lval + (fraction * (uval - lval));
1029 /* x is a control point in the data */
1030 _lookup_cache.left = -1;
1031 return (*range.first)->value;
1034 /** Get the earliest event between \a start and \a end.
1036 * If an event is found, \a x and \a y are set to its coordinates.
1037 * \return true if event is found (and \a x and \a y are valid).
1040 AutomationList::rt_safe_earliest_event (double start, double end, double& x, double& y) const
1042 // FIXME: It would be nice if this was unnecessary..
1043 Glib::Mutex::Lock lm(_lock, Glib::TRY_LOCK);
1048 /* Only do the range lookup if x is in a different range than last time
1049 * this was called (or if the search cache has been marked "dirty" (left<0) */
1050 if ((_search_cache.left < 0) ||
1051 ((_search_cache.left > start) ||
1052 (_search_cache.right < end))) {
1054 const ControlEvent start_point (start, 0);
1055 const ControlEvent end_point (end, 0);
1058 //cerr << "REBUILD: (" << _search_cache.left << ".." << _search_cache.right << ") -> ("
1059 // << start << ".." << end << ")" << endl;
1061 _search_cache.range.first = lower_bound (_events.begin(), _events.end(), &start_point, cmp);
1062 _search_cache.range.second = upper_bound (_events.begin(), _events.end(), &end_point, cmp);
1064 _search_cache.left = start;
1065 _search_cache.right = end;
1068 pair<const_iterator,const_iterator> range = _search_cache.range;
1070 if (range.first != _events.end()) {
1071 const ControlEvent* const first = *range.first;
1073 /* Earliest points is in range, return it */
1074 if (first->when >= start && first->when < end) {
1079 /* Move left of cache to this point
1080 * (Optimize for immediate call this cycle within range) */
1081 _search_cache.left = x;
1082 ++_search_cache.range.first;
1093 /* No points in range */
1100 AutomationList::cut (iterator start, iterator end)
1102 AutomationList* nal = new AutomationList (_parameter, _min_yval, _max_yval, _default_value);
1105 Glib::Mutex::Lock lm (_lock);
1107 for (iterator x = start; x != end; ) {
1113 nal->_events.push_back (new ControlEvent (**x));
1116 reposition_for_rt_add (0);
1124 maybe_signal_changed ();
1130 AutomationList::cut_copy_clear (double start, double end, int op)
1132 AutomationList* nal = new AutomationList (_parameter, _min_yval, _max_yval, _default_value);
1134 ControlEvent cp (start, 0.0);
1136 bool changed = false;
1139 Glib::Mutex::Lock lm (_lock);
1141 if ((s = lower_bound (_events.begin(), _events.end(), &cp, cmp)) == _events.end()) {
1146 e = upper_bound (_events.begin(), _events.end(), &cp, cmp);
1148 if (op != 2 && (*s)->when != start) {
1149 nal->_events.push_back (new ControlEvent (0, unlocked_eval (start)));
1152 for (iterator x = s; x != e; ) {
1160 /* adjust new points to be relative to start, which
1161 has been set to zero.
1165 nal->_events.push_back (new ControlEvent ((*x)->when - start, (*x)->value));
1175 if (op != 2 && nal->_events.back()->when != end - start) {
1176 nal->_events.push_back (new ControlEvent (end - start, unlocked_eval (end)));
1180 reposition_for_rt_add (0);
1186 maybe_signal_changed ();
1193 AutomationList::copy (iterator start, iterator end)
1195 AutomationList* nal = new AutomationList (_parameter, _min_yval, _max_yval, _default_value);
1198 Glib::Mutex::Lock lm (_lock);
1200 for (iterator x = start; x != end; ) {
1206 nal->_events.push_back (new ControlEvent (**x));
1216 AutomationList::cut (double start, double end)
1218 return cut_copy_clear (start, end, 0);
1222 AutomationList::copy (double start, double end)
1224 return cut_copy_clear (start, end, 1);
1228 AutomationList::clear (double start, double end)
1230 (void) cut_copy_clear (start, end, 2);
1234 AutomationList::paste (AutomationList& alist, double pos, float times)
1236 if (alist._events.empty()) {
1241 Glib::Mutex::Lock lm (_lock);
1245 ControlEvent cp (pos, 0.0);
1248 where = upper_bound (_events.begin(), _events.end(), &cp, cmp);
1250 for (iterator i = alist.begin();i != alist.end(); ++i) {
1251 _events.insert (where, new ControlEvent( (*i)->when+pos,( *i)->value));
1252 end = (*i)->when + pos;
1256 /* move all points after the insertion along the timeline by
1260 while (where != _events.end()) {
1262 if ((*where)->when <= end) {
1265 _events.erase(where);
1273 reposition_for_rt_add (0);
1277 maybe_signal_changed ();
1282 AutomationList::get_state ()
1284 return state (true);
1288 AutomationList::state (bool full)
1290 XMLNode* root = new XMLNode (X_("AutomationList"));
1292 LocaleGuard lg (X_("POSIX"));
1294 root->add_property ("automation-id", _parameter.to_string());
1296 root->add_property ("id", _id.to_s());
1298 snprintf (buf, sizeof (buf), "%.12g", _default_value);
1299 root->add_property ("default", buf);
1300 snprintf (buf, sizeof (buf), "%.12g", _min_yval);
1301 root->add_property ("min_yval", buf);
1302 snprintf (buf, sizeof (buf), "%.12g", _max_yval);
1303 root->add_property ("max_yval", buf);
1304 snprintf (buf, sizeof (buf), "%.12g", _max_xval);
1305 root->add_property ("max_xval", buf);
1307 root->add_property ("interpolation-style", enum_2_string (_interpolation));
1310 root->add_property ("state", auto_state_to_string (_state));
1312 /* never save anything but Off for automation state to a template */
1313 root->add_property ("state", auto_state_to_string (Off));
1316 root->add_property ("style", auto_style_to_string (_style));
1318 if (!_events.empty()) {
1319 root->add_child_nocopy (serialize_events());
1326 AutomationList::serialize_events ()
1328 XMLNode* node = new XMLNode (X_("events"));
1331 for (iterator xx = _events.begin(); xx != _events.end(); ++xx) {
1332 str << (double) (*xx)->when;
1334 str <<(double) (*xx)->value;
1338 /* XML is a bit wierd */
1340 XMLNode* content_node = new XMLNode (X_("foo")); /* it gets renamed by libxml when we set content */
1341 content_node->set_content (str.str());
1343 node->add_child_nocopy (*content_node);
1349 AutomationList::deserialize_events (const XMLNode& node)
1351 if (node.children().empty()) {
1355 XMLNode* content_node = node.children().front();
1357 if (content_node->content().empty()) {
1364 stringstream str (content_node->content());
1380 fast_simple_add (x, y);
1385 error << _("automation list: cannot load coordinates from XML, all points ignored") << endmsg;
1388 reposition_for_rt_add (0);
1389 maybe_signal_changed ();
1398 AutomationList::set_state (const XMLNode& node)
1400 XMLNodeList nlist = node.children();
1402 XMLNodeIterator niter;
1403 const XMLProperty* prop;
1405 if (node.name() == X_("events")) {
1406 /* partial state setting*/
1407 return deserialize_events (node);
1410 if (node.name() == X_("Envelope") || node.name() == X_("FadeOut") || node.name() == X_("FadeIn")) {
1412 if ((nsos = node.child (X_("AutomationList")))) {
1413 /* new school in old school clothing */
1414 return set_state (*nsos);
1419 const XMLNodeList& elist = node.children();
1420 XMLNodeConstIterator i;
1428 for (i = elist.begin(); i != elist.end(); ++i) {
1430 if ((prop = (*i)->property ("x")) == 0) {
1431 error << _("automation list: no x-coordinate stored for control point (point ignored)") << endmsg;
1434 x = atoi (prop->value().c_str());
1436 if ((prop = (*i)->property ("y")) == 0) {
1437 error << _("automation list: no y-coordinate stored for control point (point ignored)") << endmsg;
1440 y = atof (prop->value().c_str());
1442 fast_simple_add (x, y);
1450 if (node.name() != X_("AutomationList") ) {
1451 error << string_compose (_("AutomationList: passed XML node called %1, not \"AutomationList\" - ignored"), node.name()) << endmsg;
1455 if ((prop = node.property ("id")) != 0) {
1456 _id = prop->value ();
1457 /* update session AL list */
1458 AutomationListCreated(this);
1461 if ((prop = node.property (X_("automation-id"))) != 0){
1462 _parameter = Parameter(prop->value());
1464 warning << "Legacy session: automation list has no automation-id property.";
1467 if ((prop = node.property (X_("interpolation-style"))) != 0) {
1468 _interpolation = (InterpolationStyle)string_2_enum(prop->value(), _interpolation);
1470 _interpolation = Linear;
1473 if ((prop = node.property (X_("default"))) != 0){
1474 _default_value = atof (prop->value().c_str());
1476 _default_value = 0.0;
1479 if ((prop = node.property (X_("style"))) != 0) {
1480 _style = string_to_auto_style (prop->value());
1485 if ((prop = node.property (X_("state"))) != 0) {
1486 _state = string_to_auto_state (prop->value());
1491 if ((prop = node.property (X_("min_yval"))) != 0) {
1492 _min_yval = atof (prop->value ().c_str());
1494 _min_yval = FLT_MIN;
1497 if ((prop = node.property (X_("max_yval"))) != 0) {
1498 _max_yval = atof (prop->value ().c_str());
1500 _max_yval = FLT_MAX;
1503 if ((prop = node.property (X_("max_xval"))) != 0) {
1504 _max_xval = atof (prop->value ().c_str());
1506 _max_xval = 0; // means "no limit ;
1509 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1510 if ((*niter)->name() == X_("events")) {
1511 deserialize_events (*(*niter));