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"
30 inline bool event_time_less_than (ControlEvent* a, ControlEvent* b)
32 return a->when < b->when;
36 ControlList::ControlList (const Parameter& id)
38 , _interpolation(Linear)
39 , _curve(new Curve(*this))
42 _changed_when_thawed = false;
45 _max_xval = 0; // means "no limit"
46 _rt_insertion_point = _events.end();
47 _lookup_cache.left = -1;
48 _lookup_cache.range.first = _events.end();
49 _search_cache.left = -1;
50 _search_cache.range.first = _events.end();
51 _sort_pending = false;
54 ControlList::ControlList (const ControlList& other)
55 : _parameter(other._parameter)
56 , _interpolation(Linear)
57 , _curve(new Curve(*this))
60 _changed_when_thawed = false;
61 _min_yval = other._min_yval;
62 _max_yval = other._max_yval;
63 _max_xval = other._max_xval;
64 _default_value = other._default_value;
65 _rt_insertion_point = _events.end();
66 _lookup_cache.range.first = _events.end();
67 _search_cache.range.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)
80 , _curve(new Curve(*this))
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 _rt_insertion_point = _events.end();
89 _lookup_cache.range.first = _events.end();
90 _search_cache.range.first = _events.end();
91 _sort_pending = false;
93 /* now grab the relevant points, and shift them back if necessary */
95 boost::shared_ptr<ControlList> section = const_cast<ControlList*>(&other)->copy (start, end);
97 if (!section->empty()) {
98 for (iterator i = section->begin(); i != section->end(); ++i) {
99 _events.push_back (new ControlEvent ((*i)->when, (*i)->value));
106 ControlList::~ControlList()
108 for (EventList::iterator x = _events.begin(); x != _events.end(); ++x) {
113 boost::shared_ptr<ControlList>
114 ControlList::create(Parameter id)
116 return boost::shared_ptr<ControlList>(new ControlList(id));
120 ControlList::operator== (const ControlList& other)
122 return _events == other._events;
126 ControlList::operator= (const ControlList& other)
128 if (this != &other) {
132 for (const_iterator i = other._events.begin(); i != other._events.end(); ++i) {
133 _events.push_back (new ControlEvent (**i));
136 _min_yval = other._min_yval;
137 _max_yval = other._max_yval;
138 _max_xval = other._max_xval;
139 _default_value = other._default_value;
142 maybe_signal_changed ();
149 ControlList::maybe_signal_changed ()
154 _changed_when_thawed = true;
158 ControlList::clear ()
161 Glib::Mutex::Lock lm (_lock);
166 maybe_signal_changed ();
170 ControlList::x_scale (double factor)
172 Glib::Mutex::Lock lm (_lock);
177 ControlList::extend_to (double when)
179 Glib::Mutex::Lock lm (_lock);
180 if (_events.empty() || _events.back()->when == when) {
183 double factor = when / _events.back()->when;
188 void ControlList::_x_scale (double factor)
190 for (iterator i = _events.begin(); i != _events.end(); ++i) {
191 (*i)->when = floor ((*i)->when * factor);
198 ControlList::reposition_for_rt_add (double when)
200 _rt_insertion_point = _events.end();
204 ControlList::rt_add (double when, double value)
206 //cerr << "RT: alist " << this << " add " << value << " @ " << when << endl;
209 Glib::Mutex::Lock lm (_lock);
212 ControlEvent cp (when, 0.0);
215 if ((_rt_insertion_point != _events.end()) && ((*_rt_insertion_point)->when < when) ) {
217 /* we have a previous insertion point, so we should delete
218 everything between it and the position where we are going
219 to insert this point.
222 iterator after = _rt_insertion_point;
224 if (++after != _events.end()) {
225 iterator far = after;
227 while (far != _events.end()) {
228 if ((*far)->when > when) {
236 _rt_insertion_point = where;
238 if ((*where)->when == when) {
239 (*where)->value = value;
243 where = _events.erase (after, far);
252 iterator previous = _rt_insertion_point;
255 if (_rt_insertion_point != _events.begin() && (*_rt_insertion_point)->value == value && (*previous)->value == value) {
256 (*_rt_insertion_point)->when = when;
263 where = lower_bound (_events.begin(), _events.end(), &cp, time_comparator);
265 if (where != _events.end()) {
266 if ((*where)->when == when) {
267 (*where)->value = value;
274 _rt_insertion_point = _events.insert (where, new ControlEvent (when, value));
281 maybe_signal_changed ();
285 ControlList::fast_simple_add (double when, double value)
287 /* to be used only for loading pre-sorted data from saved state */
288 _events.insert (_events.end(), new ControlEvent (when, value));
289 assert(_events.back());
293 ControlList::add (double when, double value)
295 /* this is for graphical editing */
298 Glib::Mutex::Lock lm (_lock);
299 ControlEvent cp (when, 0.0f);
301 iterator insertion_point;
303 for (insertion_point = lower_bound (_events.begin(), _events.end(), &cp, time_comparator); insertion_point != _events.end(); ++insertion_point) {
305 /* only one point allowed per time point */
307 if ((*insertion_point)->when == when) {
308 (*insertion_point)->value = value;
313 if ((*insertion_point)->when >= when) {
320 _events.insert (insertion_point, new ControlEvent (when, value));
321 reposition_for_rt_add (0);
328 maybe_signal_changed ();
332 ControlList::erase (iterator i)
335 Glib::Mutex::Lock lm (_lock);
337 reposition_for_rt_add (0);
340 maybe_signal_changed ();
344 ControlList::erase (iterator start, iterator end)
347 Glib::Mutex::Lock lm (_lock);
348 _events.erase (start, end);
349 reposition_for_rt_add (0);
352 maybe_signal_changed ();
356 ControlList::reset_range (double start, double endt)
361 Glib::Mutex::Lock lm (_lock);
362 ControlEvent cp (start, 0.0f);
366 if ((s = lower_bound (_events.begin(), _events.end(), &cp, time_comparator)) != _events.end()) {
369 e = upper_bound (_events.begin(), _events.end(), &cp, time_comparator);
371 for (iterator i = s; i != e; ++i) {
372 (*i)->value = _default_value;
382 maybe_signal_changed ();
387 ControlList::erase_range (double start, double endt)
392 Glib::Mutex::Lock lm (_lock);
393 erased = erase_range_internal (start, endt, _events);
396 reposition_for_rt_add (0);
403 maybe_signal_changed ();
408 ControlList::erase_range_internal (double start, double endt, EventList & events)
411 ControlEvent cp (start, 0.0f);
415 if ((s = lower_bound (events.begin(), events.end(), &cp, time_comparator)) != events.end()) {
417 e = upper_bound (events.begin(), events.end(), &cp, time_comparator);
426 ControlList::slide (iterator before, double distance)
429 Glib::Mutex::Lock lm (_lock);
431 if (before == _events.end()) {
435 while (before != _events.end()) {
436 (*before)->when += distance;
441 maybe_signal_changed ();
445 ControlList::modify (iterator iter, double when, double val)
447 /* note: we assume higher level logic is in place to avoid this
448 reordering the time-order of control events in the list. ie. all
449 points after *iter are later than when.
453 Glib::Mutex::Lock lm (_lock);
455 (*iter)->when = when;
456 (*iter)->value = val;
463 _events.sort (event_time_less_than);
465 _sort_pending = true;
471 maybe_signal_changed ();
474 std::pair<ControlList::iterator,ControlList::iterator>
475 ControlList::control_points_adjacent (double xval)
477 Glib::Mutex::Lock lm (_lock);
479 ControlEvent cp (xval, 0.0f);
480 std::pair<iterator,iterator> ret;
482 ret.first = _events.end();
483 ret.second = _events.end();
485 for (i = lower_bound (_events.begin(), _events.end(), &cp, time_comparator); i != _events.end(); ++i) {
487 if (ret.first == _events.end()) {
488 if ((*i)->when >= xval) {
489 if (i != _events.begin()) {
498 if ((*i)->when > xval) {
508 ControlList::set_max_xval (double x)
514 ControlList::freeze ()
529 Glib::Mutex::Lock lm (_lock);
532 _events.sort (event_time_less_than);
533 _sort_pending = false;
539 ControlList::mark_dirty () const
541 _lookup_cache.left = -1;
542 _search_cache.left = -1;
544 _curve->mark_dirty();
548 ControlList::truncate_end (double last_coordinate)
551 Glib::Mutex::Lock lm (_lock);
552 ControlEvent cp (last_coordinate, 0);
553 ControlList::reverse_iterator i;
556 if (_events.empty()) {
560 if (last_coordinate == _events.back()->when) {
564 if (last_coordinate > _events.back()->when) {
569 iterator foo = _events.begin();
572 if (foo == _events.end()) {
574 } else if (++foo == _events.end()) {
581 /* less than 2 points: add a new point */
582 _events.push_back (new ControlEvent (last_coordinate, _events.back()->value));
585 /* more than 2 points: check to see if the last 2 values
586 are equal. if so, just move the position of the
587 last point. otherwise, add a new point.
590 iterator penultimate = _events.end();
591 --penultimate; /* points at last point */
592 --penultimate; /* points at the penultimate point */
594 if (_events.back()->value == (*penultimate)->value) {
595 _events.back()->when = last_coordinate;
597 _events.push_back (new ControlEvent (last_coordinate, _events.back()->value));
605 last_val = unlocked_eval (last_coordinate);
606 last_val = max ((double) _min_yval, last_val);
607 last_val = min ((double) _max_yval, last_val);
609 i = _events.rbegin();
611 /* make i point to the last control point */
615 /* now go backwards, removing control points that are
616 beyond the new last coordinate.
619 // FIXME: SLOW! (size() == O(n))
621 uint32_t sz = _events.size();
623 while (i != _events.rend() && sz > 2) {
624 ControlList::reverse_iterator tmp;
629 if ((*i)->when < last_coordinate) {
633 _events.erase (i.base());
639 _events.back()->when = last_coordinate;
640 _events.back()->value = last_val;
643 reposition_for_rt_add (0);
647 maybe_signal_changed ();
651 ControlList::truncate_start (double overall_length)
654 Glib::Mutex::Lock lm (_lock);
656 double first_legal_value;
657 double first_legal_coordinate;
659 assert(!_events.empty());
661 if (overall_length == _events.back()->when) {
662 /* no change in overall length */
666 if (overall_length > _events.back()->when) {
668 /* growing at front: duplicate first point. shift all others */
670 double shift = overall_length - _events.back()->when;
673 for (np = 0, i = _events.begin(); i != _events.end(); ++i, ++np) {
679 /* less than 2 points: add a new point */
680 _events.push_front (new ControlEvent (0, _events.front()->value));
684 /* more than 2 points: check to see if the first 2 values
685 are equal. if so, just move the position of the
686 first point. otherwise, add a new point.
689 iterator second = _events.begin();
690 ++second; /* points at the second point */
692 if (_events.front()->value == (*second)->value) {
693 /* first segment is flat, just move start point back to zero */
694 _events.front()->when = 0;
696 /* leave non-flat segment in place, add a new leading point. */
697 _events.push_front (new ControlEvent (0, _events.front()->value));
703 /* shrinking at front */
705 first_legal_coordinate = _events.back()->when - overall_length;
706 first_legal_value = unlocked_eval (first_legal_coordinate);
707 first_legal_value = max (_min_yval, first_legal_value);
708 first_legal_value = min (_max_yval, first_legal_value);
710 /* remove all events earlier than the new "front" */
714 while (i != _events.end() && !_events.empty()) {
715 ControlList::iterator tmp;
720 if ((*i)->when > first_legal_coordinate) {
730 /* shift all remaining points left to keep their same
734 for (i = _events.begin(); i != _events.end(); ++i) {
735 (*i)->when -= first_legal_coordinate;
738 /* add a new point for the interpolated new value */
740 _events.push_front (new ControlEvent (0, first_legal_value));
743 reposition_for_rt_add (0);
748 maybe_signal_changed ();
752 ControlList::unlocked_eval (double x) const
754 pair<EventList::iterator,EventList::iterator> range;
760 const_iterator length_check_iter = _events.begin();
761 for (npoints = 0; npoints < 4; ++npoints, ++length_check_iter)
762 if (length_check_iter == _events.end())
767 return _default_value;
770 if (x >= _events.front()->when) {
771 return _events.front()->value;
773 // hansfbaier: v--------- Why commented ???
774 // return _default_value;
775 return _events.front()->value;
779 if (x >= _events.back()->when) {
780 return _events.back()->value;
781 } else if (x == _events.front()->when) {
782 return _events.front()->value;
783 } else if (x < _events.front()->when) {
784 // hansfbaier: v--------- Why commented ???
785 // return _default_value;
786 return _events.front()->value;
789 lpos = _events.front()->when;
790 lval = _events.front()->value;
791 upos = _events.back()->when;
792 uval = _events.back()->value;
794 if (_interpolation == Discrete) {
798 /* linear interpolation betweeen the two points
801 fraction = (double) (x - lpos) / (double) (upos - lpos);
802 return lval + (fraction * (uval - lval));
806 if (x >= _events.back()->when) {
807 return _events.back()->value;
808 } else if (x == _events.front()->when) {
809 return _events.front()->value;
810 } else if (x < _events.front()->when) {
811 // hansfbaier: v--------- Why commented ???
812 // return _default_value;
813 return _events.front()->value;
816 return multipoint_eval (x);
820 /*NOTREACHED*/ /* stupid gcc */
825 ControlList::multipoint_eval (double x) const
831 /* "Stepped" lookup (no interpolation) */
832 /* FIXME: no cache. significant? */
833 if (_interpolation == Discrete) {
834 const ControlEvent cp (x, 0);
835 EventList::const_iterator i = lower_bound (_events.begin(), _events.end(), &cp, time_comparator);
837 // shouldn't have made it to multipoint_eval
838 assert(i != _events.end());
840 if (i == _events.begin() || (*i)->when == x)
843 return (*(--i))->value;
846 /* Only do the range lookup if x is in a different range than last time
847 * this was called (or if the lookup cache has been marked "dirty" (left<0) */
848 if ((_lookup_cache.left < 0) ||
849 ((_lookup_cache.left > x) ||
850 (_lookup_cache.range.first == _events.end()) ||
851 ((*_lookup_cache.range.second)->when < x))) {
853 const ControlEvent cp (x, 0);
855 _lookup_cache.range = equal_range (_events.begin(), _events.end(), &cp, time_comparator);
858 pair<const_iterator,const_iterator> range = _lookup_cache.range;
860 if (range.first == range.second) {
862 /* x does not exist within the list as a control point */
864 _lookup_cache.left = x;
866 if (range.first != _events.begin()) {
868 lpos = (*range.first)->when;
869 lval = (*range.first)->value;
871 /* we're before the first point */
872 // return _default_value;
873 return _events.front()->value;
876 if (range.second == _events.end()) {
877 /* we're after the last point */
878 return _events.back()->value;
881 upos = (*range.second)->when;
882 uval = (*range.second)->value;
884 /* linear interpolation betweeen the two points
888 fraction = (double) (x - lpos) / (double) (upos - lpos);
889 return lval + (fraction * (uval - lval));
893 /* x is a control point in the data */
894 _lookup_cache.left = -1;
895 return (*range.first)->value;
899 ControlList::build_search_cache_if_necessary(double start, double end) const
901 /* Only do the range lookup if x is in a different range than last time
902 * this was called (or if the search cache has been marked "dirty" (left<0) */
903 if (!_events.empty() && ((_search_cache.left < 0) ||
904 ((_search_cache.left > start) ||
905 (_search_cache.right < end)))) {
907 const ControlEvent start_point (start, 0);
908 const ControlEvent end_point (end, 0);
910 //cerr << "REBUILD: (" << _search_cache.left << ".." << _search_cache.right << ") := ("
911 // << start << ".." << end << ")" << endl;
913 _search_cache.range.first = lower_bound (_events.begin(), _events.end(), &start_point, time_comparator);
914 _search_cache.range.second = upper_bound (_events.begin(), _events.end(), &end_point, time_comparator);
916 _search_cache.left = start;
917 _search_cache.right = end;
921 /** Get the earliest event between \a start and \a end, using the current interpolation style.
923 * If an event is found, \a x and \a y are set to its coordinates.
925 * \param inclusive Include events with timestamp exactly equal to \a start
926 * \return true if event is found (and \a x and \a y are valid).
929 ControlList::rt_safe_earliest_event(double start, double end, double& x, double& y, bool inclusive) const
931 // FIXME: It would be nice if this was unnecessary..
932 Glib::Mutex::Lock lm(_lock, Glib::TRY_LOCK);
937 return rt_safe_earliest_event_unlocked(start, end, x, y, inclusive);
941 /** Get the earliest event between \a start and \a end, using the current interpolation style.
943 * If an event is found, \a x and \a y are set to its coordinates.
945 * \param inclusive Include events with timestamp exactly equal to \a start
946 * \return true if event is found (and \a x and \a y are valid).
949 ControlList::rt_safe_earliest_event_unlocked(double start, double end, double& x, double& y, bool inclusive) const
951 if (_interpolation == Discrete)
952 return rt_safe_earliest_event_discrete_unlocked(start, end, x, y, inclusive);
954 return rt_safe_earliest_event_linear_unlocked(start, end, x, y, inclusive);
958 /** Get the earliest event between \a start and \a end (Discrete (lack of) interpolation)
960 * If an event is found, \a x and \a y are set to its coordinates.
962 * \param inclusive Include events with timestamp exactly equal to \a start
963 * \return true if event is found (and \a x and \a y are valid).
966 ControlList::rt_safe_earliest_event_discrete_unlocked (double start, double end, double& x, double& y, bool inclusive) const
968 build_search_cache_if_necessary(start, end);
970 const pair<const_iterator,const_iterator>& range = _search_cache.range;
972 if (range.first != _events.end()) {
973 const ControlEvent* const first = *range.first;
975 const bool past_start = (inclusive ? first->when >= start : first->when > start);
977 /* Earliest points is in range, return it */
978 if (past_start && first->when < end) {
983 /* Move left of cache to this point
984 * (Optimize for immediate call this cycle within range) */
985 _search_cache.left = x;
986 ++_search_cache.range.first;
996 /* No points in range */
1002 /** Get the earliest time the line crosses an integer (Linear interpolation).
1004 * If an event is found, \a x and \a y are set to its coordinates.
1006 * \param inclusive Include events with timestamp exactly equal to \a start
1007 * \return true if event is found (and \a x and \a y are valid).
1010 ControlList::rt_safe_earliest_event_linear_unlocked (double start, double end, double& x, double& y, bool inclusive) const
1012 cerr << "earliest_event(start: " << start << ", end: " << end << ", x: " << x << ", y: " << y << ", inclusive: " << inclusive << ")" << endl;
1014 const_iterator length_check_iter = _events.begin();
1015 if (_events.empty()) // 0 events
1017 else if (_events.end() == ++length_check_iter) // 1 event
1018 return rt_safe_earliest_event_discrete_unlocked(start, end, x, y, inclusive);
1020 // Hack to avoid infinitely repeating the same event
1021 build_search_cache_if_necessary(start, end);
1023 pair<const_iterator,const_iterator> range = _search_cache.range;
1025 if (range.first != _events.end()) {
1027 const ControlEvent* first = NULL;
1028 const ControlEvent* next = NULL;
1030 /* No events past start (maybe?) */
1031 if (next && next->when < start)
1034 /* Step is after first */
1035 if (range.first == _events.begin() || (*range.first)->when == start) {
1036 first = *range.first;
1037 next = *(++range.first);
1038 ++_search_cache.range.first;
1040 /* Step is before first */
1042 const_iterator prev = range.first;
1045 next = *range.first;
1048 if (inclusive && first->when == start) {
1051 /* Move left of cache to this point
1052 * (Optimize for immediate call this cycle within range) */
1053 _search_cache.left = x;
1054 //++_search_cache.range.first;
1059 if (fabs(first->value - next->value) <= 1) {
1060 if (next->when <= end && (next->when > start)) {
1063 /* Move left of cache to this point
1064 * (Optimize for immediate call this cycle within range) */
1065 _search_cache.left = x;
1066 //++_search_cache.range.first;
1067 assert(inclusive ? x >= start : x > start);
1074 const double slope = (next->value - first->value) / (double)(next->when - first->when);
1075 //cerr << "start y: " << start_y << endl;
1077 //y = first->value + (slope * fabs(start - first->when));
1080 if (first->value < next->value) // ramping up
1082 else // ramping down
1085 x = first->when + (y - first->value) / (double)slope;
1087 while ((inclusive && x < start) || (x <= start && y != next->value)) {
1089 if (first->value < next->value) // ramping up
1091 else // ramping down
1094 x = first->when + (y - first->value) / (double)slope;
1097 cerr << first->value << " @ " << first->when << " ... "
1098 << next->value << " @ " << next->when
1099 << " = " << y << " @ " << x << endl;
1101 assert( (y >= first->value && y <= next->value)
1102 || (y <= first->value && y >= next->value) );
1105 const bool past_start = (inclusive ? x >= start : x > start);
1106 if (past_start && x < end) {
1107 /* Move left of cache to this point
1108 * (Optimize for immediate call this cycle within range) */
1109 _search_cache.left = x;
1110 assert(inclusive ? x >= start : x > start);
1116 /* No points in the future, so no steps (towards them) in the future */
1122 boost::shared_ptr<ControlList>
1123 ControlList::cut (iterator start, iterator end)
1125 boost::shared_ptr<ControlList> nal = create (_parameter);
1128 Glib::Mutex::Lock lm (_lock);
1130 for (iterator x = start; x != end; ) {
1136 nal->_events.push_back (new ControlEvent (**x));
1139 reposition_for_rt_add (0);
1147 maybe_signal_changed ();
1152 boost::shared_ptr<ControlList>
1153 ControlList::cut_copy_clear (double start, double end, int op)
1155 boost::shared_ptr<ControlList> nal = create (_parameter);
1157 ControlEvent cp (start, 0.0);
1158 bool changed = false;
1161 Glib::Mutex::Lock lm (_lock);
1163 if ((s = lower_bound (_events.begin(), _events.end(), &cp, time_comparator)) == _events.end()) {
1168 e = upper_bound (_events.begin(), _events.end(), &cp, time_comparator);
1170 if (op != 2 && (*s)->when != start) {
1171 nal->_events.push_back (new ControlEvent (0, unlocked_eval (start)));
1174 for (iterator x = s; x != e; ) {
1182 /* adjust new points to be relative to start, which
1183 has been set to zero.
1187 nal->_events.push_back (new ControlEvent ((*x)->when - start, (*x)->value));
1197 if (op != 2 && nal->_events.back()->when != end - start) {
1198 nal->_events.push_back (new ControlEvent (end - start, unlocked_eval (end)));
1202 reposition_for_rt_add (0);
1208 maybe_signal_changed ();
1214 boost::shared_ptr<ControlList>
1215 ControlList::copy (iterator start, iterator end)
1217 boost::shared_ptr<ControlList> nal = create (_parameter);
1220 Glib::Mutex::Lock lm (_lock);
1222 for (iterator x = start; x != end; ) {
1228 nal->_events.push_back (new ControlEvent (**x));
1237 boost::shared_ptr<ControlList>
1238 ControlList::cut (double start, double end)
1240 return cut_copy_clear (start, end, 0);
1243 boost::shared_ptr<ControlList>
1244 ControlList::copy (double start, double end)
1246 return cut_copy_clear (start, end, 1);
1250 ControlList::clear (double start, double end)
1252 (void) cut_copy_clear (start, end, 2);
1256 ControlList::paste (ControlList& alist, double pos, float times)
1258 if (alist._events.empty()) {
1263 Glib::Mutex::Lock lm (_lock);
1267 ControlEvent cp (pos, 0.0);
1269 where = upper_bound (_events.begin(), _events.end(), &cp, time_comparator);
1271 for (iterator i = alist.begin();i != alist.end(); ++i) {
1272 _events.insert (where, new ControlEvent( (*i)->when+pos,( *i)->value));
1273 end = (*i)->when + pos;
1277 /* move all points after the insertion along the timeline by
1281 while (where != _events.end()) {
1283 if ((*where)->when <= end) {
1286 _events.erase(where);
1294 reposition_for_rt_add (0);
1298 maybe_signal_changed ();
1302 /** Move automation around according to a list of region movements */
1304 ControlList::move_ranges (RangeMoveList const & movements)
1307 Glib::Mutex::Lock lm (_lock);
1309 /* a copy of the events list before we started moving stuff around */
1310 EventList old_events = _events;
1312 /* clear the source and destination ranges in the new list */
1313 for (RangeMoveList::const_iterator i = movements.begin (); i != movements.end (); ++i) {
1315 erase_range_internal (i->from, i->from + i->length, _events);
1316 erase_range_internal (i->to, i->to + i->length, _events);
1320 /* copy the events into the new list */
1321 for (RangeMoveList::const_iterator i = movements.begin (); i != movements.end (); ++i) {
1322 iterator j = old_events.begin ();
1323 EventTime const limit = i->from + i->length;
1324 EventTime const dx = i->to - i->from;
1325 while (j != old_events.end () && (*j)->when <= limit) {
1326 if ((*j)->when >= i->from) {
1327 ControlEvent* ev = new ControlEvent (**j);
1329 _events.push_back (ev);
1336 _events.sort (event_time_less_than);
1338 _sort_pending = true;
1341 reposition_for_rt_add (0);
1345 maybe_signal_changed ();
1348 } // namespace Evoral