limit automation event density - fixes #5928
authorRobin Gareus <robin@gareus.org>
Sat, 7 Jun 2014 15:43:12 +0000 (17:43 +0200)
committerRobin Gareus <robin@gareus.org>
Sat, 7 Jun 2014 15:43:12 +0000 (17:43 +0200)
Constrain control points to one per tick (1/1920 beats).

Prior to this it was possible to set two values to the
same time (interpolation and iteration failed).

gtk2_ardour/automation_line.cc
gtk2_ardour/automation_line.h
libs/evoral/src/ControlList.cpp

index 7e37c32eb734f3a37d22a0ad5e51f86a2623e7f4..b0cc6eeea378610ab9fda5af2bff01cb607c4654 100644 (file)
@@ -39,6 +39,7 @@
 #include "ardour/automation_list.h"
 #include "ardour/dB.h"
 #include "ardour/debug.h"
+#include "ardour/tempo.h"
 
 #include "evoral/Curve.hpp"
 
@@ -520,11 +521,12 @@ AutomationLine::ContiguousControlPoints::ContiguousControlPoints (AutomationLine
 }
 
 void
-AutomationLine::ContiguousControlPoints::compute_x_bounds ()
+AutomationLine::ContiguousControlPoints::compute_x_bounds (PublicEditor& e)
 {
        uint32_t sz = size();
 
        if (sz > 0 && sz < line.npoints()) {
+               const TempoMap& map (e.session()->tempo_map());
 
                /* determine the limits on x-axis motion for this 
                   contiguous range of control points
@@ -532,14 +534,28 @@ AutomationLine::ContiguousControlPoints::compute_x_bounds ()
 
                if (front()->view_index() > 0) {
                        before_x = line.nth (front()->view_index() - 1)->get_x();
+
+                       const framepos_t pos = e.pixel_to_sample(before_x);
+                       const Meter& meter = map.meter_at (pos);
+                       const framecnt_t len = ceil(meter.frames_per_bar (map.tempo_at (pos), e.session()->frame_rate()) / 1920.0 / meter.divisions_per_bar());
+                       const double one_tick_in_pixels = e.sample_to_pixel_unrounded (len);
+
+                       before_x += one_tick_in_pixels;
                }
 
                /* if our last point has a point after it in the line,
                   we have an "after" bound
                */
 
-               if (back()->view_index() < (line.npoints() - 2)) {
+               if (back()->view_index() < (line.npoints() - 1)) {
                        after_x = line.nth (back()->view_index() + 1)->get_x();
+
+                       const framepos_t pos = e.pixel_to_sample(after_x);
+                       const Meter& meter = map.meter_at (pos);
+                       const framecnt_t len = ceil(meter.frames_per_bar (map.tempo_at (pos), e.session()->frame_rate()) / 1920.0 / meter.divisions_per_bar());
+                       const double one_tick_in_pixels = e.sample_to_pixel_unrounded (len);
+
+                       after_x -= one_tick_in_pixels;
                }
        }
 }
@@ -643,7 +659,7 @@ AutomationLine::drag_motion (double const x, float fraction, bool ignore_x, bool
                }
 
                for (vector<CCP>::iterator ccp = contiguous_points.begin(); ccp != contiguous_points.end(); ++ccp) {
-                       (*ccp)->compute_x_bounds ();
+                       (*ccp)->compute_x_bounds (trackview.editor());
                }
        }       
 
index dcd81c8b4eb31a10b29d4e22780ed47111f10dad..67e8fbc52ba46e418df180946de1bad6240dc44b 100644 (file)
@@ -47,6 +47,7 @@ class TimeAxisView;
 class AutomationTimeAxisView;
 class Selectable;
 class Selection;
+class PublicEditor;
 
 
 /** A GUI representation of an ARDOUR::AutomationList */
@@ -183,7 +184,7 @@ public:
                ContiguousControlPoints (AutomationLine& al);
                double clamp_dx (double dx);
                void move (double dx, double dy);
-               void compute_x_bounds ();
+               void compute_x_bounds (PublicEditor& e);
 private:
                AutomationLine& line;
                double before_x;
index 4b7704fff129688720c1c59e3543c05d11b67da4..e5073182143d2e889754f566594df9ab30fee75b 100644 (file)
@@ -1446,7 +1446,13 @@ ControlList::rt_safe_earliest_event_linear_unlocked (double start, double& x, do
                        assert(inclusive ? x >= start : x > start);
                        return true;
                } else {
-                       return false;
+                       if (inclusive) {
+                               x = next->when;
+                       } else {
+                               x = start;
+                       }
+                       _search_cache.left = x;
+                       return true;
                }
 
                /* No points in the future, so no steps (towards them) in the future */