rename Marker class
[ardour.git] / gtk2_ardour / editor_drag.cc
index 6f1abba69cfe3d4a19e7af38429abce88c4b9021..d17ee4b3a2c7297d1ed201b07ca38c7e6b1d71aa 100644 (file)
@@ -96,8 +96,6 @@ DragManager::abort ()
 {
        _ending = true;
 
-       cerr << "Aborting drag\n";
-
        for (list<Drag*>::const_iterator i = _drags.begin(); i != _drags.end(); ++i) {
                (*i)->abort ();
                delete *i;
@@ -218,6 +216,8 @@ Drag::Drag (Editor* e, ArdourCanvas::Item* i, bool trackview_only)
        : _editor (e)
        , _item (i)
        , _pointer_frame_offset (0)
+       , _x_constrained (false)
+       , _y_constrained (false)
        , _trackview_only (trackview_only)
        , _move_threshold_passed (false)
        , _starting_point_passed (false)
@@ -226,6 +226,7 @@ Drag::Drag (Editor* e, ArdourCanvas::Item* i, bool trackview_only)
        , _raw_grab_frame (0)
        , _grab_frame (0)
        , _last_pointer_frame (0)
+       , _snap_delta (0)
 {
 
 }
@@ -248,22 +249,11 @@ Drag::swap_grab (ArdourCanvas::Item* new_item, Gdk::Cursor* cursor, uint32_t /*t
 void
 Drag::start_grab (GdkEvent* event, Gdk::Cursor *cursor)
 {
-       // if dragging with button2, the motion is x constrained, with Alt-button2 it is y constrained
 
-       if (Keyboard::is_button2_event (&event->button)) {
-               if (Keyboard::modifier_state_equals (event->button.state, Keyboard::SecondaryModifier)) {
-                       _y_constrained = true;
-                       _x_constrained = false;
-               } else {
-                       _y_constrained = false;
-                       _x_constrained = true;
-               }
-       } else {
-               _x_constrained = false;
-               _y_constrained = false;
-       }
+       /* we set up x/y dragging constraints on first move */
 
        _raw_grab_frame = _editor->canvas_event_sample (event, &_grab_x, &_grab_y);
+
        setup_pointer_frame_offset ();
        _grab_frame = adjusted_frame (_raw_grab_frame, event);
        _last_pointer_frame = _grab_frame;
@@ -343,6 +333,16 @@ Drag::adjusted_current_frame (GdkEvent const * event, bool snap) const
        return adjusted_frame (_drags->current_pointer_frame (), event, snap);
 }
 
+frameoffset_t
+Drag::snap_delta (guint state) const
+{
+       if (ArdourKeyboard::indicates_snap_delta (state)) {
+               return _snap_delta;
+       }
+
+       return 0;
+}
+
 double
 Drag::current_pointer_x() const
 {
@@ -359,6 +359,14 @@ Drag::current_pointer_y () const
        return _drags->current_pointer_y () - _editor->get_trackview_group()->canvas_origin().y;
 }
 
+void
+Drag::setup_snap_delta (framepos_t pos)
+{
+       framepos_t temp = pos;
+       _editor->snap_to (temp, ARDOUR::RoundNearest, false, true);
+       _snap_delta = temp - pos;
+}
+
 bool
 Drag::motion_handler (GdkEvent* event, bool from_autoscroll)
 {
@@ -394,6 +402,39 @@ Drag::motion_handler (GdkEvent* event, bool from_autoscroll)
                                } else {
                                        _initially_vertical = false;
                                }
+                               /** check constraints for this drag.
+                                *  Note that the current convention is to use "contains" for 
+                                *  key modifiers during motion and "equals" when initiating a drag.
+                                *  In this case we haven't moved yet, so "equals" applies here.
+                                */
+                               if (Config->get_edit_mode() != Lock) {
+                                       if (event->motion.state & Gdk::BUTTON2_MASK) {
+                                               // if dragging with button2, the motion is x constrained, with constraint modifier it is y constrained
+                                               if (Keyboard::modifier_state_equals (event->button.state, ArdourKeyboard::constraint_modifier ())) {
+                                                       _x_constrained = false;
+                                                       _y_constrained = true;
+                                               } else {
+                                                       _x_constrained = true;
+                                                       _y_constrained = false;
+                                               }
+                                       } else if (Keyboard::modifier_state_equals (event->button.state, ArdourKeyboard::constraint_modifier ())) {
+                                               // if dragging normally, the motion is constrained to the first direction of movement.
+                                               if (_initially_vertical) {
+                                                       _x_constrained = true;
+                                                       _y_constrained = false;
+                                               } else {
+                                                       _x_constrained = false;
+                                                       _y_constrained = true;
+                                               }
+                                       }
+                               } else {
+                                       if (event->button.state & Gdk::BUTTON2_MASK) {
+                                               _x_constrained = false;
+                                       } else {
+                                               _x_constrained = true;
+                                       }
+                                       _y_constrained = false;
+                               }
                        }
 
                        if (!from_autoscroll) {
@@ -555,7 +596,6 @@ RegionMotionDrag::RegionMotionDrag (Editor* e, ArdourCanvas::Item* i, RegionView
        , _total_x_delta (0)
        , _last_pointer_time_axis_view (0)
        , _last_pointer_layer (0)
-       , _single_axis (false)
        , _ndropzone (0)
        , _pdropzone (0)
        , _ddropzone (0)
@@ -567,10 +607,7 @@ void
 RegionMotionDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
 {
        Drag::start_grab (event, cursor);
-
-       if (Keyboard::modifier_state_contains (event->button.state, Keyboard::TertiaryModifier)) {
-               _single_axis = true;
-       }
+       setup_snap_delta (_last_frame_position);
 
        show_verbose_cursor_time (_last_frame_position);
 
@@ -580,6 +617,11 @@ RegionMotionDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
                assert(_last_pointer_time_axis_view >= 0);
                _last_pointer_layer = tv.first->layer_display() == Overlaid ? 0 : tv.second;
        }
+
+       if (_brushing) {
+               /* cross track dragging seems broken here. disabled for now. */
+               _y_constrained = true;
+       }
 }
 
 double
@@ -588,7 +630,7 @@ RegionMotionDrag::compute_x_delta (GdkEvent const * event, framepos_t* pending_r
        /* compute the amount of pointer motion in frames, and where
           the region would be if we moved it by that much.
        */
-       *pending_region_position = adjusted_current_frame (event);
+       *pending_region_position = adjusted_frame (_drags->current_pointer_frame () + snap_delta (event->button.state), event, true);
 
        framepos_t sync_frame;
        framecnt_t sync_offset;
@@ -600,11 +642,11 @@ RegionMotionDrag::compute_x_delta (GdkEvent const * event, framepos_t* pending_r
         */
        if (sync_dir >= 0 || (sync_dir < 0 && *pending_region_position >= sync_offset)) {
 
-               sync_frame = *pending_region_position + (sync_dir*sync_offset);
+               sync_frame = *pending_region_position + (sync_dir * sync_offset);
 
                _editor->snap_to_with_modifier (sync_frame, event);
 
-               *pending_region_position = _primary->region()->adjust_to_sync (sync_frame);
+               *pending_region_position = _primary->region()->adjust_to_sync (sync_frame) - snap_delta (event->button.state);
 
        } else {
                *pending_region_position = _last_frame_position;
@@ -616,8 +658,7 @@ RegionMotionDrag::compute_x_delta (GdkEvent const * event, framepos_t* pending_r
 
        double dx = 0;
 
-       /* in locked edit mode, reverse the usual meaning of _x_constrained */
-       bool const x_move_allowed = Config->get_edit_mode() == Lock ? _x_constrained : !_x_constrained;
+       bool const x_move_allowed = !_x_constrained;
 
        if ((*pending_region_position != _last_frame_position) && x_move_allowed) {
 
@@ -750,18 +791,6 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
 
        assert (!_views.empty ());
 
-       if (first_move) {
-               if (_single_axis) {
-                       if (initially_vertical()) {
-                               _y_constrained = false;
-                               _x_constrained = true;
-                       } else {
-                               _y_constrained = true;
-                               _x_constrained = false;
-                       }
-               }
-       }
-
        /* Note: time axis views in this method are often expressed as an index into the _time_axis_views vector */
 
        /* Find the TimeAxisView that the pointer is now over */
@@ -1010,8 +1039,7 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
                        this_delta_layer = - i->layer;
                }
 
-               int this_delta_time_axis_view = delta_time_axis_view;
-               this_delta_time_axis_view = apply_track_delta(i->time_axis_view, delta_time_axis_view, delta_skip) - i->time_axis_view;
+               int this_delta_time_axis_view = apply_track_delta(i->time_axis_view, delta_time_axis_view, delta_skip) - i->time_axis_view;
 
                int track_index = i->time_axis_view + this_delta_time_axis_view;
                assert(track_index >= 0);
@@ -1173,8 +1201,9 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
                                /* if all logic and maths are correct, there is no need to assign the 'current' pointer.
                                 * the current position can be calculated as follows:
                                 */
-                               assert (current_pointer_time_axis_view == _time_axis_views.size() - dtz + _ddropzone + delta_time_axis_view);
-                               // robin crosses his fingers, and looks at busses.
+                               // a well placed oofus attack can still throw this off.
+                               // likley auto-scroll related, printf() debugging may tell, commented out for now.
+                               //assert (current_pointer_time_axis_view == _time_axis_views.size() - dtz + _ddropzone + delta_time_axis_view);
                        }
                } else {
                        /* last motion event was also over a time axis view */
@@ -1197,13 +1226,13 @@ void
 RegionMoveDrag::motion (GdkEvent* event, bool first_move)
 {
        if (_copy && first_move) {
-
-               if (_x_constrained) {
+               if (_x_constrained && !_brushing) {
                        _editor->begin_reversible_command (Operations::fixed_time_region_copy);
-               } else {
+               } else if (!_brushing) {
                        _editor->begin_reversible_command (Operations::region_copy);
+               } else if (_brushing) {
+                       _editor->begin_reversible_command (Operations::drag_region_brush);
                }
-
                /* duplicate the regionview(s) and region(s) */
 
                list<DraggingView> new_regionviews;
@@ -1261,14 +1290,14 @@ RegionMoveDrag::motion (GdkEvent* event, bool first_move)
                }
 
        } else if (!_copy && first_move) {
-
-               if (_x_constrained) {
+               if (_x_constrained && !_brushing) {
                        _editor->begin_reversible_command (_("fixed time region drag"));
-               } else {
+               } else if (!_brushing) {
                        _editor->begin_reversible_command (Operations::region_drag);
+               } else if (_brushing) {
+                       _editor->begin_reversible_command (Operations::drag_region_brush);
                }
        }
-
        RegionMotionDrag::motion (event, first_move);
 }
 
@@ -1304,14 +1333,6 @@ RegionMoveDrag::finished (GdkEvent* ev, bool movement_occurred)
                return;
        }
 
-       /* reverse this here so that we have the correct logic to finalize
-          the drag.
-       */
-
-       if (Config->get_edit_mode() == Lock) {
-               _x_constrained = !_x_constrained;
-       }
-
        assert (!_views.empty ());
 
        /* We might have hidden region views so that they weren't visible during the drag
@@ -1357,7 +1378,11 @@ RegionMoveDrag::create_destination_time_axis (boost::shared_ptr<Region> region,
        try {
                if (boost::dynamic_pointer_cast<AudioRegion> (region)) {
                        list<boost::shared_ptr<AudioTrack> > audio_tracks;
-                       audio_tracks = _editor->session()->new_audio_track (region->n_channels(), region->n_channels(), ARDOUR::Normal, 0, 1, region->name());
+                       uint32_t output_chan = region->n_channels();
+                       if ((Config->get_output_auto_connect() & AutoConnectMaster) && _editor->session()->master_out()) {
+                               output_chan =  _editor->session()->master_out()->n_inputs().n_audio();
+                       }
+                       audio_tracks = _editor->session()->new_audio_track (region->n_channels(), output_chan, ARDOUR::Normal, 0, 1, region->name());
                        RouteTimeAxisView* rtav = _editor->axis_view_from_route (audio_tracks.front());
                        if (rtav) {
                                rtav->set_height (original->current_height());
@@ -1480,12 +1505,6 @@ RegionMoveDrag::finished_no_copy (
        set<RouteTimeAxisView*> views_to_update;
        RouteTimeAxisView* new_time_axis_view = 0;
 
-       if (_brushing) {
-               /* all changes were made during motion event handlers */
-               _editor->commit_reversible_command ();
-               return;
-       }
-
        typedef map<boost::shared_ptr<Playlist>, RouteTimeAxisView*> PlaylistMapping;
        PlaylistMapping playlist_mapping;
 
@@ -1599,7 +1618,6 @@ RegionMoveDrag::finished_no_copy (
                        }
 
                        rv->region()->set_position (where);
-
                        _editor->session()->add_command (new StatefulDiffCommand (rv->region()));
                }
 
@@ -1648,7 +1666,7 @@ RegionMoveDrag::finished_no_copy (
 
        /* write commands for the accumulated diffs for all our modified playlists */
        add_stateful_diff_commands_for_playlists (modified_playlists);
-
+       /* applies to _brushing */
        _editor->commit_reversible_command ();
 
        /* We have futzed with the layering of canvas items on our streamviews.
@@ -2314,6 +2332,9 @@ RegionCreateDrag::aborted (bool)
 NoteResizeDrag::NoteResizeDrag (Editor* e, ArdourCanvas::Item* i)
        : Drag (e, i)
        , region (0)
+       , relative (false)
+       , at_front (true)
+       , _snap_delta (0)
 {
        DEBUG_TRACE (DEBUG::Drags, "New NoteResizeDrag\n");
 }
@@ -2338,64 +2359,114 @@ NoteResizeDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*ignored*/)
 
        region = &cnote->region_view();
 
+       double temp;
+       temp = region->snap_to_pixel (cnote->x0 (), true);
+       _snap_delta = temp - cnote->x0 ();
+
        _item->grab ();
 
-       if (event->motion.state & Keyboard::PrimaryModifier) {
+       if (event->motion.state & ArdourKeyboard::note_size_relative_modifier ()) {
                relative = false;
        } else {
                relative = true;
        }
-
        MidiRegionSelection& ms (_editor->get_selection().midi_regions);
-
        if (ms.size() > 1) {
                /* has to be relative, may make no sense otherwise */
                relative = true;
        }
-
        /* select this note; if it is already selected, preserve the existing selection,
           otherwise make this note the only one selected.
        */
        region->note_selected (cnote, cnote->selected ());
-
-       _editor->begin_reversible_command (_("resize notes"));
-
-       for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ) {
-               MidiRegionSelection::iterator next;
-               next = r;
-               ++next;
-               MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(*r);
-               if (mrv) {
-                       mrv->begin_resizing (at_front);
-               }
-               r = next;
-       }
 }
 
 void
-NoteResizeDrag::motion (GdkEvent* /*event*/, bool /*first_move*/)
+NoteResizeDrag::motion (GdkEvent* event, bool first_move)
 {
        MidiRegionSelection& ms (_editor->get_selection().midi_regions);
+       if (first_move) {
+               _editor->begin_reversible_command (_("resize notes"));
+
+               for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ) {
+                       MidiRegionSelection::iterator next;
+                       next = r;
+                       ++next;
+                       MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(*r);
+                       if (mrv) {
+                               mrv->begin_resizing (at_front);
+                       }
+                       r = next;
+               }
+       }
+
        for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ++r) {
                NoteBase* nb = reinterpret_cast<NoteBase*> (_item->get_data ("notebase"));
                assert (nb);
                MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(*r);
                if (mrv) {
-                       mrv->update_resizing (nb, at_front, _drags->current_pointer_x() - grab_x(), relative);
+                       double sd = 0.0;
+                       bool snap = true;
+                       bool apply_snap_delta = ArdourKeyboard::indicates_snap_delta (event->button.state);
+
+                       if (ArdourKeyboard::indicates_snap (event->button.state)) {
+                               if (_editor->snap_mode () != SnapOff) {
+                                       snap = false;
+                               }
+                       } else {
+                               if (_editor->snap_mode () == SnapOff) {
+                                       snap = false;
+                                       /* inverted logic here - we;re in snapoff but we've pressed the snap delta modifier */
+                                       if (apply_snap_delta) {
+                                               snap = true;
+                                       }
+                               }
+                       }
+
+                       if (apply_snap_delta) {
+                               sd = _snap_delta;
+                       }
+
+                       mrv->update_resizing (nb, at_front, _drags->current_pointer_x() - grab_x(), relative, sd, snap);
                }
        }
 }
 
 void
-NoteResizeDrag::finished (GdkEvent*, bool /*movement_occurred*/)
+NoteResizeDrag::finished (GdkEvent* event, bool movement_occurred)
 {
+       if (!movement_occurred) {
+               return;
+       }
+
        MidiRegionSelection& ms (_editor->get_selection().midi_regions);
        for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ++r) {
                NoteBase* nb = reinterpret_cast<NoteBase*> (_item->get_data ("notebase"));
                assert (nb);
                MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(*r);
+               double sd = 0.0;
+               bool snap = true;
+               bool apply_snap_delta = ArdourKeyboard::indicates_snap_delta (event->button.state);
                if (mrv) {
-                       mrv->commit_resizing (nb, at_front, _drags->current_pointer_x() - grab_x(), relative);
+                       if (ArdourKeyboard::indicates_snap (event->button.state)) {
+                               if (_editor->snap_mode () != SnapOff) {
+                                       snap = false;
+                               }
+                       } else {
+                               if (_editor->snap_mode () == SnapOff) {
+                                       snap = false;
+                                       /* inverted logic here - we;re in snapoff but we've pressed the snap delta modifier */
+                                       if (apply_snap_delta) {
+                                               snap = true;
+                                       }
+                               }
+                       }
+
+                       if (apply_snap_delta) {
+                               sd = _snap_delta;
+                       }
+
+                       mrv->commit_resizing (nb, at_front, _drags->current_pointer_x() - grab_x(), relative, sd, snap);
                }
        }
 
@@ -2593,8 +2664,9 @@ TrimDrag::start_grab (GdkEvent* event, Gdk::Cursor*)
        framecnt_t const region_length = (framecnt_t) (_primary->region()->length() / speed);
 
        framepos_t const pf = adjusted_current_frame (event);
+       setup_snap_delta (region_start);
 
-       if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
+       if (Keyboard::modifier_state_equals (event->button.state, ArdourKeyboard::trim_contents_modifier ())) {
                /* Move the contents of the region around without changing the region bounds */
                _operation = ContentsTrim;
                Drag::start_grab (event, _editor->cursors()->trimmer);
@@ -2603,8 +2675,7 @@ TrimDrag::start_grab (GdkEvent* event, Gdk::Cursor*)
                if (pf < (region_start + region_length/2)) {
                        /* closer to front */
                        _operation = StartTrim;
-
-                       if (Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
+                       if (Keyboard::modifier_state_equals (event->button.state, ArdourKeyboard::trim_anchored_modifier ())) {
                                Drag::start_grab (event, _editor->cursors()->anchored_left_side_trim);
                        } else {
                                Drag::start_grab (event, _editor->cursors()->left_side_trim);
@@ -2612,17 +2683,18 @@ TrimDrag::start_grab (GdkEvent* event, Gdk::Cursor*)
                } else {
                        /* closer to end */
                        _operation = EndTrim;
-                       if (Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
+                       if (Keyboard::modifier_state_equals (event->button.state, ArdourKeyboard::trim_anchored_modifier ())) {
                                Drag::start_grab (event, _editor->cursors()->anchored_right_side_trim);
                        } else {
                                Drag::start_grab (event, _editor->cursors()->right_side_trim);
                        }
                }
        }
-
-       if (Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
+       /* jump trim disabled for now
+       if (Keyboard::modifier_state_equals (event->button.state, Keyboard::trim_jump_modifier ())) {
                _jump_position_when_done = true;
        }
+       */
 
        switch (_operation) {
        case StartTrim:
@@ -2632,7 +2704,7 @@ TrimDrag::start_grab (GdkEvent* event, Gdk::Cursor*)
                }
                break;
        case EndTrim:
-               show_verbose_cursor_time (region_end);
+               show_verbose_cursor_duration (region_start, region_end);
                break;
        case ContentsTrim:
                show_verbose_cursor_time (pf);
@@ -2658,8 +2730,8 @@ TrimDrag::motion (GdkEvent* event, bool first_move)
        if (tv && tv->is_track()) {
                speed = tv->track()->speed();
        }
-
-       framecnt_t dt = adjusted_current_frame (event) - raw_grab_frame () + _pointer_frame_offset;
+       framecnt_t adj_frame = adjusted_frame (_drags->current_pointer_frame () + snap_delta (event->button.state), event, true);
+       framecnt_t dt = adj_frame - raw_grab_frame () + _pointer_frame_offset - snap_delta (event->button.state);
 
        if (first_move) {
 
@@ -2705,7 +2777,7 @@ TrimDrag::motion (GdkEvent* event, bool first_move)
 
        bool non_overlap_trim = false;
 
-       if (event && Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
+       if (event && Keyboard::modifier_state_contains (event->button.state, ArdourKeyboard::trim_overlap_modifier ())) {
                non_overlap_trim = true;
        }
 
@@ -2791,7 +2863,7 @@ TrimDrag::motion (GdkEvent* event, bool first_move)
                show_verbose_cursor_time ((framepos_t) (rv->region()->position() / speed));
                break;
        case EndTrim:
-               show_verbose_cursor_time ((framepos_t) (rv->region()->last_frame() / speed));
+               show_verbose_cursor_duration ((framepos_t)  rv->region()->position() / speed, (framepos_t) rv->region()->last_frame() / speed);
                break;
        case ContentsTrim:
                // show_verbose_cursor_time (frame_delta);
@@ -2799,7 +2871,6 @@ TrimDrag::motion (GdkEvent* event, bool first_move)
        }
 }
 
-
 void
 TrimDrag::finished (GdkEvent* event, bool movement_occurred)
 {
@@ -3243,10 +3314,11 @@ void
 CursorDrag::start_grab (GdkEvent* event, Gdk::Cursor* c)
 {
        Drag::start_grab (event, c);
+       setup_snap_delta (_editor->playhead_cursor->current_frame ());
 
        _grab_zoom = _editor->samples_per_pixel;
 
-       framepos_t where = _editor->canvas_event_sample (event);
+       framepos_t where = _editor->canvas_event_sample (event) + snap_delta (event->button.state);
 
        _editor->snap_to_with_modifier (where, event);
 
@@ -3284,15 +3356,16 @@ CursorDrag::start_grab (GdkEvent* event, Gdk::Cursor* c)
                }
        }
 
-       fake_locate (where);
+       fake_locate (where - snap_delta (event->button.state));
 }
 
 void
 CursorDrag::motion (GdkEvent* event, bool)
 {
-       framepos_t const adjusted_frame = adjusted_current_frame (event);
-       if (adjusted_frame != last_pointer_frame()) {
-               fake_locate (adjusted_frame);
+       framepos_t where = _editor->canvas_event_sample (event) + snap_delta (event->button.state);
+       _editor->snap_to_with_modifier (where, event);
+       if (where != last_pointer_frame()) {
+               fake_locate (where - snap_delta (event->button.state));
        }
 }
 
@@ -3343,6 +3416,7 @@ FadeInDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
 
        AudioRegionView* arv = dynamic_cast<AudioRegionView*> (_primary);
        boost::shared_ptr<AudioRegion> const r = arv->audio_region ();
+       setup_snap_delta (r->position ());
 
        show_verbose_cursor_duration (r->position(), r->position() + r->fade_in()->back()->when, 32);
 }
@@ -3359,7 +3433,11 @@ void
 FadeInDrag::motion (GdkEvent* event, bool)
 {
        framecnt_t fade_length;
-       framepos_t const pos = adjusted_current_frame (event);
+
+       framepos_t pos = _editor->canvas_event_sample (event) + snap_delta (event->button.state);
+       _editor->snap_to_with_modifier (pos, event);
+       pos -= snap_delta (event->button.state);
+
        boost::shared_ptr<AudioRegion> region = boost::dynamic_pointer_cast<AudioRegion> (_primary->region ());
 
        if (pos < (region->position() + 64)) {
@@ -3392,8 +3470,9 @@ FadeInDrag::finished (GdkEvent* event, bool movement_occurred)
        }
 
        framecnt_t fade_length;
-
-       framepos_t const pos = adjusted_current_frame (event);
+       framepos_t pos = _editor->canvas_event_sample (event) + snap_delta (event->button.state);
+       _editor->snap_to_with_modifier (pos, event);
+       pos -= snap_delta (event->button.state);
 
        boost::shared_ptr<AudioRegion> region = boost::dynamic_pointer_cast<AudioRegion> (_primary->region ());
 
@@ -3405,7 +3484,7 @@ FadeInDrag::finished (GdkEvent* event, bool movement_occurred)
                fade_length = pos - region->position();
        }
 
-       _editor->begin_reversible_command (_("change fade in length"));
+       bool in_command = false;
 
        for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
 
@@ -3421,11 +3500,17 @@ FadeInDrag::finished (GdkEvent* event, bool movement_occurred)
                tmp->audio_region()->set_fade_in_length (fade_length);
                tmp->audio_region()->set_fade_in_active (true);
 
+               if (!in_command) {
+                       _editor->begin_reversible_command (_("change fade in length"));
+                       in_command = true;
+               }
                XMLNode &after = alist->get_state();
                _editor->session()->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &after));
        }
 
-       _editor->commit_reversible_command ();
+       if (in_command) {
+               _editor->commit_reversible_command ();
+       }
 }
 
 void
@@ -3455,6 +3540,7 @@ FadeOutDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
 
        AudioRegionView* arv = dynamic_cast<AudioRegionView*> (_primary);
        boost::shared_ptr<AudioRegion> r = arv->audio_region ();
+       setup_snap_delta (r->last_frame ());
 
        show_verbose_cursor_duration (r->last_frame() - r->fade_out()->back()->when, r->last_frame());
 }
@@ -3472,7 +3558,9 @@ FadeOutDrag::motion (GdkEvent* event, bool)
 {
        framecnt_t fade_length;
 
-       framepos_t const pos = adjusted_current_frame (event);
+       framepos_t pos = _editor->canvas_event_sample (event) + snap_delta (event->button.state);
+       _editor->snap_to_with_modifier (pos, event);
+       pos -= snap_delta (event->button.state);
 
        boost::shared_ptr<AudioRegion> region = boost::dynamic_pointer_cast<AudioRegion> (_primary->region ());
 
@@ -3507,7 +3595,9 @@ FadeOutDrag::finished (GdkEvent* event, bool movement_occurred)
 
        framecnt_t fade_length;
 
-       framepos_t const pos = adjusted_current_frame (event);
+       framepos_t pos = _editor->canvas_event_sample (event) + snap_delta (event->button.state);
+       _editor->snap_to_with_modifier (pos, event);
+       pos -= snap_delta (event->button.state);
 
        boost::shared_ptr<AudioRegion> region = boost::dynamic_pointer_cast<AudioRegion> (_primary->region ());
 
@@ -3519,7 +3609,7 @@ FadeOutDrag::finished (GdkEvent* event, bool movement_occurred)
                fade_length = region->last_frame() - pos;
        }
 
-       _editor->begin_reversible_command (_("change fade out length"));
+       bool in_command = false;
 
        for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
 
@@ -3535,11 +3625,17 @@ FadeOutDrag::finished (GdkEvent* event, bool movement_occurred)
                tmp->audio_region()->set_fade_out_length (fade_length);
                tmp->audio_region()->set_fade_out_active (true);
 
+               if (!in_command) {
+                       _editor->begin_reversible_command (_("change fade out length"));
+                       in_command = false;
+               }
                XMLNode &after = alist->get_state();
                _editor->session()->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &after));
        }
 
-       _editor->commit_reversible_command ();
+       if (in_command) {
+               _editor->commit_reversible_command ();
+       }
 }
 
 void
@@ -3561,7 +3657,7 @@ MarkerDrag::MarkerDrag (Editor* e, ArdourCanvas::Item* i)
 {
        DEBUG_TRACE (DEBUG::Drags, "New MarkerDrag\n");
 
-       _marker = reinterpret_cast<Marker*> (_item->get_data ("marker"));
+       _marker = reinterpret_cast<ArdourMarker*> (_item->get_data ("marker"));
        assert (_marker);
 
        _points.push_back (ArdourCanvas::Duple (0, 0));
@@ -3575,7 +3671,7 @@ MarkerDrag::~MarkerDrag ()
        }
 }
 
-MarkerDrag::CopiedLocationMarkerInfo::CopiedLocationMarkerInfo (Location* l, Marker* m)
+MarkerDrag::CopiedLocationMarkerInfo::CopiedLocationMarkerInfo (Location* l, ArdourMarker* m)
 {
        location = new Location (*l);
        markers.push_back (m);
@@ -3617,7 +3713,7 @@ MarkerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
        case Selection::Extend:
        {
                Locations::LocationList ll;
-               list<Marker*> to_add;
+               list<ArdourMarker*> to_add;
                framepos_t s, e;
                _editor->selection->markers.range (s, e);
                s = min (_marker->position(), s);
@@ -3703,7 +3799,7 @@ MarkerDrag::motion (GdkEvent* event, bool)
        framepos_t const newframe = adjusted_current_frame (event);
        framepos_t next = newframe;
 
-       if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
+       if (Keyboard::modifier_state_contains (event->button.state, ArdourKeyboard::push_points_modifier ())) {
                move_both = true;
        }
 
@@ -3732,17 +3828,17 @@ MarkerDrag::motion (GdkEvent* event, bool)
 
 
                                switch (_marker->type()) {
-                               case Marker::SessionStart:
-                               case Marker::RangeStart:
-                               case Marker::LoopStart:
-                               case Marker::PunchIn:
+                               case ArdourMarker::SessionStart:
+                               case ArdourMarker::RangeStart:
+                               case ArdourMarker::LoopStart:
+                               case ArdourMarker::PunchIn:
                                        f_delta = newframe - copy_location->start();
                                        break;
 
-                               case Marker::SessionEnd:
-                               case Marker::RangeEnd:
-                               case Marker::LoopEnd:
-                               case Marker::PunchOut:
+                               case ArdourMarker::SessionEnd:
+                               case ArdourMarker::RangeEnd:
+                               case ArdourMarker::LoopEnd:
+                               case ArdourMarker::PunchOut:
                                        f_delta = newframe - copy_location->end();
                                        break;
                                default:
@@ -3873,8 +3969,8 @@ MarkerDrag::finished (GdkEvent* event, bool movement_occurred)
 
        _editor->_dragging_edit_point = false;
 
-       _editor->begin_reversible_command ( _("move marker") );
        XMLNode &before = _editor->session()->locations()->get_state();
+       bool in_command = false;
 
        MarkerSelection::iterator i;
        CopiedLocationInfo::iterator x;
@@ -3889,9 +3985,12 @@ MarkerDrag::finished (GdkEvent* event, bool movement_occurred)
                if (location) {
 
                        if (location->locked()) {
-                               return;
+                               continue;
+                       }
+                       if (!in_command) {
+                               _editor->begin_reversible_command ( _("move marker") );
+                               in_command = true;
                        }
-
                        if (location->is_mark()) {
                                location->set_start (((*x).location)->start());
                        } else {
@@ -3900,9 +3999,11 @@ MarkerDrag::finished (GdkEvent* event, bool movement_occurred)
                }
        }
 
-       XMLNode &after = _editor->session()->locations()->get_state();
-       _editor->session()->add_command(new MementoCommand<Locations>(*(_editor->session()->locations()), &before, &after));
-       _editor->commit_reversible_command ();
+       if (in_command) {
+               XMLNode &after = _editor->session()->locations()->get_state();
+               _editor->session()->add_command(new MementoCommand<Locations>(*(_editor->session()->locations()), &before, &after));
+               _editor->commit_reversible_command ();
+       }
 }
 
 void
@@ -3917,7 +4018,7 @@ MarkerDrag::aborted (bool movement_occured)
                /* move all markers to their original location */
 
 
-               for (vector<Marker*>::iterator m = x->markers.begin(); m != x->markers.end(); ++m) {
+               for (vector<ArdourMarker*>::iterator m = x->markers.begin(); m != x->markers.end(); ++m) {
 
                        bool is_start;
                        Location * location = _editor->find_location_from_marker (*m, is_start);
@@ -3961,13 +4062,13 @@ ControlPointDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*cursor*/)
        _fixed_grab_x = _point->get_x();
        _fixed_grab_y = _point->get_y();
 
-       float const fraction = 1 - (_point->get_y() / _point->line().height());
-
-       _point->line().start_drag_single (_point, _fixed_grab_x, fraction);
+       framepos_t pos = _editor->pixel_to_sample (_fixed_grab_x);
+       setup_snap_delta (pos);
 
+       float const fraction = 1 - (_point->get_y() / _point->line().height());
        show_verbose_cursor_text (_point->line().get_verbose_cursor_string (fraction));
 
-       _pushing = Keyboard::modifier_state_contains (event->button.state, Keyboard::PrimaryModifier);
+       _pushing = Keyboard::modifier_state_equals (event->button.state, ArdourKeyboard::push_points_modifier ());
 
        if (!_point->can_slide ()) {
                _x_constrained = true;
@@ -3975,12 +4076,12 @@ ControlPointDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*cursor*/)
 }
 
 void
-ControlPointDrag::motion (GdkEvent* event, bool)
+ControlPointDrag::motion (GdkEvent* event, bool first_motion)
 {
        double dx = _drags->current_pointer_x() - last_pointer_x();
        double dy = current_pointer_y() - last_pointer_y();
 
-       if (event->button.state & Keyboard::SecondaryModifier) {
+       if (event->button.state & ArdourKeyboard::fine_adjust_modifier ()) {
                dx *= 0.1;
                dy *= 0.1;
        }
@@ -3994,11 +4095,6 @@ ControlPointDrag::motion (GdkEvent* event, bool)
        // positive side of zero
        double const zero_gain_y = (1.0 - _zero_gain_fraction) * _point->line().height() - .01;
 
-       // make sure we hit zero when passing through
-       if ((cy < zero_gain_y && (cy - dy) > zero_gain_y) || (cy > zero_gain_y && (cy - dy) < zero_gain_y)) {
-               cy = zero_gain_y;
-       }
-
        if (_x_constrained) {
                cx = _fixed_grab_x;
        }
@@ -4009,20 +4105,31 @@ ControlPointDrag::motion (GdkEvent* event, bool)
        _cumulative_x_drag = cx - _fixed_grab_x;
        _cumulative_y_drag = cy - _fixed_grab_y;
 
+       // make sure we hit zero when passing through
+       if ((cy < zero_gain_y && (cy - dy) > zero_gain_y) || (cy > zero_gain_y && (cy - dy) < zero_gain_y)) {
+               cy = zero_gain_y;
+       }
+
        cx = max (0.0, cx);
        cy = max (0.0, cy);
        cy = min ((double) _point->line().height(), cy);
 
-       framepos_t cx_frames = _editor->pixel_to_sample (cx);
+       framepos_t cx_frames = _editor->pixel_to_sample (cx) + snap_delta (event->button.state);
 
        if (!_x_constrained) {
                _editor->snap_to_with_modifier (cx_frames, event);
        }
 
+       cx_frames -= snap_delta (event->button.state);
        cx_frames = min (cx_frames, _point->line().maximum_time());
 
        float const fraction = 1.0 - (cy / _point->line().height());
 
+       if (first_motion) {
+               _editor->begin_reversible_command (_("automation event move"));
+               _point->line().start_drag_single (_point, _fixed_grab_x, fraction);
+       }
+
        _point->line().drag_motion (_editor->sample_to_pixel_unrounded (cx_frames), fraction, false, _pushing, _final_index);
 
        show_verbose_cursor_text (_point->line().get_verbose_cursor_string (fraction));
@@ -4034,17 +4141,15 @@ ControlPointDrag::finished (GdkEvent* event, bool movement_occurred)
        if (!movement_occurred) {
 
                /* just a click */
-
-               if (Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
+               if (Keyboard::modifier_state_equals (event->button.state, Keyboard::ModifierMask (Keyboard::TertiaryModifier))) {
                        _editor->reset_point_selection ();
                }
 
        } else {
                motion (event, false);
+               _point->line().end_drag (_pushing, _final_index);
+               _editor->commit_reversible_command ();
        }
-
-       _point->line().end_drag (_pushing, _final_index);
-       _editor->commit_reversible_command ();
 }
 
 void
@@ -4066,9 +4171,11 @@ ControlPointDrag::active (Editing::MouseMode m)
 }
 
 LineDrag::LineDrag (Editor* e, ArdourCanvas::Item* i)
-       : Drag (e, i),
-         _line (0),
-         _cumulative_y_drag (0)
+       : Drag (e, i)
+       , _line (0)
+       , _cumulative_y_drag (0)
+       , _before (0)
+       , _after (0)
 {
        DEBUG_TRACE (DEBUG::Drags, "New LineDrag\n");
 }
@@ -4092,10 +4199,7 @@ LineDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*cursor*/)
 
        framecnt_t const frame_within_region = (framecnt_t) floor (cx * _editor->samples_per_pixel);
 
-       uint32_t before;
-       uint32_t after;
-
-       if (!_line->control_points_adjacent (frame_within_region, before, after)) {
+       if (!_line->control_points_adjacent (frame_within_region, _before, _after)) {
                /* no adjacent points */
                return;
        }
@@ -4109,17 +4213,15 @@ LineDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*cursor*/)
 
        double fraction = 1.0 - (cy / _line->height());
 
-       _line->start_drag_line (before, after, fraction);
-
        show_verbose_cursor_text (_line->get_verbose_cursor_string (fraction));
 }
 
 void
-LineDrag::motion (GdkEvent* event, bool)
+LineDrag::motion (GdkEvent* event, bool first_move)
 {
        double dy = current_pointer_y() - last_pointer_y();
 
-       if (event->button.state & Keyboard::SecondaryModifier) {
+       if (event->button.state & ArdourKeyboard::fine_adjust_modifier ()) {
                dy *= 0.1;
        }
 
@@ -4133,6 +4235,11 @@ LineDrag::motion (GdkEvent* event, bool)
        double const fraction = 1.0 - (cy / _line->height());
        uint32_t ignored;
 
+       if (first_move) {
+               _editor->begin_reversible_command (_("automation range move"));
+               _line->start_drag_line (_before, _after, fraction);
+       }
+
        /* we are ignoring x position for this drag, so we can just pass in anything */
        _line->drag_motion (0, fraction, true, false, ignored);
 
@@ -4145,20 +4252,17 @@ LineDrag::finished (GdkEvent* event, bool movement_occured)
        if (movement_occured) {
                motion (event, false);
                _line->end_drag (false, 0);
+               _editor->commit_reversible_command ();
        } else {
                /* add a new control point on the line */
 
                AutomationTimeAxisView* atv;
 
-               _line->end_drag (false, 0);
-
                if ((atv = dynamic_cast<AutomationTimeAxisView*>(_editor->clicked_axisview)) != 0) {
                        framepos_t where = _editor->window_event_sample (event, 0, 0);
                        atv->add_automation_event (event, where, event->button.y, false);
                }
        }
-
-       _editor->commit_reversible_command ();
 }
 
 void
@@ -4428,7 +4532,12 @@ TimeFXDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
 {
        Drag::start_grab (event, cursor);
 
-       show_verbose_cursor_time (adjusted_current_frame (event));
+       _editor->get_selection().add (_primary);
+
+       framepos_t where = _primary->region()->position();
+       setup_snap_delta (where);
+
+       show_verbose_cursor_duration (where, adjusted_current_frame (event), 0);
 }
 
 void
@@ -4440,14 +4549,15 @@ TimeFXDrag::motion (GdkEvent* event, bool)
        pair<TimeAxisView*, double> const tv = _editor->trackview_by_y_position (grab_y());
        int layer = tv.first->layer_display() == Overlaid ? 0 : tv.second;
        int layers = tv.first->layer_display() == Overlaid ? 1 : cv->layers();
-
-       framepos_t const pf = adjusted_current_frame (event);
+       framepos_t pf = _editor->canvas_event_sample (event) + snap_delta (event->button.state);
+       _editor->snap_to_with_modifier (pf, event);
+       pf -= snap_delta (event->button.state);
 
        if (pf > rv->region()->position()) {
                rv->get_time_axis_view().show_timestretch (rv->region()->position(), pf, layers, layer);
        }
 
-       show_verbose_cursor_time (pf);
+       show_verbose_cursor_duration (_primary->region()->position(), pf, 0);
 }
 
 void
@@ -4805,7 +4915,7 @@ SelectionDrag::finished (GdkEvent* event, bool movement_occurred)
 
                /* XXX what if its a music time selection? */
                if (s) {
-                       if ( s->get_play_range() && s->transport_rolling() ) {
+                       if (s->get_play_range() && s->transport_rolling()) {
                                s->request_play_range (&_editor->selection->time, true);
                        } else {
                                if (ARDOUR_UI::config()->get_follow_edits() && !s->transport_rolling()) {
@@ -4815,8 +4925,14 @@ SelectionDrag::finished (GdkEvent* event, bool movement_occurred)
                                                s->request_locate (_editor->get_selection().time.start());
                                }
                        }
-               }
 
+                       if (_editor->get_selection().time.length() != 0) {
+                               s->set_range_selection (_editor->get_selection().time.start(), _editor->get_selection().time.end_frame());
+                       } else {
+                               s->clear_range_selection ();
+                       }
+               }
+               
        } else {
                /* just a click, no pointer movement.
                 */
@@ -4905,7 +5021,7 @@ RangeMarkerBarDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
        case CreateTransportMarker:
        case CreateCDMarker:
 
-               if (Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
+               if (Keyboard::modifier_state_equals (event->button.state, Keyboard::CopyModifier)) {
                        _copy = true;
                } else {
                        _copy = false;
@@ -5126,6 +5242,7 @@ void
 NoteDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
 {
        Drag::start_grab (event);
+       setup_snap_delta (_region->source_beats_to_absolute_frames (_primary->note()->time ()));
 
        if (!(_was_selected = _primary->selected())) {
 
@@ -5153,7 +5270,7 @@ NoteDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
 
 /** @return Current total drag x change in frames */
 frameoffset_t
-NoteDrag::total_dx () const
+NoteDrag::total_dx (const guint state) const
 {
        /* dx in frames */
        frameoffset_t const dx = _editor->pixel_to_sample (_drags->current_pointer_x() - grab_x());
@@ -5162,15 +5279,38 @@ NoteDrag::total_dx () const
        frameoffset_t const n = _region->source_beats_to_absolute_frames (_primary->note()->time ());
 
        /* new time of the primary note in session frames */
-       frameoffset_t st = n + dx;
+       frameoffset_t st = n + dx + snap_delta (state);
 
        framepos_t const rp = _region->region()->position ();
 
        /* prevent the note being dragged earlier than the region's position */
        st = max (st, rp);
 
-       /* snap and return corresponding delta */
-       return _region->snap_frame_to_frame (st - rp) + rp - n;
+       /* possibly snap and return corresponding delta */
+
+       bool snap = true;
+
+       if (ArdourKeyboard::indicates_snap (state)) {
+               if (_editor->snap_mode () != SnapOff) {
+                       snap = false;
+               }
+       } else {
+               if (_editor->snap_mode () == SnapOff) {
+                       snap = false;
+                       /* inverted logic here - we;re in snapoff but we've pressed the snap delta modifier */
+                       if (ArdourKeyboard::indicates_snap_delta (state)) {
+                               snap = true;
+                       }
+               }
+       }
+
+       frameoffset_t ret;
+       if (snap) {
+               ret =  _region->snap_frame_to_frame (st - rp) + rp - n - snap_delta (state);
+       } else {
+               ret = st - n - snap_delta (state);
+       }
+       return ret;
 }
 
 /** @return Current total drag y change in note number */
@@ -5189,10 +5329,10 @@ NoteDrag::total_dy () const
 }
 
 void
-NoteDrag::motion (GdkEvent *, bool)
+NoteDrag::motion (GdkEvent * event, bool)
 {
        /* Total change in x and y since the start of the drag */
-       frameoffset_t const dx = total_dx ();
+       frameoffset_t const dx = total_dx (event->button.state);
        int8_t const dy = total_dy ();
 
        /* Now work out what we have to do to the note canvas items to set this new drag delta */
@@ -5261,7 +5401,7 @@ NoteDrag::finished (GdkEvent* ev, bool moved)
                        }
                }
        } else {
-               _region->note_dropped (_primary, total_dx(), total_dy());
+               _region->note_dropped (_primary, total_dx (ev->button.state), total_dy());
        }
 }
 
@@ -5407,8 +5547,8 @@ AutomationRangeDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
                                double const p = j->line->time_converter().from (i->start - j->line->time_converter().origin_b ());
                                double const q = j->line->time_converter().from (a - j->line->time_converter().origin_b ());
 
-                               the_list->editor_add (p, value (the_list, p));
-                               the_list->editor_add (q, value (the_list, q));
+                               the_list->editor_add (p, value (the_list, p), false);
+                               the_list->editor_add (q, value (the_list, q), false);
                        }
 
                        /* same thing for the end */
@@ -5433,8 +5573,8 @@ AutomationRangeDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
                                double const p = j->line->time_converter().from (b - j->line->time_converter().origin_b ());
                                double const q = j->line->time_converter().from (i->end - j->line->time_converter().origin_b ());
 
-                               the_list->editor_add (p, value (the_list, p));
-                               the_list->editor_add (q, value (the_list, q));
+                               the_list->editor_add (p, value (the_list, p), false);
+                               the_list->editor_add (q, value (the_list, q), false);
                        }
                }
 
@@ -5471,19 +5611,22 @@ AutomationRangeDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
        if (_nothing_to_drag) {
                return;
        }
-
-       for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
-               i->line->start_drag_multiple (i->points, y_fraction (i->line, current_pointer_y()), i->state);
-       }
 }
 
 void
-AutomationRangeDrag::motion (GdkEvent*, bool /*first_move*/)
+AutomationRangeDrag::motion (GdkEvent*, bool first_move)
 {
        if (_nothing_to_drag) {
                return;
        }
 
+       if (first_move) {
+               _editor->begin_reversible_command (_("automation range move"));
+               for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
+                       i->line->start_drag_multiple (i->points, y_fraction (i->line, current_pointer_y()), i->state);
+               }
+       }
+
        for (list<Line>::iterator l = _lines.begin(); l != _lines.end(); ++l) {
                float const f = y_fraction (l->line, current_pointer_y());
                /* we are ignoring x position for this drag, so we can just pass in anything */
@@ -5494,9 +5637,9 @@ AutomationRangeDrag::motion (GdkEvent*, bool /*first_move*/)
 }
 
 void
-AutomationRangeDrag::finished (GdkEvent* event, bool)
+AutomationRangeDrag::finished (GdkEvent* event, bool motion_occurred)
 {
-       if (_nothing_to_drag) {
+       if (_nothing_to_drag || !motion_occurred) {
                return;
        }