13
0

(mostly) fix note drag creation drawing

This commit is contained in:
Paul Davis 2021-02-14 16:44:02 -07:00
parent 17fd3f5d3d
commit 21e6f1cf50
3 changed files with 23 additions and 22 deletions

View File

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

View File

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

View File

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