Clam points to valid values on drag end.
authorDavid Robillard <d@drobilla.net>
Thu, 26 Mar 2015 17:22:57 +0000 (13:22 -0400)
committerDavid Robillard <d@drobilla.net>
Thu, 26 Mar 2015 17:22:57 +0000 (13:22 -0400)
Fixes bug #6214.

It would be better to do this while dragging, but this would require rewriting
much of the drag code to keep track of a cumulative y delta since the current
position of points would be "sticky" and prevent any movement at all, so this
will have to do for now.

gtk2_ardour/automation_line.cc
gtk2_ardour/automation_line.h

index ed0321a2d716218a0cc12461c1792dddb82d71e6..43245f58d8afb03f1366154e1e4ef780a74429cb 100644 (file)
@@ -289,16 +289,16 @@ AutomationLine::modify_point_y (ControlPoint& cp, double y)
 
        cp.move_to (x, y, ControlPoint::Full);
 
+       alist->freeze ();
+       sync_model_with_view_point (cp);
+       alist->thaw ();
+
        reset_line_coords (cp);
 
        if (line_points.size() > 1) {
                line->set_steps (line_points, is_stepped());
        }
 
-       alist->freeze ();
-       sync_model_with_view_point (cp);
-       alist->thaw ();
-
        update_pending = false;
 
        trackview.editor().session()->add_command (
@@ -317,14 +317,17 @@ AutomationLine::reset_line_coords (ControlPoint& cp)
        }
 }
 
-void
+bool
 AutomationLine::sync_model_with_view_points (list<ControlPoint*> cp)
 {
        update_pending = true;
 
+       bool moved = false;
        for (list<ControlPoint*>::iterator i = cp.begin(); i != cp.end(); ++i) {
-               sync_model_with_view_point (**i);
+               moved = sync_model_with_view_point (**i) || moved;
        }
+
+       return moved;
 }
 
 string
@@ -743,13 +746,13 @@ AutomationLine::end_drag (bool with_push, uint32_t final_index)
        }
 
        alist->freeze ();
-       sync_model_with_view_points (_drag_points);
+       bool moved = sync_model_with_view_points (_drag_points);
 
        if (with_push) {
                ControlPoint* p;
                uint32_t i = final_index;
                while ((p = nth (i)) != 0 && p->can_slide()) {
-                       sync_model_with_view_point (*p);
+                       moved = sync_model_with_view_point (*p) || moved;
                        ++i;
                }
        }
@@ -758,6 +761,12 @@ AutomationLine::end_drag (bool with_push, uint32_t final_index)
 
        update_pending = false;
 
+       if (moved) {
+               /* A point has moved as a result of sync (clamped to integer or boolean
+                  value), update line accordingly. */
+               line->set_steps (line_points, is_stepped());
+       }
+
        trackview.editor().session()->add_command (
                new MementoCommand<AutomationList>(memento_command_binder (), 0, &alist->get_state()));
 
@@ -767,7 +776,7 @@ AutomationLine::end_drag (bool with_push, uint32_t final_index)
        contiguous_points.clear ();
 }
 
-void
+bool
 AutomationLine::sync_model_with_view_point (ControlPoint& cp)
 {
        /* find out where the visual control point is.
@@ -792,6 +801,17 @@ AutomationLine::sync_model_with_view_point (ControlPoint& cp)
        view_to_model_coord_y (view_y);
 
        alist->modify (cp.model(), view_x, view_y);
+
+       /* convert back from model to view y for clamping position (for integer/boolean/etc) */
+       model_to_view_coord_y (view_y);
+       const double point_y = _height - (view_y * _height);
+       if (point_y != cp.get_y()) {
+               cp.move_to (cp.get_x(), point_y, ControlPoint::Full);
+               reset_line_coords (cp);
+               return true;
+       }
+
+       return false;
 }
 
 bool
@@ -1178,8 +1198,10 @@ AutomationLine::view_to_model_coord_y (double& y) const
                y = 2.0 * y - 1.0;
        } else {
                y = y * (double)(alist->get_max_y() - alist->get_min_y()) + alist->get_min_y();
-               if (_desc.toggled || _desc.integer_step) {
+               if (_desc.integer_step) {
                        y = round(y);
+               } else if (_desc.toggled) {
+                       y = (y > 0.5) ? 1.0 : 0.0;
                }
        }
 }
index 8554d487ee877208c3369420db297112cc667fd3..edf5f521aa06158500d49c97f9eb452fdef45316 100644 (file)
@@ -202,8 +202,8 @@ private:
        typedef boost::shared_ptr<ContiguousControlPoints> CCP;
        std::vector<CCP> contiguous_points;
 
-       void sync_model_with_view_point (ControlPoint&);
-       void sync_model_with_view_points (std::list<ControlPoint*>);
+       bool sync_model_with_view_point (ControlPoint&);
+       bool sync_model_with_view_points (std::list<ControlPoint*>);
        void start_drag_common (double, float);
 
        void reset_callback (const Evoral::ControlList&);