From 9e5211e9b112fdf48ebc166dc51162a14714f08a Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 4 Jan 2024 18:16:24 -0700 Subject: [PATCH] move 2 relative time methods from RegionView to EditingContext --- gtk2_ardour/automation_region_view.cc | 2 +- gtk2_ardour/editing_context.cc | 31 ++++++++++++++++++++++++ gtk2_ardour/editing_context.h | 2 ++ gtk2_ardour/midi_region_view.cc | 2 +- gtk2_ardour/region_view.cc | 34 --------------------------- 5 files changed, 35 insertions(+), 36 deletions(-) diff --git a/gtk2_ardour/automation_region_view.cc b/gtk2_ardour/automation_region_view.cc index a636a8cf78..bc5d656066 100644 --- a/gtk2_ardour/automation_region_view.cc +++ b/gtk2_ardour/automation_region_view.cc @@ -184,7 +184,7 @@ AutomationRegionView::add_automation_event (timepos_t const & w, double y, bool /* snap time */ - when = snap_region_time_to_region_time (_region->source_position().distance (when), false); + when = view->editor().snap_relative_time_to_relative_time (_region->position(), _region->source_position().distance (when), false); /* map using line */ diff --git a/gtk2_ardour/editing_context.cc b/gtk2_ardour/editing_context.cc index da0d4ed6cc..1d2b8bfac0 100644 --- a/gtk2_ardour/editing_context.cc +++ b/gtk2_ardour/editing_context.cc @@ -1555,3 +1555,34 @@ EditingContext::get_quantize_op () quantize_dialog->threshold()); } +timecnt_t +EditingContext::relative_distance (timepos_t const & origin, timecnt_t const & duration, Temporal::TimeDomain domain) +{ + return Temporal::TempoMap::use()->convert_duration (duration, origin, domain); +} + +/** Snap a time offset within our region using the current snap settings. + * @param x Time offset from this region's position. + * @param ensure_snap whether to ignore snap_mode (in the case of SnapOff) and magnetic snap. + * Used when inverting snap mode logic with key modifiers, or snap distance calculation. + * @return Snapped time offset from this region's position. + */ +timecnt_t +EditingContext::snap_relative_time_to_relative_time (timepos_t const & origin, timecnt_t const & x, bool ensure_snap) const +{ + /* x is relative to origin, convert it to global absolute time */ + timepos_t const session_pos = origin + x; + + /* try a snap in either direction */ + timepos_t snapped = session_pos; + snap_to (snapped, Temporal::RoundNearest, SnapToAny_Visual, ensure_snap); + + /* if we went off the beginning of the region, snap forwards */ + if (snapped < origin) { + snapped = session_pos; + snap_to (snapped, Temporal::RoundUpAlways, SnapToAny_Visual, ensure_snap); + } + + /* back to relative */ + return origin.distance (snapped); +} diff --git a/gtk2_ardour/editing_context.h b/gtk2_ardour/editing_context.h index 4ee757f542..fd4dea6097 100644 --- a/gtk2_ardour/editing_context.h +++ b/gtk2_ardour/editing_context.h @@ -107,6 +107,8 @@ public: virtual void redisplay_grid (bool immediate_redraw) = 0; virtual Temporal::timecnt_t get_nudge_distance (Temporal::timepos_t const & pos, Temporal::timecnt_t& next) = 0; + Temporal::timecnt_t relative_distance (Temporal::timepos_t const & origin, Temporal::timecnt_t const & duration, Temporal::TimeDomain domain); + Temporal::timecnt_t snap_relative_time_to_relative_time (Temporal::timepos_t const & origin, Temporal::timecnt_t const & x, bool ensure_snap) const; /** Set whether the editor should follow the playhead. * @param yn true to follow playhead, otherwise false. diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index e525095c9c..f5e0d0e1cf 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -2973,7 +2973,7 @@ MidiRegionView::note_dropped(NoteBase *, timecnt_t const & d_qn, int8_t dnote, b timecnt_t MidiRegionView::snap_pixel_to_time (double x, bool ensure_snap) { - return snap_region_time_to_region_time (timecnt_t (editing_context.pixel_to_sample (x)), ensure_snap); + return trackview.editor().snap_relative_time_to_relative_time (_region->position(), timecnt_t (editing_context.pixel_to_sample (x)), ensure_snap); } /** @param x Pixel relative to the region position. diff --git a/gtk2_ardour/region_view.cc b/gtk2_ardour/region_view.cc index 76f06391d7..bb8e550295 100644 --- a/gtk2_ardour/region_view.cc +++ b/gtk2_ardour/region_view.cc @@ -1148,40 +1148,6 @@ RegionView::move_contents (timecnt_t const & distance) region_changed (PropertyChange (ARDOUR::Properties::start)); } - -/** Snap a time offset within our region using the current snap settings. - * @param x Time offset from this region's position. - * @param ensure_snap whether to ignore snap_mode (in the case of SnapOff) and magnetic snap. - * Used when inverting snap mode logic with key modifiers, or snap distance calculation. - * @return Snapped time offset from this region's position. - */ -timecnt_t -RegionView::snap_region_time_to_region_time (timecnt_t const & x, bool ensure_snap) const -{ - PublicEditor& editor = trackview.editor(); - /* x is region relative, convert it to global absolute time */ - timepos_t const session_pos = _region->position() + x; - - /* try a snap in either direction */ - timepos_t snapped = session_pos; - editor.snap_to (snapped, Temporal::RoundNearest, SnapToAny_Visual, ensure_snap); - - /* if we went off the beginning of the region, snap forwards */ - if (snapped < _region->position ()) { - snapped = session_pos; - editor.snap_to (snapped, Temporal::RoundUpAlways, SnapToAny_Visual, ensure_snap); - } - - /* back to region relative */ - return _region->region_relative_position (snapped); -} - -timecnt_t -RegionView::region_relative_distance (timecnt_t const & duration, Temporal::TimeDomain domain) -{ - return Temporal::TempoMap::use()->convert_duration (duration, _region->position(), domain); -} - void RegionView::update_visibility () {