diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index 05a2e736db..30edfd5f31 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -6796,8 +6796,8 @@ NoteCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) * coordinates relative to the region in order to draw it correctly. */ - const timecnt_t rrp1 (_midi_view->midi_region ()->region_relative_position (_note[0])); - const timecnt_t rrp2 (_midi_view->midi_region ()->region_relative_position (_note[1])); + const timecnt_t rrp1 (_midi_view->relative_position (_note[0])); + const timecnt_t rrp2 (_midi_view->relative_position (_note[1])); double const x0 = editing_context.sample_to_pixel (rrp1.samples ()); double const x1 = editing_context.sample_to_pixel (rrp2.samples ()); @@ -6820,11 +6820,12 @@ NoteCreateDrag::motion (GdkEvent* event, bool) _note[1] = std::max (aligned_beats, (_note[0].beats () + min_length)); - const timecnt_t rrp1 (_midi_view->midi_region ()->region_relative_position (_note[0])); - const timecnt_t rrp2 (_midi_view->midi_region ()->region_relative_position (_note[1])); + const timecnt_t rrp1 (_midi_view->relative_position (_note[0])); + const timecnt_t rrp2 (_midi_view->relative_position (_note[1])); double const x0 = editing_context.sample_to_pixel (rrp1.samples ()); double const x1 = editing_context.sample_to_pixel (rrp2.samples ()); + _drag_rect->set_x0 (std::min (x0, x1)); _drag_rect->set_x1 (std::max (x0, x1)); } diff --git a/gtk2_ardour/midi_view.cc b/gtk2_ardour/midi_view.cc index 693d07affe..1d78829f98 100644 --- a/gtk2_ardour/midi_view.cc +++ b/gtk2_ardour/midi_view.cc @@ -2973,6 +2973,20 @@ MidiView::snap_pixel_to_time (double x, bool ensure_snap) return _editing_context.snap_relative_time_to_relative_time (_midi_region->position(), timecnt_t (_editing_context.pixel_to_sample (x)), ensure_snap); } +timecnt_t +MidiView::relative_position (timepos_t const & p) const +{ + if (!_midi_region) { + return timecnt_t (Beats (0,0)); + } + + if (_show_source) { + return _midi_region->source_relative_position (p); + } + + return _midi_region->region_relative_position (p); +} + /** @param x Pixel relative to the region position. * @param ensure_snap defaults to false. true = ignore magnetic snap and snap mode (used for snap delta calculation). * @return Snapped pixel relative to the region position. diff --git a/gtk2_ardour/midi_view.h b/gtk2_ardour/midi_view.h index 920e594e56..72b7bd9b14 100644 --- a/gtk2_ardour/midi_view.h +++ b/gtk2_ardour/midi_view.h @@ -284,6 +284,15 @@ class MidiView : public virtual sigc::trackable, public LineMerger ArdourCanvas::Rectangle *resize_rect; }; + /* Convert a position to a distance (origin+position) relative to the + * start of this MidiView. + * + * What this is relative to will depend on whether or not _show_source + * is true. + */ + + Temporal::timecnt_t relative_position (Temporal::timepos_t const & p) const; + /** Snap a region relative pixel coordinate to pixel units. * @param x a pixel coordinate relative to region start * @param ensure_snap do not use magnetic snap (required for snap delta calculation)