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"
47 _rt_insertion_point = _events.end();
48 _lookup_cache.left = -1;
49 _lookup_cache.range.first = _events.end();
50 _search_cache.left = -1;
51 _search_cache.range.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 _rt_insertion_point = _events.end();
67 _lookup_cache.range.first = _events.end();
68 _search_cache.range.first = _events.end();
69 _sort_pending = false;
71 for (const_iterator i = other._events.begin(); i != other._events.end(); ++i) {
72 _events.push_back (new ControlEvent (**i));
78 ControlList::ControlList (const ControlList& other, double start, double end)
79 : _parameter(other._parameter)
80 , _interpolation(Linear)
84 _changed_when_thawed = false;
85 _min_yval = other._min_yval;
86 _max_yval = other._max_yval;
87 _max_xval = other._max_xval;
88 _default_value = other._default_value;
89 _rt_insertion_point = _events.end();
90 _lookup_cache.range.first = _events.end();
91 _search_cache.range.first = _events.end();
92 _sort_pending = false;
94 /* now grab the relevant points, and shift them back if necessary */
96 boost::shared_ptr<ControlList> section = const_cast<ControlList*>(&other)->copy (start, end);
98 if (!section->empty()) {
99 for (iterator i = section->begin(); i != section->end(); ++i) {
100 _events.push_back (new ControlEvent ((*i)->when, (*i)->value));
107 ControlList::~ControlList()
109 for (EventList::iterator x = _events.begin(); x != _events.end(); ++x) {
116 boost::shared_ptr<ControlList>
117 ControlList::create(Parameter id)
119 return boost::shared_ptr<ControlList>(new ControlList(id));
123 ControlList::operator== (const ControlList& other)
125 return _events == other._events;
129 ControlList::operator= (const ControlList& other)
131 if (this != &other) {
135 for (const_iterator i = other._events.begin(); i != other._events.end(); ++i) {
136 _events.push_back (new ControlEvent (**i));
139 _min_yval = other._min_yval;
140 _max_yval = other._max_yval;
141 _max_xval = other._max_xval;
142 _default_value = other._default_value;
145 maybe_signal_changed ();
152 ControlList::create_curve()
154 _curve = new Curve(*this);
158 ControlList::destroy_curve()
165 ControlList::maybe_signal_changed ()
170 _changed_when_thawed = true;
174 ControlList::clear ()
177 Glib::Mutex::Lock lm (_lock);
182 maybe_signal_changed ();
186 ControlList::x_scale (double factor)
188 Glib::Mutex::Lock lm (_lock);
193 ControlList::extend_to (double when)
195 Glib::Mutex::Lock lm (_lock);
196 if (_events.empty() || _events.back()->when == when) {
199 double factor = when / _events.back()->when;
204 void ControlList::_x_scale (double factor)
206 for (iterator i = _events.begin(); i != _events.end(); ++i) {
207 (*i)->when = floor ((*i)->when * factor);
214 ControlList::reposition_for_rt_add (double /*when*/)
216 _rt_insertion_point = _events.end();
220 ControlList::rt_add (double when, double value)
222 //cerr << "RT: alist " << this << " add " << value << " @ " << when << endl;
225 Glib::Mutex::Lock lm (_lock);
228 ControlEvent cp (when, 0.0);
231 if ((_rt_insertion_point != _events.end()) && ((*_rt_insertion_point)->when < when) ) {
233 /* we have a previous insertion point, so we should delete
234 everything between it and the position where we are going
235 to insert this point.
238 iterator after = _rt_insertion_point;
240 if (++after != _events.end()) {
241 iterator far = after;
243 while (far != _events.end()) {
244 if ((*far)->when > when) {
252 _rt_insertion_point = where;
254 if ((*where)->when == when) {
255 (*where)->value = value;
259 where = _events.erase (after, far);
268 iterator previous = _rt_insertion_point;
271 if (_rt_insertion_point != _events.begin() && (*_rt_insertion_point)->value == value && (*previous)->value == value) {
272 (*_rt_insertion_point)->when = when;
279 where = lower_bound (_events.begin(), _events.end(), &cp, time_comparator);
281 if (where != _events.end()) {
282 if ((*where)->when == when) {
283 (*where)->value = value;
290 _rt_insertion_point = _events.insert (where, new ControlEvent (when, value));
297 maybe_signal_changed ();
301 ControlList::fast_simple_add (double when, double value)
303 /* to be used only for loading pre-sorted data from saved state */
304 _events.insert (_events.end(), new ControlEvent (when, value));
305 assert(_events.back());
309 ControlList::add (double when, double value)
311 /* this is for graphical editing */
314 Glib::Mutex::Lock lm (_lock);
315 ControlEvent cp (when, 0.0f);
317 iterator insertion_point;
319 for (insertion_point = lower_bound (_events.begin(), _events.end(), &cp, time_comparator); insertion_point != _events.end(); ++insertion_point) {
321 /* only one point allowed per time point */
323 if ((*insertion_point)->when == when) {
324 (*insertion_point)->value = value;
329 if ((*insertion_point)->when >= when) {
336 _events.insert (insertion_point, new ControlEvent (when, value));
337 reposition_for_rt_add (0);
344 maybe_signal_changed ();
348 ControlList::erase (iterator i)
351 Glib::Mutex::Lock lm (_lock);
353 reposition_for_rt_add (0);
356 maybe_signal_changed ();
360 ControlList::erase (iterator start, iterator end)
363 Glib::Mutex::Lock lm (_lock);
364 _events.erase (start, end);
365 reposition_for_rt_add (0);
368 maybe_signal_changed ();
372 ControlList::reset_range (double start, double endt)
377 Glib::Mutex::Lock lm (_lock);
378 ControlEvent cp (start, 0.0f);
382 if ((s = lower_bound (_events.begin(), _events.end(), &cp, time_comparator)) != _events.end()) {
385 e = upper_bound (_events.begin(), _events.end(), &cp, time_comparator);
387 for (iterator i = s; i != e; ++i) {
388 (*i)->value = _default_value;
398 maybe_signal_changed ();
403 ControlList::erase_range (double start, double endt)
408 Glib::Mutex::Lock lm (_lock);
409 erased = erase_range_internal (start, endt, _events);
412 reposition_for_rt_add (0);
419 maybe_signal_changed ();
424 ControlList::erase_range_internal (double start, double endt, EventList & events)
427 ControlEvent cp (start, 0.0f);
431 if ((s = lower_bound (events.begin(), events.end(), &cp, time_comparator)) != events.end()) {
433 e = upper_bound (events.begin(), events.end(), &cp, time_comparator);
442 ControlList::slide (iterator before, double distance)
445 Glib::Mutex::Lock lm (_lock);
447 if (before == _events.end()) {
451 while (before != _events.end()) {
452 (*before)->when += distance;
457 maybe_signal_changed ();
461 ControlList::modify (iterator iter, double when, double val)
463 /* note: we assume higher level logic is in place to avoid this
464 reordering the time-order of control events in the list. ie. all
465 points after *iter are later than when.
469 Glib::Mutex::Lock lm (_lock);
471 (*iter)->when = when;
472 (*iter)->value = val;
479 _events.sort (event_time_less_than);
481 _sort_pending = true;
487 maybe_signal_changed ();
490 std::pair<ControlList::iterator,ControlList::iterator>
491 ControlList::control_points_adjacent (double xval)
493 Glib::Mutex::Lock lm (_lock);
495 ControlEvent cp (xval, 0.0f);
496 std::pair<iterator,iterator> ret;
498 ret.first = _events.end();
499 ret.second = _events.end();
501 for (i = lower_bound (_events.begin(), _events.end(), &cp, time_comparator); i != _events.end(); ++i) {
503 if (ret.first == _events.end()) {
504 if ((*i)->when >= xval) {
505 if (i != _events.begin()) {
514 if ((*i)->when > xval) {
524 ControlList::set_max_xval (double x)
530 ControlList::freeze ()
545 Glib::Mutex::Lock lm (_lock);
548 _events.sort (event_time_less_than);
549 _sort_pending = false;
555 ControlList::mark_dirty () const
557 _lookup_cache.left = -1;
558 _search_cache.left = -1;
560 _curve->mark_dirty();
564 ControlList::truncate_end (double last_coordinate)
567 Glib::Mutex::Lock lm (_lock);
568 ControlEvent cp (last_coordinate, 0);
569 ControlList::reverse_iterator i;
572 if (_events.empty()) {
576 if (last_coordinate == _events.back()->when) {
580 if (last_coordinate > _events.back()->when) {
585 iterator foo = _events.begin();
588 if (foo == _events.end()) {
590 } else if (++foo == _events.end()) {
597 /* less than 2 points: add a new point */
598 _events.push_back (new ControlEvent (last_coordinate, _events.back()->value));
601 /* more than 2 points: check to see if the last 2 values
602 are equal. if so, just move the position of the
603 last point. otherwise, add a new point.
606 iterator penultimate = _events.end();
607 --penultimate; /* points at last point */
608 --penultimate; /* points at the penultimate point */
610 if (_events.back()->value == (*penultimate)->value) {
611 _events.back()->when = last_coordinate;
613 _events.push_back (new ControlEvent (last_coordinate, _events.back()->value));
621 last_val = unlocked_eval (last_coordinate);
622 last_val = max ((double) _min_yval, last_val);
623 last_val = min ((double) _max_yval, last_val);
625 i = _events.rbegin();
627 /* make i point to the last control point */
631 /* now go backwards, removing control points that are
632 beyond the new last coordinate.
635 // FIXME: SLOW! (size() == O(n))
637 uint32_t sz = _events.size();
639 while (i != _events.rend() && sz > 2) {
640 ControlList::reverse_iterator tmp;
645 if ((*i)->when < last_coordinate) {
649 _events.erase (i.base());
655 _events.back()->when = last_coordinate;
656 _events.back()->value = last_val;
659 reposition_for_rt_add (0);
663 maybe_signal_changed ();
667 ControlList::truncate_start (double overall_length)
670 Glib::Mutex::Lock lm (_lock);
672 double first_legal_value;
673 double first_legal_coordinate;
675 assert(!_events.empty());
677 if (overall_length == _events.back()->when) {
678 /* no change in overall length */
682 if (overall_length > _events.back()->when) {
684 /* growing at front: duplicate first point. shift all others */
686 double shift = overall_length - _events.back()->when;
689 for (np = 0, i = _events.begin(); i != _events.end(); ++i, ++np) {
695 /* less than 2 points: add a new point */
696 _events.push_front (new ControlEvent (0, _events.front()->value));
700 /* more than 2 points: check to see if the first 2 values
701 are equal. if so, just move the position of the
702 first point. otherwise, add a new point.
705 iterator second = _events.begin();
706 ++second; /* points at the second point */
708 if (_events.front()->value == (*second)->value) {
709 /* first segment is flat, just move start point back to zero */
710 _events.front()->when = 0;
712 /* leave non-flat segment in place, add a new leading point. */
713 _events.push_front (new ControlEvent (0, _events.front()->value));
719 /* shrinking at front */
721 first_legal_coordinate = _events.back()->when - overall_length;
722 first_legal_value = unlocked_eval (first_legal_coordinate);
723 first_legal_value = max (_min_yval, first_legal_value);
724 first_legal_value = min (_max_yval, first_legal_value);
726 /* remove all events earlier than the new "front" */
730 while (i != _events.end() && !_events.empty()) {
731 ControlList::iterator tmp;
736 if ((*i)->when > first_legal_coordinate) {
746 /* shift all remaining points left to keep their same
750 for (i = _events.begin(); i != _events.end(); ++i) {
751 (*i)->when -= first_legal_coordinate;
754 /* add a new point for the interpolated new value */
756 _events.push_front (new ControlEvent (0, first_legal_value));
759 reposition_for_rt_add (0);
764 maybe_signal_changed ();
768 ControlList::unlocked_eval (double x) const
770 pair<EventList::iterator,EventList::iterator> range;
776 const_iterator length_check_iter = _events.begin();
777 for (npoints = 0; npoints < 4; ++npoints, ++length_check_iter) {
778 if (length_check_iter == _events.end()) {
785 return _default_value;
788 return _events.front()->value;
791 if (x >= _events.back()->when) {
792 return _events.back()->value;
793 } else if (x <= _events.front()->when) {
794 return _events.front()->value;
797 lpos = _events.front()->when;
798 lval = _events.front()->value;
799 upos = _events.back()->when;
800 uval = _events.back()->value;
802 if (_interpolation == Discrete) {
806 /* linear interpolation betweeen the two points */
807 fraction = (double) (x - lpos) / (double) (upos - lpos);
808 return lval + (fraction * (uval - lval));
811 if (x >= _events.back()->when) {
812 return _events.back()->value;
813 } else if (x <= _events.front()->when) {
814 return _events.front()->value;
817 return multipoint_eval (x);
820 /*NOTREACHED*/ /* stupid gcc */
821 return _default_value;
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
1013 //<< ", x: " << x << ", y: " << y << ", inclusive: " << inclusive << ")" << endl;
1015 const_iterator length_check_iter = _events.begin();
1016 if (_events.empty()) // 0 events
1018 else if (_events.end() == ++length_check_iter) // 1 event
1019 return rt_safe_earliest_event_discrete_unlocked(start, end, x, y, inclusive);
1021 // Hack to avoid infinitely repeating the same event
1022 build_search_cache_if_necessary(start, end);
1024 pair<const_iterator,const_iterator> range = _search_cache.range;
1026 if (range.first != _events.end()) {
1028 const ControlEvent* first = NULL;
1029 const ControlEvent* next = NULL;
1031 /* No events past start (maybe?) */
1032 if (next && next->when < start)
1035 /* Step is after first */
1036 if (range.first == _events.begin() || (*range.first)->when == start) {
1037 first = *range.first;
1038 next = *(++range.first);
1039 ++_search_cache.range.first;
1041 /* Step is before first */
1043 const_iterator prev = range.first;
1046 next = *range.first;
1049 if (inclusive && first->when == start) {
1052 /* Move left of cache to this point
1053 * (Optimize for immediate call this cycle within range) */
1054 _search_cache.left = x;
1055 //++_search_cache.range.first;
1060 if (fabs(first->value - next->value) <= 1) {
1061 if (next->when <= end && (next->when > start)) {
1064 /* Move left of cache to this point
1065 * (Optimize for immediate call this cycle within range) */
1066 _search_cache.left = x;
1067 //++_search_cache.range.first;
1068 assert(inclusive ? x >= start : x > start);
1075 const double slope = (next->value - first->value) / (double)(next->when - first->when);
1076 //cerr << "start y: " << start_y << endl;
1078 //y = first->value + (slope * fabs(start - first->when));
1081 if (first->value < next->value) // ramping up
1083 else // ramping down
1086 x = first->when + (y - first->value) / (double)slope;
1088 while ((inclusive && x < start) || (x <= start && y != next->value)) {
1090 if (first->value < next->value) // ramping up
1092 else // ramping down
1095 x = first->when + (y - first->value) / (double)slope;
1098 cerr << first->value << " @ " << first->when << " ... "
1099 << next->value << " @ " << next->when
1100 << " = " << y << " @ " << x << endl;
1102 assert( (y >= first->value && y <= next->value)
1103 || (y <= first->value && y >= next->value) );
1106 const bool past_start = (inclusive ? x >= start : x > start);
1107 if (past_start && x < end) {
1108 /* Move left of cache to this point
1109 * (Optimize for immediate call this cycle within range) */
1110 _search_cache.left = x;
1111 assert(inclusive ? x >= start : x > start);
1117 /* No points in the future, so no steps (towards them) in the future */
1123 boost::shared_ptr<ControlList>
1124 ControlList::cut (iterator start, iterator end)
1126 boost::shared_ptr<ControlList> nal = create (_parameter);
1129 Glib::Mutex::Lock lm (_lock);
1131 for (iterator x = start; x != end; ) {
1137 nal->_events.push_back (new ControlEvent (**x));
1140 reposition_for_rt_add (0);
1148 maybe_signal_changed ();
1153 boost::shared_ptr<ControlList>
1154 ControlList::cut_copy_clear (double start, double end, int op)
1156 boost::shared_ptr<ControlList> nal = create (_parameter);
1158 ControlEvent cp (start, 0.0);
1159 bool changed = false;
1162 Glib::Mutex::Lock lm (_lock);
1164 if ((s = lower_bound (_events.begin(), _events.end(), &cp, time_comparator)) == _events.end()) {
1169 e = upper_bound (_events.begin(), _events.end(), &cp, time_comparator);
1171 if (op != 2 && (*s)->when != start) {
1172 nal->_events.push_back (new ControlEvent (0, unlocked_eval (start)));
1175 for (iterator x = s; x != e; ) {
1183 /* adjust new points to be relative to start, which
1184 has been set to zero.
1188 nal->_events.push_back (new ControlEvent ((*x)->when - start, (*x)->value));
1198 if (op != 2 && nal->_events.back()->when != end - start) {
1199 nal->_events.push_back (new ControlEvent (end - start, unlocked_eval (end)));
1203 reposition_for_rt_add (0);
1209 maybe_signal_changed ();
1215 boost::shared_ptr<ControlList>
1216 ControlList::copy (iterator start, iterator end)
1218 boost::shared_ptr<ControlList> nal = create (_parameter);
1221 Glib::Mutex::Lock lm (_lock);
1223 for (iterator x = start; x != end; ) {
1229 nal->_events.push_back (new ControlEvent (**x));
1238 boost::shared_ptr<ControlList>
1239 ControlList::cut (double start, double end)
1241 return cut_copy_clear (start, end, 0);
1244 boost::shared_ptr<ControlList>
1245 ControlList::copy (double start, double end)
1247 return cut_copy_clear (start, end, 1);
1251 ControlList::clear (double start, double end)
1253 (void) cut_copy_clear (start, end, 2);
1257 ControlList::paste (ControlList& alist, double pos, float /*times*/)
1259 if (alist._events.empty()) {
1264 Glib::Mutex::Lock lm (_lock);
1268 ControlEvent cp (pos, 0.0);
1270 where = upper_bound (_events.begin(), _events.end(), &cp, time_comparator);
1272 for (iterator i = alist.begin();i != alist.end(); ++i) {
1273 _events.insert (where, new ControlEvent( (*i)->when+pos,( *i)->value));
1274 end = (*i)->when + pos;
1278 /* move all points after the insertion along the timeline by
1282 while (where != _events.end()) {
1284 if ((*where)->when <= end) {
1287 _events.erase(where);
1295 reposition_for_rt_add (0);
1299 maybe_signal_changed ();
1303 /** Move automation around according to a list of region movements */
1305 ControlList::move_ranges (const list< RangeMove<double> >& movements)
1307 typedef list< RangeMove<double> > RangeMoveList;
1310 Glib::Mutex::Lock lm (_lock);
1312 /* a copy of the events list before we started moving stuff around */
1313 EventList old_events = _events;
1315 /* clear the source and destination ranges in the new list */
1316 for (RangeMoveList::const_iterator i = movements.begin (); i != movements.end (); ++i) {
1318 erase_range_internal (i->from, i->from + i->length, _events);
1319 erase_range_internal (i->to, i->to + i->length, _events);
1323 /* copy the events into the new list */
1324 for (RangeMoveList::const_iterator i = movements.begin (); i != movements.end (); ++i) {
1325 iterator j = old_events.begin ();
1326 const double limit = i->from + i->length;
1327 const double dx = i->to - i->from;
1328 while (j != old_events.end () && (*j)->when <= limit) {
1329 if ((*j)->when >= i->from) {
1330 ControlEvent* ev = new ControlEvent (**j);
1332 _events.push_back (ev);
1339 _events.sort (event_time_less_than);
1341 _sort_pending = true;
1344 reposition_for_rt_add (0);
1348 maybe_signal_changed ();
1351 } // namespace Evoral