From 5a647cd84a46a11ab506d91af1db0c33d3684b66 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 12 Jul 2024 00:45:37 +0200 Subject: [PATCH] Fix guard point logic for editor_add_ordered API. Previously the code was too simple and potentially added points out of order, leading to automation jumping back in time. --- libs/evoral/ControlList.cc | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/libs/evoral/ControlList.cc b/libs/evoral/ControlList.cc index 6d913c99a7..a6a3395b6f 100644 --- a/libs/evoral/ControlList.cc +++ b/libs/evoral/ControlList.cc @@ -732,8 +732,8 @@ ControlList::editor_add_ordered (OrderedPoints const & points, bool with_guard) { Glib::Threads::RWLock::WriterLock lm (_lock); - Temporal::timepos_t earliest = points.front().when; - Temporal::timepos_t latest = points.back().when; + Temporal::timepos_t earliest = ensure_time_domain (points.front().when); + Temporal::timepos_t latest = ensure_time_domain (points.back().when); assert (earliest <= latest); @@ -742,20 +742,12 @@ ControlList::editor_add_ordered (OrderedPoints const & points, bool with_guard) (void) erase_range_internal (earliest, latest, _events); if (with_guard) { - ControlEvent cp (earliest, 0.0); - double v = unlocked_eval (earliest); - iterator s = lower_bound (_events.begin (), _events.end (), &cp, time_comparator); - if (s != _events.end ()) { - _events.insert (s, new ControlEvent (earliest, v)); - } + unlocked_invalidate_insert_iterator (); + add_guard_point (earliest, -GUARD_POINT_DELTA (*this)); } if (with_guard && !distance.is_zero()) { - ControlEvent cp (latest, 0.0); - double v = unlocked_eval (latest); - iterator s = lower_bound (_events.begin (), _events.end (), &cp, time_comparator); - if (s != _events.end ()) { - _events.insert (s, new ControlEvent (latest, v)); - } + unlocked_invalidate_insert_iterator (); + add_guard_point (latest, GUARD_POINT_DELTA (*this)); } /* Get the iterator where we should start insertion */