X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Feditor_drag.cc;h=6f5723086ed0e95fc09fcbeea4b299e81fc7fae3;hb=62f37da98930b055406a90b4206aa26a949d2959;hp=47cf09e0e9cf8a798c7c45ad6b6644cb938b2776;hpb=ca046a8bb2379d80c1cfe1e919d63dc0ac6d2475;p=ardour.git diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index 47cf09e0e9..6f5723086e 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -6203,13 +6203,12 @@ NoteCreateDrag::~NoteCreateDrag () framecnt_t NoteCreateDrag::grid_frames (framepos_t t) const { - bool success; - Evoral::Beats grid_beats = _editor->get_grid_type_as_beats (success, t); - if (!success) { - grid_beats = Evoral::Beats(1); - } - return _region_view->region_beats_to_region_frames (grid_beats); + const Evoral::Beats grid_beats = _region_view->get_grid_beats (t); + const Evoral::Beats t_beats = _region_view->region_frames_to_region_beats (t); + + return _region_view->region_beats_to_region_frames (t_beats + grid_beats) + - _region_view->region_beats_to_region_frames (t_beats); } void @@ -6223,14 +6222,11 @@ NoteCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) const framepos_t pf = _drags->current_pointer_frame (); const int32_t divisions = _editor->get_grid_music_divisions (event->button.state); + const Evoral::Beats grid_beats = _region_view->get_grid_beats (pf); + double eqaf = map.exact_qn_at_frame (pf, divisions); if (divisions != 0) { - bool success = false; - Evoral::Beats grid_beats = _editor->get_grid_type_as_beats (success, pf); - if (!success) { - grid_beats = Evoral::Beats(1); - } const double qaf = map.quarter_note_at_frame (pf); @@ -6245,13 +6241,15 @@ NoteCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) } _note[0] = map.frame_at_quarter_note (eqaf) - _region_view->region()->position(); - _note[1] = _note[0]; + /* minimum initial length is grid beats */ + _note[1] = map.frame_at_quarter_note (eqaf + grid_beats.to_double()) - _region_view->region()->position(); MidiStreamView* sv = _region_view->midi_stream_view (); - double const x = _editor->sample_to_pixel (_note[0]); + double const x0 = _editor->sample_to_pixel (_note[0]); + double const x1 = _editor->sample_to_pixel (_note[1]); double const y = sv->note_to_y (sv->y_to_note (y_to_region (event->button.y))); - _drag_rect->set (ArdourCanvas::Rect (x, y, x, y + floor (_region_view->midi_stream_view()->note_height ()))); + _drag_rect->set (ArdourCanvas::Rect (x0, y, x1, y + floor (_region_view->midi_stream_view()->note_height ()))); _drag_rect->set_outline_all (); _drag_rect->set_outline_color (0xffffff99); _drag_rect->set_fill_color (0xffffff66); @@ -6266,11 +6264,8 @@ NoteCreateDrag::motion (GdkEvent* event, bool) double eqaf = map.exact_qn_at_frame (pf, divisions); if (divisions != 0) { - bool success = false; - Evoral::Beats grid_beats = _editor->get_grid_type_as_beats (success, pf); - if (!success) { - grid_beats = Evoral::Beats(1); - } + + const Evoral::Beats grid_beats = _region_view->get_grid_beats (pf); const double qaf = map.quarter_note_at_frame (pf); /* Hack so that we always snap to the note that we are over, instead of snapping @@ -6295,25 +6290,20 @@ NoteCreateDrag::motion (GdkEvent* event, bool) void NoteCreateDrag::finished (GdkEvent* ev, bool had_movement) { - if (!had_movement) { - return; - } - + /* we create a note even if there was no movement */ framepos_t const start = min (_note[0], _note[1]); framepos_t const start_sess_rel = start + _region_view->region()->position(); - framecnt_t length = (framecnt_t) fabs ((double)(_note[0] - _note[1])); - + framecnt_t length = max (_editor->pixel_to_sample (1.0), (framecnt_t) fabs ((double)(_note[0] - _note[1]))); framecnt_t const g = grid_frames (start); - Evoral::Beats const one_tick = Evoral::Beats::ticks(1); if (_editor->get_grid_music_divisions (ev->button.state) != 0 && length < g) { length = g; } TempoMap& map (_editor->session()->tempo_map()); - const double qn_length = map.quarter_note_at_frame (start_sess_rel + length) - map.quarter_note_at_frame (start_sess_rel); + const double qn_length = map.quarter_notes_between_frames (start_sess_rel, start_sess_rel + length); + Evoral::Beats qn_length_beats = max (Evoral::Beats::ticks(1), Evoral::Beats (qn_length)); - Evoral::Beats qn_length_beats = max (one_tick, Evoral::Beats (qn_length)); _region_view->create_note_at (start, _drag_rect->y0(), qn_length_beats, ev->button.state, false); } @@ -6331,6 +6321,104 @@ NoteCreateDrag::aborted (bool) } +HitCreateDrag::HitCreateDrag (Editor* e, ArdourCanvas::Item* i, MidiRegionView* rv) + : Drag (e, i) + , _region_view (rv) + , _last_pos (0) + , _last_y (0.0) +{ +} + +HitCreateDrag::~HitCreateDrag () +{ +} + +void +HitCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) +{ + Drag::start_grab (event, cursor); + + TempoMap& map (_editor->session()->tempo_map()); + + const framepos_t pf = _drags->current_pointer_frame (); + const int32_t divisions = _editor->get_grid_music_divisions (event->button.state); + + const double eqaf = map.exact_qn_at_frame (pf, divisions); + + boost::shared_ptr mr = _region_view->midi_region(); + + if (eqaf >= mr->quarter_note() + mr->length_beats()) { + return; + } + + const framepos_t start = map.frame_at_quarter_note (eqaf) - _region_view->region()->position(); + + MidiStreamView* sv = _region_view->midi_stream_view (); + const double y = sv->note_to_y (sv->y_to_note (y_to_region (event->button.y))); + + Evoral::Beats length = _region_view->get_grid_beats (pf); + + _region_view->create_note_at (start, y, length, event->button.state, false); + + _last_pos = start; + _last_y = y; +} + +void +HitCreateDrag::motion (GdkEvent* event, bool) +{ + TempoMap& map (_editor->session()->tempo_map()); + + const framepos_t pf = _drags->current_pointer_frame (); + const int32_t divisions = _editor->get_grid_music_divisions (event->button.state); + + if (divisions == 0) { + return; + } + + const double eqaf = map.exact_qn_at_frame (pf, divisions); + const framepos_t start = map.frame_at_quarter_note (eqaf) - _region_view->region()->position (); + + MidiStreamView* sv = _region_view->midi_stream_view (); + const double y = sv->note_to_y (sv->y_to_note (y_to_region (event->button.y))); + + if (_last_pos == start && y == _last_y) { + return; + } + + Evoral::Beats length = _region_view->get_grid_beats (pf); + + boost::shared_ptr mr = _region_view->midi_region(); + if (eqaf >= mr->quarter_note() + mr->length_beats()) { + return; + } + + _region_view->create_note_at (start, y, length, event->button.state, false); + + _last_pos = start; + _last_y = y; +} + +void +HitCreateDrag::finished (GdkEvent* /* ev */, bool /* had_movement */) +{ + +} + +double +HitCreateDrag::y_to_region (double y) const +{ + double x = 0; + _region_view->get_canvas_group()->canvas_to_item (x, y); + return y; +} + +void +HitCreateDrag::aborted (bool) +{ + // umm.. +} + CrossfadeEdgeDrag::CrossfadeEdgeDrag (Editor* e, AudioRegionView* rv, ArdourCanvas::Item* i, bool start_yn) : Drag (e, i) , arv (rv) @@ -6433,6 +6521,7 @@ RegionCutDrag::RegionCutDrag (Editor* e, ArdourCanvas::Item* item, framepos_t po { line->set_position (pos); line->show (); + line->track_canvas_item().reparent (_editor->_drag_motion_group); } RegionCutDrag::~RegionCutDrag () @@ -6441,12 +6530,19 @@ RegionCutDrag::~RegionCutDrag () } void -RegionCutDrag::motion (GdkEvent*, bool) +RegionCutDrag::start_grab (GdkEvent* event, Gdk::Cursor* c) { - framepos_t where = _drags->current_pointer_frame(); - _editor->snap_to (where); + Drag::start_grab (event, c); + motion (event, false); +} - line->set_position (where); +void +RegionCutDrag::motion (GdkEvent* event, bool) +{ + framepos_t pos = _drags->current_pointer_frame(); + _editor->snap_to_with_modifier (pos, event); + + line->set_position (pos); } void @@ -6455,6 +6551,7 @@ RegionCutDrag::finished (GdkEvent* event, bool) _editor->get_track_canvas()->canvas()->re_enter(); framepos_t pos = _drags->current_pointer_frame(); + _editor->snap_to_with_modifier (pos, event); line->hide (); @@ -6464,7 +6561,8 @@ RegionCutDrag::finished (GdkEvent* event, bool) return; } - _editor->split_regions_at (pos, rs, _editor->get_grid_music_divisions (event->button.state)); + _editor->split_regions_at (pos, rs, _editor->get_grid_music_divisions (event->button.state), + false); } void