add clamp for adding points to a ControlList from a (G)UI
[ardour.git] / libs / evoral / src / ControlList.cpp
index 70500ba8de0319e0e56b40574dcc9000dd04f7eb..0b2184a97280f3181b8a754b21c1e017730a546c 100644 (file)
@@ -36,6 +36,7 @@
 #include "evoral/Curve.hpp"
 #include "evoral/ParameterDescriptor.hpp"
 #include "evoral/TypeMap.hpp"
+#include "evoral/types.hpp"
 
 #include "pbd/compose.h"
 #include "pbd/debug.h"
@@ -138,6 +139,7 @@ ControlList::~ControlList()
        for (EventList::iterator x = _events.begin(); x != _events.end(); ++x) {
                delete (*x);
        }
+       _events.clear ();
 
        delete _curve;
 }
@@ -165,7 +167,7 @@ ControlList::operator= (const ControlList& other)
 
                _interpolation = other._interpolation;
                _default_value = other._default_value;
-               
+
                copy_events (other);
        }
 
@@ -176,7 +178,10 @@ void
 ControlList::copy_events (const ControlList& other)
 {
        {
-               Glib::Threads::Mutex::Lock lm (_lock);
+               Glib::Threads::RWLock::WriterLock lm (_lock);
+               for (EventList::iterator x = _events.begin(); x != _events.end(); ++x) {
+                       delete (*x);
+               }
                _events.clear ();
                for (const_iterator i = other.begin(); i != other.end(); ++i) {
                        _events.push_back (new ControlEvent ((*i)->when, (*i)->value));
@@ -214,7 +219,10 @@ void
 ControlList::clear ()
 {
        {
-               Glib::Threads::Mutex::Lock lm (_lock);
+               Glib::Threads::RWLock::WriterLock lm (_lock);
+               for (EventList::iterator x = _events.begin(); x != _events.end(); ++x) {
+                       delete (*x);
+               }
                _events.clear ();
                unlocked_invalidate_insert_iterator ();
                mark_dirty ();
@@ -226,14 +234,14 @@ ControlList::clear ()
 void
 ControlList::x_scale (double factor)
 {
-       Glib::Threads::Mutex::Lock lm (_lock);
+       Glib::Threads::RWLock::WriterLock lm (_lock);
        _x_scale (factor);
 }
 
 bool
 ControlList::extend_to (double when)
 {
-       Glib::Threads::Mutex::Lock lm (_lock);
+       Glib::Threads::RWLock::WriterLock lm (_lock);
        if (_events.empty() || _events.back()->when == when) {
                return false;
        }
@@ -268,50 +276,50 @@ ControlList::thin (double thinning_factor)
        bool changed = false;
 
        {
-               Glib::Threads::Mutex::Lock lm (_lock);
-               
+               Glib::Threads::RWLock::WriterLock lm (_lock);
+
                ControlEvent* prevprev = 0;
                ControlEvent* cur = 0;
                ControlEvent* prev = 0;
                iterator pprev;
                int counter = 0;
-               
+
                DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 thin from %2 events\n", this, _events.size()));
-               
+
                for (iterator i = _events.begin(); i != _events.end(); ++i) {
-                       
+
                        cur = *i;
                        counter++;
-                       
+
                        if (counter > 2) {
-                               
+
                                /* compute the area of the triangle formed by 3 points
                                 */
-                               
-                               double area = fabs ((prevprev->when * (prev->value - cur->value)) + 
-                                                   (prev->when * (cur->value - prevprev->value)) + 
+
+                               double area = fabs ((prevprev->when * (prev->value - cur->value)) +
+                                                   (prev->when * (cur->value - prevprev->value)) +
                                                    (cur->when * (prevprev->value - prev->value)));
-                               
+
                                if (area < thinning_factor) {
                                        iterator tmp = pprev;
-                                       
+
                                        /* pprev will change to current
                                           i is incremented to the next event
                                           as we loop.
                                        */
-                                       
+
                                        pprev = i;
                                        _events.erase (tmp);
                                        changed = true;
                                        continue;
                                }
                        }
-                       
+
                        prevprev = prev;
                        prev = cur;
                        pprev = i;
                }
-               
+
                DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 thin => %2 events\n", this, _events.size()));
 
                if (changed) {
@@ -328,10 +336,9 @@ ControlList::thin (double thinning_factor)
 void
 ControlList::fast_simple_add (double when, double value)
 {
-       Glib::Threads::Mutex::Lock lm (_lock);
+       Glib::Threads::RWLock::WriterLock lm (_lock);
        /* to be used only for loading pre-sorted data from saved state */
        _events.insert (_events.end(), new ControlEvent (when, value));
-       assert(_events.back());
 
        mark_dirty ();
 }
@@ -339,7 +346,7 @@ ControlList::fast_simple_add (double when, double value)
 void
 ControlList::invalidate_insert_iterator ()
 {
-       Glib::Threads::Mutex::Lock lm (_lock);
+       Glib::Threads::RWLock::WriterLock lm (_lock);
        unlocked_invalidate_insert_iterator ();
 }
 
@@ -352,19 +359,19 @@ ControlList::unlocked_invalidate_insert_iterator ()
 void
 ControlList::start_write_pass (double when)
 {
-       Glib::Threads::Mutex::Lock lm (_lock);
+       Glib::Threads::RWLock::WriterLock lm (_lock);
 
        DEBUG_TRACE (DEBUG::ControlList, string_compose ("%1: setup write pass @ %2\n", this, when));
 
        new_write_pass = true;
        did_write_during_pass = false;
        insert_position = when;
-       
+
        /* leave the insert iterator invalid, so that we will do the lookup
           of where it should be in a "lazy" way - deferring it until
           we actually add the first point (which may never happen).
        */
-       
+
        unlocked_invalidate_insert_iterator ();
 }
 
@@ -383,9 +390,9 @@ ControlList::write_pass_finished (double /*when*/, double thinning_factor)
 
 void
 ControlList::set_in_write_pass (bool yn, bool add_point, double when)
-{      
+{
        DEBUG_TRACE (DEBUG::ControlList, string_compose ("now in write pass @ %1, add point ? %2\n", when, add_point));
-       
+
        _in_write_pass = yn;
 
        if (yn && add_point) {
@@ -400,49 +407,49 @@ ControlList::add_guard_point (double when)
        most_recent_insert_iterator = lower_bound (_events.begin(), _events.end(), &cp, time_comparator);
 
        double eval_value = unlocked_eval (insert_position);
-       
+
        if (most_recent_insert_iterator == _events.end()) {
-               
+
                DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 insert iterator at end, adding eval-value there %2\n", this, eval_value));
                _events.push_back (new ControlEvent (when, eval_value));
                /* leave insert iterator at the end */
-               
+
        } else if ((*most_recent_insert_iterator)->when == when) {
-               
+
                DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 insert iterator at existing point, setting eval-value there %2\n", this, eval_value));
-               
+
                /* most_recent_insert_iterator points to a control event
                   already at the insert position, so there is
                   nothing to do.
-                  
-                  ... except ... 
-                  
+
+                  ... except ...
+
                   advance most_recent_insert_iterator so that the "real"
-                  insert occurs in the right place, since it 
+                  insert occurs in the right place, since it
                   points to the control event just inserted.
                */
-               
+
                ++most_recent_insert_iterator;
        } else {
-               
+
                /* insert a new control event at the right spot
                 */
-               
-               DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 insert eval-value %2 just before iterator @ %3\n", 
+
+               DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 insert eval-value %2 just before iterator @ %3\n",
                                                                 this, eval_value, (*most_recent_insert_iterator)->when));
-               
+
                most_recent_insert_iterator = _events.insert (most_recent_insert_iterator, new ControlEvent (when, eval_value));
-               
+
                /* advance most_recent_insert_iterator so that the "real"
-                * insert occurs in the right place, since it 
+                * insert occurs in the right place, since it
                 * points to the control event just inserted.
                 */
-               
+
                ++most_recent_insert_iterator;
        }
-       
+
        /* don't do this again till the next write pass */
-       
+
        new_write_pass = false;
 }
 
@@ -452,33 +459,56 @@ ControlList::in_write_pass () const
        return _in_write_pass;
 }
 
-void
-ControlList::editor_add (double when, double value)
+bool
+ControlList::editor_add (double when, double value, bool with_guard)
 {
        /* this is for making changes from a graphical line editor
        */
 
+       ControlEvent cp (when, 0.0f);
+       iterator i = lower_bound (_events.begin(), _events.end(), &cp, time_comparator);
+
+       if (i != _events.end () && (*i)->when == when) {
+               return false;
+       }
+
        if (_events.empty()) {
-               
+
                /* as long as the point we're adding is not at zero,
                 * add an "anchor" point there.
                 */
 
                if (when >= 1) {
-                       _events.insert (_events.end(), new ControlEvent (0, _default_value));
-                       DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 added default value %2 at zero\n", this, _default_value));
+                       _events.insert (_events.end(), new ControlEvent (0, value));
+                       DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 added value %2 at zero\n", this, value));
                }
        }
 
-       ControlEvent cp (when, 0.0f);
-       iterator i = lower_bound (_events.begin(), _events.end(), &cp, time_comparator);
+       insert_position = when;
+       if (with_guard) {
+               if (when > 64) {
+                       add_guard_point (when - 64);
+               }
+               maybe_add_insert_guard (when);
+       }
+
+       /* clamp new value to allowed range */
+
+       value = max (_min_yval, value);
+       value = min (_max_yval, value);
+
+       iterator result;
        DEBUG_TRACE (DEBUG::ControlList, string_compose ("editor_add: actually add when= %1 value= %2\n", when, value));
-       _events.insert (i, new ControlEvent (when, value));
+       result = _events.insert (i, new ControlEvent (when, value));
 
-       mark_dirty ();
+       if (i == result) {
+               return false;
+       }
 
+       mark_dirty ();
        maybe_signal_changed ();
 
+       return true;
 }
 
 void
@@ -492,9 +522,9 @@ ControlList::maybe_add_insert_guard (double when)
                           new control point so that our insert will happen correctly. */
                        most_recent_insert_iterator = _events.insert (
                                most_recent_insert_iterator,
-                               new ControlEvent (when + 1, (*most_recent_insert_iterator)->value));
+                               new ControlEvent (when + 64, (*most_recent_insert_iterator)->value));
                        DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 added insert guard point @ %2 = %3\n",
-                                                                        this, when+1,
+                                                                        this, when + 64,
                                                                         (*most_recent_insert_iterator)->value));
                }
        }
@@ -547,7 +577,7 @@ ControlList::erase_from_iterator_to (iterator iter, double when)
 }
 
 void
-ControlList::add (double when, double value, bool with_guards, bool with_default)
+ControlList::add (double when, double value, bool with_guards, bool with_initial)
 {
        /* this is for making changes from some kind of user interface or
           control surface (GUI, MIDI, OSC etc)
@@ -558,17 +588,24 @@ ControlList::add (double when, double value, bool with_guards, bool with_default
                                     this, value, when, with_guards, _in_write_pass, new_write_pass,
                                     (most_recent_insert_iterator == _events.end())));
        {
-               Glib::Threads::Mutex::Lock lm (_lock);
+               Glib::Threads::RWLock::WriterLock lm (_lock);
                ControlEvent cp (when, 0.0f);
                iterator insertion_point;
 
-               if (_events.empty() && with_default) {
-                       
+               if (_events.empty() && with_initial) {
+
                        /* empty: add an "anchor" point if the point we're adding past time 0 */
 
                        if (when >= 1) {
-                               _events.insert (_events.end(), new ControlEvent (0, _default_value));
-                               DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 added default value %2 at zero\n", this, _default_value));
+                               if (_desc.toggled) {
+                                       const double opp_val = ((value < 0.5) ? 1.0 : 0.0);
+                                       _events.insert (_events.end(), new ControlEvent (0, opp_val));
+                                       DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 added toggled value %2 at zero\n", this, opp_val));
+
+                               } else {
+                                       _events.insert (_events.end(), new ControlEvent (0, value));
+                                       DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 added default value %2 at zero\n", this, _default_value));
+                               }
                        }
                }
 
@@ -602,7 +639,7 @@ ControlList::add (double when, double value, bool with_guards, bool with_default
                        }
 
                } else if (!_in_write_pass) {
-                               
+
                        /* not in a write pass: figure out the iterator we should insert in front of */
 
                        DEBUG_TRACE (DEBUG::ControlList, string_compose ("compute(b) MRI for position %1\n", when));
@@ -614,7 +651,7 @@ ControlList::add (double when, double value, bool with_guards, bool with_default
 
                if (most_recent_insert_iterator == _events.end()) {
                        DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 appending new point at end\n", this));
-                       
+
                        const bool done = maybe_insert_straight_line (when, value);
                        if (!done) {
                                _events.push_back (new ControlEvent (when, value));
@@ -629,10 +666,10 @@ ControlList::add (double when, double value, bool with_guards, bool with_default
                        if ((*most_recent_insert_iterator)->value != value) {
                                DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 reset existing point to new value %2\n", this, value));
 
-                               /* only one point allowed per time point, so just
-                                * reset the value here.
+                               /* only one point allowed per time point, so add a guard point
+                                * before it if needed then reset the value of the point.
                                 */
-                               
+
                                (*most_recent_insert_iterator)->value = value;
 
                                /* if we modified the final value, then its as
@@ -650,10 +687,35 @@ ControlList::add (double when, double value, bool with_guards, bool with_default
 
                } else {
                        DEBUG_TRACE (DEBUG::ControlList, string_compose ("@%1 insert new point at %2 at iterator at %3\n", this, when, (*most_recent_insert_iterator)->when));
-                       
-                       const bool done = maybe_insert_straight_line (when, value);
+                       bool done = false;
+                       /* check for possible straight line here until maybe_insert_straight_line () handles the insert iterator properly*/
+                       if (most_recent_insert_iterator != _events.begin ()) {
+                               bool have_point2 = false;
+                               --most_recent_insert_iterator;
+                               const bool have_point1 = (*most_recent_insert_iterator)->value == value;
+
+                               if (most_recent_insert_iterator != _events.begin ()) {
+                                       --most_recent_insert_iterator;
+                                       have_point2 = (*most_recent_insert_iterator)->value == value;
+                                       ++most_recent_insert_iterator;
+                               }
+
+                               if (have_point1 && have_point2) {
+                                       (*most_recent_insert_iterator)->when = when;
+                                       done = true;
+                               } else {
+                                       ++most_recent_insert_iterator;
+                               }
+                       }
+                       //done = maybe_insert_straight_line (when, value) || done;
+                       /* if the transport is stopped, add guard points (?) */
+                       if (!done && !_in_write_pass && when > 64) {
+                               add_guard_point (when - 64);
+                               maybe_add_insert_guard (when);
+                       }
+
                        if (with_guards) {
-                               maybe_add_insert_guard(when);
+                               maybe_add_insert_guard (when);
                        }
 
                        if (!done) {
@@ -673,7 +735,7 @@ void
 ControlList::erase (iterator i)
 {
        {
-               Glib::Threads::Mutex::Lock lm (_lock);
+               Glib::Threads::RWLock::WriterLock lm (_lock);
                if (most_recent_insert_iterator == i) {
                        unlocked_invalidate_insert_iterator ();
                }
@@ -687,7 +749,7 @@ void
 ControlList::erase (iterator start, iterator end)
 {
        {
-               Glib::Threads::Mutex::Lock lm (_lock);
+               Glib::Threads::RWLock::WriterLock lm (_lock);
                _events.erase (start, end);
                unlocked_invalidate_insert_iterator ();
                mark_dirty ();
@@ -700,7 +762,7 @@ void
 ControlList::erase (double when, double value)
 {
        {
-               Glib::Threads::Mutex::Lock lm (_lock);
+               Glib::Threads::RWLock::WriterLock lm (_lock);
 
                iterator i = begin ();
                while (i != end() && ((*i)->when != when || (*i)->value != value)) {
@@ -726,7 +788,7 @@ ControlList::erase_range (double start, double endt)
        bool erased = false;
 
        {
-               Glib::Threads::Mutex::Lock lm (_lock);
+               Glib::Threads::RWLock::WriterLock lm (_lock);
                erased = erase_range_internal (start, endt, _events);
 
                if (erased) {
@@ -765,7 +827,7 @@ void
 ControlList::slide (iterator before, double distance)
 {
        {
-               Glib::Threads::Mutex::Lock lm (_lock);
+               Glib::Threads::RWLock::WriterLock lm (_lock);
 
                if (before == _events.end()) {
                        return;
@@ -786,7 +848,7 @@ void
 ControlList::shift (double pos, double frames)
 {
        {
-               Glib::Threads::Mutex::Lock lm (_lock);
+               Glib::Threads::RWLock::WriterLock lm (_lock);
 
                for (iterator i = _events.begin(); i != _events.end(); ++i) {
                        if ((*i)->when >= pos) {
@@ -809,7 +871,7 @@ ControlList::modify (iterator iter, double when, double val)
        */
 
        {
-               Glib::Threads::Mutex::Lock lm (_lock);
+               Glib::Threads::RWLock::WriterLock lm (_lock);
 
                (*iter)->when = when;
                (*iter)->value = val;
@@ -833,7 +895,7 @@ ControlList::modify (iterator iter, double when, double val)
 std::pair<ControlList::iterator,ControlList::iterator>
 ControlList::control_points_adjacent (double xval)
 {
-       Glib::Threads::Mutex::Lock lm (_lock);
+       Glib::Threads::RWLock::ReaderLock lm (_lock);
        iterator i;
        ControlEvent cp (xval, 0.0f);
        std::pair<iterator,iterator> ret;
@@ -879,7 +941,7 @@ ControlList::thaw ()
        }
 
        {
-               Glib::Threads::Mutex::Lock lm (_lock);
+               Glib::Threads::RWLock::WriterLock lm (_lock);
 
                if (_sort_pending) {
                        _events.sort (event_time_less_than);
@@ -909,7 +971,7 @@ void
 ControlList::truncate_end (double last_coordinate)
 {
        {
-               Glib::Threads::Mutex::Lock lm (_lock);
+               Glib::Threads::RWLock::WriterLock lm (_lock);
                ControlEvent cp (last_coordinate, 0);
                ControlList::reverse_iterator i;
                double last_val;
@@ -1000,7 +1062,7 @@ ControlList::truncate_end (double last_coordinate)
                        _events.back()->when = last_coordinate;
                        _events.back()->value = last_val;
                }
-               
+
                unlocked_invalidate_insert_iterator ();
                mark_dirty();
        }
@@ -1012,14 +1074,15 @@ void
 ControlList::truncate_start (double overall_length)
 {
        {
-               Glib::Threads::Mutex::Lock lm (_lock);
+               Glib::Threads::RWLock::WriterLock lm (_lock);
                iterator i;
                double first_legal_value;
                double first_legal_coordinate;
 
-               assert(!_events.empty());
-
-               if (overall_length == _events.back()->when) {
+               if (_events.empty()) {
+                       /* nothing to truncate */
+                       return;
+               } else if (overall_length == _events.back()->when) {
                        /* no change in overall length */
                        return;
                }
@@ -1147,7 +1210,7 @@ ControlList::unlocked_eval (double x) const
                        return lval;
                }
 
-               /* linear interpolation betweeen the two points */
+               /* linear interpolation between the two points */
                fraction = (double) (x - lpos) / (double) (upos - lpos);
                return lval + (fraction * (uval - lval));
 
@@ -1242,21 +1305,27 @@ ControlList::multipoint_eval (double x) const
 void
 ControlList::build_search_cache_if_necessary (double start) const
 {
-       /* Only do the range lookup if x is in a different range than last time
-        * this was called (or if the search cache has been marked "dirty" (left<0) */
        if (_events.empty()) {
+               /* Empty, nothing to cache, move to end. */
                _search_cache.first = _events.end();
                _search_cache.left = 0;
+               return;
        } else if ((_search_cache.left < 0) || (_search_cache.left > start)) {
+               /* Marked dirty (left < 0), or we're too far forward, re-search. */
 
                const ControlEvent start_point (start, 0);
 
-               //cerr << "REBUILD: (" << _search_cache.left << ".." << _search_cache.right << ") := ("
-               //      << start << ".." << end << ")" << endl;
-
                _search_cache.first = lower_bound (_events.begin(), _events.end(), &start_point, time_comparator);
                _search_cache.left = start;
        }
+
+       /* We now have a search cache that is not too far right, but it may be too
+          far left and need to be advanced. */
+
+       while (_search_cache.first != end() && (*_search_cache.first)->when < start) {
+               ++_search_cache.first;
+       }
+       _search_cache.left = start;
 }
 
 /** Get the earliest event after \a start using the current interpolation style.
@@ -1270,7 +1339,7 @@ bool
 ControlList::rt_safe_earliest_event (double start, double& x, double& y, bool inclusive) const
 {
        // FIXME: It would be nice if this was unnecessary..
-       Glib::Threads::Mutex::Lock lm(_lock, Glib::Threads::TRY_LOCK);
+       Glib::Threads::RWLock::ReaderLock lm(_lock, Glib::Threads::TRY_LOCK);
        if (!lm.locked()) {
                return false;
        }
@@ -1365,8 +1434,8 @@ ControlList::rt_safe_earliest_event_linear_unlocked (double start, double& x, do
                const ControlEvent* first = NULL;
                const ControlEvent* next = NULL;
 
-               /* Step is after first */
                if (_search_cache.first == _events.begin() || (*_search_cache.first)->when <= start) {
+                       /* Step is after first */
                        first = *_search_cache.first;
                        ++_search_cache.first;
                        if (_search_cache.first == _events.end()) {
@@ -1374,8 +1443,8 @@ ControlList::rt_safe_earliest_event_linear_unlocked (double start, double& x, do
                        }
                        next = *_search_cache.first;
 
-                       /* Step is before first */
                } else {
+                       /* Step is before first */
                        const_iterator prev = _search_cache.first;
                        --prev;
                        first = *prev;
@@ -1455,8 +1524,8 @@ ControlList::rt_safe_earliest_event_linear_unlocked (double start, double& x, do
                        return true;
                }
 
-               /* No points in the future, so no steps (towards them) in the future */
        } else {
+               /* No points in the future, so no steps (towards them) in the future */
                return false;
        }
 }
@@ -1474,7 +1543,7 @@ ControlList::cut_copy_clear (double start, double end, int op)
        ControlEvent cp (start, 0.0);
 
        {
-               Glib::Threads::Mutex::Lock lm (_lock);
+               Glib::Threads::RWLock::WriterLock lm (_lock);
 
                /* first, determine s & e, two iterators that define the range of points
                   affected by this operation
@@ -1590,7 +1659,7 @@ ControlList::paste (const ControlList& alist, double pos, float /*times*/)
        }
 
        {
-               Glib::Threads::Mutex::Lock lm (_lock);
+               Glib::Threads::RWLock::WriterLock lm (_lock);
                iterator where;
                iterator prev;
                double end = 0;
@@ -1603,10 +1672,19 @@ ControlList::paste (const ControlList& alist, double pos, float /*times*/)
                        if (alist.parameter() != parameter()) {
                                const ParameterDescriptor& src_desc = alist.descriptor();
 
+                               // This does not work for logscale and will probably also not do
+                               // the right thing for integer_step and sr_dependent parameters.
+                               //
+                               // TODO various flags from from ARDOUR::ParameterDescriptor
+                               // to Evoral::ParameterDescriptor
+
                                value -= src_desc.lower;  // translate to 0-relative
                                value /= (src_desc.upper - src_desc.lower);  // normalize range
                                value *= (_desc.upper - _desc.lower);  // scale to our range
                                value += _desc.lower;  // translate to our offset
+                               if (_desc.toggled) {
+                                       value = (value < 0.5) ? 0.0 : 1.0;
+                               }
                        }
                        _events.insert (where, new ControlEvent((*i)->when + pos, value));
                        end = (*i)->when + pos;
@@ -1647,7 +1725,7 @@ ControlList::move_ranges (const list< RangeMove<double> >& movements)
        typedef list< RangeMove<double> > RangeMoveList;
 
        {
-               Glib::Threads::Mutex::Lock lm (_lock);
+               Glib::Threads::RWLock::WriterLock lm (_lock);
 
                /* a copy of the events list before we started moving stuff around */
                EventList old_events = _events;
@@ -1728,7 +1806,7 @@ ControlList::operator!= (ControlList const & other) const
        if (i != _events.end ()) {
                return true;
        }
-       
+
        return (
                _parameter != other._parameter ||
                _interpolation != other._interpolation ||