1 /* This file is part of Evoral.
2 * Copyright (C) 2008 Dave Robillard <http://drobilla.net>
3 * Copyright (C) 2000-2008 Paul Davis
5 * Evoral is free software; you can redistribute it and/or modify it under the
6 * terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option) any later
10 * Evoral is distributed in the hope that it will be useful, but WITHOUT ANY
11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "evoral/ControlList.hpp"
24 #include "evoral/Curve.hpp"
31 inline bool event_time_less_than (ControlEvent* a, ControlEvent* b)
33 return a->when < b->when;
37 ControlList::ControlList (const Parameter& id)
39 , _interpolation(Linear)
43 _changed_when_thawed = false;
46 _max_xval = 0; // means "no limit"
48 _lookup_cache.left = -1;
49 _lookup_cache.range.first = _events.end();
50 _search_cache.left = -1;
51 _search_cache.first = _events.end();
52 _sort_pending = false;
55 ControlList::ControlList (const ControlList& other)
56 : _parameter(other._parameter)
57 , _interpolation(Linear)
61 _changed_when_thawed = false;
62 _min_yval = other._min_yval;
63 _max_yval = other._max_yval;
64 _max_xval = other._max_xval;
65 _default_value = other._default_value;
66 _lookup_cache.range.first = _events.end();
67 _search_cache.first = _events.end();
68 _sort_pending = false;
70 for (const_iterator i = other._events.begin(); i != other._events.end(); ++i) {
71 _events.push_back (new ControlEvent (**i));
77 ControlList::ControlList (const ControlList& other, double start, double end)
78 : _parameter(other._parameter)
79 , _interpolation(Linear)
83 _changed_when_thawed = false;
84 _min_yval = other._min_yval;
85 _max_yval = other._max_yval;
86 _max_xval = other._max_xval;
87 _default_value = other._default_value;
88 _lookup_cache.range.first = _events.end();
89 _search_cache.first = _events.end();
90 _sort_pending = false;
92 /* now grab the relevant points, and shift them back if necessary */
94 boost::shared_ptr<ControlList> section = const_cast<ControlList*>(&other)->copy (start, end);
96 if (!section->empty()) {
97 for (iterator i = section->begin(); i != section->end(); ++i) {
98 _events.push_back (new ControlEvent ((*i)->when, (*i)->value));
105 ControlList::~ControlList()
107 for (EventList::iterator x = _events.begin(); x != _events.end(); ++x) {
111 for (list<NascentInfo*>::iterator n = nascent.begin(); n != nascent.end(); ++n) {
112 for (EventList::iterator x = (*n)->events.begin(); x != (*n)->events.end(); ++x) {
121 boost::shared_ptr<ControlList>
122 ControlList::create(Parameter id)
124 return boost::shared_ptr<ControlList>(new ControlList(id));
128 ControlList::operator== (const ControlList& other)
130 return _events == other._events;
134 ControlList::operator= (const ControlList& other)
136 if (this != &other) {
140 for (const_iterator i = other._events.begin(); i != other._events.end(); ++i) {
141 _events.push_back (new ControlEvent (**i));
144 _min_yval = other._min_yval;
145 _max_yval = other._max_yval;
146 _max_xval = other._max_xval;
147 _default_value = other._default_value;
150 maybe_signal_changed ();
157 ControlList::create_curve()
159 _curve = new Curve(*this);
163 ControlList::destroy_curve()
170 ControlList::maybe_signal_changed ()
175 _changed_when_thawed = true;
180 ControlList::clear ()
183 Glib::Mutex::Lock lm (_lock);
188 maybe_signal_changed ();
192 ControlList::x_scale (double factor)
194 Glib::Mutex::Lock lm (_lock);
199 ControlList::extend_to (double when)
201 Glib::Mutex::Lock lm (_lock);
202 if (_events.empty() || _events.back()->when == when) {
205 double factor = when / _events.back()->when;
211 ControlList::_x_scale (double factor)
213 for (iterator i = _events.begin(); i != _events.end(); ++i) {
214 (*i)->when = floor ((*i)->when * factor);
221 ControlList::write_pass_finished (double when)
223 merge_nascent (when);
227 ControlList::merge_nascent (double when)
230 Glib::Mutex::Lock lm (_lock);
232 if (nascent.empty()) {
236 for (list<NascentInfo*>::iterator n = nascent.begin(); n != nascent.end(); ++n) {
238 NascentInfo* ninfo = *n;
239 EventList& nascent_events (ninfo->events);
240 bool need_adjacent_start_clamp;
241 bool need_adjacent_end_clamp;
243 if (nascent_events.empty()) {
248 if (ninfo->start_time < 0.0) {
249 ninfo->start_time = nascent_events.front()->when;
252 if (ninfo->end_time < 0.0) {
253 ninfo->end_time = when;
256 bool preexisting = !_events.empty();
260 _events = nascent_events;
262 } else if (ninfo->end_time < _events.front()->when) {
264 /* all points in nascent are before the first existing point */
266 _events.insert (_events.begin(), nascent_events.begin(), nascent_events.end());
268 } else if (ninfo->start_time > _events.back()->when) {
270 /* all points in nascent are after the last existing point */
272 _events.insert (_events.end(), nascent_events.begin(), nascent_events.end());
276 /* find the range that overaps with nascent events,
277 and insert the contents of nascent events.
281 iterator range_begin = _events.end();
282 iterator range_end = _events.end();
283 double end_value = unlocked_eval (ninfo->end_time);
284 double start_value = unlocked_eval (ninfo->start_time - 1);
286 need_adjacent_end_clamp = true;
287 need_adjacent_start_clamp = true;
289 for (i = _events.begin(); i != _events.end(); ++i) {
291 if ((*i)->when == ninfo->start_time) {
292 /* existing point at same time, remove it
293 and the consider the next point instead.
295 i = _events.erase (i);
297 if (i == _events.end()) {
301 if (range_begin == _events.end()) {
303 need_adjacent_start_clamp = false;
305 need_adjacent_end_clamp = false;
308 if ((*i)->when > ninfo->end_time) {
313 } else if ((*i)->when > ninfo->start_time) {
315 if (range_begin == _events.end()) {
319 if ((*i)->when > ninfo->end_time) {
326 assert (range_begin != _events.end());
328 if (range_begin != _events.begin()) {
329 /* clamp point before */
330 if (need_adjacent_start_clamp) {
331 _events.insert (range_begin, new ControlEvent (ninfo->start_time, start_value));
335 _events.insert (range_begin, nascent_events.begin(), nascent_events.end());
337 if (range_end != _events.end()) {
338 /* clamp point after */
339 if (need_adjacent_end_clamp) {
340 _events.insert (range_begin, new ControlEvent (ninfo->end_time, end_value));
344 _events.erase (range_begin, range_end);
353 nascent.push_back (new NascentInfo (false));
357 maybe_signal_changed ();
361 ControlList::rt_add (double when, double value)
363 // this is for automation recording
365 if (touch_enabled() && !touching()) {
369 //cerr << "RT: alist " << this << " add " << value << " @ " << when << endl;
371 Glib::Mutex::Lock lm (_lock, Glib::TRY_LOCK);
374 assert (!nascent.empty());
375 if (!nascent.back()->events.empty()) {
376 assert (when > nascent.back()->events.back()->when);
378 nascent.back()->events.push_back (new ControlEvent (when, value));
383 ControlList::fast_simple_add (double when, double value)
385 /* to be used only for loading pre-sorted data from saved state */
386 _events.insert (_events.end(), new ControlEvent (when, value));
387 assert(_events.back());
391 ControlList::add (double when, double value)
393 /* this is for graphical editing */
396 Glib::Mutex::Lock lm (_lock);
397 ControlEvent cp (when, 0.0f);
399 iterator insertion_point;
401 for (insertion_point = lower_bound (_events.begin(), _events.end(), &cp, time_comparator); insertion_point != _events.end(); ++insertion_point) {
403 /* only one point allowed per time point */
405 if ((*insertion_point)->when == when) {
406 (*insertion_point)->value = value;
411 if ((*insertion_point)->when >= when) {
418 _events.insert (insertion_point, new ControlEvent (when, value));
425 maybe_signal_changed ();
429 ControlList::erase (iterator i)
432 Glib::Mutex::Lock lm (_lock);
436 maybe_signal_changed ();
440 ControlList::erase (iterator start, iterator end)
443 Glib::Mutex::Lock lm (_lock);
444 _events.erase (start, end);
447 maybe_signal_changed ();
451 ControlList::reset_range (double start, double endt)
456 Glib::Mutex::Lock lm (_lock);
457 ControlEvent cp (start, 0.0f);
461 if ((s = lower_bound (_events.begin(), _events.end(), &cp, time_comparator)) != _events.end()) {
464 e = upper_bound (_events.begin(), _events.end(), &cp, time_comparator);
466 for (iterator i = s; i != e; ++i) {
467 (*i)->value = _default_value;
477 maybe_signal_changed ();
482 ControlList::erase_range (double start, double endt)
487 Glib::Mutex::Lock lm (_lock);
488 erased = erase_range_internal (start, endt, _events);
497 maybe_signal_changed ();
502 ControlList::erase_range_internal (double start, double endt, EventList & events)
505 ControlEvent cp (start, 0.0f);
509 if ((s = lower_bound (events.begin(), events.end(), &cp, time_comparator)) != events.end()) {
511 e = upper_bound (events.begin(), events.end(), &cp, time_comparator);
520 ControlList::slide (iterator before, double distance)
523 Glib::Mutex::Lock lm (_lock);
525 if (before == _events.end()) {
529 while (before != _events.end()) {
530 (*before)->when += distance;
535 maybe_signal_changed ();
539 ControlList::modify (iterator iter, double when, double val)
541 /* note: we assume higher level logic is in place to avoid this
542 reordering the time-order of control events in the list. ie. all
543 points after *iter are later than when.
547 Glib::Mutex::Lock lm (_lock);
549 (*iter)->when = when;
550 (*iter)->value = val;
557 _events.sort (event_time_less_than);
559 _sort_pending = true;
565 maybe_signal_changed ();
568 std::pair<ControlList::iterator,ControlList::iterator>
569 ControlList::control_points_adjacent (double xval)
571 Glib::Mutex::Lock lm (_lock);
573 ControlEvent cp (xval, 0.0f);
574 std::pair<iterator,iterator> ret;
576 ret.first = _events.end();
577 ret.second = _events.end();
579 for (i = lower_bound (_events.begin(), _events.end(), &cp, time_comparator); i != _events.end(); ++i) {
581 if (ret.first == _events.end()) {
582 if ((*i)->when >= xval) {
583 if (i != _events.begin()) {
592 if ((*i)->when > xval) {
602 ControlList::set_max_xval (double x)
608 ControlList::freeze ()
623 Glib::Mutex::Lock lm (_lock);
626 _events.sort (event_time_less_than);
627 _sort_pending = false;
633 ControlList::mark_dirty () const
635 _lookup_cache.left = -1;
636 _search_cache.left = -1;
639 _curve->mark_dirty();
642 Dirty (); /* EMIT SIGNAL */
646 ControlList::truncate_end (double last_coordinate)
649 Glib::Mutex::Lock lm (_lock);
650 ControlEvent cp (last_coordinate, 0);
651 ControlList::reverse_iterator i;
654 if (_events.empty()) {
658 if (last_coordinate == _events.back()->when) {
662 if (last_coordinate > _events.back()->when) {
667 iterator foo = _events.begin();
670 if (foo == _events.end()) {
672 } else if (++foo == _events.end()) {
679 /* less than 2 points: add a new point */
680 _events.push_back (new ControlEvent (last_coordinate, _events.back()->value));
683 /* more than 2 points: check to see if the last 2 values
684 are equal. if so, just move the position of the
685 last point. otherwise, add a new point.
688 iterator penultimate = _events.end();
689 --penultimate; /* points at last point */
690 --penultimate; /* points at the penultimate point */
692 if (_events.back()->value == (*penultimate)->value) {
693 _events.back()->when = last_coordinate;
695 _events.push_back (new ControlEvent (last_coordinate, _events.back()->value));
703 last_val = unlocked_eval (last_coordinate);
704 last_val = max ((double) _min_yval, last_val);
705 last_val = min ((double) _max_yval, last_val);
707 i = _events.rbegin();
709 /* make i point to the last control point */
713 /* now go backwards, removing control points that are
714 beyond the new last coordinate.
717 // FIXME: SLOW! (size() == O(n))
719 uint32_t sz = _events.size();
721 while (i != _events.rend() && sz > 2) {
722 ControlList::reverse_iterator tmp;
727 if ((*i)->when < last_coordinate) {
731 _events.erase (i.base());
737 _events.back()->when = last_coordinate;
738 _events.back()->value = last_val;
744 maybe_signal_changed ();
748 ControlList::truncate_start (double overall_length)
751 Glib::Mutex::Lock lm (_lock);
753 double first_legal_value;
754 double first_legal_coordinate;
756 assert(!_events.empty());
758 if (overall_length == _events.back()->when) {
759 /* no change in overall length */
763 if (overall_length > _events.back()->when) {
765 /* growing at front: duplicate first point. shift all others */
767 double shift = overall_length - _events.back()->when;
770 for (np = 0, i = _events.begin(); i != _events.end(); ++i, ++np) {
776 /* less than 2 points: add a new point */
777 _events.push_front (new ControlEvent (0, _events.front()->value));
781 /* more than 2 points: check to see if the first 2 values
782 are equal. if so, just move the position of the
783 first point. otherwise, add a new point.
786 iterator second = _events.begin();
787 ++second; /* points at the second point */
789 if (_events.front()->value == (*second)->value) {
790 /* first segment is flat, just move start point back to zero */
791 _events.front()->when = 0;
793 /* leave non-flat segment in place, add a new leading point. */
794 _events.push_front (new ControlEvent (0, _events.front()->value));
800 /* shrinking at front */
802 first_legal_coordinate = _events.back()->when - overall_length;
803 first_legal_value = unlocked_eval (first_legal_coordinate);
804 first_legal_value = max (_min_yval, first_legal_value);
805 first_legal_value = min (_max_yval, first_legal_value);
807 /* remove all events earlier than the new "front" */
811 while (i != _events.end() && !_events.empty()) {
812 ControlList::iterator tmp;
817 if ((*i)->when > first_legal_coordinate) {
827 /* shift all remaining points left to keep their same
831 for (i = _events.begin(); i != _events.end(); ++i) {
832 (*i)->when -= first_legal_coordinate;
835 /* add a new point for the interpolated new value */
837 _events.push_front (new ControlEvent (0, first_legal_value));
843 maybe_signal_changed ();
847 ControlList::unlocked_eval (double x) const
849 pair<EventList::iterator,EventList::iterator> range;
855 const_iterator length_check_iter = _events.begin();
856 for (npoints = 0; npoints < 4; ++npoints, ++length_check_iter) {
857 if (length_check_iter == _events.end()) {
864 return _default_value;
867 return _events.front()->value;
870 if (x >= _events.back()->when) {
871 return _events.back()->value;
872 } else if (x <= _events.front()->when) {
873 return _events.front()->value;
876 lpos = _events.front()->when;
877 lval = _events.front()->value;
878 upos = _events.back()->when;
879 uval = _events.back()->value;
881 if (_interpolation == Discrete) {
885 /* linear interpolation betweeen the two points */
886 fraction = (double) (x - lpos) / (double) (upos - lpos);
887 return lval + (fraction * (uval - lval));
890 if (x >= _events.back()->when) {
891 return _events.back()->value;
892 } else if (x <= _events.front()->when) {
893 return _events.front()->value;
896 return multipoint_eval (x);
899 /*NOTREACHED*/ /* stupid gcc */
900 return _default_value;
904 ControlList::multipoint_eval (double x) const
910 /* "Stepped" lookup (no interpolation) */
911 /* FIXME: no cache. significant? */
912 if (_interpolation == Discrete) {
913 const ControlEvent cp (x, 0);
914 EventList::const_iterator i = lower_bound (_events.begin(), _events.end(), &cp, time_comparator);
916 // shouldn't have made it to multipoint_eval
917 assert(i != _events.end());
919 if (i == _events.begin() || (*i)->when == x)
922 return (*(--i))->value;
925 /* Only do the range lookup if x is in a different range than last time
926 * this was called (or if the lookup cache has been marked "dirty" (left<0) */
927 if ((_lookup_cache.left < 0) ||
928 ((_lookup_cache.left > x) ||
929 (_lookup_cache.range.first == _events.end()) ||
930 ((*_lookup_cache.range.second)->when < x))) {
932 const ControlEvent cp (x, 0);
934 _lookup_cache.range = equal_range (_events.begin(), _events.end(), &cp, time_comparator);
937 pair<const_iterator,const_iterator> range = _lookup_cache.range;
939 if (range.first == range.second) {
941 /* x does not exist within the list as a control point */
943 _lookup_cache.left = x;
945 if (range.first != _events.begin()) {
947 lpos = (*range.first)->when;
948 lval = (*range.first)->value;
950 /* we're before the first point */
951 // return _default_value;
952 return _events.front()->value;
955 if (range.second == _events.end()) {
956 /* we're after the last point */
957 return _events.back()->value;
960 upos = (*range.second)->when;
961 uval = (*range.second)->value;
963 /* linear interpolation betweeen the two points
967 fraction = (double) (x - lpos) / (double) (upos - lpos);
968 return lval + (fraction * (uval - lval));
972 /* x is a control point in the data */
973 _lookup_cache.left = -1;
974 return (*range.first)->value;
978 ControlList::build_search_cache_if_necessary (double start) const
980 /* Only do the range lookup if x is in a different range than last time
981 * this was called (or if the search cache has been marked "dirty" (left<0) */
982 if (!_events.empty() && ((_search_cache.left < 0) || (_search_cache.left > start))) {
984 const ControlEvent start_point (start, 0);
986 //cerr << "REBUILD: (" << _search_cache.left << ".." << _search_cache.right << ") := ("
987 // << start << ".." << end << ")" << endl;
989 _search_cache.first = lower_bound (_events.begin(), _events.end(), &start_point, time_comparator);
990 _search_cache.left = start;
994 /** Get the earliest event after \a start using the current interpolation style.
996 * If an event is found, \a x and \a y are set to its coordinates.
998 * \param inclusive Include events with timestamp exactly equal to \a start
999 * \return true if event is found (and \a x and \a y are valid).
1002 ControlList::rt_safe_earliest_event (double start, double& x, double& y, bool inclusive) const
1004 // FIXME: It would be nice if this was unnecessary..
1005 Glib::Mutex::Lock lm(_lock, Glib::TRY_LOCK);
1010 return rt_safe_earliest_event_unlocked (start, x, y, inclusive);
1014 /** Get the earliest event after \a start using the current interpolation style.
1016 * If an event is found, \a x and \a y are set to its coordinates.
1018 * \param inclusive Include events with timestamp exactly equal to \a start
1019 * \return true if event is found (and \a x and \a y are valid).
1022 ControlList::rt_safe_earliest_event_unlocked (double start, double& x, double& y, bool inclusive) const
1024 if (_interpolation == Discrete) {
1025 return rt_safe_earliest_event_discrete_unlocked(start, x, y, inclusive);
1027 return rt_safe_earliest_event_linear_unlocked(start, x, y, inclusive);
1032 /** Get the earliest event after \a start without interpolation.
1034 * If an event is found, \a x and \a y are set to its coordinates.
1036 * \param inclusive Include events with timestamp exactly equal to \a start
1037 * \return true if event is found (and \a x and \a y are valid).
1040 ControlList::rt_safe_earliest_event_discrete_unlocked (double start, double& x, double& y, bool inclusive) const
1042 build_search_cache_if_necessary (start);
1044 if (_search_cache.first != _events.end()) {
1045 const ControlEvent* const first = *_search_cache.first;
1047 const bool past_start = (inclusive ? first->when >= start : first->when > start);
1049 /* Earliest points is in range, return it */
1055 /* Move left of cache to this point
1056 * (Optimize for immediate call this cycle within range) */
1057 _search_cache.left = x;
1058 ++_search_cache.first;
1067 /* No points in range */
1073 /** Get the earliest time the line crosses an integer (Linear interpolation).
1075 * If an event is found, \a x and \a y are set to its coordinates.
1077 * \param inclusive Include events with timestamp exactly equal to \a start
1078 * \return true if event is found (and \a x and \a y are valid).
1081 ControlList::rt_safe_earliest_event_linear_unlocked (double start, double& x, double& y, bool inclusive) const
1083 // cout << "earliest_event(start: " << start << ", x: " << x << ", y: " << y << ", inclusive: " << inclusive << ")" << endl;
1085 const_iterator length_check_iter = _events.begin();
1086 if (_events.empty()) { // 0 events
1088 } else if (_events.end() == ++length_check_iter) { // 1 event
1089 return rt_safe_earliest_event_discrete_unlocked (start, x, y, inclusive);
1092 // Hack to avoid infinitely repeating the same event
1093 build_search_cache_if_necessary (start);
1095 if (_search_cache.first != _events.end()) {
1097 const ControlEvent* first = NULL;
1098 const ControlEvent* next = NULL;
1100 /* Step is after first */
1101 if (_search_cache.first == _events.begin() || (*_search_cache.first)->when <= start) {
1102 first = *_search_cache.first;
1103 ++_search_cache.first;
1104 if (_search_cache.first == _events.end()) {
1107 next = *_search_cache.first;
1109 /* Step is before first */
1111 const_iterator prev = _search_cache.first;
1114 next = *_search_cache.first;
1117 if (inclusive && first->when == start) {
1120 /* Move left of cache to this point
1121 * (Optimize for immediate call this cycle within range) */
1122 _search_cache.left = x;
1123 //++_search_cache.range.first;
1128 if (fabs(first->value - next->value) <= 1) {
1129 if (next->when > start) {
1132 /* Move left of cache to this point
1133 * (Optimize for immediate call this cycle within range) */
1134 _search_cache.left = x;
1135 //++_search_cache.range.first;
1136 assert(inclusive ? x >= start : x > start);
1143 const double slope = (next->value - first->value) / (double)(next->when - first->when);
1144 //cerr << "start y: " << start_y << endl;
1146 //y = first->value + (slope * fabs(start - first->when));
1149 if (first->value < next->value) // ramping up
1151 else // ramping down
1154 x = first->when + (y - first->value) / (double)slope;
1156 while ((inclusive && x < start) || (x <= start && y != next->value)) {
1158 if (first->value < next->value) // ramping up
1160 else // ramping down
1163 x = first->when + (y - first->value) / (double)slope;
1166 /*cerr << first->value << " @ " << first->when << " ... "
1167 << next->value << " @ " << next->when
1168 << " = " << y << " @ " << x << endl;*/
1170 assert( (y >= first->value && y <= next->value)
1171 || (y <= first->value && y >= next->value) );
1174 const bool past_start = (inclusive ? x >= start : x > start);
1176 /* Move left of cache to this point
1177 * (Optimize for immediate call this cycle within range) */
1178 _search_cache.left = x;
1179 assert(inclusive ? x >= start : x > start);
1185 /* No points in the future, so no steps (towards them) in the future */
1192 /** @param start Start position in model coordinates.
1193 * @param end End position in model coordinates.
1194 * @param op 0 = cut, 1 = copy, 2 = clear.
1196 boost::shared_ptr<ControlList>
1197 ControlList::cut_copy_clear (double start, double end, int op)
1199 boost::shared_ptr<ControlList> nal = create (_parameter);
1201 ControlEvent cp (start, 0.0);
1204 Glib::Mutex::Lock lm (_lock);
1206 /* first, determine s & e, two iterators that define the range of points
1207 affected by this operation
1210 if ((s = lower_bound (_events.begin(), _events.end(), &cp, time_comparator)) == _events.end()) {
1214 /* and the last that is at or after `end' */
1216 e = upper_bound (_events.begin(), _events.end(), &cp, time_comparator);
1219 /* if "start" isn't the location of an existing point,
1220 evaluate the curve to get a value for the start. Add a point to
1221 both the existing event list, and if its not a "clear" operation,
1222 to the copy ("nal") as well.
1224 Note that the time positions of the points in each list are different
1225 because we want the copy ("nal") to have a zero time reference.
1229 /* before we begin any cut/clear operations, get the value of the curve
1233 double end_value = unlocked_eval (end);
1235 if ((*s)->when != start) {
1237 double val = unlocked_eval (start);
1239 if (op == 0) { // cut
1240 if (start > _events.front()->when) {
1241 _events.insert (s, (new ControlEvent (start, val)));
1245 if (op != 2) { // ! clear
1246 nal->_events.push_back (new ControlEvent (0, val));
1250 for (iterator x = s; x != e; ) {
1252 /* adjust new points to be relative to start, which
1253 has been set to zero.
1257 nal->_events.push_back (new ControlEvent ((*x)->when - start, (*x)->value));
1261 x = _events.erase (x);
1267 if (e == _events.end() || (*e)->when != end) {
1269 /* only add a boundary point if there is a point after "end"
1272 if (op == 0 && (e != _events.end() && end < (*e)->when)) { // cut
1273 _events.insert (e, new ControlEvent (end, end_value));
1276 if (op != 2 && (e != _events.end() && end < (*e)->when)) { // cut/copy
1277 nal->_events.push_back (new ControlEvent (end - start, end_value));
1285 maybe_signal_changed ();
1292 boost::shared_ptr<ControlList>
1293 ControlList::cut (double start, double end)
1295 return cut_copy_clear (start, end, 0);
1298 boost::shared_ptr<ControlList>
1299 ControlList::copy (double start, double end)
1301 return cut_copy_clear (start, end, 1);
1305 ControlList::clear (double start, double end)
1307 cut_copy_clear (start, end, 2);
1310 /** @param pos Position in model coordinates */
1312 ControlList::paste (ControlList& alist, double pos, float /*times*/)
1314 if (alist._events.empty()) {
1319 Glib::Mutex::Lock lm (_lock);
1323 ControlEvent cp (pos, 0.0);
1325 where = upper_bound (_events.begin(), _events.end(), &cp, time_comparator);
1327 for (iterator i = alist.begin();i != alist.end(); ++i) {
1328 _events.insert (where, new ControlEvent( (*i)->when+pos,( *i)->value));
1329 end = (*i)->when + pos;
1333 /* move all points after the insertion along the timeline by
1337 while (where != _events.end()) {
1339 if ((*where)->when <= end) {
1342 _events.erase(where);
1353 maybe_signal_changed ();
1357 /** Move automation around according to a list of region movements */
1359 ControlList::move_ranges (const list< RangeMove<double> >& movements)
1361 typedef list< RangeMove<double> > RangeMoveList;
1364 Glib::Mutex::Lock lm (_lock);
1366 /* a copy of the events list before we started moving stuff around */
1367 EventList old_events = _events;
1369 /* clear the source and destination ranges in the new list */
1370 for (RangeMoveList::const_iterator i = movements.begin (); i != movements.end (); ++i) {
1372 erase_range_internal (i->from, i->from + i->length, _events);
1373 erase_range_internal (i->to, i->to + i->length, _events);
1377 /* copy the events into the new list */
1378 for (RangeMoveList::const_iterator i = movements.begin (); i != movements.end (); ++i) {
1379 iterator j = old_events.begin ();
1380 const double limit = i->from + i->length;
1381 const double dx = i->to - i->from;
1382 while (j != old_events.end () && (*j)->when <= limit) {
1383 if ((*j)->when >= i->from) {
1384 ControlEvent* ev = new ControlEvent (**j);
1386 _events.push_back (ev);
1393 _events.sort (event_time_less_than);
1395 _sort_pending = true;
1401 maybe_signal_changed ();
1405 ControlList::set_interpolation (InterpolationStyle s)
1407 if (_interpolation == s) {
1412 InterpolationChanged (s); /* EMIT SIGNAL */
1415 } // namespace Evoral