- trackview.editor().current_session()->add_command (new MementoCommand<AutomationList>(*alist.get(), 0, &alist->get_state()));
- trackview.editor().current_session()->commit_reversible_command ();
- trackview.editor().current_session()->set_dirty ();
-}
-
-
-void
-AutomationLine::modify_view_point (ControlPoint& cp, double x, double y, bool with_push)
-{
- double delta = 0.0;
- uint32_t last_movable = UINT_MAX;
- double x_limit = DBL_MAX;
-
- /* this just changes the current view. it does not alter
- the model in any way at all.
- */
-
- /* clamp y-coord appropriately. y is supposed to be a normalized fraction (0.0-1.0),
- and needs to be converted to a canvas unit distance.
- */
-
- y = max (0.0, y);
- y = min (1.0, y);
- y = _height - (y * _height);
-
- if (cp.can_slide()) {
-
- /* x-coord cannot move beyond adjacent points or the start/end, and is
- already in frames. it needs to be converted to canvas units.
- */
-
- x = trackview.editor().frame_to_unit (x);
-
- /* clamp x position using view coordinates */
-
- ControlPoint *before;
- ControlPoint *after;
-
- if (cp.view_index()) {
- before = nth (cp.view_index() - 1);
- x = max (x, before->get_x()+1.0);
- } else {
- before = &cp;
- }
-
-
- if (!with_push) {
- if (cp.view_index() < control_points.size() - 1) {
-
- after = nth (cp.view_index() + 1);
-
- /*if it is a "spike" leave the x alone */
-
- if (after->get_x() - before->get_x() < 2) {
- x = cp.get_x();
-
- } else {
- x = min (x, after->get_x()-1.0);
- }
- } else {
- after = &cp;
- }
-
- } else {
-
- ControlPoint* after;
-
- /* find the first point that can't move */
-
- for (uint32_t n = cp.view_index() + 1; (after = nth (n)) != 0; ++n) {
- if (!after->can_slide()) {
- x_limit = after->get_x() - 1.0;
- last_movable = after->view_index();
- break;
- }
- }
-
- delta = x - cp.get_x();
- }
-
- } else {
-
- /* leave the x-coordinate alone */
-
- x = trackview.editor().frame_to_unit (_time_converter.to((*cp.model())->when));
-
- }
-
- if (!with_push) {
-
- cp.move_to (x, y, ControlPoint::Full);
- reset_line_coords (cp);
-
- } else {
-
- uint32_t limit = min (control_points.size(), (size_t)last_movable);
-
- /* move the current point to wherever the user told it to go, subject
- to x_limit.
- */
-
- cp.move_to (min (x, x_limit), y, ControlPoint::Full);
- reset_line_coords (cp);
-
- /* now move all subsequent control points, to reflect the motion.
- */
-
- for (uint32_t i = cp.view_index() + 1; i < limit; ++i) {
- ControlPoint *p = nth (i);
- double new_x;
-
- if (p->can_slide()) {
- new_x = min (p->get_x() + delta, x_limit);
- p->move_to (new_x, p->get_y(), ControlPoint::Full);
- reset_line_coords (*p);
- }
- }
- }