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.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.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.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;
563 _curve->mark_dirty();
566 Dirty (); /* EMIT SIGNAL */
570 ControlList::truncate_end (double last_coordinate)
573 Glib::Mutex::Lock lm (_lock);
574 ControlEvent cp (last_coordinate, 0);
575 ControlList::reverse_iterator i;
578 if (_events.empty()) {
582 if (last_coordinate == _events.back()->when) {
586 if (last_coordinate > _events.back()->when) {
591 iterator foo = _events.begin();
594 if (foo == _events.end()) {
596 } else if (++foo == _events.end()) {
603 /* less than 2 points: add a new point */
604 _events.push_back (new ControlEvent (last_coordinate, _events.back()->value));
607 /* more than 2 points: check to see if the last 2 values
608 are equal. if so, just move the position of the
609 last point. otherwise, add a new point.
612 iterator penultimate = _events.end();
613 --penultimate; /* points at last point */
614 --penultimate; /* points at the penultimate point */
616 if (_events.back()->value == (*penultimate)->value) {
617 _events.back()->when = last_coordinate;
619 _events.push_back (new ControlEvent (last_coordinate, _events.back()->value));
627 last_val = unlocked_eval (last_coordinate);
628 last_val = max ((double) _min_yval, last_val);
629 last_val = min ((double) _max_yval, last_val);
631 i = _events.rbegin();
633 /* make i point to the last control point */
637 /* now go backwards, removing control points that are
638 beyond the new last coordinate.
641 // FIXME: SLOW! (size() == O(n))
643 uint32_t sz = _events.size();
645 while (i != _events.rend() && sz > 2) {
646 ControlList::reverse_iterator tmp;
651 if ((*i)->when < last_coordinate) {
655 _events.erase (i.base());
661 _events.back()->when = last_coordinate;
662 _events.back()->value = last_val;
665 reposition_for_rt_add (0);
669 maybe_signal_changed ();
673 ControlList::truncate_start (double overall_length)
676 Glib::Mutex::Lock lm (_lock);
678 double first_legal_value;
679 double first_legal_coordinate;
681 assert(!_events.empty());
683 if (overall_length == _events.back()->when) {
684 /* no change in overall length */
688 if (overall_length > _events.back()->when) {
690 /* growing at front: duplicate first point. shift all others */
692 double shift = overall_length - _events.back()->when;
695 for (np = 0, i = _events.begin(); i != _events.end(); ++i, ++np) {
701 /* less than 2 points: add a new point */
702 _events.push_front (new ControlEvent (0, _events.front()->value));
706 /* more than 2 points: check to see if the first 2 values
707 are equal. if so, just move the position of the
708 first point. otherwise, add a new point.
711 iterator second = _events.begin();
712 ++second; /* points at the second point */
714 if (_events.front()->value == (*second)->value) {
715 /* first segment is flat, just move start point back to zero */
716 _events.front()->when = 0;
718 /* leave non-flat segment in place, add a new leading point. */
719 _events.push_front (new ControlEvent (0, _events.front()->value));
725 /* shrinking at front */
727 first_legal_coordinate = _events.back()->when - overall_length;
728 first_legal_value = unlocked_eval (first_legal_coordinate);
729 first_legal_value = max (_min_yval, first_legal_value);
730 first_legal_value = min (_max_yval, first_legal_value);
732 /* remove all events earlier than the new "front" */
736 while (i != _events.end() && !_events.empty()) {
737 ControlList::iterator tmp;
742 if ((*i)->when > first_legal_coordinate) {
752 /* shift all remaining points left to keep their same
756 for (i = _events.begin(); i != _events.end(); ++i) {
757 (*i)->when -= first_legal_coordinate;
760 /* add a new point for the interpolated new value */
762 _events.push_front (new ControlEvent (0, first_legal_value));
765 reposition_for_rt_add (0);
770 maybe_signal_changed ();
774 ControlList::unlocked_eval (double x) const
776 pair<EventList::iterator,EventList::iterator> range;
782 const_iterator length_check_iter = _events.begin();
783 for (npoints = 0; npoints < 4; ++npoints, ++length_check_iter) {
784 if (length_check_iter == _events.end()) {
791 return _default_value;
794 return _events.front()->value;
797 if (x >= _events.back()->when) {
798 return _events.back()->value;
799 } else if (x <= _events.front()->when) {
800 return _events.front()->value;
803 lpos = _events.front()->when;
804 lval = _events.front()->value;
805 upos = _events.back()->when;
806 uval = _events.back()->value;
808 if (_interpolation == Discrete) {
812 /* linear interpolation betweeen the two points */
813 fraction = (double) (x - lpos) / (double) (upos - lpos);
814 return lval + (fraction * (uval - lval));
817 if (x >= _events.back()->when) {
818 return _events.back()->value;
819 } else if (x <= _events.front()->when) {
820 return _events.front()->value;
823 return multipoint_eval (x);
826 /*NOTREACHED*/ /* stupid gcc */
827 return _default_value;
831 ControlList::multipoint_eval (double x) const
837 /* "Stepped" lookup (no interpolation) */
838 /* FIXME: no cache. significant? */
839 if (_interpolation == Discrete) {
840 const ControlEvent cp (x, 0);
841 EventList::const_iterator i = lower_bound (_events.begin(), _events.end(), &cp, time_comparator);
843 // shouldn't have made it to multipoint_eval
844 assert(i != _events.end());
846 if (i == _events.begin() || (*i)->when == x)
849 return (*(--i))->value;
852 /* Only do the range lookup if x is in a different range than last time
853 * this was called (or if the lookup cache has been marked "dirty" (left<0) */
854 if ((_lookup_cache.left < 0) ||
855 ((_lookup_cache.left > x) ||
856 (_lookup_cache.range.first == _events.end()) ||
857 ((*_lookup_cache.range.second)->when < x))) {
859 const ControlEvent cp (x, 0);
861 _lookup_cache.range = equal_range (_events.begin(), _events.end(), &cp, time_comparator);
864 pair<const_iterator,const_iterator> range = _lookup_cache.range;
866 if (range.first == range.second) {
868 /* x does not exist within the list as a control point */
870 _lookup_cache.left = x;
872 if (range.first != _events.begin()) {
874 lpos = (*range.first)->when;
875 lval = (*range.first)->value;
877 /* we're before the first point */
878 // return _default_value;
879 return _events.front()->value;
882 if (range.second == _events.end()) {
883 /* we're after the last point */
884 return _events.back()->value;
887 upos = (*range.second)->when;
888 uval = (*range.second)->value;
890 /* linear interpolation betweeen the two points
894 fraction = (double) (x - lpos) / (double) (upos - lpos);
895 return lval + (fraction * (uval - lval));
899 /* x is a control point in the data */
900 _lookup_cache.left = -1;
901 return (*range.first)->value;
905 ControlList::build_search_cache_if_necessary (double start) const
907 /* Only do the range lookup if x is in a different range than last time
908 * this was called (or if the search cache has been marked "dirty" (left<0) */
909 if (!_events.empty() && ((_search_cache.left < 0) || (_search_cache.left > start))) {
911 const ControlEvent start_point (start, 0);
913 //cerr << "REBUILD: (" << _search_cache.left << ".." << _search_cache.right << ") := ("
914 // << start << ".." << end << ")" << endl;
916 _search_cache.first = lower_bound (_events.begin(), _events.end(), &start_point, time_comparator);
917 _search_cache.left = start;
921 /** Get the earliest event after \a start 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& 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, x, y, inclusive);
941 /** Get the earliest event after \a start 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& x, double& y, bool inclusive) const
951 if (_interpolation == Discrete) {
952 return rt_safe_earliest_event_discrete_unlocked(start, x, y, inclusive);
954 return rt_safe_earliest_event_linear_unlocked(start, x, y, inclusive);
959 /** Get the earliest event after \a start without 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& x, double& y, bool inclusive) const
969 build_search_cache_if_necessary (start);
971 if (_search_cache.first != _events.end()) {
972 const ControlEvent* const first = *_search_cache.first;
974 const bool past_start = (inclusive ? first->when >= start : first->when > start);
976 /* Earliest points is in range, return it */
982 /* Move left of cache to this point
983 * (Optimize for immediate call this cycle within range) */
984 _search_cache.left = x;
985 ++_search_cache.first;
994 /* No points in range */
1000 /** Get the earliest time the line crosses an integer (Linear interpolation).
1002 * If an event is found, \a x and \a y are set to its coordinates.
1004 * \param inclusive Include events with timestamp exactly equal to \a start
1005 * \return true if event is found (and \a x and \a y are valid).
1008 ControlList::rt_safe_earliest_event_linear_unlocked (double start, double& x, double& y, bool inclusive) const
1010 // cout << "earliest_event(start: " << start << ", x: " << x << ", y: " << y << ", inclusive: " << inclusive << ")" << endl;
1012 const_iterator length_check_iter = _events.begin();
1013 if (_events.empty()) { // 0 events
1015 } else if (_events.end() == ++length_check_iter) { // 1 event
1016 return rt_safe_earliest_event_discrete_unlocked (start, x, y, inclusive);
1019 // Hack to avoid infinitely repeating the same event
1020 build_search_cache_if_necessary (start);
1022 if (_search_cache.first != _events.end()) {
1024 const ControlEvent* first = NULL;
1025 const ControlEvent* next = NULL;
1027 /* Step is after first */
1028 if (_search_cache.first == _events.begin() || (*_search_cache.first)->when <= start) {
1029 first = *_search_cache.first;
1030 ++_search_cache.first;
1031 if (_search_cache.first == _events.end()) {
1034 next = *_search_cache.first;
1036 /* Step is before first */
1038 const_iterator prev = _search_cache.first;
1041 next = *_search_cache.first;
1044 if (inclusive && first->when == start) {
1047 /* Move left of cache to this point
1048 * (Optimize for immediate call this cycle within range) */
1049 _search_cache.left = x;
1050 //++_search_cache.range.first;
1055 if (fabs(first->value - next->value) <= 1) {
1056 if (next->when > start) {
1059 /* Move left of cache to this point
1060 * (Optimize for immediate call this cycle within range) */
1061 _search_cache.left = x;
1062 //++_search_cache.range.first;
1063 assert(inclusive ? x >= start : x > start);
1070 const double slope = (next->value - first->value) / (double)(next->when - first->when);
1071 //cerr << "start y: " << start_y << endl;
1073 //y = first->value + (slope * fabs(start - first->when));
1076 if (first->value < next->value) // ramping up
1078 else // ramping down
1081 x = first->when + (y - first->value) / (double)slope;
1083 while ((inclusive && x < start) || (x <= start && y != next->value)) {
1085 if (first->value < next->value) // ramping up
1087 else // ramping down
1090 x = first->when + (y - first->value) / (double)slope;
1093 /*cerr << first->value << " @ " << first->when << " ... "
1094 << next->value << " @ " << next->when
1095 << " = " << y << " @ " << x << endl;*/
1097 assert( (y >= first->value && y <= next->value)
1098 || (y <= first->value && y >= next->value) );
1101 const bool past_start = (inclusive ? x >= start : x > start);
1103 /* Move left of cache to this point
1104 * (Optimize for immediate call this cycle within range) */
1105 _search_cache.left = x;
1106 assert(inclusive ? x >= start : x > start);
1112 /* No points in the future, so no steps (towards them) in the future */
1118 boost::shared_ptr<ControlList>
1119 ControlList::cut (iterator start, iterator end)
1121 boost::shared_ptr<ControlList> nal = create (_parameter);
1124 Glib::Mutex::Lock lm (_lock);
1126 for (iterator x = start; x != end; ) {
1132 nal->_events.push_back (new ControlEvent (**x));
1135 reposition_for_rt_add (0);
1143 maybe_signal_changed ();
1148 /** @param op 0 = cut, 1 = copy, 2 = clear */
1149 boost::shared_ptr<ControlList>
1150 ControlList::cut_copy_clear (double start, double end, int op)
1152 boost::shared_ptr<ControlList> nal = create (_parameter);
1155 bool changed = false;
1158 Glib::Mutex::Lock lm (_lock);
1160 /* find the first event in our list that is at or before `start' in time */
1161 ControlEvent cp (start, 0.0);
1162 if ((s = lower_bound (_events.begin(), _events.end(), &cp, time_comparator)) == _events.end()) {
1166 /* and the last that is at or after `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; ) {
1180 /* adjust new points to be relative to start, which
1181 has been set to zero.
1185 nal->_events.push_back (new ControlEvent ((*x)->when - start, (*x)->value));
1195 if (op != 2 && nal->_events.back()->when != end - start) {
1196 nal->_events.push_back (new ControlEvent (end - start, unlocked_eval (end)));
1200 reposition_for_rt_add (0);
1206 maybe_signal_changed ();
1212 boost::shared_ptr<ControlList>
1213 ControlList::copy (iterator start, iterator end)
1215 boost::shared_ptr<ControlList> nal = create (_parameter);
1218 Glib::Mutex::Lock lm (_lock);
1220 for (iterator x = start; x != end; ) {
1226 nal->_events.push_back (new ControlEvent (**x));
1235 boost::shared_ptr<ControlList>
1236 ControlList::cut (double start, double end)
1238 return cut_copy_clear (start, end, 0);
1241 boost::shared_ptr<ControlList>
1242 ControlList::copy (double start, double end)
1244 return cut_copy_clear (start, end, 1);
1248 ControlList::clear (double start, double end)
1250 (void) cut_copy_clear (start, end, 2);
1254 ControlList::paste (ControlList& alist, double pos, float /*times*/)
1256 if (alist._events.empty()) {
1261 Glib::Mutex::Lock lm (_lock);
1265 ControlEvent cp (pos, 0.0);
1267 where = upper_bound (_events.begin(), _events.end(), &cp, time_comparator);
1269 for (iterator i = alist.begin();i != alist.end(); ++i) {
1270 _events.insert (where, new ControlEvent( (*i)->when+pos,( *i)->value));
1271 end = (*i)->when + pos;
1275 /* move all points after the insertion along the timeline by
1279 while (where != _events.end()) {
1281 if ((*where)->when <= end) {
1284 _events.erase(where);
1292 reposition_for_rt_add (0);
1296 maybe_signal_changed ();
1300 /** Move automation around according to a list of region movements */
1302 ControlList::move_ranges (const list< RangeMove<double> >& movements)
1304 typedef list< RangeMove<double> > RangeMoveList;
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 const double limit = i->from + i->length;
1324 const double 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 ();
1349 ControlList::set_interpolation (InterpolationStyle s)
1351 if (_interpolation == s) {
1356 InterpolationChanged (s); /* EMIT SIGNAL */
1359 } // namespace Evoral