Revert to old Lock mode (still called Lock).
[ardour.git] / gtk2_ardour / editor_drag.cc
index 30e89bdc7641485c2cd4c66257b77715374a20b7..0e75c48cdb1aa0cd882edf5065fd840f80232e58 100644 (file)
@@ -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)
 {
 
 }
@@ -250,20 +251,12 @@ 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 */
+       _x_constrained = false;
+       _y_constrained = false;
 
        _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 +336,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 (GdkEvent const * event) const
+{
+       if (Keyboard::modifier_state_equals (event->button.state, Keyboard::snap_delta_modifier())) {
+               return 0;
+       } else {
+               return _snap_delta;
+       }
+}
+
 double
 Drag::current_pointer_x() const
 {
@@ -359,6 +362,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_no_magnets (temp);
+       _snap_delta = temp - pos;
+}
+
 bool
 Drag::motion_handler (GdkEvent* event, bool from_autoscroll)
 {
@@ -390,10 +401,27 @@ Drag::motion_handler (GdkEvent* event, bool from_autoscroll)
                                /* just changed */
 
                                if (fabs (current_pointer_y() - _grab_y) > fabs (current_pointer_x() - _grab_x)) {
+                                       if ((event->motion.state & Gdk::BUTTON2_MASK) && Config->get_edit_mode() != Lock) {
+                                               _x_constrained = true;
+                                               _y_constrained = false;
+                                       }
                                        _initially_vertical = true;
                                } else {
+                                       if ((event->motion.state & Gdk::BUTTON2_MASK) && Config->get_edit_mode() != Lock) {
+                                               _x_constrained = false;
+                                               _y_constrained = true;
+                                       }
                                        _initially_vertical = false;
                                }
+
+                               if (Config->get_edit_mode() == Lock) {
+                                       if (event->button.state & Gdk::BUTTON2_MASK) {
+                                               _x_constrained = false;
+                                       } else {
+                                               _x_constrained = true;
+                                       }
+                                       _y_constrained = false;
+                               }
                        }
 
                        if (!from_autoscroll) {
@@ -485,8 +513,9 @@ struct EditorOrderTimeAxisViewSorter {
 };
 
 RegionDrag::RegionDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v)
-       : Drag (e, i),
-         _primary (p)
+       : Drag (e, i)
+       , _primary (p)
+       , _ntracks (0)
 {
        _editor->visible_order_range (&_visible_y_low, &_visible_y_high);
 
@@ -554,7 +583,9 @@ 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)
 {
        DEBUG_TRACE (DEBUG::Drags, "New RegionMotionDrag\n");
 }
@@ -563,10 +594,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);
 
@@ -584,7 +612,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), event, true);
 
        framepos_t sync_frame;
        framecnt_t sync_offset;
@@ -596,11 +624,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);
 
        } else {
                *pending_region_position = _last_frame_position;
@@ -612,8 +640,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) {
 
@@ -647,36 +674,23 @@ RegionDrag::apply_track_delta (const int start, const int delta, const int skip,
                return start;
        }
 
+       const int tavsize  = _time_axis_views.size();
        const int dt = delta > 0 ? +1 : -1;
-       int current = start;
-       int target  = start + delta - skip;
+       int current  = start;
+       int target   = start + delta - skip;
 
-       assert (current < 0 || current >= _time_axis_views.size() || !_time_axis_views[current]->hidden());
+       assert (current < 0 || current >= tavsize || !_time_axis_views[current]->hidden());
        assert (skip == 0 || (skip < 0 && delta < 0) || (skip > 0 && delta > 0));
 
-#ifdef DEBUG_DROPZONEDRAG
-       if (current >= _time_axis_views.size() && target >= 0 && target < _time_axis_views.size()) {
-               printf("MOVE OUT OF THE ZONE cur: %d  d: %d s: %d\n", start, delta, skip);
-       } else {
-               printf("CALC DISTANCE cur: %d  d: %d s: %d\n", start, delta, skip);
-       }
-#endif
-
        while (current >= 0 && current != target) {
                current += dt;
                if (current < 0 && dt < 0) {
-#ifdef DEBUG_DROPZONEDRAG
-                       printf("BREAK AT BOTTOM\n");
-#endif
                        break;
                }
-               if (current >= _time_axis_views.size() && dt > 0) {
-#ifdef DEBUG_DROPZONEDRAG
-                       printf("BREAK AT TOP\n");
-#endif
+               if (current >= tavsize && dt > 0) {
                        break;
                }
-               if (current < 0 || current >= _time_axis_views.size()) {
+               if (current < 0 || current >= tavsize) {
                        continue;
                }
 
@@ -686,9 +700,6 @@ RegionDrag::apply_track_delta (const int start, const int delta, const int skip,
                }
 
                if (distance_only && current == start + delta) {
-#ifdef DEBUG_DROPZONEDRAG
-                       printf("BREAK AFTER DISTANCE\n");
-#endif
                        break;
                }
        }
@@ -702,33 +713,24 @@ RegionMotionDrag::y_movement_allowed (int delta_track, double delta_layer, int s
                return false;
        }
 
+       const int tavsize  = _time_axis_views.size();
        for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
                int n = apply_track_delta (i->time_axis_view, delta_track, skip_invisible);
-#ifdef DEBUG_DROPZONEDRAG
-               printf("Y MOVEMENT CHECK: from %d to %d skip: %d\n",
-                               i->time_axis_view, i->time_axis_view + delta_track,
-                               skip_invisible);
-#endif
-               assert (n < 0 || n >= _time_axis_views.size() || !_time_axis_views[n]->hidden());
+               assert (n < 0 || n >= tavsize || !_time_axis_views[n]->hidden());
 
-               if (i->time_axis_view < 0 || i->time_axis_view >= _time_axis_views.size()) {
+               if (i->time_axis_view < 0 || i->time_axis_view >= tavsize) {
                        /* already in the drop zone */
                        if (delta_track >= 0) {
-                               /* downward motion - might be OK if others are still not in the dropzone,
-                                  so check at the end of the loop if that is the case.
-                                */
+                               /* downward motion - OK if others are still not in the dropzone */
                                continue;
                        }
 
-                       /* upward motion - set n to the track we would end up in if motion
-                          is successful, and check validity below. */
-                       n = _time_axis_views.size() + delta_track;
                }
 
                if (n < 0) {
                        /* off the top */
                        return false;
-               } else if (n >= int (_time_axis_views.size())) {
+               } else if (n >= tavsize) {
                        /* downward motion into drop zone. That's fine. */
                        continue;
                }
@@ -771,27 +773,10 @@ 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;
-                       }
-               }
-       }
-
-#ifdef DEBUG_DROPZONEDRAG
-       printf("--------- LAST AXIS: %d\n", _last_pointer_time_axis_view);
-#endif
        /* 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 */
-
        const double cur_y = current_pointer_y ();
-
        pair<TimeAxisView*, double> const r = _editor->trackview_by_y_position (cur_y);
        TimeAxisView* tv = r.first;
 
@@ -800,7 +785,18 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
                return;
        }
 
+       /* find drop-zone y-position */
+       Coord last_track_bottom_edge;
+       last_track_bottom_edge = 0;
+       for (std::vector<TimeAxisView*>::reverse_iterator t = _time_axis_views.rbegin(); t != _time_axis_views.rend(); ++t) {
+               if (!(*t)->hidden()) {
+                       last_track_bottom_edge = (*t)->canvas_display()->canvas_origin ().y + (*t)->effective_height();
+                       break;
+               }
+       }
+
        if (tv && tv->view()) {
+               /* the mouse is over a track */
                double layer = r.second;
 
                if (first_move && tv->view()->layer_display() == Stacked) {
@@ -810,15 +806,15 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
                /* Here's the current pointer position in terms of time axis view and layer */
                current_pointer_time_axis_view = find_time_axis_view (tv);
                assert(current_pointer_time_axis_view >= 0);
-#ifdef DEBUG_DROPZONEDRAG
-               printf("            On AXIS: %d\n", current_pointer_time_axis_view);
-#endif
 
                double const current_pointer_layer = tv->layer_display() == Overlaid ? 0 : layer;
 
                /* Work out the change in y */
 
-               if (_last_pointer_time_axis_view < 0) {
+               RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (tv);
+               if (!rtv || !rtv->is_track()) {
+                       /* ignore busses early on. we can't move any regions on them */
+               } else if (_last_pointer_time_axis_view < 0) {
                        /* Was in the drop-zone, now over a track.
                         * Hence it must be an upward move (from the bottom)
                         *
@@ -826,12 +822,13 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
                         * move up the correct number of tracks from the bottom.
                         *
                         * This is necessary because steps may be skipped if
-                        * the bottom-most track is not a valid target,
+                        * the bottom-most track is not a valid target and/or
+                        * if there are hidden tracks at the bottom.
+                        * Hence the initial offset (_ddropzone) as well as the
+                        * last valid pointer position (_pdropzone) need to be
+                        * taken into account.
                         */
-#ifdef DEBUG_DROPZONEDRAG
-                       printf("MOVE OUT OF THE ZONE...\n");
-#endif
-                       delta_time_axis_view = current_pointer_time_axis_view - _time_axis_views.size ();
+                       delta_time_axis_view = current_pointer_time_axis_view - _time_axis_views.size () + _ddropzone - _pdropzone;
                } else {
                        delta_time_axis_view = current_pointer_time_axis_view - _last_pointer_time_axis_view;
                }
@@ -860,32 +857,44 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
                delta_layer = current_pointer_layer - _last_pointer_layer;
 
        }
-       /* for automation lanes, there is a TimeAxisView but no ->view() */
+       /* for automation lanes, there is a TimeAxisView but no ->view()
+        * if (!tv) -> dropzone 
+        */
        else if (!tv && cur_y >= 0 && _last_pointer_time_axis_view >= 0) {
-               /* Moving into the drop-zone..
-                *
-                * TODO allow moving further down in drop-zone:
-                * e.g. 2 Tracks, select a region on both of them.
-                *
-                * A) grab the upper, drag 2 down, both regions are in  the dropzone: all fine (works)
-                *
-                * B) grab the lower, drag 1 down, region (and mouse) are in dropzone, The End.
-                *    upper region is only down one track and cannot be moved into the zone.
-                *
-                * Proposed solution:
-                *  keep track of how many regions are in the DZ (private var),
-                *  also count from how many tracks the dragged-regions come from (first move)
-                *
-                *  if not all regions are in the DZ, keep going.
+               /* Moving into the drop-zone.. */
+               delta_time_axis_view = _time_axis_views.size () - _last_pointer_time_axis_view;
+               /* delta_time_axis_view may not be sufficient to move into the DZ
+                * the mouse may enter it, but it may not be a valid move due to
+                * constraints.
                 *
-                *  Using 'default height' H for all dropzone regions will make things
-                *  a lot simpler: (number_of_DZ_entries * H + Pointer_YPOS - DZ_YPOS) / H.
-                *  (because at this point in time PlaylistDropzoneMap is not yet populated)
+                * -> remember the delta needed to move into the dropzone
                 */
-               delta_time_axis_view = _time_axis_views.size () - _last_pointer_time_axis_view;
-#ifdef DEBUG_DROPZONEDRAG
-               printf("INTO THE ZONE DELTA: %d\n", delta_time_axis_view);
-#endif
+               _ddropzone = delta_time_axis_view;
+               /* ..but subtract hidden tracks (or routes) at the bottom.
+                * we silently move mover them
+                */
+               _ddropzone -= apply_track_delta(_last_pointer_time_axis_view, delta_time_axis_view, 0, true)
+                             - _time_axis_views.size();
+       }
+       else if (!tv && cur_y >= 0 && _last_pointer_time_axis_view < 0) {
+               /* move around inside the zone.
+                * This allows to move further down until all regions are in the zone.
+                */
+               const double ptr_y = cur_y + _editor->get_trackview_group()->canvas_origin().y;
+               assert(ptr_y >= last_track_bottom_edge);
+               assert(_ddropzone > 0);
+
+               /* calculate mouse position in 'tracks' below last track. */
+               const double dzi_h = TimeAxisView::preset_height (HeightNormal);
+               uint32_t dzpos = _ddropzone + floor((1 + ptr_y - last_track_bottom_edge) / dzi_h);
+
+               if (dzpos > _pdropzone && _ndropzone < _ntracks) {
+                       // move further down
+                       delta_time_axis_view =  dzpos - _pdropzone;
+               } else if (dzpos < _pdropzone && _ndropzone > 0) {
+                       // move up inside the DZ
+                       delta_time_axis_view =  dzpos - _pdropzone;
+               }
        }
 
        /* Work out the change in x */
@@ -893,26 +902,37 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
        double const x_delta = compute_x_delta (event, &pending_region_position);
        _last_frame_position = pending_region_position;
 
-       /* calculate hidden tracks in current delta */
+       /* calculate hidden tracks in current y-axis delta */
        int delta_skip = 0;
-       if (_last_pointer_time_axis_view < 0) {
-               // Moving out of the zone, check for hidden tracks at the bottom.
+       if (_last_pointer_time_axis_view < 0 && _pdropzone > 0) {
+               /* The mouse is more than one track below the dropzone.
+                * distance calculation is not needed (and would not work, either
+                * because the dropzone is "packed").
+                *
+                * Except when [partially] moving regions out of dropzone in a large step.
+                * (the mouse may or may not remain in the DZ)
+                * Hidden tracks at the bottom of the TAV need to be skipped.
+                *
+                * This also handles the case if the mouse entered the DZ
+                * in a large step (exessive delta), either due to fast-movement,
+                * autoscroll, laggy UI. _ddropzone copensates for that (see "move into dz" above)
+                */
+               if (delta_time_axis_view < 0 && (int)_ddropzone - delta_time_axis_view >= (int)_pdropzone) {
+                       const int dt = delta_time_axis_view + (int)_pdropzone - (int)_ddropzone;
+                       assert(dt <= 0);
+                       delta_skip = apply_track_delta(_time_axis_views.size(), dt, 0, true)
+                               -_time_axis_views.size() - dt;
+               }
+       }
+       else if (_last_pointer_time_axis_view < 0) {
+               /* Moving out of the zone. Check for hidden tracks at the bottom. */
                delta_skip = apply_track_delta(_time_axis_views.size(), delta_time_axis_view, 0, true)
                             -_time_axis_views.size() - delta_time_axis_view;
-#ifdef DEBUG_DROPZONEDRAG
-               printf("NOW WHAT?? last: %d  delta %d || skip %d\n", _last_pointer_time_axis_view, delta_time_axis_view, delta_skip);
-#endif
        } else {
-               // calculate hidden tracks that are skipped by the pointer movement
+               /* calculate hidden tracks that are skipped by the pointer movement */
                delta_skip = apply_track_delta(_last_pointer_time_axis_view, delta_time_axis_view, 0, true)
                             - _last_pointer_time_axis_view
                             - delta_time_axis_view;
-#ifdef DEBUG_DROPZONEDRAG
-               printf("Drag from %d to %d || skip %d\n",
-                               _last_pointer_time_axis_view,
-                               _last_pointer_time_axis_view + delta_time_axis_view,
-                               delta_skip);
-#endif
        }
 
        /* Verify change in y */
@@ -921,9 +941,6 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
                delta_time_axis_view = 0;
                delta_layer = 0;
                delta_skip = 0;
-#ifdef DEBUG_DROPZONEDRAG
-               printf(" ** NOT ALLOWED\n");
-#endif
        }
 
        if (x_delta == 0 && (tv && tv->view() && delta_time_axis_view == 0) && delta_layer == 0 && !first_move) {
@@ -933,20 +950,9 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
                return;
        }
 
-       typedef pair<int,double> NewTrackIndexAndPosition;
-       typedef map<boost::shared_ptr<Playlist>,NewTrackIndexAndPosition> PlaylistDropzoneMap;
+       typedef map<boost::shared_ptr<Playlist>, double> PlaylistDropzoneMap;
        PlaylistDropzoneMap playlist_dropzone_map;
-       int biggest_drop_zone_offset = 0;
-
-       /* find drop-zone y-position */
-       Coord last_track_bottom_edge;
-       last_track_bottom_edge = 0;
-       for (std::vector<TimeAxisView*>::reverse_iterator t = _time_axis_views.rbegin(); t != _time_axis_views.rend(); ++t) {
-               if (!(*t)->hidden()) {
-                       last_track_bottom_edge = (*t)->canvas_display()->canvas_origin ().y + (*t)->effective_height();
-                       break;
-               }
-       }
+       _ndropzone = 0; // number of elements currently in the dropzone
 
        if (first_move) {
                /* sort views by time_axis.
@@ -954,6 +960,27 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
                 * of actual selection order
                 */
                _views.sort (DraggingViewSorter());
+
+               /* count number of distinct tracks of all regions
+                * being dragged, used for dropzone.
+                */
+               int prev_track = -1;
+               for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
+                       if (i->time_axis_view != prev_track) {
+                               prev_track = i->time_axis_view;
+                               ++_ntracks;
+                       }
+               }
+#ifndef NDEBUG
+               int spread =
+                       _views.back().time_axis_view -
+                       _views.front().time_axis_view;
+
+               spread -= apply_track_delta (_views.front().time_axis_view, spread, 0, true)
+                         -  _views.back().time_axis_view;
+
+               printf("Dragging region(s) from %d different track(s), max dist: %d\n", _ntracks, spread);
+#endif
        }
 
        for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
@@ -994,42 +1021,30 @@ 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);
 
                if (track_index < 0 || track_index >= (int) _time_axis_views.size()) {
+                       /* Track is in the Dropzone */
+
                        i->time_axis_view = track_index;
-#ifdef DEBUG_DROPZONEDRAG
-                       printf("IN THE ZONE\n");
-#endif
-                       assert(i->time_axis_view >= _time_axis_views.size());
+                       assert(i->time_axis_view >= (int) _time_axis_views.size());
                        if (cur_y >= 0) {
 
-                               int dzoffset;
-                               NewTrackIndexAndPosition ip;
+                               double yposition = 0;
                                PlaylistDropzoneMap::iterator pdz = playlist_dropzone_map.find (i->view->region()->playlist());
+                               rv->set_height (TimeAxisView::preset_height (HeightNormal));
+                               ++_ndropzone;
 
                                /* store index of each new playlist as a negative count, starting at -1 */
 
                                if (pdz == playlist_dropzone_map.end()) {
-
-                                       /* TODO
-                                        * retain the ordering top -> bottom in the drop-zone
-                                        * this can be done by sorting the regions according to
-                                        * i->time_axis_view Y, prior to iterating over DraggingView
-                                        */
-
-                                       int n = playlist_dropzone_map.size() + 1;
-
                                        /* compute where this new track (which doesn't exist yet) will live
                                           on the y-axis.
                                        */
-
-                                       ip.first = -n;  /* in time axis units, negative to signify "in drop zone " */
-                                       ip.second = last_track_bottom_edge; /* where to place the top edge of the regionview */
+                                       yposition = last_track_bottom_edge; /* where to place the top edge of the regionview */
 
                                        /* How high is this region view ? */
 
@@ -1042,17 +1057,14 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
 
                                        last_track_bottom_edge += bbox.height();
 
-                                       playlist_dropzone_map.insert (make_pair (i->view->region()->playlist(), ip));
-                                       dzoffset = -n;
+                                       playlist_dropzone_map.insert (make_pair (i->view->region()->playlist(), yposition));
 
                                } else {
-                                       ip = pdz->second;
-                                       dzoffset = ip.first;
+                                       yposition = pdz->second;
                                }
 
                                /* values are zero or negative, hence the use of min() */
-                               biggest_drop_zone_offset = min (biggest_drop_zone_offset, dzoffset);
-                               y_delta = ip.second - rv->get_canvas_group()->canvas_origin().y;
+                               y_delta = yposition - rv->get_canvas_group()->canvas_origin().y;
                        }
 
                } else {
@@ -1129,26 +1141,54 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
                show_verbose_cursor_time (_last_frame_position);
        }
 
+       /* keep track of pointer movement */
        if (tv) {
-
                /* the pointer is currently over a time axis view */
 
                if (_last_pointer_time_axis_view < 0) {
-
-                       /* last motion event was not over a time axis view */
-
+                       /* last motion event was not over a time axis view
+                        * or last y-movement out of the dropzone was not valid
+                        */
+                       int dtz = 0;
                        if (delta_time_axis_view < 0) {
-                               /* was in the drop zone, moving up */
+                               /* in the drop zone, moving up */
+
+                               /* _pdropzone is the last known pointer y-axis position inside the DZ.
+                                * We do not use negative _last_pointer_time_axis_view because
+                                * the dropzone is "packed" (the actual track offset is ignored)
+                                *
+                                * As opposed to the actual number 
+                                * of elements in the dropzone (_ndropzone)
+                                * _pdropzone is not constrained. This is necessary
+                                * to allow moving multiple regions with y-distance
+                                * into the DZ.
+                                *
+                                * There can be 0 elements in the dropzone,
+                                * even though the drag-pointer is inside the DZ.
+                                *
+                                * example:
+                                * [ Audio-track, Midi-track, Audio-track, DZ ]
+                                * move regions from both audio tracks at the same time into the
+                                * DZ by grabbing the region in the bottom track.
+                                */
                                assert(current_pointer_time_axis_view >= 0);
-                               _last_pointer_time_axis_view = current_pointer_time_axis_view;
-                       } else {
-                               /* was in the drop zone, moving down ... not possible */
+                               dtz = std::min((int)_pdropzone, (int)_ddropzone - delta_time_axis_view);
+                               _pdropzone -= dtz;
                        }
 
+                       /* only move out of the zone if the movement is OK */
+                       if (_pdropzone == 0 && delta_time_axis_view != 0) {
+                               assert(delta_time_axis_view < 0);
+                               _last_pointer_time_axis_view = current_pointer_time_axis_view;
+                               /* if all logic and maths are correct, there is no need to assign the 'current' pointer.
+                                * the current position can be calculated as follows:
+                                */
+                               // 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 */
-
                        _last_pointer_time_axis_view += delta_time_axis_view;
                        assert(_last_pointer_time_axis_view >= 0);
                }
@@ -1156,8 +1196,9 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
        } else {
 
                /* the pointer is not over a time axis view */
-
-               _last_pointer_time_axis_view = biggest_drop_zone_offset;
+               assert ((delta_time_axis_view > 0) || (((int)_pdropzone) >= (delta_skip - delta_time_axis_view)));
+               _pdropzone += delta_time_axis_view - delta_skip;
+               _last_pointer_time_axis_view = -1; // <0 : we're in the zone, value does not matter.
        }
 
        _last_pointer_layer += delta_layer;
@@ -1274,14 +1315,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
@@ -1327,7 +1360,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());
@@ -1387,7 +1424,7 @@ RegionMoveDrag::finished_copy (bool const changed_position, bool const /*changed
                        where = i->view->region()->position();
                }
 
-               if (i->time_axis_view < 0 || i->time_axis_view >= _time_axis_views.size()) {
+               if (i->time_axis_view < 0 || i->time_axis_view >= (int)_time_axis_views.size()) {
                        /* dragged to drop zone */
 
                        PlaylistMapping::iterator pm;
@@ -1469,7 +1506,7 @@ RegionMoveDrag::finished_no_copy (
                        continue;
                }
 
-               if (i->time_axis_view < 0 || i->time_axis_view >= _time_axis_views.size()) {
+               if (i->time_axis_view < 0 || i->time_axis_view >= (int)_time_axis_views.size()) {
                        /* dragged to drop zone */
 
                        PlaylistMapping::iterator pm;
@@ -1816,7 +1853,7 @@ void
 RegionInsertDrag::finished (GdkEvent *, bool)
 {
        int pos = _views.front().time_axis_view;
-       assert(pos >= 0 && pos < _time_axis_views.size());
+       assert(pos >= 0 && pos < (int)_time_axis_views.size());
 
        RouteTimeAxisView* dest_rtv = dynamic_cast<RouteTimeAxisView*> (_time_axis_views[pos]);
 
@@ -2284,6 +2321,7 @@ RegionCreateDrag::aborted (bool)
 NoteResizeDrag::NoteResizeDrag (Editor* e, ArdourCanvas::Item* i)
        : Drag (e, i)
        , region (0)
+       , _snap_delta (0)
 {
        DEBUG_TRACE (DEBUG::Drags, "New NoteResizeDrag\n");
 }
@@ -2308,6 +2346,10 @@ NoteResizeDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*ignored*/)
 
        region = &cnote->region_view();
 
+       double temp;
+       temp = region->snap_to_pixel_no_magnets (cnote->x0 ());
+       _snap_delta = temp - cnote->x0 ();
+
        _item->grab ();
 
        if (event->motion.state & Keyboard::PrimaryModifier) {
@@ -2343,7 +2385,7 @@ NoteResizeDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*ignored*/)
 }
 
 void
-NoteResizeDrag::motion (GdkEvent* /*event*/, bool /*first_move*/)
+NoteResizeDrag::motion (GdkEvent* event, bool /*first_move*/)
 {
        MidiRegionSelection& ms (_editor->get_selection().midi_regions);
        for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ++r) {
@@ -2351,21 +2393,29 @@ NoteResizeDrag::motion (GdkEvent* /*event*/, bool /*first_move*/)
                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;
+                       if (!Keyboard::modifier_state_equals (event->button.state, Keyboard::snap_delta_modifier())) {
+                               sd = _snap_delta;
+                       }
+                       mrv->update_resizing (nb, at_front, _drags->current_pointer_x() - grab_x(), relative, sd);
                }
        }
 }
 
 void
-NoteResizeDrag::finished (GdkEvent*, bool /*movement_occurred*/)
+NoteResizeDrag::finished (GdkEvent* event, bool /*movement_occurred*/)
 {
        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;
+               if (!Keyboard::modifier_state_equals (event->button.state, Keyboard::snap_delta_modifier())) {
+                       sd = _snap_delta;
+               }
                if (mrv) {
-                       mrv->commit_resizing (nb, at_front, _drags->current_pointer_x() - grab_x(), relative);
+                       mrv->commit_resizing (nb, at_front, _drags->current_pointer_x() - grab_x(), relative, sd);
                }
        }
 
@@ -2542,7 +2592,6 @@ VideoTimeLineDrag::aborted (bool)
 TrimDrag::TrimDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v, bool preserve_fade_anchor)
        : RegionDrag (e, i, p, v)
        , _preserve_fade_anchor (preserve_fade_anchor)
-       , _jump_position_when_done (false)
 {
        DEBUG_TRACE (DEBUG::Drags, "New TrimDrag\n");
 }
@@ -2563,8 +2612,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, Keyboard::SecondaryModifier)) {
                /* Move the contents of the region around without changing the region bounds */
                _operation = ContentsTrim;
                Drag::start_grab (event, _editor->cursors()->trimmer);
@@ -2573,8 +2623,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, Keyboard::PrimaryModifier)) {
                                Drag::start_grab (event, _editor->cursors()->anchored_left_side_trim);
                        } else {
                                Drag::start_grab (event, _editor->cursors()->left_side_trim);
@@ -2582,7 +2631,7 @@ 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, Keyboard::PrimaryModifier)) {
                                Drag::start_grab (event, _editor->cursors()->anchored_right_side_trim);
                        } else {
                                Drag::start_grab (event, _editor->cursors()->right_side_trim);
@@ -2590,10 +2639,6 @@ TrimDrag::start_grab (GdkEvent* event, Gdk::Cursor*)
                }
        }
 
-       if (Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
-               _jump_position_when_done = true;
-       }
-
        switch (_operation) {
        case StartTrim:
                show_verbose_cursor_time (region_start);
@@ -2602,7 +2647,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);
@@ -2628,8 +2673,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), event, true);
+       framecnt_t dt = adj_frame - raw_grab_frame () + _pointer_frame_offset - snap_delta (event);
 
        if (first_move) {
 
@@ -2675,7 +2720,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_equals (event->button.state, Keyboard::ModifierMask (Keyboard::PrimaryModifier | Keyboard::TertiaryModifier))) {
                non_overlap_trim = true;
        }
 
@@ -2761,7 +2806,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);
@@ -2769,7 +2814,6 @@ TrimDrag::motion (GdkEvent* event, bool first_move)
        }
 }
 
-
 void
 TrimDrag::finished (GdkEvent* event, bool movement_occurred)
 {
@@ -2794,9 +2838,6 @@ TrimDrag::finished (GdkEvent* event, bool movement_occurred)
                                                ar->set_fade_in_active(true);
                                        }
                                }
-                               if (_jump_position_when_done) {
-                                       i->view->region()->set_position (i->initial_position);
-                               }
                        }
                } else if (_operation == EndTrim) {
                        for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
@@ -2809,9 +2850,6 @@ TrimDrag::finished (GdkEvent* event, bool movement_occurred)
                                                ar->set_fade_out_active(true);
                                        }
                                }
-                               if (_jump_position_when_done) {
-                                       i->view->region()->set_position (i->initial_end - i->view->region()->length());
-                               }
                        }
                }
 
@@ -3213,10 +3251,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);
 
        _editor->snap_to_with_modifier (where, event);
 
@@ -3254,15 +3293,16 @@ CursorDrag::start_grab (GdkEvent* event, Gdk::Cursor* c)
                }
        }
 
-       fake_locate (where);
+       fake_locate (where - snap_delta (event));
 }
 
 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);
+       _editor->snap_to_with_modifier (where, event);
+       if (where != last_pointer_frame()) {
+               fake_locate (where - snap_delta (event));
        }
 }
 
@@ -3313,6 +3353,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);
 }
@@ -3329,7 +3370,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);
+       _editor->snap_to_with_modifier (pos, event);
+       pos -= snap_delta (event);
+
        boost::shared_ptr<AudioRegion> region = boost::dynamic_pointer_cast<AudioRegion> (_primary->region ());
 
        if (pos < (region->position() + 64)) {
@@ -3362,8 +3407,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);
+       _editor->snap_to_with_modifier (pos, event);
+       pos -= snap_delta (event);
 
        boost::shared_ptr<AudioRegion> region = boost::dynamic_pointer_cast<AudioRegion> (_primary->region ());
 
@@ -3425,6 +3471,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());
 }
@@ -3442,7 +3489,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);
+       _editor->snap_to_with_modifier (pos, event);
+       pos -= snap_delta (event);
 
        boost::shared_ptr<AudioRegion> region = boost::dynamic_pointer_cast<AudioRegion> (_primary->region ());
 
@@ -3477,7 +3526,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);
+       _editor->snap_to_with_modifier (pos, event);
+       pos -= snap_delta (event);
 
        boost::shared_ptr<AudioRegion> region = boost::dynamic_pointer_cast<AudioRegion> (_primary->region ());
 
@@ -3931,6 +3982,9 @@ ControlPointDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*cursor*/)
        _fixed_grab_x = _point->get_x();
        _fixed_grab_y = _point->get_y();
 
+       framepos_t pos = _editor->pixel_to_sample (_fixed_grab_x);
+       setup_snap_delta (pos);
+
        float const fraction = 1 - (_point->get_y() / _point->line().height());
 
        _point->line().start_drag_single (_point, _fixed_grab_x, fraction);
@@ -3983,12 +4037,13 @@ ControlPointDrag::motion (GdkEvent* event, bool)
        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);
 
        if (!_x_constrained) {
                _editor->snap_to_with_modifier (cx_frames, event);
        }
 
+       cx_frames -= snap_delta (event);
        cx_frames = min (cx_frames, _point->line().maximum_time());
 
        float const fraction = 1.0 - (cy / _point->line().height());
@@ -4004,8 +4059,7 @@ 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::PrimaryModifier | Keyboard::TertiaryModifier))) {
                        _editor->reset_point_selection ();
                }
 
@@ -4036,9 +4090,9 @@ 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)
 {
        DEBUG_TRACE (DEBUG::Drags, "New LineDrag\n");
 }
@@ -4398,7 +4452,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
@@ -4410,14 +4469,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);
+       _editor->snap_to_with_modifier (pf, event);
+       pf -= snap_delta (event);
 
        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
@@ -5096,6 +5156,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())) {
 
@@ -5123,7 +5184,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 (GdkEvent const * event) const
 {
        /* dx in frames */
        frameoffset_t const dx = _editor->pixel_to_sample (_drags->current_pointer_x() - grab_x());
@@ -5132,7 +5193,7 @@ 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 (event);
 
        framepos_t const rp = _region->region()->position ();
 
@@ -5140,7 +5201,7 @@ NoteDrag::total_dx () const
        st = max (st, rp);
 
        /* snap and return corresponding delta */
-       return _region->snap_frame_to_frame (st - rp) + rp - n;
+       return _region->snap_frame_to_frame (st - rp) + rp - n - snap_delta (event);
 }
 
 /** @return Current total drag y change in note number */
@@ -5159,10 +5220,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);
        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 */
@@ -5231,7 +5292,7 @@ NoteDrag::finished (GdkEvent* ev, bool moved)
                        }
                }
        } else {
-               _region->note_dropped (_primary, total_dx(), total_dy());
+               _region->note_dropped (_primary, total_dx (ev), total_dy());
        }
 }