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 _rt_insertion_point = _events.end();
49 _lookup_cache.left = -1;
50 _lookup_cache.range.first = _events.end();
51 _search_cache.left = -1;
52 _search_cache.range.first = _events.end();
53 _sort_pending = false;
56 ControlList::ControlList (const ControlList& other)
57 : _parameter(other._parameter)
58 , _interpolation(Linear)
62 _changed_when_thawed = false;
63 _min_yval = other._min_yval;
64 _max_yval = other._max_yval;
65 _max_xval = other._max_xval;
66 _default_value = other._default_value;
67 _rt_insertion_point = _events.end();
68 _lookup_cache.range.first = _events.end();
69 _search_cache.range.first = _events.end();
70 _sort_pending = false;
72 for (const_iterator i = other._events.begin(); i != other._events.end(); ++i) {
73 _events.push_back (new ControlEvent (**i));
79 ControlList::ControlList (const ControlList& other, double start, double end)
80 : _parameter(other._parameter)
81 , _interpolation(Linear)
85 _changed_when_thawed = false;
86 _min_yval = other._min_yval;
87 _max_yval = other._max_yval;
88 _max_xval = other._max_xval;
89 _default_value = other._default_value;
90 _rt_insertion_point = _events.end();
91 _lookup_cache.range.first = _events.end();
92 _search_cache.range.first = _events.end();
93 _sort_pending = false;
95 /* now grab the relevant points, and shift them back if necessary */
97 boost::shared_ptr<ControlList> section = const_cast<ControlList*>(&other)->copy (start, end);
99 if (!section->empty()) {
100 for (iterator i = section->begin(); i != section->end(); ++i) {
101 _events.push_back (new ControlEvent ((*i)->when, (*i)->value));
108 ControlList::~ControlList()
110 for (EventList::iterator x = _events.begin(); x != _events.end(); ++x) {
117 boost::shared_ptr<ControlList>
118 ControlList::create(Parameter id)
120 return boost::shared_ptr<ControlList>(new ControlList(id));
124 ControlList::operator== (const ControlList& other)
126 return _events == other._events;
130 ControlList::operator= (const ControlList& other)
132 if (this != &other) {
136 for (const_iterator i = other._events.begin(); i != other._events.end(); ++i) {
137 _events.push_back (new ControlEvent (**i));
140 _min_yval = other._min_yval;
141 _max_yval = other._max_yval;
142 _max_xval = other._max_xval;
143 _default_value = other._default_value;
146 maybe_signal_changed ();
153 ControlList::create_curve()
155 _curve = new Curve(*this);
159 ControlList::destroy_curve()
166 ControlList::maybe_signal_changed ()
171 _changed_when_thawed = true;
175 ControlList::clear ()
178 Glib::Mutex::Lock lm (_lock);
183 maybe_signal_changed ();
187 ControlList::x_scale (double factor)
189 Glib::Mutex::Lock lm (_lock);
194 ControlList::extend_to (double when)
196 Glib::Mutex::Lock lm (_lock);
197 if (_events.empty() || _events.back()->when == when) {
200 double factor = when / _events.back()->when;
205 void ControlList::_x_scale (double factor)
207 for (iterator i = _events.begin(); i != _events.end(); ++i) {
208 (*i)->when = floor ((*i)->when * factor);
215 ControlList::reposition_for_rt_add (double /*when*/)
217 _rt_insertion_point = _events.end();
221 ControlList::rt_add (double when, double value)
223 //cerr << "RT: alist " << this << " add " << value << " @ " << when << endl;
226 Glib::Mutex::Lock lm (_lock);
229 ControlEvent cp (when, 0.0);
232 if ((_rt_insertion_point != _events.end()) && ((*_rt_insertion_point)->when < when) ) {
234 /* we have a previous insertion point, so we should delete
235 everything between it and the position where we are going
236 to insert this point.
239 iterator after = _rt_insertion_point;
241 if (++after != _events.end()) {
242 iterator far = after;
244 while (far != _events.end()) {
245 if ((*far)->when > when) {
253 _rt_insertion_point = where;
255 if ((*where)->when == when) {
256 (*where)->value = value;
260 where = _events.erase (after, far);
269 iterator previous = _rt_insertion_point;
272 if (_rt_insertion_point != _events.begin() && (*_rt_insertion_point)->value == value && (*previous)->value == value) {
273 (*_rt_insertion_point)->when = when;
280 where = lower_bound (_events.begin(), _events.end(), &cp, time_comparator);
282 if (where != _events.end()) {
283 if ((*where)->when == when) {
284 (*where)->value = value;
291 _rt_insertion_point = _events.insert (where, new ControlEvent (when, value));
298 maybe_signal_changed ();
302 ControlList::fast_simple_add (double when, double value)
304 /* to be used only for loading pre-sorted data from saved state */
305 _events.insert (_events.end(), new ControlEvent (when, value));
306 assert(_events.back());
310 ControlList::add (double when, double value)
312 /* this is for graphical editing */
315 Glib::Mutex::Lock lm (_lock);
316 ControlEvent cp (when, 0.0f);
318 iterator insertion_point;
320 for (insertion_point = lower_bound (_events.begin(), _events.end(), &cp, time_comparator); insertion_point != _events.end(); ++insertion_point) {
322 /* only one point allowed per time point */
324 if ((*insertion_point)->when == when) {
325 (*insertion_point)->value = value;
330 if ((*insertion_point)->when >= when) {
337 _events.insert (insertion_point, new ControlEvent (when, value));
338 reposition_for_rt_add (0);
345 maybe_signal_changed ();
349 ControlList::erase (iterator i)
352 Glib::Mutex::Lock lm (_lock);
354 reposition_for_rt_add (0);
357 maybe_signal_changed ();
361 ControlList::erase (iterator start, iterator end)
364 Glib::Mutex::Lock lm (_lock);
365 _events.erase (start, end);
366 reposition_for_rt_add (0);
369 maybe_signal_changed ();
373 ControlList::reset_range (double start, double endt)
378 Glib::Mutex::Lock lm (_lock);
379 ControlEvent cp (start, 0.0f);
383 if ((s = lower_bound (_events.begin(), _events.end(), &cp, time_comparator)) != _events.end()) {
386 e = upper_bound (_events.begin(), _events.end(), &cp, time_comparator);
388 for (iterator i = s; i != e; ++i) {
389 (*i)->value = _default_value;
399 maybe_signal_changed ();
404 ControlList::erase_range (double start, double endt)
409 Glib::Mutex::Lock lm (_lock);
410 erased = erase_range_internal (start, endt, _events);
413 reposition_for_rt_add (0);
420 maybe_signal_changed ();
425 ControlList::erase_range_internal (double start, double endt, EventList & events)
428 ControlEvent cp (start, 0.0f);
432 if ((s = lower_bound (events.begin(), events.end(), &cp, time_comparator)) != events.end()) {
434 e = upper_bound (events.begin(), events.end(), &cp, time_comparator);
443 ControlList::slide (iterator before, double distance)
446 Glib::Mutex::Lock lm (_lock);
448 if (before == _events.end()) {
452 while (before != _events.end()) {
453 (*before)->when += distance;
458 maybe_signal_changed ();
462 ControlList::modify (iterator iter, double when, double val)
464 /* note: we assume higher level logic is in place to avoid this
465 reordering the time-order of control events in the list. ie. all
466 points after *iter are later than when.
470 Glib::Mutex::Lock lm (_lock);
472 (*iter)->when = when;
473 (*iter)->value = val;
480 _events.sort (event_time_less_than);
482 _sort_pending = true;
488 maybe_signal_changed ();
491 std::pair<ControlList::iterator,ControlList::iterator>
492 ControlList::control_points_adjacent (double xval)
494 Glib::Mutex::Lock lm (_lock);
496 ControlEvent cp (xval, 0.0f);
497 std::pair<iterator,iterator> ret;
499 ret.first = _events.end();
500 ret.second = _events.end();
502 for (i = lower_bound (_events.begin(), _events.end(), &cp, time_comparator); i != _events.end(); ++i) {
504 if (ret.first == _events.end()) {
505 if ((*i)->when >= xval) {
506 if (i != _events.begin()) {
515 if ((*i)->when > xval) {
525 ControlList::set_max_xval (double x)
531 ControlList::freeze ()
546 Glib::Mutex::Lock lm (_lock);
549 _events.sort (event_time_less_than);
550 _sort_pending = false;
556 ControlList::mark_dirty () const
558 _lookup_cache.left = -1;
559 _search_cache.left = -1;
561 _curve->mark_dirty();
565 ControlList::truncate_end (double last_coordinate)
568 Glib::Mutex::Lock lm (_lock);
569 ControlEvent cp (last_coordinate, 0);
570 ControlList::reverse_iterator i;
573 if (_events.empty()) {
577 if (last_coordinate == _events.back()->when) {
581 if (last_coordinate > _events.back()->when) {
586 iterator foo = _events.begin();
589 if (foo == _events.end()) {
591 } else if (++foo == _events.end()) {
598 /* less than 2 points: add a new point */
599 _events.push_back (new ControlEvent (last_coordinate, _events.back()->value));
602 /* more than 2 points: check to see if the last 2 values
603 are equal. if so, just move the position of the
604 last point. otherwise, add a new point.
607 iterator penultimate = _events.end();
608 --penultimate; /* points at last point */
609 --penultimate; /* points at the penultimate point */
611 if (_events.back()->value == (*penultimate)->value) {
612 _events.back()->when = last_coordinate;
614 _events.push_back (new ControlEvent (last_coordinate, _events.back()->value));
622 last_val = unlocked_eval (last_coordinate);
623 last_val = max ((double) _min_yval, last_val);
624 last_val = min ((double) _max_yval, last_val);
626 i = _events.rbegin();
628 /* make i point to the last control point */
632 /* now go backwards, removing control points that are
633 beyond the new last coordinate.
636 // FIXME: SLOW! (size() == O(n))
638 uint32_t sz = _events.size();
640 while (i != _events.rend() && sz > 2) {
641 ControlList::reverse_iterator tmp;
646 if ((*i)->when < last_coordinate) {
650 _events.erase (i.base());
656 _events.back()->when = last_coordinate;
657 _events.back()->value = last_val;
660 reposition_for_rt_add (0);
664 maybe_signal_changed ();
668 ControlList::truncate_start (double overall_length)
671 Glib::Mutex::Lock lm (_lock);
673 double first_legal_value;
674 double first_legal_coordinate;
676 assert(!_events.empty());
678 if (overall_length == _events.back()->when) {
679 /* no change in overall length */
683 if (overall_length > _events.back()->when) {
685 /* growing at front: duplicate first point. shift all others */
687 double shift = overall_length - _events.back()->when;
690 for (np = 0, i = _events.begin(); i != _events.end(); ++i, ++np) {
696 /* less than 2 points: add a new point */
697 _events.push_front (new ControlEvent (0, _events.front()->value));
701 /* more than 2 points: check to see if the first 2 values
702 are equal. if so, just move the position of the
703 first point. otherwise, add a new point.
706 iterator second = _events.begin();
707 ++second; /* points at the second point */
709 if (_events.front()->value == (*second)->value) {
710 /* first segment is flat, just move start point back to zero */
711 _events.front()->when = 0;
713 /* leave non-flat segment in place, add a new leading point. */
714 _events.push_front (new ControlEvent (0, _events.front()->value));
720 /* shrinking at front */
722 first_legal_coordinate = _events.back()->when - overall_length;
723 first_legal_value = unlocked_eval (first_legal_coordinate);
724 first_legal_value = max (_min_yval, first_legal_value);
725 first_legal_value = min (_max_yval, first_legal_value);
727 /* remove all events earlier than the new "front" */
731 while (i != _events.end() && !_events.empty()) {
732 ControlList::iterator tmp;
737 if ((*i)->when > first_legal_coordinate) {
747 /* shift all remaining points left to keep their same
751 for (i = _events.begin(); i != _events.end(); ++i) {
752 (*i)->when -= first_legal_coordinate;
755 /* add a new point for the interpolated new value */
757 _events.push_front (new ControlEvent (0, first_legal_value));
760 reposition_for_rt_add (0);
765 maybe_signal_changed ();
769 ControlList::unlocked_eval (double x) const
771 pair<EventList::iterator,EventList::iterator> range;
777 const_iterator length_check_iter = _events.begin();
778 for (npoints = 0; npoints < 4; ++npoints, ++length_check_iter) {
779 if (length_check_iter == _events.end()) {
786 return _default_value;
789 return _events.front()->value;
792 if (x >= _events.back()->when) {
793 return _events.back()->value;
794 } else if (x <= _events.front()->when) {
795 return _events.front()->value;
798 lpos = _events.front()->when;
799 lval = _events.front()->value;
800 upos = _events.back()->when;
801 uval = _events.back()->value;
803 if (_interpolation == Discrete) {
807 /* linear interpolation betweeen the two points */
808 fraction = (double) (x - lpos) / (double) (upos - lpos);
809 return lval + (fraction * (uval - lval));
812 if (x >= _events.back()->when) {
813 return _events.back()->value;
814 } else if (x <= _events.front()->when) {
815 return _events.front()->value;
818 return multipoint_eval (x);
821 /*NOTREACHED*/ /* stupid gcc */
822 return _default_value;
826 ControlList::multipoint_eval (double x) const
832 /* "Stepped" lookup (no interpolation) */
833 /* FIXME: no cache. significant? */
834 if (_interpolation == Discrete) {
835 const ControlEvent cp (x, 0);
836 EventList::const_iterator i = lower_bound (_events.begin(), _events.end(), &cp, time_comparator);
838 // shouldn't have made it to multipoint_eval
839 assert(i != _events.end());
841 if (i == _events.begin() || (*i)->when == x)
844 return (*(--i))->value;
847 /* Only do the range lookup if x is in a different range than last time
848 * this was called (or if the lookup cache has been marked "dirty" (left<0) */
849 if ((_lookup_cache.left < 0) ||
850 ((_lookup_cache.left > x) ||
851 (_lookup_cache.range.first == _events.end()) ||
852 ((*_lookup_cache.range.second)->when < x))) {
854 const ControlEvent cp (x, 0);
856 _lookup_cache.range = equal_range (_events.begin(), _events.end(), &cp, time_comparator);
859 pair<const_iterator,const_iterator> range = _lookup_cache.range;
861 if (range.first == range.second) {
863 /* x does not exist within the list as a control point */
865 _lookup_cache.left = x;
867 if (range.first != _events.begin()) {
869 lpos = (*range.first)->when;
870 lval = (*range.first)->value;
872 /* we're before the first point */
873 // return _default_value;
874 return _events.front()->value;
877 if (range.second == _events.end()) {
878 /* we're after the last point */
879 return _events.back()->value;
882 upos = (*range.second)->when;
883 uval = (*range.second)->value;
885 /* linear interpolation betweeen the two points
889 fraction = (double) (x - lpos) / (double) (upos - lpos);
890 return lval + (fraction * (uval - lval));
894 /* x is a control point in the data */
895 _lookup_cache.left = -1;
896 return (*range.first)->value;
900 ControlList::build_search_cache_if_necessary(double start, double end) const
902 /* Only do the range lookup if x is in a different range than last time
903 * this was called (or if the search cache has been marked "dirty" (left<0) */
904 if (!_events.empty() && ((_search_cache.left < 0) ||
905 ((_search_cache.left > start) ||
906 (_search_cache.right < end)))) {
908 const ControlEvent start_point (start, 0);
909 const ControlEvent end_point (end, 0);
911 //cerr << "REBUILD: (" << _search_cache.left << ".." << _search_cache.right << ") := ("
912 // << start << ".." << end << ")" << endl;
914 _search_cache.range.first = lower_bound (_events.begin(), _events.end(), &start_point, time_comparator);
915 _search_cache.range.second = upper_bound (_events.begin(), _events.end(), &end_point, time_comparator);
917 _search_cache.left = start;
918 _search_cache.right = end;
922 /** Get the earliest event between \a start and \a end, using the current interpolation style.
924 * If an event is found, \a x and \a y are set to its coordinates.
926 * \param inclusive Include events with timestamp exactly equal to \a start
927 * \return true if event is found (and \a x and \a y are valid).
930 ControlList::rt_safe_earliest_event(double start, double end, double& x, double& y, bool inclusive) const
932 // FIXME: It would be nice if this was unnecessary..
933 Glib::Mutex::Lock lm(_lock, Glib::TRY_LOCK);
938 return rt_safe_earliest_event_unlocked(start, end, x, y, inclusive);
942 /** Get the earliest event between \a start and \a end, using the current interpolation style.
944 * If an event is found, \a x and \a y are set to its coordinates.
946 * \param inclusive Include events with timestamp exactly equal to \a start
947 * \return true if event is found (and \a x and \a y are valid).
950 ControlList::rt_safe_earliest_event_unlocked(double start, double end, double& x, double& y, bool inclusive) const
952 if (_interpolation == Discrete)
953 return rt_safe_earliest_event_discrete_unlocked(start, end, x, y, inclusive);
955 return rt_safe_earliest_event_linear_unlocked(start, end, x, y, inclusive);
959 /** Get the earliest event between \a start and \a end (Discrete (lack of) interpolation)
961 * If an event is found, \a x and \a y are set to its coordinates.
963 * \param inclusive Include events with timestamp exactly equal to \a start
964 * \return true if event is found (and \a x and \a y are valid).
967 ControlList::rt_safe_earliest_event_discrete_unlocked (double start, double end, double& x, double& y, bool inclusive) const
969 build_search_cache_if_necessary(start, end);
971 const pair<const_iterator,const_iterator>& range = _search_cache.range;
973 if (range.first != _events.end()) {
974 const ControlEvent* const first = *range.first;
976 const bool past_start = (inclusive ? first->when >= start : first->when > start);
978 /* Earliest points is in range, return it */
979 if (past_start && first->when < end) {
984 /* Move left of cache to this point
985 * (Optimize for immediate call this cycle within range) */
986 _search_cache.left = x;
987 ++_search_cache.range.first;
997 /* No points in range */
1003 /** Get the earliest time the line crosses an integer (Linear interpolation).
1005 * If an event is found, \a x and \a y are set to its coordinates.
1007 * \param inclusive Include events with timestamp exactly equal to \a start
1008 * \return true if event is found (and \a x and \a y are valid).
1011 ControlList::rt_safe_earliest_event_linear_unlocked (double start, double end, double& x, double& y, bool inclusive) const
1013 //cerr << "earliest_event(start: " << start << ", end: " << end
1014 //<< ", x: " << x << ", y: " << y << ", inclusive: " << inclusive << ")" << endl;
1016 const_iterator length_check_iter = _events.begin();
1017 if (_events.empty()) // 0 events
1019 else if (_events.end() == ++length_check_iter) // 1 event
1020 return rt_safe_earliest_event_discrete_unlocked(start, end, x, y, inclusive);
1022 // Hack to avoid infinitely repeating the same event
1023 build_search_cache_if_necessary(start, end);
1025 pair<const_iterator,const_iterator> range = _search_cache.range;
1027 if (range.first != _events.end()) {
1029 const ControlEvent* first = NULL;
1030 const ControlEvent* next = NULL;
1032 /* No events past start (maybe?) */
1033 if (next && next->when < start)
1036 /* Step is after first */
1037 if (range.first == _events.begin() || (*range.first)->when == start) {
1038 first = *range.first;
1039 next = *(++range.first);
1040 ++_search_cache.range.first;
1042 /* Step is before first */
1044 const_iterator prev = range.first;
1047 next = *range.first;
1050 if (inclusive && first->when == start) {
1053 /* Move left of cache to this point
1054 * (Optimize for immediate call this cycle within range) */
1055 _search_cache.left = x;
1056 //++_search_cache.range.first;
1061 if (fabs(first->value - next->value) <= 1) {
1062 if (next->when <= end && (next->when > start)) {
1065 /* Move left of cache to this point
1066 * (Optimize for immediate call this cycle within range) */
1067 _search_cache.left = x;
1068 //++_search_cache.range.first;
1069 assert(inclusive ? x >= start : x > start);
1076 const double slope = (next->value - first->value) / (double)(next->when - first->when);
1077 //cerr << "start y: " << start_y << endl;
1079 //y = first->value + (slope * fabs(start - first->when));
1082 if (first->value < next->value) // ramping up
1084 else // ramping down
1087 x = first->when + (y - first->value) / (double)slope;
1089 while ((inclusive && x < start) || (x <= start && y != next->value)) {
1091 if (first->value < next->value) // ramping up
1093 else // ramping down
1096 x = first->when + (y - first->value) / (double)slope;
1099 cerr << first->value << " @ " << first->when << " ... "
1100 << next->value << " @ " << next->when
1101 << " = " << y << " @ " << x << endl;
1103 assert( (y >= first->value && y <= next->value)
1104 || (y <= first->value && y >= next->value) );
1107 const bool past_start = (inclusive ? x >= start : x > start);
1108 if (past_start && x < end) {
1109 /* Move left of cache to this point
1110 * (Optimize for immediate call this cycle within range) */
1111 _search_cache.left = x;
1112 assert(inclusive ? x >= start : x > start);
1118 /* No points in the future, so no steps (towards them) in the future */
1124 boost::shared_ptr<ControlList>
1125 ControlList::cut (iterator start, iterator end)
1127 boost::shared_ptr<ControlList> nal = create (_parameter);
1130 Glib::Mutex::Lock lm (_lock);
1132 for (iterator x = start; x != end; ) {
1138 nal->_events.push_back (new ControlEvent (**x));
1141 reposition_for_rt_add (0);
1149 maybe_signal_changed ();
1154 boost::shared_ptr<ControlList>
1155 ControlList::cut_copy_clear (double start, double end, int op)
1157 boost::shared_ptr<ControlList> nal = create (_parameter);
1159 ControlEvent cp (start, 0.0);
1160 bool changed = false;
1163 Glib::Mutex::Lock lm (_lock);
1165 if ((s = lower_bound (_events.begin(), _events.end(), &cp, time_comparator)) == _events.end()) {
1170 e = upper_bound (_events.begin(), _events.end(), &cp, time_comparator);
1172 if (op != 2 && (*s)->when != start) {
1173 nal->_events.push_back (new ControlEvent (0, unlocked_eval (start)));
1176 for (iterator x = s; x != e; ) {
1184 /* adjust new points to be relative to start, which
1185 has been set to zero.
1189 nal->_events.push_back (new ControlEvent ((*x)->when - start, (*x)->value));
1199 if (op != 2 && nal->_events.back()->when != end - start) {
1200 nal->_events.push_back (new ControlEvent (end - start, unlocked_eval (end)));
1204 reposition_for_rt_add (0);
1210 maybe_signal_changed ();
1216 boost::shared_ptr<ControlList>
1217 ControlList::copy (iterator start, iterator end)
1219 boost::shared_ptr<ControlList> nal = create (_parameter);
1222 Glib::Mutex::Lock lm (_lock);
1224 for (iterator x = start; x != end; ) {
1230 nal->_events.push_back (new ControlEvent (**x));
1239 boost::shared_ptr<ControlList>
1240 ControlList::cut (double start, double end)
1242 return cut_copy_clear (start, end, 0);
1245 boost::shared_ptr<ControlList>
1246 ControlList::copy (double start, double end)
1248 return cut_copy_clear (start, end, 1);
1252 ControlList::clear (double start, double end)
1254 (void) cut_copy_clear (start, end, 2);
1258 ControlList::paste (ControlList& alist, double pos, float /*times*/)
1260 if (alist._events.empty()) {
1265 Glib::Mutex::Lock lm (_lock);
1269 ControlEvent cp (pos, 0.0);
1271 where = upper_bound (_events.begin(), _events.end(), &cp, time_comparator);
1273 for (iterator i = alist.begin();i != alist.end(); ++i) {
1274 _events.insert (where, new ControlEvent( (*i)->when+pos,( *i)->value));
1275 end = (*i)->when + pos;
1279 /* move all points after the insertion along the timeline by
1283 while (where != _events.end()) {
1285 if ((*where)->when <= end) {
1288 _events.erase(where);
1296 reposition_for_rt_add (0);
1300 maybe_signal_changed ();
1304 /** Move automation around according to a list of region movements */
1306 ControlList::move_ranges (const list< RangeMove<double> >& movements)
1308 typedef list< RangeMove<double> > RangeMoveList;
1311 Glib::Mutex::Lock lm (_lock);
1313 /* a copy of the events list before we started moving stuff around */
1314 EventList old_events = _events;
1316 /* clear the source and destination ranges in the new list */
1317 for (RangeMoveList::const_iterator i = movements.begin (); i != movements.end (); ++i) {
1319 erase_range_internal (i->from, i->from + i->length, _events);
1320 erase_range_internal (i->to, i->to + i->length, _events);
1324 /* copy the events into the new list */
1325 for (RangeMoveList::const_iterator i = movements.begin (); i != movements.end (); ++i) {
1326 iterator j = old_events.begin ();
1327 const double limit = i->from + i->length;
1328 const double dx = i->to - i->from;
1329 while (j != old_events.end () && (*j)->when <= limit) {
1330 if ((*j)->when >= i->from) {
1331 ControlEvent* ev = new ControlEvent (**j);
1333 _events.push_back (ev);
1340 _events.sort (event_time_less_than);
1342 _sort_pending = true;
1345 reposition_for_rt_add (0);
1349 maybe_signal_changed ();
1352 } // namespace Evoral