From 62372b48eaefde1beffe93f2a4039b5e1e5622b2 Mon Sep 17 00:00:00 2001 From: nick_m Date: Tue, 16 Aug 2016 00:48:54 +1000 Subject: [PATCH] Fix frame-based beat calculation in MidiRegionView::snap_frame_to_grid_underneath() - this caused the ghost note under the pointer to behave badly when hovering near an audio-locked meter. --- gtk2_ardour/midi_region_view.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index 6a4f08a332..bb8092807d 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -4122,18 +4122,19 @@ MidiRegionView::snap_frame_to_grid_underneath (framepos_t p, framecnt_t& grid_fr { PublicEditor& editor = trackview.editor (); const Evoral::Beats grid_beats = get_grid_beats(p); - const Evoral::Beats p_beat = max (Evoral::Beats(), region_frames_to_region_beats (p)); - - grid_frames = region_beats_to_region_frames (p_beat + grid_beats) - region_beats_to_region_frames (p_beat); + Evoral::Beats p_beat = max (Evoral::Beats(), region_frames_to_region_beats (p)); + const double rem = fmod (p_beat.to_double(), grid_beats.to_double()); /* 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. */ - if (editor.snap_mode() == SnapNormal && p >= grid_frames / 2) { - p -= grid_frames / 2; + if (editor.snap_mode() == SnapNormal && rem >= grid_beats.to_double() / 2.0) { + p_beat -= Evoral::Beats(grid_beats.to_double() / 2.0); } - return snap_frame_to_frame (p); + const framepos_t snap_me = trackview.session()->tempo_map().frame_at_beat (p_beat.to_double() + _region->beat()) - _region->position(); + + return snap_frame_to_frame (snap_me); } ChannelMode