From 7fca55eeb5257895b295d36f91bf5727ca0993e1 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 4 Nov 2021 18:27:02 -0600 Subject: [PATCH] Fix placement of drawn MIDI notes. Important logic from 6.9 was either missing or incorrectly implemented. New version is much simpler - we just use the RoundDownMaybe mode of round_to_bbt() to ensure that the note start is always within the current grid even if the mouse is more than halfway "through" it. --- gtk2_ardour/editor_drag.cc | 32 +++++++------------------------- gtk2_ardour/editor_drag.h | 2 +- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index 4905df2770..4653b9a367 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -6962,9 +6962,9 @@ NoteCreateDrag::~NoteCreateDrag () } Temporal::Beats -NoteCreateDrag::grid_aligned_beats (timepos_t const & pos, GdkEvent const * event) const +NoteCreateDrag::round_down_to_grid (timepos_t const & pos, GdkEvent const * event) const { - return _editor->snap_to_bbt (pos, RoundNearest, SnapToGrid_Unscaled).beats (); + return _editor->snap_to_bbt (pos, RoundDownMaybe, SnapToGrid_Unscaled).beats (); } void @@ -6975,12 +6975,12 @@ NoteCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) _drag_rect = new ArdourCanvas::Rectangle (_region_view->get_canvas_group ()); const timepos_t pos = _drags->current_pointer_time (); - timepos_t aligned_start (grid_aligned_beats (pos, event)); - const timepos_t grid_beats (_region_view->get_grid_beats (aligned_start)); + Temporal::Beats aligned_beats (round_down_to_grid (pos, event)); + const Temporal::Beats grid_beats (_region_view->get_grid_beats (pos)); - _note[0] = aligned_start; + _note[0] = timepos_t (aligned_beats); /* minimum initial length is grid beats */ - _note[1] = _note[0] + grid_beats; + _note[1] = _note[0] + timepos_t (grid_beats); /* the note positions we've just computed are in absolute beats, but * the drag rect is a member of the region view group, so we need @@ -7004,25 +7004,7 @@ void NoteCreateDrag::motion (GdkEvent* event, bool) { const timepos_t pos = _drags->current_pointer_time (); - Temporal::Beats aligned_beats = grid_aligned_beats (pos, event); - - if (_editor->snap_mode() != SnapOff) { - - const Temporal::Beats grid_beats = _region_view->get_grid_beats (pos); - const Temporal::Beats unaligned_beats = pos.beats (); - - /* Hack so that we always snap to the note that we are over, instead of snapping - to the next one if we're more than halfway through the one we're over. - */ - - const Temporal::Beats rem = aligned_beats - unaligned_beats; - - if (rem >= std::numeric_limits::lowest()) { - aligned_beats -= grid_beats; - } - - aligned_beats += grid_beats; - } + Temporal::Beats aligned_beats = round_down_to_grid (pos, event); _note[1] = timepos_t (max (Temporal::Beats(), aligned_beats)); diff --git a/gtk2_ardour/editor_drag.h b/gtk2_ardour/editor_drag.h index 51290b1e69..f07fa9ae2d 100644 --- a/gtk2_ardour/editor_drag.h +++ b/gtk2_ardour/editor_drag.h @@ -671,7 +671,7 @@ public: private: double y_to_region (double) const; - Temporal::Beats grid_aligned_beats (Temporal::timepos_t const & pos, GdkEvent const * event) const; + Temporal::Beats round_down_to_grid (Temporal::timepos_t const & pos, GdkEvent const * event) const; /** @return minimum number of samples (in x) and pixels (in y) that should be considered a movement */ std::pair move_threshold () const {