diff options
author | Carl Hetherington <carl@carlh.net> | 2011-12-11 13:42:18 +0000 |
---|---|---|
committer | Carl Hetherington <carl@carlh.net> | 2011-12-11 13:42:18 +0000 |
commit | b4d7120a58cb3fc2a49542acab868e0eb0790864 (patch) | |
tree | 110f5491babbb7f58ccd225d9f8745a1737d4f99 /gtk2_ardour | |
parent | ab4e7cf4720071b709742dfaa1311244cb0d093f (diff) |
Fix some bugs I introduced with the last commit.
git-svn-id: svn://localhost/ardour2/branches/3.0@10973 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'gtk2_ardour')
-rw-r--r-- | gtk2_ardour/editor_drag.cc | 38 | ||||
-rw-r--r-- | gtk2_ardour/editor_drag.h | 1 |
2 files changed, 25 insertions, 14 deletions
diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index 43482aaffd..5962877ef6 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -4281,26 +4281,31 @@ NoteCreateDrag::~NoteCreateDrag () delete _drag_rect; } -void -NoteCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) +framecnt_t +NoteCreateDrag::grid_frames (framepos_t t) const { - _drag_rect = new ArdourCanvas::SimpleRect (*_region_view->get_canvas_group ()); - - framepos_t pf = _drags->current_pointer_frame (); - bool success; - Evoral::MusicalTime grid_beats = _editor->get_grid_type_as_beats (success, pf); + Evoral::MusicalTime grid_beats = _editor->get_grid_type_as_beats (success, t); if (!success) { grid_beats = 1; } - framecnt_t grid_frames = _region_view->region_beats_to_region_frames (grid_beats); + return _region_view->region_beats_to_region_frames (grid_beats); +} + +void +NoteCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) +{ + _drag_rect = new ArdourCanvas::SimpleRect (*_region_view->get_canvas_group ()); + + framepos_t pf = _drags->current_pointer_frame (); + framecnt_t const g = grid_frames (pf); /* Hack so that we always snap to the note that we are over, instead of snapping to the next one if we're more than halfway through the one we're over. */ - if (_editor->snap_mode() == SnapNormal && pf > grid_frames / 2) { - pf -= grid_frames / 2; + if (_editor->snap_mode() == SnapNormal && pf > g / 2) { + pf -= g / 2; } _note[0] = adjusted_frame (pf, event) - _region_view->region()->position (); @@ -4332,14 +4337,19 @@ NoteCreateDrag::motion (GdkEvent* event, bool) } void -NoteCreateDrag::finished (GdkEvent* event, bool) +NoteCreateDrag::finished (GdkEvent* event, bool had_movement) { - if (_drag_rect->property_x2() < _drag_rect->property_x1() + 2) { + if (!had_movement) { abort (); } - + framepos_t const start = min (_note[0], _note[1]); - framecnt_t const length = abs (_note[0] - _note[1]); + framecnt_t length = abs (_note[0] - _note[1]); + + framecnt_t const g = grid_frames (start); + if (_editor->snap_mode() == SnapNormal && length < g) { + length = g; + } _region_view->create_note_at (start, _drag_rect->property_y1(), _region_view->region_frames_to_region_beats (length), true, false); } diff --git a/gtk2_ardour/editor_drag.h b/gtk2_ardour/editor_drag.h index 72a7534be2..c8308c6910 100644 --- a/gtk2_ardour/editor_drag.h +++ b/gtk2_ardour/editor_drag.h @@ -471,6 +471,7 @@ public: private: double y_to_region (double) const; + framecnt_t grid_frames (framepos_t) const; MidiRegionView* _region_view; ArdourCanvas::SimpleRect* _drag_rect; |