move 2 relative time methods from RegionView to EditingContext

This commit is contained in:
Paul Davis 2024-01-04 18:16:24 -07:00
parent 45328723b0
commit 9e5211e9b1
5 changed files with 35 additions and 36 deletions

View file

@ -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 */

View file

@ -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);
}

View file

@ -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.

View file

@ -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.

View file

@ -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 ()
{