step editing now accessed via a context menu on MIDI track rec-enable buttons. along...
[ardour.git] / libs / evoral / src / ControlList.cpp
index b84586ab738473b32a860d91f4958e7056d9ba41..4a710cfbb063221af71d9a76c40d4d9b54f60c61 100644 (file)
@@ -1,16 +1,16 @@
 /* This file is part of Evoral.
  * Copyright (C) 2008 Dave Robillard <http://drobilla.net>
  * Copyright (C) 2000-2008 Paul Davis
- * 
+ *
  * Evoral is free software; you can redistribute it and/or modify it under the
  * terms of the GNU General Public License as published by the Free Software
  * Foundation; either version 2 of the License, or (at your option) any later
  * version.
- * 
+ *
  * Evoral is distributed in the hope that it will be useful, but WITHOUT ANY
  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for details.
- * 
+ *
  * You should have received a copy of the GNU General Public License along
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
@@ -20,7 +20,8 @@
 #include <cassert>
 #include <utility>
 #include <iostream>
-#include <evoral/ControlList.hpp>
+#include "evoral/ControlList.hpp"
+#include "evoral/Curve.hpp"
 
 using namespace std;
 
@@ -36,13 +37,14 @@ inline bool event_time_less_than (ControlEvent* a, ControlEvent* b)
 ControlList::ControlList (const Parameter& id)
        : _parameter(id)
        , _interpolation(Linear)
-       , _curve(new Curve(*this))
-{      
+       , _curve(0)
+{
        _frozen = 0;
        _changed_when_thawed = false;
        _min_yval = id.min();
        _max_yval = id.max();
-       _max_xval = 0; // means "no limit" 
+       _max_xval = 0; // means "no limit"
+       _default_value = 0;
        _rt_insertion_point = _events.end();
        _lookup_cache.left = -1;
        _lookup_cache.range.first = _events.end();
@@ -54,7 +56,7 @@ ControlList::ControlList (const Parameter& id)
 ControlList::ControlList (const ControlList& other)
        : _parameter(other._parameter)
        , _interpolation(Linear)
-       , _curve(new Curve(*this))
+       , _curve(0)
 {
        _frozen = 0;
        _changed_when_thawed = false;
@@ -77,7 +79,7 @@ ControlList::ControlList (const ControlList& other)
 ControlList::ControlList (const ControlList& other, double start, double end)
        : _parameter(other._parameter)
        , _interpolation(Linear)
-       , _curve(new Curve(*this))
+       , _curve(0)
 {
        _frozen = 0;
        _changed_when_thawed = false;
@@ -108,6 +110,8 @@ ControlList::~ControlList()
        for (EventList::iterator x = _events.begin(); x != _events.end(); ++x) {
                delete (*x);
        }
+
+       delete _curve;
 }
 
 boost::shared_ptr<ControlList>
@@ -126,18 +130,18 @@ ControlList&
 ControlList::operator= (const ControlList& other)
 {
        if (this != &other) {
-               
+
                _events.clear ();
-               
+
                for (const_iterator i = other._events.begin(); i != other._events.end(); ++i) {
                        _events.push_back (new ControlEvent (**i));
                }
-               
+
                _min_yval = other._min_yval;
                _max_yval = other._max_yval;
                _max_xval = other._max_xval;
                _default_value = other._default_value;
-               
+
                mark_dirty ();
                maybe_signal_changed ();
        }
@@ -145,13 +149,27 @@ ControlList::operator= (const ControlList& other)
        return *this;
 }
 
+void
+ControlList::create_curve()
+{
+       _curve = new Curve(*this);
+}
+
+void
+ControlList::destroy_curve()
+{
+       delete _curve;
+       _curve = NULL;
+}
+
 void
 ControlList::maybe_signal_changed ()
 {
        mark_dirty ();
-       
-       if (_frozen)
+
+       if (_frozen) {
                _changed_when_thawed = true;
+       }
 }
 
 void
@@ -195,7 +213,7 @@ void ControlList::_x_scale (double factor)
 }
 
 void
-ControlList::reposition_for_rt_add (double when)
+ControlList::reposition_for_rt_add (double /*when*/)
 {
        _rt_insertion_point = _events.end();
 }
@@ -248,16 +266,16 @@ ControlList::rt_add (double when, double value)
                                where = after;
 
                        }
-                       
+
                        iterator previous = _rt_insertion_point;
                        --previous;
-                       
+
                        if (_rt_insertion_point != _events.begin() && (*_rt_insertion_point)->value == value && (*previous)->value == value) {
                                (*_rt_insertion_point)->when = when;
                                done = true;
-                               
+
                        }
-                       
+
                } else {
 
                        where = lower_bound (_events.begin(), _events.end(), &cp, time_comparator);
@@ -273,7 +291,7 @@ ControlList::rt_add (double when, double value)
                if (!done) {
                        _rt_insertion_point = _events.insert (where, new ControlEvent (when, value));
                }
-               
+
                _new_value = false;
                mark_dirty ();
        }
@@ -308,7 +326,7 @@ ControlList::add (double when, double value)
                                (*insertion_point)->value = value;
                                insert = false;
                                break;
-                       } 
+                       }
 
                        if ((*insertion_point)->when >= when) {
                                break;
@@ -316,11 +334,11 @@ ControlList::add (double when, double value)
                }
 
                if (insert) {
-                       
+
                        _events.insert (insertion_point, new ControlEvent (when, value));
                        reposition_for_rt_add (0);
 
-               } 
+               }
 
                mark_dirty ();
        }
@@ -350,7 +368,7 @@ ControlList::erase (iterator start, iterator end)
                mark_dirty ();
        }
        maybe_signal_changed ();
-}      
+}
 
 void
 ControlList::reset_range (double start, double endt)
@@ -358,11 +376,11 @@ ControlList::reset_range (double start, double endt)
        bool reset = false;
 
        {
-        Glib::Mutex::Lock lm (_lock);
+               Glib::Mutex::Lock lm (_lock);
                ControlEvent cp (start, 0.0f);
                iterator s;
                iterator e;
-               
+
                if ((s = lower_bound (_events.begin(), _events.end(), &cp, time_comparator)) != _events.end()) {
 
                        cp.when = endt;
@@ -371,7 +389,7 @@ ControlList::reset_range (double start, double endt)
                        for (iterator i = s; i != e; ++i) {
                                (*i)->value = _default_value;
                        }
-                       
+
                        reset = true;
 
                        mark_dirty ();
@@ -390,19 +408,13 @@ ControlList::erase_range (double start, double endt)
 
        {
                Glib::Mutex::Lock lm (_lock);
-               ControlEvent cp (start, 0.0f);
-               iterator s;
-               iterator e;
+               erased = erase_range_internal (start, endt, _events);
 
-               if ((s = lower_bound (_events.begin(), _events.end(), &cp, time_comparator)) != _events.end()) {
-                       cp.when = endt;
-                       e = upper_bound (_events.begin(), _events.end(), &cp, time_comparator);
-                       _events.erase (s, e);
+               if (erased) {
                        reposition_for_rt_add (0);
-                       erased = true;
                        mark_dirty ();
                }
-               
+
        }
 
        if (erased) {
@@ -410,36 +422,22 @@ ControlList::erase_range (double start, double endt)
        }
 }
 
-void
-ControlList::move_range (iterator start, iterator end, double xdelta, double ydelta)
+bool
+ControlList::erase_range_internal (double start, double endt, EventList & events)
 {
-       /* note: we assume higher level logic is in place to avoid this
-          reordering the time-order of control events in the list. ie. all
-          points after end are later than (end)->when.
-       */
-
-       {
-               Glib::Mutex::Lock lm (_lock);
-
-               while (start != end) {
-                       (*start)->when += xdelta;
-                       (*start)->value += ydelta;
-                       if (isnan ((*start)->value)) {
-                               abort ();
-                       }
-                       ++start;
-               }
-
-               if (!_frozen) {
-                       _events.sort (event_time_less_than);
-               } else {
-                       _sort_pending = true;
-               }
-
-               mark_dirty ();
+       bool erased = false;
+       ControlEvent cp (start, 0.0f);
+       iterator s;
+       iterator e;
+
+       if ((s = lower_bound (events.begin(), events.end(), &cp, time_comparator)) != events.end()) {
+               cp.when = endt;
+               e = upper_bound (events.begin(), events.end(), &cp, time_comparator);
+               events.erase (s, e);
+               erased = true;
        }
 
-       maybe_signal_changed ();
+       return erased;
 }
 
 void
@@ -451,7 +449,7 @@ ControlList::slide (iterator before, double distance)
                if (before == _events.end()) {
                        return;
                }
-               
+
                while (before != _events.end()) {
                        (*before)->when += distance;
                        ++before;
@@ -503,7 +501,7 @@ ControlList::control_points_adjacent (double xval)
        ret.second = _events.end();
 
        for (i = lower_bound (_events.begin(), _events.end(), &cp, time_comparator); i != _events.end(); ++i) {
-               
+
                if (ret.first == _events.end()) {
                        if ((*i)->when >= xval) {
                                if (i != _events.begin()) {
@@ -513,8 +511,8 @@ ControlList::control_points_adjacent (double xval)
                                        return ret;
                                }
                        }
-               } 
-               
+               }
+
                if ((*i)->when > xval) {
                        ret.second = i;
                        break;
@@ -555,13 +553,17 @@ ControlList::thaw ()
        }
 }
 
-void 
+void
 ControlList::mark_dirty () const
 {
        _lookup_cache.left = -1;
        _search_cache.left = -1;
-       if (_curve)
+
+       if (_curve) {
                _curve->mark_dirty();
+       }
+
+       Dirty (); /* EMIT SIGNAL */
 }
 
 void
@@ -582,7 +584,7 @@ ControlList::truncate_end (double last_coordinate)
                }
 
                if (last_coordinate > _events.back()->when) {
-                       
+
                        /* extending end:
                        */
 
@@ -610,7 +612,7 @@ ControlList::truncate_end (double last_coordinate)
                                iterator penultimate = _events.end();
                                --penultimate; /* points at last point */
                                --penultimate; /* points at the penultimate point */
-                               
+
                                if (_events.back()->value == (*penultimate)->value) {
                                        _events.back()->when = last_coordinate;
                                } else {
@@ -625,35 +627,37 @@ ControlList::truncate_end (double last_coordinate)
                        last_val = unlocked_eval (last_coordinate);
                        last_val = max ((double) _min_yval, last_val);
                        last_val = min ((double) _max_yval, last_val);
-                       
+
                        i = _events.rbegin();
-                       
+
                        /* make i point to the last control point */
-                       
+
                        ++i;
-                       
+
                        /* now go backwards, removing control points that are
                           beyond the new last coordinate.
                        */
 
+                       // FIXME: SLOW! (size() == O(n))
+
                        uint32_t sz = _events.size();
-                       
+
                        while (i != _events.rend() && sz > 2) {
                                ControlList::reverse_iterator tmp;
-                               
+
                                tmp = i;
                                ++tmp;
-                               
+
                                if ((*i)->when < last_coordinate) {
                                        break;
                                }
-                               
+
                                _events.erase (i.base());
                                --sz;
 
                                i = tmp;
                        }
-                       
+
                        _events.back()->when = last_coordinate;
                        _events.back()->value = last_val;
                }
@@ -675,14 +679,14 @@ ControlList::truncate_start (double overall_length)
                double first_legal_coordinate;
 
                assert(!_events.empty());
-               
+
                if (overall_length == _events.back()->when) {
                        /* no change in overall length */
                        return;
                }
-               
+
                if (overall_length > _events.back()->when) {
-                       
+
                        /* growing at front: duplicate first point. shift all others */
 
                        double shift = overall_length - _events.back()->when;
@@ -706,7 +710,7 @@ ControlList::truncate_start (double overall_length)
 
                                iterator second = _events.begin();
                                ++second; /* points at the second point */
-                               
+
                                if (_events.front()->value == (*second)->value) {
                                        /* first segment is flat, just move start point back to zero */
                                        _events.front()->when = 0;
@@ -719,7 +723,7 @@ ControlList::truncate_start (double overall_length)
                } else {
 
                        /* shrinking at front */
-                       
+
                        first_legal_coordinate = _events.back()->when - overall_length;
                        first_legal_value = unlocked_eval (first_legal_coordinate);
                        first_legal_value = max (_min_yval, first_legal_value);
@@ -728,35 +732,35 @@ ControlList::truncate_start (double overall_length)
                        /* remove all events earlier than the new "front" */
 
                        i = _events.begin();
-                       
+
                        while (i != _events.end() && !_events.empty()) {
                                ControlList::iterator tmp;
-                               
+
                                tmp = i;
                                ++tmp;
-                               
+
                                if ((*i)->when > first_legal_coordinate) {
                                        break;
                                }
-                               
+
                                _events.erase (i);
-                               
+
                                i = tmp;
                        }
-                       
+
 
                        /* shift all remaining points left to keep their same
                           relative position
                        */
-                       
+
                        for (i = _events.begin(); i != _events.end(); ++i) {
                                (*i)->when -= first_legal_coordinate;
                        }
 
                        /* add a new point for the interpolated new value */
-                       
+
                        _events.push_front (new ControlEvent (0, first_legal_value));
-               }           
+               }
 
                reposition_for_rt_add (0);
 
@@ -775,27 +779,24 @@ ControlList::unlocked_eval (double x) const
        double lval, uval;
        double fraction;
 
-       npoints = _events.size();
+       const_iterator length_check_iter = _events.begin();
+       for (npoints = 0; npoints < 4; ++npoints, ++length_check_iter) {
+               if (length_check_iter == _events.end()) {
+                       break;
+               }
+       }
 
        switch (npoints) {
        case 0:
                return _default_value;
 
        case 1:
-               if (x >= _events.front()->when) {
-                       return _events.front()->value;
-               } else {
-                       // return _default_value;
-                       return _events.front()->value;
-               } 
-               
+               return _events.front()->value;
+
        case 2:
                if (x >= _events.back()->when) {
                        return _events.back()->value;
-               } else if (x == _events.front()->when) {
-                       return _events.front()->value;
-               } else if (x < _events.front()->when) {
-                       // return _default_value;
+               } else if (x <= _events.front()->when) {
                        return _events.front()->value;
                }
 
@@ -803,33 +804,27 @@ ControlList::unlocked_eval (double x) const
                lval = _events.front()->value;
                upos = _events.back()->when;
                uval = _events.back()->value;
-               
-               if (_interpolation == Discrete)
-                       return lval;
 
-               /* linear interpolation betweeen the two points
-               */
+               if (_interpolation == Discrete) {
+                       return lval;
+               }
 
+               /* linear interpolation betweeen the two points */
                fraction = (double) (x - lpos) / (double) (upos - lpos);
                return lval + (fraction * (uval - lval));
 
        default:
-
                if (x >= _events.back()->when) {
                        return _events.back()->value;
-               } else if (x == _events.front()->when) {
-                       return _events.front()->value;
-               } else if (x < _events.front()->when) {
-                       // return _default_value;
+               } else if (x <= _events.front()->when) {
                        return _events.front()->value;
                }
 
                return multipoint_eval (x);
-               break;
        }
 
        /*NOTREACHED*/ /* stupid gcc */
-       return 0.0;
+       return _default_value;
 }
 
 double
@@ -838,7 +833,7 @@ ControlList::multipoint_eval (double x) const
        double upos, lpos;
        double uval, lval;
        double fraction;
-       
+
        /* "Stepped" lookup (no interpolation) */
        /* FIXME: no cache.  significant? */
        if (_interpolation == Discrete) {
@@ -857,15 +852,15 @@ ControlList::multipoint_eval (double x) const
        /* Only do the range lookup if x is in a different range than last time
         * this was called (or if the lookup cache has been marked "dirty" (left<0) */
        if ((_lookup_cache.left < 0) ||
-           ((_lookup_cache.left > x) || 
-            (_lookup_cache.range.first == _events.end()) || 
+           ((_lookup_cache.left > x) ||
+            (_lookup_cache.range.first == _events.end()) ||
             ((*_lookup_cache.range.second)->when < x))) {
 
                const ControlEvent cp (x, 0);
-               
+
                _lookup_cache.range = equal_range (_events.begin(), _events.end(), &cp, time_comparator);
        }
-       
+
        pair<const_iterator,const_iterator> range = _lookup_cache.range;
 
        if (range.first == range.second) {
@@ -883,7 +878,7 @@ ControlList::multipoint_eval (double x) const
                        // return _default_value;
                        return _events.front()->value;
                }
-               
+
                if (range.second == _events.end()) {
                        /* we're after the last point */
                        return _events.back()->value;
@@ -891,7 +886,7 @@ ControlList::multipoint_eval (double x) const
 
                upos = (*range.second)->when;
                uval = (*range.second)->value;
-               
+
                /* linear interpolation betweeen the two points
                   on either side of x
                */
@@ -899,7 +894,7 @@ ControlList::multipoint_eval (double x) const
                fraction = (double) (x - lpos) / (double) (upos - lpos);
                return lval + (fraction * (uval - lval));
 
-       } 
+       }
 
        /* x is a control point in the data */
        _lookup_cache.left = -1;
@@ -946,7 +941,7 @@ ControlList::rt_safe_earliest_event(double start, double end, double& x, double&
        }
 
        return rt_safe_earliest_event_unlocked(start, end, x, y, inclusive);
-} 
+}
 
 
 /** Get the earliest event between \a start and \a end, using the current interpolation style.
@@ -959,11 +954,12 @@ ControlList::rt_safe_earliest_event(double start, double end, double& x, double&
 bool
 ControlList::rt_safe_earliest_event_unlocked(double start, double end, double& x, double& y, bool inclusive) const
 {
-       if (_interpolation == Discrete)
+       if (_interpolation == Discrete) {
                return rt_safe_earliest_event_discrete_unlocked(start, end, x, y, inclusive);
-       else
+       } else {
                return rt_safe_earliest_event_linear_unlocked(start, end, x, y, inclusive);
-} 
+       }
+}
 
 
 /** Get the earliest event between \a start and \a end (Discrete (lack of) interpolation)
@@ -986,7 +982,7 @@ ControlList::rt_safe_earliest_event_discrete_unlocked (double start, double end,
                const bool past_start = (inclusive ? first->when >= start : first->when > start);
 
                /* Earliest points is in range, return it */
-               if (past_start >= start && first->when < end) {
+               if (past_start && first->when < end) {
 
                        x = first->when;
                        y = first->value;
@@ -1003,7 +999,7 @@ ControlList::rt_safe_earliest_event_discrete_unlocked (double start, double end,
                } else {
                        return false;
                }
-       
+
        /* No points in range */
        } else {
                return false;
@@ -1020,16 +1016,19 @@ ControlList::rt_safe_earliest_event_discrete_unlocked (double start, double end,
 bool
 ControlList::rt_safe_earliest_event_linear_unlocked (double start, double end, double& x, double& y, bool inclusive) const
 {
-       //cerr << "earliest_event(" << start << ", " << end << ", " << x << ", " << y << ", " << inclusive << endl;
+       //cerr << "earliest_event(start: " << start << ", end: " << end
+       //<< ", x: " << x << ", y: " << y << ", inclusive: " << inclusive <<  ")" << endl;
 
-       if (_events.size() == 0)
+       const_iterator length_check_iter = _events.begin();
+       if (_events.empty()) { // 0 events
                return false;
-       else if (_events.size() == 1)
+        } else if (_events.end() == ++length_check_iter) { // 1 event
                return rt_safe_earliest_event_discrete_unlocked(start, end, x, y, inclusive);
+        }
 
        // Hack to avoid infinitely repeating the same event
        build_search_cache_if_necessary(start, end);
-       
+
        pair<const_iterator,const_iterator> range = _search_cache.range;
 
        if (range.first != _events.end()) {
@@ -1037,6 +1036,10 @@ ControlList::rt_safe_earliest_event_linear_unlocked (double start, double end, d
                const ControlEvent* first = NULL;
                const ControlEvent* next = NULL;
 
+               /* No events past start (maybe?) */
+               if (next && next->when < start)
+                       return false;
+
                /* Step is after first */
                if (range.first == _events.begin() || (*range.first)->when == start) {
                        first = *range.first;
@@ -1050,7 +1053,7 @@ ControlList::rt_safe_earliest_event_linear_unlocked (double start, double end, d
                        first = *prev;
                        next = *range.first;
                }
-               
+
                if (inclusive && first->when == start) {
                        x = first->when;
                        y = first->value;
@@ -1058,12 +1061,12 @@ ControlList::rt_safe_earliest_event_linear_unlocked (double start, double end, d
                         * (Optimize for immediate call this cycle within range) */
                        _search_cache.left = x;
                        //++_search_cache.range.first;
-                       assert(inclusive ? x >= start : x > start);
+                       assert(x >= start);
                        return true;
                }
-                       
-               if (abs(first->value - next->value) <= 1) {
-                       if (next->when <= end && (!inclusive || next->when > start)) {
+
+               if (fabs(first->value - next->value) <= 1) {
+                       if (next->when <= end && (next->when > start)) {
                                x = next->when;
                                y = next->value;
                                /* Move left of cache to this point
@@ -1089,9 +1092,9 @@ ControlList::rt_safe_earliest_event_linear_unlocked (double start, double end, d
                        y = floor(y);
 
                x = first->when + (y - first->value) / (double)slope;
-               
+
                while ((inclusive && x < start) || (x <= start && y != next->value)) {
-                       
+
                        if (first->value < next->value) // ramping up
                                y += 1.0;
                        else // ramping down
@@ -1107,7 +1110,7 @@ ControlList::rt_safe_earliest_event_linear_unlocked (double start, double end, d
                assert(    (y >= first->value && y <= next->value)
                                || (y <= first->value && y >= next->value) );
 
-               
+
                const bool past_start = (inclusive ? x >= start : x > start);
                if (past_start && x < end) {
                        /* Move left of cache to this point
@@ -1118,7 +1121,7 @@ ControlList::rt_safe_earliest_event_linear_unlocked (double start, double end, d
                } else {
                        return false;
                }
-       
+
        /* No points in the future, so no steps (towards them) in the future */
        } else {
                return false;
@@ -1135,13 +1138,13 @@ ControlList::cut (iterator start, iterator end)
 
                for (iterator x = start; x != end; ) {
                        iterator tmp;
-                       
+
                        tmp = x;
                        ++tmp;
-                       
+
                        nal->_events.push_back (new ControlEvent (**x));
                        _events.erase (x);
-                       
+
                        reposition_for_rt_add (0);
 
                        x = tmp;
@@ -1155,21 +1158,25 @@ ControlList::cut (iterator start, iterator end)
        return nal;
 }
 
+/** @param op 0 = cut, 1 = copy, 2 = clear */
 boost::shared_ptr<ControlList>
 ControlList::cut_copy_clear (double start, double end, int op)
 {
        boost::shared_ptr<ControlList> nal = create (_parameter);
+       
        iterator s, e;
-       ControlEvent cp (start, 0.0);
        bool changed = false;
-       
+
        {
                Glib::Mutex::Lock lm (_lock);
 
+               /* find the first event in our list that is at or before `start' in time */
+               ControlEvent cp (start, 0.0);
                if ((s = lower_bound (_events.begin(), _events.end(), &cp, time_comparator)) == _events.end()) {
                        return nal;
                }
 
+               /* and the last that is at or after `end' */
                cp.when = end;
                e = upper_bound (_events.begin(), _events.end(), &cp, time_comparator);
 
@@ -1178,17 +1185,15 @@ ControlList::cut_copy_clear (double start, double end, int op)
                }
 
                for (iterator x = s; x != e; ) {
-                       iterator tmp;
-                       
-                       tmp = x;
+                       iterator tmp = x;
                        ++tmp;
 
                        changed = true;
-                       
+
                        /* adjust new points to be relative to start, which
                           has been set to zero.
                        */
-                       
+
                        if (op != 2) {
                                nal->_events.push_back (new ControlEvent ((*x)->when - start, (*x)->value));
                        }
@@ -1196,7 +1201,7 @@ ControlList::cut_copy_clear (double start, double end, int op)
                        if (op != 1) {
                                _events.erase (x);
                        }
-                       
+
                        x = tmp;
                }
 
@@ -1224,15 +1229,15 @@ ControlList::copy (iterator start, iterator end)
 
        {
                Glib::Mutex::Lock lm (_lock);
-               
+
                for (iterator x = start; x != end; ) {
                        iterator tmp;
-                       
+
                        tmp = x;
                        ++tmp;
-                       
+
                        nal->_events.push_back (new ControlEvent (**x));
-                       
+
                        x = tmp;
                }
        }
@@ -1259,7 +1264,7 @@ ControlList::clear (double start, double end)
 }
 
 bool
-ControlList::paste (ControlList& alist, double pos, float times)
+ControlList::paste (ControlList& alist, double pos, float /*times*/)
 {
        if (alist._events.empty()) {
                return false;
@@ -1278,9 +1283,9 @@ ControlList::paste (ControlList& alist, double pos, float times)
                        _events.insert (where, new ControlEvent( (*i)->when+pos,( *i)->value));
                        end = (*i)->when + pos;
                }
-       
-       
-               /* move all  points after the insertion along the timeline by 
+
+
+               /* move all  points after the insertion along the timeline by
                   the correct amount.
                */
 
@@ -1305,5 +1310,64 @@ ControlList::paste (ControlList& alist, double pos, float times)
        return true;
 }
 
+/** Move automation around according to a list of region movements */
+void
+ControlList::move_ranges (const list< RangeMove<double> >& movements)
+{
+       typedef list< RangeMove<double> > RangeMoveList;
+
+       {
+               Glib::Mutex::Lock lm (_lock);
+
+               /* a copy of the events list before we started moving stuff around */
+               EventList old_events = _events;
+
+               /* clear the source and destination ranges in the new list */
+               for (RangeMoveList::const_iterator i = movements.begin (); i != movements.end (); ++i) {
+
+                       erase_range_internal (i->from, i->from + i->length, _events);
+                       erase_range_internal (i->to, i->to + i->length, _events);
+
+               }
+
+               /* copy the events into the new list */
+               for (RangeMoveList::const_iterator i = movements.begin (); i != movements.end (); ++i) {
+                       iterator j = old_events.begin ();
+                       const double limit = i->from + i->length;
+                       const double dx    = i->to - i->from;
+                       while (j != old_events.end () && (*j)->when <= limit) {
+                               if ((*j)->when >= i->from) {
+                                       ControlEvent* ev = new ControlEvent (**j);
+                                       ev->when += dx;
+                                       _events.push_back (ev);
+                               }
+                               ++j;
+                       }
+               }
+
+               if (!_frozen) {
+                       _events.sort (event_time_less_than);
+               } else {
+                       _sort_pending = true;
+               }
+
+               reposition_for_rt_add (0);
+               mark_dirty ();
+       }
+
+       maybe_signal_changed ();
+}
+
+void
+ControlList::set_interpolation (InterpolationStyle s)
+{
+       if (_interpolation == s) {
+               return;
+       }
+
+       _interpolation = s;
+       InterpolationChanged (s); /* EMIT SIGNAL */
+}
+
 } // namespace Evoral