From e90e1cc771ac3c660e136db0cdc03e39524da895 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 20 Apr 2011 23:48:39 +0000 Subject: [PATCH] Prevent snap_frame_to_frame returning -ve offset from the region start (fixes #3925). git-svn-id: svn://localhost/ardour2/branches/3.0@9396 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/midi_region_view.cc | 28 ++++++++++++++++++++++------ gtk2_ardour/midi_region_view.h | 6 +----- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index 9be06cb1b7..7b9bb4ae30 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -2238,14 +2238,30 @@ MidiRegionView::snap_pixel_to_frame(double x) return frame - _region->position(); // convert back to region relative } -framepos_t -MidiRegionView::snap_frame_to_frame(framepos_t x) +/** Snap a frame offset within our region using the current snap settings. + * @param x Frame offset from this region's position. + * @return Snapped frame offset from this region's position. + */ +frameoffset_t +MidiRegionView::snap_frame_to_frame (frameoffset_t x) { PublicEditor& editor = trackview.editor(); - // x is region relative, convert it to global absolute frames - framepos_t frame = x + _region->position(); - editor.snap_to(frame); - return frame - _region->position(); // convert back to region relative + + /* x is region relative, convert it to global absolute frames */ + framepos_t const session_frame = x + _region->position(); + + /* try a snap in either direction */ + framepos_t frame = session_frame; + editor.snap_to (frame, 0); + + /* if we went off the beginning of the region, snap forwards */ + if (frame < _region->position ()) { + frame = session_frame; + editor.snap_to (frame, 1); + } + + /* back to region relative */ + return frame - _region->position(); } double diff --git a/gtk2_ardour/midi_region_view.h b/gtk2_ardour/midi_region_view.h index ccd6a82dec..97cc07b7e2 100644 --- a/gtk2_ardour/midi_region_view.h +++ b/gtk2_ardour/midi_region_view.h @@ -250,11 +250,7 @@ class MidiRegionView : public RegionView */ framepos_t snap_pixel_to_frame(double x); - /** Snap a region relative frame coordinate to frame units. - * @param x a pixel coordinate relative to region start - * @return the snapped framepos_t coordinate relative to region start - */ - framepos_t snap_frame_to_frame(framepos_t x); + ARDOUR::frameoffset_t snap_frame_to_frame (ARDOUR::frameoffset_t); /** Convert a timestamp in beats to frames (both relative to region start) */ framepos_t beats_to_frames(double beats) const;