+ initial_position = v->region()->position ();
+ initial_end = v->region()->position () + v->region()->length ();
+}
+
+PatchChangeDrag::PatchChangeDrag (Editor* e, CanvasPatchChange* i, MidiRegionView* r)
+ : Drag (e, i)
+ , _region_view (r)
+ , _patch_change (i)
+ , _cumulative_dx (0)
+{
+ DEBUG_TRACE (DEBUG::Drags, "New PatchChangeDrag\n");
+}
+
+void
+PatchChangeDrag::motion (GdkEvent* ev, bool)
+{
+ framepos_t f = adjusted_current_frame (ev);
+ boost::shared_ptr<Region> r = _region_view->region ();
+ f = max (f, r->position ());
+ f = min (f, r->last_frame ());
+
+ framecnt_t const dxf = f - grab_frame();
+ double const dxu = _editor->frame_to_unit (dxf);
+ _patch_change->move (dxu - _cumulative_dx, 0);
+ _cumulative_dx = dxu;
+}
+
+void
+PatchChangeDrag::finished (GdkEvent* ev, bool movement_occurred)
+{
+ if (!movement_occurred) {
+ return;
+ }
+
+ boost::shared_ptr<Region> r (_region_view->region ());
+
+ framepos_t f = adjusted_current_frame (ev);
+ f = max (f, r->position ());
+ f = min (f, r->last_frame ());
+
+ _region_view->move_patch_change (
+ *_patch_change,
+ _region_view->region_frames_to_region_beats (f - r->position() - r->start())
+ );
+}
+
+void
+PatchChangeDrag::aborted (bool)
+{
+ _patch_change->move (-_cumulative_dx, 0);
+}
+
+void
+PatchChangeDrag::setup_pointer_frame_offset ()
+{
+ boost::shared_ptr<Region> region = _region_view->region ();
+ _pointer_frame_offset = raw_grab_frame() - _region_view->source_beats_to_absolute_frames (_patch_change->patch()->time());
+}
+
+MidiRubberbandSelectDrag::MidiRubberbandSelectDrag (Editor* e, MidiRegionView* rv)
+ : RubberbandSelectDrag (e, rv->get_canvas_frame ())
+ , _region_view (rv)
+{
+
+}
+
+void
+MidiRubberbandSelectDrag::select_things (int button_state, framepos_t x1, framepos_t x2, double y1, double y2, bool drag_in_progress)
+{
+ framepos_t const p = _region_view->region()->position ();
+ double const y = _region_view->midi_view()->y_position ();
+
+ x1 = max ((framepos_t) 0, x1 - p);
+ x2 = max ((framepos_t) 0, x2 - p);
+ y1 = max (0.0, y1 - y);
+ y2 = max (0.0, y2 - y);
+
+ _region_view->update_drag_selection (
+ _editor->frame_to_pixel (x1),
+ _editor->frame_to_pixel (x2),
+ y1,
+ y2,
+ Keyboard::modifier_state_contains (button_state, Keyboard::TertiaryModifier)
+ );
+}
+
+void
+MidiRubberbandSelectDrag::deselect_things ()
+{
+ /* XXX */
+}
+
+EditorRubberbandSelectDrag::EditorRubberbandSelectDrag (Editor* e, ArdourCanvas::Item* i)
+ : RubberbandSelectDrag (e, i)
+{
+
+}
+
+void
+EditorRubberbandSelectDrag::select_things (int button_state, framepos_t x1, framepos_t x2, double y1, double y2, bool drag_in_progress)
+{
+ if (drag_in_progress) {
+ /* We just want to select things at the end of the drag, not during it */
+ return;
+ }
+
+ Selection::Operation op = ArdourKeyboard::selection_type (button_state);
+
+ _editor->begin_reversible_command (_("rubberband selection"));
+ _editor->select_all_within (x1, x2 - 1, y1, y2, _editor->track_views, op, false);
+ _editor->commit_reversible_command ();
+}
+
+void
+EditorRubberbandSelectDrag::deselect_things ()
+{
+ if (!getenv("ARDOUR_SAE")) {
+ _editor->selection->clear_tracks();
+ }
+ _editor->selection->clear_regions();
+ _editor->selection->clear_points ();
+ _editor->selection->clear_lines ();
+}
+
+NoteCreateDrag::NoteCreateDrag (Editor* e, ArdourCanvas::Item* i, MidiRegionView* rv)
+ : Drag (e, i)
+ , _region_view (rv)
+ , _drag_rect (0)
+{
+
+}
+
+NoteCreateDrag::~NoteCreateDrag ()
+{
+ delete _drag_rect;
+}
+
+framecnt_t
+NoteCreateDrag::grid_frames (framepos_t t) const
+{
+ bool success;
+ Evoral::MusicalTime grid_beats = _editor->get_grid_type_as_beats (success, t);
+ if (!success) {
+ grid_beats = 1;
+ }
+
+ return _region_view->region_beats_to_region_frames (grid_beats);
+}
+
+void
+NoteCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
+{
+ Drag::start_grab (event, 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 > g / 2) {
+ pf -= g / 2;
+ }
+
+ _note[0] = adjusted_frame (pf, event) - _region_view->region()->position ();
+
+ MidiStreamView* sv = _region_view->midi_stream_view ();
+ double const x = _editor->frame_to_pixel (_note[0]);
+ double const y = sv->note_to_y (sv->y_to_note (y_to_region (event->button.y)));
+
+ _drag_rect->property_x1() = x;
+ _drag_rect->property_y1() = y;
+ _drag_rect->property_x2() = x;
+ _drag_rect->property_y2() = y + floor (_region_view->midi_stream_view()->note_height ());
+
+ _drag_rect->property_outline_what() = 0xff;
+ _drag_rect->property_outline_color_rgba() = 0xffffff99;
+ _drag_rect->property_fill_color_rgba() = 0xffffff66;
+}
+
+void
+NoteCreateDrag::motion (GdkEvent* event, bool)
+{
+ _note[1] = adjusted_current_frame (event) - _region_view->region()->position ();
+ double const x = _editor->frame_to_pixel (_note[1]);
+ if (_note[1] > _note[0]) {
+ _drag_rect->property_x2() = x;
+ } else {
+ _drag_rect->property_x1() = x;
+ }
+}
+
+void
+NoteCreateDrag::finished (GdkEvent* event, bool had_movement)
+{
+ if (!had_movement) {
+ return;
+ }
+
+ framepos_t const start = min (_note[0], _note[1]);
+ framecnt_t length = abs (_note[0] - _note[1]);
+
+ framecnt_t const g = grid_frames (start);
+ double const one_tick = 1 / Timecode::BBT_Time::ticks_per_beat;
+
+ if (_editor->snap_mode() == SnapNormal && length < g) {
+ length = g - one_tick;
+ }
+
+ double const length_beats = max (one_tick, _region_view->region_frames_to_region_beats (length));
+
+ _region_view->create_note_at (start, _drag_rect->property_y1(), length_beats, false);
+}
+
+double
+NoteCreateDrag::y_to_region (double y) const
+{
+ double x = 0;
+ _region_view->get_canvas_group()->w2i (x, y);
+ return y;
+}
+
+void
+NoteCreateDrag::aborted (bool)
+{
+