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;
176 ControlList::clear ()
179 Glib::Mutex::Lock lm (_lock);
184 maybe_signal_changed ();
188 ControlList::x_scale (double factor)
190 Glib::Mutex::Lock lm (_lock);
195 ControlList::extend_to (double when)
197 Glib::Mutex::Lock lm (_lock);
198 if (_events.empty() || _events.back()->when == when) {
201 double factor = when / _events.back()->when;
206 void ControlList::_x_scale (double factor)
208 for (iterator i = _events.begin(); i != _events.end(); ++i) {
209 (*i)->when = floor ((*i)->when * factor);
216 ControlList::reposition_for_rt_add (double /*when*/)
218 _rt_insertion_point = _events.end();
222 ControlList::rt_add (double when, double value)
224 //cerr << "RT: alist " << this << " add " << value << " @ " << when << endl;
227 Glib::Mutex::Lock lm (_lock);
230 ControlEvent cp (when, 0.0);
233 if ((_rt_insertion_point != _events.end()) && ((*_rt_insertion_point)->when < when) ) {
235 /* we have a previous insertion point, so we should delete
236 everything between it and the position where we are going
237 to insert this point.
240 iterator after = _rt_insertion_point;
242 if (++after != _events.end()) {
243 iterator far = after;
245 while (far != _events.end()) {
246 if ((*far)->when > when) {
254 _rt_insertion_point = where;
256 if ((*where)->when == when) {
257 (*where)->value = value;
261 where = _events.erase (after, far);
270 iterator previous = _rt_insertion_point;
273 if (_rt_insertion_point != _events.begin() && (*_rt_insertion_point)->value == value && (*previous)->value == value) {
274 (*_rt_insertion_point)->when = when;
281 where = lower_bound (_events.begin(), _events.end(), &cp, time_comparator);
283 if (where != _events.end()) {
284 if ((*where)->when == when) {
285 (*where)->value = value;
292 _rt_insertion_point = _events.insert (where, new ControlEvent (when, value));
299 maybe_signal_changed ();
303 ControlList::fast_simple_add (double when, double value)
305 /* to be used only for loading pre-sorted data from saved state */
306 _events.insert (_events.end(), new ControlEvent (when, value));
307 assert(_events.back());
311 ControlList::add (double when, double value)
313 /* this is for graphical editing */
316 Glib::Mutex::Lock lm (_lock);
317 ControlEvent cp (when, 0.0f);
319 iterator insertion_point;
321 for (insertion_point = lower_bound (_events.begin(), _events.end(), &cp, time_comparator); insertion_point != _events.end(); ++insertion_point) {
323 /* only one point allowed per time point */
325 if ((*insertion_point)->when == when) {
326 (*insertion_point)->value = value;
331 if ((*insertion_point)->when >= when) {
338 _events.insert (insertion_point, new ControlEvent (when, value));
339 reposition_for_rt_add (0);
346 maybe_signal_changed ();
350 ControlList::erase (iterator i)
353 Glib::Mutex::Lock lm (_lock);
355 reposition_for_rt_add (0);
358 maybe_signal_changed ();
362 ControlList::erase (iterator start, iterator end)
365 Glib::Mutex::Lock lm (_lock);
366 _events.erase (start, end);
367 reposition_for_rt_add (0);
370 maybe_signal_changed ();
374 ControlList::reset_range (double start, double endt)
379 Glib::Mutex::Lock lm (_lock);
380 ControlEvent cp (start, 0.0f);
384 if ((s = lower_bound (_events.begin(), _events.end(), &cp, time_comparator)) != _events.end()) {
387 e = upper_bound (_events.begin(), _events.end(), &cp, time_comparator);
389 for (iterator i = s; i != e; ++i) {
390 (*i)->value = _default_value;
400 maybe_signal_changed ();
405 ControlList::erase_range (double start, double endt)
410 Glib::Mutex::Lock lm (_lock);
411 erased = erase_range_internal (start, endt, _events);
414 reposition_for_rt_add (0);
421 maybe_signal_changed ();
426 ControlList::erase_range_internal (double start, double endt, EventList & events)
429 ControlEvent cp (start, 0.0f);
433 if ((s = lower_bound (events.begin(), events.end(), &cp, time_comparator)) != events.end()) {
435 e = upper_bound (events.begin(), events.end(), &cp, time_comparator);
444 ControlList::slide (iterator before, double distance)
447 Glib::Mutex::Lock lm (_lock);
449 if (before == _events.end()) {
453 while (before != _events.end()) {
454 (*before)->when += distance;
459 maybe_signal_changed ();
463 ControlList::modify (iterator iter, double when, double val)
465 /* note: we assume higher level logic is in place to avoid this
466 reordering the time-order of control events in the list. ie. all
467 points after *iter are later than when.
471 Glib::Mutex::Lock lm (_lock);
473 (*iter)->when = when;
474 (*iter)->value = val;
481 _events.sort (event_time_less_than);
483 _sort_pending = true;
489 maybe_signal_changed ();
492 std::pair<ControlList::iterator,ControlList::iterator>
493 ControlList::control_points_adjacent (double xval)
495 Glib::Mutex::Lock lm (_lock);
497 ControlEvent cp (xval, 0.0f);
498 std::pair<iterator,iterator> ret;
500 ret.first = _events.end();
501 ret.second = _events.end();
503 for (i = lower_bound (_events.begin(), _events.end(), &cp, time_comparator); i != _events.end(); ++i) {
505 if (ret.first == _events.end()) {
506 if ((*i)->when >= xval) {
507 if (i != _events.begin()) {
516 if ((*i)->when > xval) {
526 ControlList::set_max_xval (double x)
532 ControlList::freeze ()
547 Glib::Mutex::Lock lm (_lock);
550 _events.sort (event_time_less_than);
551 _sort_pending = false;
557 ControlList::mark_dirty () const
559 _lookup_cache.left = -1;
560 _search_cache.left = -1;
562 _curve->mark_dirty();
566 ControlList::truncate_end (double last_coordinate)
569 Glib::Mutex::Lock lm (_lock);
570 ControlEvent cp (last_coordinate, 0);
571 ControlList::reverse_iterator i;
574 if (_events.empty()) {
578 if (last_coordinate == _events.back()->when) {
582 if (last_coordinate > _events.back()->when) {
587 iterator foo = _events.begin();
590 if (foo == _events.end()) {
592 } else if (++foo == _events.end()) {
599 /* less than 2 points: add a new point */
600 _events.push_back (new ControlEvent (last_coordinate, _events.back()->value));
603 /* more than 2 points: check to see if the last 2 values
604 are equal. if so, just move the position of the
605 last point. otherwise, add a new point.
608 iterator penultimate = _events.end();
609 --penultimate; /* points at last point */
610 --penultimate; /* points at the penultimate point */
612 if (_events.back()->value == (*penultimate)->value) {
613 _events.back()->when = last_coordinate;
615 _events.push_back (new ControlEvent (last_coordinate, _events.back()->value));
623 last_val = unlocked_eval (last_coordinate);
624 last_val = max ((double) _min_yval, last_val);
625 last_val = min ((double) _max_yval, last_val);
627 i = _events.rbegin();
629 /* make i point to the last control point */
633 /* now go backwards, removing control points that are
634 beyond the new last coordinate.
637 // FIXME: SLOW! (size() == O(n))
639 uint32_t sz = _events.size();
641 while (i != _events.rend() && sz > 2) {
642 ControlList::reverse_iterator tmp;
647 if ((*i)->when < last_coordinate) {
651 _events.erase (i.base());
657 _events.back()->when = last_coordinate;
658 _events.back()->value = last_val;
661 reposition_for_rt_add (0);
665 maybe_signal_changed ();
669 ControlList::truncate_start (double overall_length)
672 Glib::Mutex::Lock lm (_lock);
674 double first_legal_value;
675 double first_legal_coordinate;
677 assert(!_events.empty());
679 if (overall_length == _events.back()->when) {
680 /* no change in overall length */
684 if (overall_length > _events.back()->when) {
686 /* growing at front: duplicate first point. shift all others */
688 double shift = overall_length - _events.back()->when;
691 for (np = 0, i = _events.begin(); i != _events.end(); ++i, ++np) {
697 /* less than 2 points: add a new point */
698 _events.push_front (new ControlEvent (0, _events.front()->value));
702 /* more than 2 points: check to see if the first 2 values
703 are equal. if so, just move the position of the
704 first point. otherwise, add a new point.
707 iterator second = _events.begin();
708 ++second; /* points at the second point */
710 if (_events.front()->value == (*second)->value) {
711 /* first segment is flat, just move start point back to zero */
712 _events.front()->when = 0;
714 /* leave non-flat segment in place, add a new leading point. */
715 _events.push_front (new ControlEvent (0, _events.front()->value));
721 /* shrinking at front */
723 first_legal_coordinate = _events.back()->when - overall_length;
724 first_legal_value = unlocked_eval (first_legal_coordinate);
725 first_legal_value = max (_min_yval, first_legal_value);
726 first_legal_value = min (_max_yval, first_legal_value);
728 /* remove all events earlier than the new "front" */
732 while (i != _events.end() && !_events.empty()) {
733 ControlList::iterator tmp;
738 if ((*i)->when > first_legal_coordinate) {
748 /* shift all remaining points left to keep their same
752 for (i = _events.begin(); i != _events.end(); ++i) {
753 (*i)->when -= first_legal_coordinate;
756 /* add a new point for the interpolated new value */
758 _events.push_front (new ControlEvent (0, first_legal_value));
761 reposition_for_rt_add (0);
766 maybe_signal_changed ();
770 ControlList::unlocked_eval (double x) const
772 pair<EventList::iterator,EventList::iterator> range;
778 const_iterator length_check_iter = _events.begin();
779 for (npoints = 0; npoints < 4; ++npoints, ++length_check_iter) {
780 if (length_check_iter == _events.end()) {
787 return _default_value;
790 return _events.front()->value;
793 if (x >= _events.back()->when) {
794 return _events.back()->value;
795 } else if (x <= _events.front()->when) {
796 return _events.front()->value;
799 lpos = _events.front()->when;
800 lval = _events.front()->value;
801 upos = _events.back()->when;
802 uval = _events.back()->value;
804 if (_interpolation == Discrete) {
808 /* linear interpolation betweeen the two points */
809 fraction = (double) (x - lpos) / (double) (upos - lpos);
810 return lval + (fraction * (uval - lval));
813 if (x >= _events.back()->when) {
814 return _events.back()->value;
815 } else if (x <= _events.front()->when) {
816 return _events.front()->value;
819 return multipoint_eval (x);
822 /*NOTREACHED*/ /* stupid gcc */
823 return _default_value;
827 ControlList::multipoint_eval (double x) const
833 /* "Stepped" lookup (no interpolation) */
834 /* FIXME: no cache. significant? */
835 if (_interpolation == Discrete) {
836 const ControlEvent cp (x, 0);
837 EventList::const_iterator i = lower_bound (_events.begin(), _events.end(), &cp, time_comparator);
839 // shouldn't have made it to multipoint_eval
840 assert(i != _events.end());
842 if (i == _events.begin() || (*i)->when == x)
845 return (*(--i))->value;
848 /* Only do the range lookup if x is in a different range than last time
849 * this was called (or if the lookup cache has been marked "dirty" (left<0) */
850 if ((_lookup_cache.left < 0) ||
851 ((_lookup_cache.left > x) ||
852 (_lookup_cache.range.first == _events.end()) ||
853 ((*_lookup_cache.range.second)->when < x))) {
855 const ControlEvent cp (x, 0);
857 _lookup_cache.range = equal_range (_events.begin(), _events.end(), &cp, time_comparator);
860 pair<const_iterator,const_iterator> range = _lookup_cache.range;
862 if (range.first == range.second) {
864 /* x does not exist within the list as a control point */
866 _lookup_cache.left = x;
868 if (range.first != _events.begin()) {
870 lpos = (*range.first)->when;
871 lval = (*range.first)->value;
873 /* we're before the first point */
874 // return _default_value;
875 return _events.front()->value;
878 if (range.second == _events.end()) {
879 /* we're after the last point */
880 return _events.back()->value;
883 upos = (*range.second)->when;
884 uval = (*range.second)->value;
886 /* linear interpolation betweeen the two points
890 fraction = (double) (x - lpos) / (double) (upos - lpos);
891 return lval + (fraction * (uval - lval));
895 /* x is a control point in the data */
896 _lookup_cache.left = -1;
897 return (*range.first)->value;
901 ControlList::build_search_cache_if_necessary(double start, double end) const
903 /* Only do the range lookup if x is in a different range than last time
904 * this was called (or if the search cache has been marked "dirty" (left<0) */
905 if (!_events.empty() && ((_search_cache.left < 0) ||
906 ((_search_cache.left > start) ||
907 (_search_cache.right < end)))) {
909 const ControlEvent start_point (start, 0);
910 const ControlEvent end_point (end, 0);
912 //cerr << "REBUILD: (" << _search_cache.left << ".." << _search_cache.right << ") := ("
913 // << start << ".." << end << ")" << endl;
915 _search_cache.range.first = lower_bound (_events.begin(), _events.end(), &start_point, time_comparator);
916 _search_cache.range.second = upper_bound (_events.begin(), _events.end(), &end_point, time_comparator);
918 _search_cache.left = start;
919 _search_cache.right = end;
923 /** Get the earliest event between \a start and \a end, using the current interpolation style.
925 * If an event is found, \a x and \a y are set to its coordinates.
927 * \param inclusive Include events with timestamp exactly equal to \a start
928 * \return true if event is found (and \a x and \a y are valid).
931 ControlList::rt_safe_earliest_event(double start, double end, double& x, double& y, bool inclusive) const
933 // FIXME: It would be nice if this was unnecessary..
934 Glib::Mutex::Lock lm(_lock, Glib::TRY_LOCK);
939 return rt_safe_earliest_event_unlocked(start, end, x, y, inclusive);
943 /** Get the earliest event between \a start and \a end, using the current interpolation style.
945 * If an event is found, \a x and \a y are set to its coordinates.
947 * \param inclusive Include events with timestamp exactly equal to \a start
948 * \return true if event is found (and \a x and \a y are valid).
951 ControlList::rt_safe_earliest_event_unlocked(double start, double end, double& x, double& y, bool inclusive) const
953 if (_interpolation == Discrete)
954 return rt_safe_earliest_event_discrete_unlocked(start, end, x, y, inclusive);
956 return rt_safe_earliest_event_linear_unlocked(start, end, x, y, inclusive);
960 /** Get the earliest event between \a start and \a end (Discrete (lack of) interpolation)
962 * If an event is found, \a x and \a y are set to its coordinates.
964 * \param inclusive Include events with timestamp exactly equal to \a start
965 * \return true if event is found (and \a x and \a y are valid).
968 ControlList::rt_safe_earliest_event_discrete_unlocked (double start, double end, double& x, double& y, bool inclusive) const
970 build_search_cache_if_necessary(start, end);
972 const pair<const_iterator,const_iterator>& range = _search_cache.range;
974 if (range.first != _events.end()) {
975 const ControlEvent* const first = *range.first;
977 const bool past_start = (inclusive ? first->when >= start : first->when > start);
979 /* Earliest points is in range, return it */
980 if (past_start && first->when < end) {
985 /* Move left of cache to this point
986 * (Optimize for immediate call this cycle within range) */
987 _search_cache.left = x;
988 ++_search_cache.range.first;
998 /* No points in range */
1004 /** Get the earliest time the line crosses an integer (Linear interpolation).
1006 * If an event is found, \a x and \a y are set to its coordinates.
1008 * \param inclusive Include events with timestamp exactly equal to \a start
1009 * \return true if event is found (and \a x and \a y are valid).
1012 ControlList::rt_safe_earliest_event_linear_unlocked (double start, double end, double& x, double& y, bool inclusive) const
1014 //cerr << "earliest_event(start: " << start << ", end: " << end
1015 //<< ", x: " << x << ", y: " << y << ", inclusive: " << inclusive << ")" << endl;
1017 const_iterator length_check_iter = _events.begin();
1018 if (_events.empty()) // 0 events
1020 else if (_events.end() == ++length_check_iter) // 1 event
1021 return rt_safe_earliest_event_discrete_unlocked(start, end, x, y, inclusive);
1023 // Hack to avoid infinitely repeating the same event
1024 build_search_cache_if_necessary(start, end);
1026 pair<const_iterator,const_iterator> range = _search_cache.range;
1028 if (range.first != _events.end()) {
1030 const ControlEvent* first = NULL;
1031 const ControlEvent* next = NULL;
1033 /* No events past start (maybe?) */
1034 if (next && next->when < start)
1037 /* Step is after first */
1038 if (range.first == _events.begin() || (*range.first)->when == start) {
1039 first = *range.first;
1040 next = *(++range.first);
1041 ++_search_cache.range.first;
1043 /* Step is before first */
1045 const_iterator prev = range.first;
1048 next = *range.first;
1051 if (inclusive && first->when == start) {
1054 /* Move left of cache to this point
1055 * (Optimize for immediate call this cycle within range) */
1056 _search_cache.left = x;
1057 //++_search_cache.range.first;
1062 if (fabs(first->value - next->value) <= 1) {
1063 if (next->when <= end && (next->when > start)) {
1066 /* Move left of cache to this point
1067 * (Optimize for immediate call this cycle within range) */
1068 _search_cache.left = x;
1069 //++_search_cache.range.first;
1070 assert(inclusive ? x >= start : x > start);
1077 const double slope = (next->value - first->value) / (double)(next->when - first->when);
1078 //cerr << "start y: " << start_y << endl;
1080 //y = first->value + (slope * fabs(start - first->when));
1083 if (first->value < next->value) // ramping up
1085 else // ramping down
1088 x = first->when + (y - first->value) / (double)slope;
1090 while ((inclusive && x < start) || (x <= start && y != next->value)) {
1092 if (first->value < next->value) // ramping up
1094 else // ramping down
1097 x = first->when + (y - first->value) / (double)slope;
1100 /*cerr << first->value << " @ " << first->when << " ... "
1101 << next->value << " @ " << next->when
1102 << " = " << y << " @ " << x << endl;*/
1104 assert( (y >= first->value && y <= next->value)
1105 || (y <= first->value && y >= next->value) );
1108 const bool past_start = (inclusive ? x >= start : x > start);
1109 if (past_start && x < end) {
1110 /* Move left of cache to this point
1111 * (Optimize for immediate call this cycle within range) */
1112 _search_cache.left = x;
1113 assert(inclusive ? x >= start : x > start);
1119 /* No points in the future, so no steps (towards them) in the future */
1125 boost::shared_ptr<ControlList>
1126 ControlList::cut (iterator start, iterator end)
1128 boost::shared_ptr<ControlList> nal = create (_parameter);
1131 Glib::Mutex::Lock lm (_lock);
1133 for (iterator x = start; x != end; ) {
1139 nal->_events.push_back (new ControlEvent (**x));
1142 reposition_for_rt_add (0);
1150 maybe_signal_changed ();
1155 /** @param op 0 = cut, 1 = copy, 2 = clear */
1156 boost::shared_ptr<ControlList>
1157 ControlList::cut_copy_clear (double start, double end, int op)
1159 boost::shared_ptr<ControlList> nal = create (_parameter);
1162 bool changed = false;
1165 Glib::Mutex::Lock lm (_lock);
1167 /* find the first event in our list that is at or before `start' in time */
1168 ControlEvent cp (start, 0.0);
1169 if ((s = lower_bound (_events.begin(), _events.end(), &cp, time_comparator)) == _events.end()) {
1173 /* and the last that is at or after `end' */
1175 e = upper_bound (_events.begin(), _events.end(), &cp, time_comparator);
1177 if (op != 2 && (*s)->when != start) {
1178 nal->_events.push_back (new ControlEvent (0, unlocked_eval (start)));
1181 for (iterator x = s; x != e; ) {
1187 /* adjust new points to be relative to start, which
1188 has been set to zero.
1192 nal->_events.push_back (new ControlEvent ((*x)->when - start, (*x)->value));
1202 if (op != 2 && nal->_events.back()->when != end - start) {
1203 nal->_events.push_back (new ControlEvent (end - start, unlocked_eval (end)));
1207 reposition_for_rt_add (0);
1213 maybe_signal_changed ();
1219 boost::shared_ptr<ControlList>
1220 ControlList::copy (iterator start, iterator end)
1222 boost::shared_ptr<ControlList> nal = create (_parameter);
1225 Glib::Mutex::Lock lm (_lock);
1227 for (iterator x = start; x != end; ) {
1233 nal->_events.push_back (new ControlEvent (**x));
1242 boost::shared_ptr<ControlList>
1243 ControlList::cut (double start, double end)
1245 return cut_copy_clear (start, end, 0);
1248 boost::shared_ptr<ControlList>
1249 ControlList::copy (double start, double end)
1251 return cut_copy_clear (start, end, 1);
1255 ControlList::clear (double start, double end)
1257 (void) cut_copy_clear (start, end, 2);
1261 ControlList::paste (ControlList& alist, double pos, float /*times*/)
1263 if (alist._events.empty()) {
1268 Glib::Mutex::Lock lm (_lock);
1272 ControlEvent cp (pos, 0.0);
1274 where = upper_bound (_events.begin(), _events.end(), &cp, time_comparator);
1276 for (iterator i = alist.begin();i != alist.end(); ++i) {
1277 _events.insert (where, new ControlEvent( (*i)->when+pos,( *i)->value));
1278 end = (*i)->when + pos;
1282 /* move all points after the insertion along the timeline by
1286 while (where != _events.end()) {
1288 if ((*where)->when <= end) {
1291 _events.erase(where);
1299 reposition_for_rt_add (0);
1303 maybe_signal_changed ();
1307 /** Move automation around according to a list of region movements */
1309 ControlList::move_ranges (const list< RangeMove<double> >& movements)
1311 typedef list< RangeMove<double> > RangeMoveList;
1314 Glib::Mutex::Lock lm (_lock);
1316 /* a copy of the events list before we started moving stuff around */
1317 EventList old_events = _events;
1319 /* clear the source and destination ranges in the new list */
1320 for (RangeMoveList::const_iterator i = movements.begin (); i != movements.end (); ++i) {
1322 erase_range_internal (i->from, i->from + i->length, _events);
1323 erase_range_internal (i->to, i->to + i->length, _events);
1327 /* copy the events into the new list */
1328 for (RangeMoveList::const_iterator i = movements.begin (); i != movements.end (); ++i) {
1329 iterator j = old_events.begin ();
1330 const double limit = i->from + i->length;
1331 const double dx = i->to - i->from;
1332 while (j != old_events.end () && (*j)->when <= limit) {
1333 if ((*j)->when >= i->from) {
1334 ControlEvent* ev = new ControlEvent (**j);
1336 _events.push_back (ev);
1343 _events.sort (event_time_less_than);
1345 _sort_pending = true;
1348 reposition_for_rt_add (0);
1352 maybe_signal_changed ();
1355 } // namespace Evoral