fix note drawing in clip editor by adding MidiView::relative_position()

This commit is contained in:
Paul Davis 2025-01-10 10:31:42 -07:00
parent c82afe4cdc
commit e273ec06bb
3 changed files with 28 additions and 4 deletions

View file

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

View file

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

View file

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