summaryrefslogtreecommitdiff
path: root/gtk2_ardour/automation_line.cc
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2015-03-26 13:22:57 -0400
committerDavid Robillard <d@drobilla.net>2015-03-26 13:22:57 -0400
commit5c11e43f083ca6a184000ff61274a99ddf5f57c4 (patch)
tree376437a11a3681611c0d0cf1310736d16e937e30 /gtk2_ardour/automation_line.cc
parent3b38d7d8a614f73f61bbed65356ba6c158d54970 (diff)
Clam points to valid values on drag end.
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.
Diffstat (limited to 'gtk2_ardour/automation_line.cc')
-rw-r--r--gtk2_ardour/automation_line.cc42
1 files changed, 32 insertions, 10 deletions
diff --git a/gtk2_ardour/automation_line.cc b/gtk2_ardour/automation_line.cc
index ed0321a2d7..43245f58d8 100644
--- a/gtk2_ardour/automation_line.cc
+++ b/gtk2_ardour/automation_line.cc
@@ -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;
}
}
}