Fix drawing percussive hits (#9234)

* HitCreateDrag::start_grab does not need to do anything
  a hit cannot be past end of region. Drawing at or past
  the end of a region will create a new region (not an event)
* HitCreateDrag::finished now calculates the position like
  NoteCreateDrag::finished.
* the selection does not need to be cleared. Creating new
  notes/hits selectes the newly created ones.
This commit is contained in:
Robin Gareus 2023-02-11 20:27:43 +01:00
parent 21d86b264a
commit adf1eb34fb
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
1 changed files with 5 additions and 29 deletions

View File

@ -6836,25 +6836,6 @@ HitCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
Drag::start_grab (event, cursor);
_y = _region_view->note_to_y (_region_view->y_to_note (y_to_region (event->button.y)));
const timepos_t pos = _drags->current_pointer_time ();
const Beats beats = pos.beats ();
/* XXX Fix this some day to use next-earliest region and extend to new
position if necessary.
*/
boost::shared_ptr<MidiRegion> mr = _region_view->midi_region();
if (beats >= mr->nt_last().beats()) {
return;
}
const Temporal::Beats start = beats - _region_view->region()->position().beats ();
_region_view->clear_note_selection();
_last_pos = timepos_t (start);
}
void
@ -6865,17 +6846,12 @@ HitCreateDrag::finished (GdkEvent* event, bool had_movement)
}
boost::shared_ptr<MidiRegion> mr = _region_view->midi_region();
const timepos_t pos (_drags->current_pointer_time());
const Beats beats = pos.beats();
if (beats > mr->nt_last().beats()) {
/* past end of region */
return;
}
timepos_t pos (_drags->current_pointer_time());
_editor->snap_to (pos, RoundNearest, SnapToGrid_Scaled);
Temporal::Beats aligned_beats (pos.beats ());
timepos_t snapped (beats);
_editor->snap_to (snapped, RoundNearest, SnapToGrid_Scaled);
const timepos_t region_offset (snapped.beats() - _region_view->region()->position ().beats());
Beats const start = _region_view->region()->absolute_time_to_region_beats (timepos_t (aligned_beats));
/* This code is like MidiRegionView::get_draw_length_beats() but
* defaults to 1/64th note rather than a 1/4 note, since we're in
@ -6890,7 +6866,7 @@ HitCreateDrag::finished (GdkEvent* event, bool had_movement)
}
/* create_note_at() implements UNDO for us */
_region_view->create_note_at (region_offset, _y, length, event->button.state, false);
_region_view->create_note_at (timepos_t (start), _y, length, event->button.state, false);
}
double