From 21e6f1cf50db1e6f53ff72d310bb653a847f773f Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sun, 14 Feb 2021 16:44:02 -0700 Subject: [PATCH] (mostly) fix note drag creation drawing --- gtk2_ardour/editor.cc | 2 +- gtk2_ardour/editor_drag.cc | 21 +++++++++------------ gtk2_ardour/midi_region_view.cc | 22 +++++++++++++--------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 1189e7c60a..465b6401c6 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -4162,7 +4162,7 @@ Editor::get_grid_type_as_beats (bool& success, timepos_t const & position) } TempoMap::SharedPtr tmap (TempoMap::use()); - + switch (_grid_type) { case GridTypeBeat: return Temporal::Beats::from_double (4.0 / tmap->meter_at (position).note_value()); diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index fadc6da947..844e588c1f 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -6967,17 +6967,13 @@ NoteCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) _note[0] = aligned_start; /* minimum initial length is grid beats */ - _note[1] = aligned_start + grid_beats; + _note[1] = _note[0] + grid_beats; - /* Note: at this point we are drawing a rect for the dragging note in - * absolute coordinates (it's not real note, there's no particular - * connection to the position/start of the regionview/region. So we - * just translate directly from absolute time (_note[0], _note[1]) to - * pixels. - */ + const timepos_t rrp1 (_region_view->region()->region_relative_position (_note[0])); + const timepos_t rrp2 (_region_view->region()->region_relative_position (_note[1])); - double const x0 = _editor->time_to_pixel (_note[0]); - double const x1 = _editor->time_to_pixel (_note[1]); + double const x0 = _editor->time_to_pixel (rrp1); + double const x1 = _editor->time_to_pixel (rrp2); double const y = _region_view->note_to_y (_region_view->y_to_note (y_to_region (event->button.y))); _drag_rect->set (ArdourCanvas::Rect (x0, y, x1, y + floor (_region_view->midi_stream_view()->note_height ()))); @@ -7012,10 +7008,11 @@ NoteCreateDrag::motion (GdkEvent* event, bool) _note[1] = timepos_t (max (Temporal::Beats(), aligned_beats)); - /* We continue to draw the dragging rect with absolute time/pixel coordinates */ + const timepos_t rrp1 (_region_view->region()->region_relative_position (_note[0])); + const timepos_t rrp2 (_region_view->region()->region_relative_position (_note[1])); - double const x0 = _editor->time_to_pixel (_note[0]); - double const x1 = _editor->time_to_pixel (_note[1]); + double const x0 = _editor->time_to_pixel (rrp1); + double const x1 = _editor->time_to_pixel (rrp2); _drag_rect->set_x0 (std::min(x0, x1)); _drag_rect->set_x1 (std::max(x0, x1)); } diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index 628c0a43e9..41f09d7846 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -2956,25 +2956,28 @@ MidiRegionView::update_resizing (NoteBase* primary, bool at_front, double delta_ Temporal::TempoMap::SharedPtr tmap (Temporal::TempoMap::use()); const timepos_t abs_beats (tmap->quarters_at (snapped_x)); - const Temporal::Beats beats = _region->absolute_time_to_source_beats (abs_beats); + const Temporal::Beats src_beats = _region->absolute_time_to_source_beats (abs_beats); Temporal::Beats len = Temporal::Beats(); if (at_front) { - if (beats < canvas_note->note()->end_time()) { - len = canvas_note->note()->time() - beats + (snap_delta_beats * sign); + if (src_beats < canvas_note->note()->end_time()) { + len = canvas_note->note()->time() - src_beats + (snap_delta_beats * sign); len += canvas_note->note()->length(); } } else { - if (beats >= canvas_note->note()->time()) { - len = beats - canvas_note->note()->time() - (snap_delta_beats * sign); + if (src_beats >= canvas_note->note()->time()) { + len = src_beats - canvas_note->note()->time() - (snap_delta_beats * sign); } } - len = std::max (Temporal::Beats::from_double (1 / 512.0), len); + /* drawn notes must be at least 1/512th note (1/4 note + divided by 128 + */ + len = std::max (Temporal::Beats (0, 128), len); char buf[16]; /* represent as float frac to help out the user */ - snprintf (buf, sizeof (buf), "%.3g beats", len.get_beats() + (len.get_ticks()/(double)Temporal::ticks_per_beat)); + snprintf (buf, sizeof (buf), "%.3f beats", len.get_beats() + (len.get_ticks()/(double)Temporal::ticks_per_beat)); show_verbose_cursor (buf, 0, 0); cursor_set = true; @@ -3064,7 +3067,8 @@ MidiRegionView::commit_resizing (NoteBase* primary, bool at_front, double delta_ } if (!at_front) { - Temporal::Beats len = std::max (Temporal::Beats (0, 1), x_beats - canvas_note->note()->time() - (snap_delta_beats * sign)); + Temporal::Beats llen = x_beats - canvas_note->note()->time() - (snap_delta_beats * sign); + Temporal::Beats len = std::max (Temporal::Beats (0, 1), llen); note_diff_add_change (canvas_note, MidiModel::NoteDiffCommand::Length, len); } @@ -3900,7 +3904,7 @@ MidiRegionView::update_ghost_note (double x, double y, uint32_t state) const Temporal::Beats snapped_beats = snap_sample_to_grid_underneath (unsnapped_sample, divisions, shift_snap); /* prevent Percussive mode from displaying a ghost hit at region end */ - if (!shift_snap && snapped_beats >= _region->start().beats() + _region->length().beats()) { + if (!shift_snap && snapped_beats >= _region->end().beats()) { _ghost_note->hide(); hide_verbose_cursor (); return;