add editor to Theme Manager for modifiers
[ardour.git] / gtk2_ardour / editor_drag.cc
index 9ad867bbcbbc8b425794341a045155f9c01ef325..370a6936b16864beb94858bf89e82a7b7a90c0c4 100644 (file)
@@ -40,6 +40,7 @@
 #include "ardour/region_factory.h"
 #include "ardour/session.h"
 
+#include "canvas/canvas.h"
 #include "canvas/scroll_group.h"
 
 #include "editor.h"
@@ -94,6 +95,8 @@ DragManager::abort ()
 {
        _ending = true;
 
+       cerr << "Aborting drag\n";
+
        for (list<Drag*>::const_iterator i = _drags.begin(); i != _drags.end(); ++i) {
                (*i)->abort ();
                delete *i;
@@ -335,6 +338,12 @@ Drag::adjusted_current_frame (GdkEvent const * event, bool snap) const
        return adjusted_frame (_drags->current_pointer_frame (), event, snap);
 }
 
+double
+Drag::current_pointer_x() const
+{
+        return _drags->current_pointer_x ();
+}
+
 double
 Drag::current_pointer_y () const
 {
@@ -350,7 +359,7 @@ Drag::motion_handler (GdkEvent* event, bool from_autoscroll)
 {
        /* check to see if we have moved in any way that matters since the last motion event */
        if (_move_threshold_passed &&
-           (!x_movement_matters() || _last_pointer_frame == adjusted_current_frame (event)) &&
+           (!x_movement_matters() || _last_pointer_x == current_pointer_x ()) &&
            (!y_movement_matters() || _last_pointer_y == current_pointer_y ()) ) {
                return false;
        }
@@ -1572,18 +1581,25 @@ RegionSpliceDrag::aborted (bool)
 void
 RegionRippleDrag::add_all_after_to_views(TimeAxisView *tav, framepos_t where, const RegionSelection &exclude, bool drag_in_progress)
 {
+
+       boost::shared_ptr<RegionList> rl = tav->playlist()->regions_with_start_within (Evoral::Range<framepos_t>(where, max_framepos));
+
+       RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(tav);
        RegionSelection to_ripple;
-       TrackViewList tracks;
-       tracks.push_back (tav);
-       _editor->get_regions_after (to_ripple, where, tracks);
+       for (RegionList::iterator i = rl->begin(); i != rl->end(); ++i) {
+               if ((*i)->position() >= where) {
+                       to_ripple.push_back (rtv->view()->find_view(*i));
+               }
+       }
 
        for (RegionSelection::iterator i = to_ripple.begin(); i != to_ripple.end(); ++i) {
                if (!exclude.contains (*i)) {
                        // the selection has already been added to _views
 
                        if (drag_in_progress) {
-                               // do the same things that RegionMotionDrag::motion does when first_move
-                               // is true for the region views that we're adding to _views this time
+                               // do the same things that RegionMotionDrag::motion does when
+                               // first_move is true, for the region views that we're adding
+                               // to _views this time
 
                                (*i)->drag_start();
                                ArdourCanvas::Item* rvg = (*i)->get_canvas_group();
@@ -1591,11 +1607,7 @@ RegionRippleDrag::add_all_after_to_views(TimeAxisView *tav, framepos_t where, co
                                Duple dmg_canvas_offset = _editor->_drag_motion_group->canvas_origin ();
                                rvg->reparent (_editor->_drag_motion_group);
 
-                               // XXX without the following, things jump in the y direction during drags
-                               // with it, they jump in the x direction
-                               // so we need to do the move in the y direction only
-                               // rvg->move (rv_canvas_offset - dmg_canvas_offset);
-                               std::cerr << "rv_canvas_offset = " << rv_canvas_offset << ", dmg_canvas_offset = " << dmg_canvas_offset << std::endl;
+                               // we only need to move in the y direction
                                Duple fudge = rv_canvas_offset - dmg_canvas_offset;
                                fudge.x = 0;
                                rvg->move (fudge);
@@ -1624,8 +1636,6 @@ RegionRippleDrag::remove_unselected_from_views(framecnt_t amount, bool move_regi
                        RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (tv);
                        assert (rtv);
 
-                       std::cerr << "rtv = " << rtv->name() << std::endl;
-
                        // plonk them back onto their own track
                        rv->get_canvas_group()->reparent(rtv->view()->canvas_item());
                        rv->get_canvas_group()->set_y_position (0);
@@ -1696,7 +1706,7 @@ RegionRippleDrag::RegionRippleDrag (Editor* e, ArdourCanvas::Item* i, RegionView
                assert (first_selected_on_this_track); // we should always find the region in one of the playlists...
                add_all_after_to_views (
                                &first_selected_on_this_track->get_time_axis_view(),
-                               first_selected_on_this_track->region()->position() + first_selected_on_this_track->region()->length(),
+                               first_selected_on_this_track->region()->position(),
                                selected_regions, false);
        }
 
@@ -1745,7 +1755,6 @@ RegionRippleDrag::motion (GdkEvent* event, bool first_move)
                        // and add the regions after the drop point on the new playlist to _views instead.
                        // undo the effect of rippling the previous playlist, and include the effect of removing
                        // the dragged region(s) from this track
-                       std::cerr << "dragged from " << prev_tav->name() << " to " << tv->name() << std::endl;
 
                        remove_unselected_from_views (prev_amount, false);
                        // ripple previous playlist according to the regions that have been removed onto the new playlist
@@ -1788,6 +1797,15 @@ void
 RegionRippleDrag::finished (GdkEvent* event, bool movement_occurred)
 {
        if (!movement_occurred) {
+               
+               /* just a click */
+
+               if (was_double_click() && !_views.empty()) {
+                       DraggingView dv = _views.front();
+                       dv.view->show_region_editor ();
+                       
+               }
+
                return;
        }
 
@@ -1802,20 +1820,16 @@ RegionRippleDrag::finished (GdkEvent* event, bool movement_occurred)
                        // if regions were dragged across tracks, we've rippled any later
                        // regions on the track the regions were dragged off, so we need
                        // to add the original track to the undo record
-                       std::cerr << "adding orig_tav " << orig_tav->name() << " to undo" << std::endl;
                        orig_tav->playlist()->clear_changes();
                        vector<Command*> cmds;
                        orig_tav->playlist()->rdiff (cmds);
                        _editor->session()->add_commands (cmds);
                }
                if (prev_tav && prev_tav != orig_tav) {
-                       std::cerr << "adding prev_tav " << prev_tav->name() << " to undo" << std::endl;
                        prev_tav->playlist()->clear_changes();
                        vector<Command*> cmds;
                        prev_tav->playlist()->rdiff (cmds);
                        _editor->session()->add_commands (cmds);
-               } else if (prev_tav) {
-                       std::cerr << "prev_tav == orig_tav" << std::endl;
                }
        } else {
                // selection spanned multiple tracks - all will need adding to undo record
@@ -1824,17 +1838,13 @@ RegionRippleDrag::finished (GdkEvent* event, bool movement_occurred)
                std::set<boost::shared_ptr<ARDOUR::Playlist> >::const_iterator pi;
 
                for (pi = playlists.begin(); pi != playlists.end(); ++pi) {
-
-                       std::cerr << "adding playlist with selection " << (*pi)->name() << " to undo" << std::endl;
                        (*pi)->clear_changes();
                        vector<Command*> cmds;
                        (*pi)->rdiff (cmds);
                        _editor->session()->add_commands (cmds);
                }
-
        }
 
-
        // other modified playlists are added to undo by RegionMoveDrag::finished()
        RegionMoveDrag::finished (event, movement_occurred);
        _editor->commit_reversible_command();
@@ -1920,25 +1930,16 @@ NoteResizeDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*ignored*/)
 
        if (x_fraction > 0.0 && x_fraction < 0.25) {
                cursor = _editor->cursors()->left_side_trim;
+               at_front = true;
        } else  {
                cursor = _editor->cursors()->right_side_trim;
+               at_front = false;
        }
 
        Drag::start_grab (event, cursor);
 
        region = &cnote->region_view();
 
-       double const region_start = region->get_position_pixels();
-       double const middle_point = region_start + cnote->x0() + (cnote->x1() - cnote->x0()) / 2.0L;
-
-       if (grab_x() <= middle_point) {
-               cursor = _editor->cursors()->left_side_trim;
-               at_front = true;
-       } else {
-               cursor = _editor->cursors()->right_side_trim;
-               at_front = false;
-       }
-
        _item->grab ();
 
        if (event->motion.state & Keyboard::PrimaryModifier) {
@@ -1963,7 +1964,10 @@ NoteResizeDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*ignored*/)
                MidiRegionSelection::iterator next;
                next = r;
                ++next;
-               (*r)->begin_resizing (at_front);
+               MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(*r);
+               if (mrv) {
+                       mrv->begin_resizing (at_front);
+               }
                r = next;
        }
 }
@@ -1975,7 +1979,10 @@ NoteResizeDrag::motion (GdkEvent* /*event*/, bool /*first_move*/)
        for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ++r) {
                NoteBase* nb = reinterpret_cast<NoteBase*> (_item->get_data ("notebase"));
                assert (nb);
-               (*r)->update_resizing (nb, at_front, _drags->current_pointer_x() - grab_x(), relative);
+               MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(*r);
+               if (mrv) {
+                       mrv->update_resizing (nb, at_front, _drags->current_pointer_x() - grab_x(), relative);
+               }
        }
 }
 
@@ -1986,7 +1993,10 @@ NoteResizeDrag::finished (GdkEvent*, bool /*movement_occurred*/)
        for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ++r) {
                NoteBase* nb = reinterpret_cast<NoteBase*> (_item->get_data ("notebase"));
                assert (nb);
-               (*r)->commit_resizing (nb, at_front, _drags->current_pointer_x() - grab_x(), relative);
+               MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(*r);
+               if (mrv) {
+                       mrv->commit_resizing (nb, at_front, _drags->current_pointer_x() - grab_x(), relative);
+               }
        }
 }
 
@@ -1995,7 +2005,10 @@ NoteResizeDrag::aborted (bool)
 {
        MidiRegionSelection& ms (_editor->get_selection().midi_regions);
        for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ++r) {
-               (*r)->abort_resizing ();
+               MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(*r);
+               if (mrv) {
+                       mrv->abort_resizing ();
+               }
        }
 }
 
@@ -2579,7 +2592,7 @@ MeterMarkerDrag::motion (GdkEvent* event, bool first_move)
                _marker = new MeterMarker (
                        *_editor,
                        *_editor->meter_group,
-                       ARDOUR_UI::config()->get_canvasvar_MeterMarker(),
+                       ARDOUR_UI::config()->color ("meter marker"),
                        name,
                        *new MeterSection (_marker->meter())
                );
@@ -2597,6 +2610,7 @@ MeterMarkerDrag::motion (GdkEvent* event, bool first_move)
        }
 
        framepos_t const pf = adjusted_current_frame (event);
+
        _marker->set_position (pf);
        show_verbose_cursor_time (pf);
 }
@@ -2709,7 +2723,7 @@ TempoMarkerDrag::motion (GdkEvent* event, bool first_move)
                _marker = new TempoMarker (
                        *_editor,
                        *_editor->tempo_group,
-                       ARDOUR_UI::config()->get_canvasvar_TempoMarker(),
+                       ARDOUR_UI::config()->color ("tempo marker"),
                        name,
                        *new TempoSection (_marker->tempo())
                        );
@@ -2748,7 +2762,7 @@ TempoMarkerDrag::finished (GdkEvent* event, bool movement_occurred)
        motion (event, false);
 
        TempoMap& map (_editor->session()->tempo_map());
-       framepos_t beat_time = map.round_to_beat (last_pointer_frame(), 0);
+       framepos_t beat_time = map.round_to_beat (last_pointer_frame(), RoundNearest);
        Timecode::BBT_Time when;
 
        map.bbt_time (beat_time, when);
@@ -3385,7 +3399,7 @@ MarkerDrag::motion (GdkEvent* event, bool)
                                } else  if (new_start < copy_location->end()) {
                                        copy_location->set_start (new_start);
                                } else if (newframe > 0) {
-                                       _editor->snap_to (next, 1, true);
+                                       _editor->snap_to (next, RoundUpAlways, true);
                                        copy_location->set_end (next);
                                        copy_location->set_start (newframe);
                                }
@@ -3398,7 +3412,7 @@ MarkerDrag::motion (GdkEvent* event, bool)
                                } else if (new_end > copy_location->start()) {
                                        copy_location->set_end (new_end);
                                } else if (newframe > 0) {
-                                       _editor->snap_to (next, -1, true);
+                                       _editor->snap_to (next, RoundDownAlways, true);
                                        copy_location->set_start (next);
                                        copy_location->set_end (newframe);
                                }
@@ -3630,8 +3644,8 @@ ControlPointDrag::aborted (bool)
 bool
 ControlPointDrag::active (Editing::MouseMode m)
 {
-       if (m == Editing::MouseGain) {
-               /* always active in mouse gain */
+       if (m == Editing::MouseDraw) {
+               /* always active in mouse draw */
                return true;
        }
 
@@ -3954,7 +3968,7 @@ RubberbandSelectDrag::finished (GdkEvent* event, bool movement_occurred)
 
                if ((mtv = dynamic_cast<MidiTimeAxisView*>(_editor->clicked_axisview)) != 0) {
                        /* MIDI track */
-                       if (_editor->selection->empty()) {
+                       if (_editor->selection->empty() && _editor->mouse_mode == MouseDraw) {
                                /* nothing selected */
                                add_midi_region (mtv);
                                do_deselect = false;
@@ -4096,9 +4110,7 @@ SelectionDrag::SelectionDrag (Editor* e, ArdourCanvas::Item* i, Operation o)
        : Drag (e, i)
        , _operation (o)
        , _add (false)
-       , _extend (false)
        , _original_pointer_time_axis (-1)
-       , _last_pointer_time_axis (-1)
        , _time_selection_at_start (!_editor->get_selection().time.empty())
 {
        DEBUG_TRACE (DEBUG::Drags, "New SelectionDrag\n");
@@ -4205,9 +4217,9 @@ SelectionDrag::motion (GdkEvent* event, bool first_move)
                if (first_move) {
                        grab = adjusted_current_frame (event, false);
                        if (grab < pending_position) {
-                               _editor->snap_to (grab, -1);
+                               _editor->snap_to (grab, RoundDownMaybe);
                        }  else {
-                               _editor->snap_to (grab, 1);
+                               _editor->snap_to (grab, RoundUpMaybe);
                        }
                }
 
@@ -4244,9 +4256,16 @@ SelectionDrag::motion (GdkEvent* event, bool first_move)
                        }
                }
                
+               //if user is selecting a range on an automation track, bail out here before we get to the grouped stuff, 
+               // because the grouped stuff will start working on tracks (routeTAVs), and end up removing this 
+               AutomationTimeAxisView *atest = dynamic_cast<AutomationTimeAxisView *>(_editor->clicked_axisview);
+               if (atest) {
+                       _editor->selection->add (atest);
+                       break; 
+               }
+               
                /* select all tracks within the rectangle that we've marked out so far */
-               TrackViewList to_be_added_to_selection;
-               TrackViewList to_be_removed_from_selection;
+               TrackViewList new_selection;
                TrackViewList& all_tracks (_editor->track_views);
 
                ArdourCanvas::Coord const top = grab_y();
@@ -4254,26 +4273,39 @@ SelectionDrag::motion (GdkEvent* event, bool first_move)
 
                if (top >= 0 && bottom >= 0) {
 
+                       //first, find the tracks that are covered in the y range selection
                        for (TrackViewList::const_iterator i = all_tracks.begin(); i != all_tracks.end(); ++i) {
-                       
                                if ((*i)->covered_by_y_range (top, bottom)) {
-                                       if (!(*i)->get_selected()) {
-                                               to_be_added_to_selection.push_back (*i);
-                                       }
-                               } else {
-                                       if ((*i)->get_selected()) {
-                                               to_be_removed_from_selection.push_back (*i);
-                                       }
+                                       new_selection.push_back (*i);
                                }
                        }
 
-                       if (!to_be_added_to_selection.empty()) {
-                               _editor->selection->add (to_be_added_to_selection);
-                       }
-                       
-                       if (!to_be_removed_from_selection.empty()) {
-                               _editor->selection->remove (to_be_removed_from_selection);
+                       //now find any tracks that are GROUPED with the tracks we selected
+                       TrackViewList grouped_add = new_selection;
+                       for (TrackViewList::const_iterator i = new_selection.begin(); i != new_selection.end(); ++i) {
+                               RouteTimeAxisView *n = dynamic_cast<RouteTimeAxisView *>(*i);
+                               if ( n && n->route()->route_group() && n->route()->route_group()->is_active() && n->route()->route_group()->enabled_property (ARDOUR::Properties::select.property_id) ) {
+                                       for (TrackViewList::const_iterator j = all_tracks.begin(); j != all_tracks.end(); ++j) {
+                                               RouteTimeAxisView *check = dynamic_cast<RouteTimeAxisView *>(*j);
+                                               if ( check && (n != check) && (check->route()->route_group() == n->route()->route_group()) )
+                                                       grouped_add.push_back (*j);
+                                       }
+                               }
                        }
+
+                       //now compare our list with the current selection, and add or remove as necessary
+                       //( NOTE: most mouse moves don't change the selection so we can't just SET it for every mouse move; it gets clunky )
+                       TrackViewList tracks_to_add;
+                       TrackViewList tracks_to_remove;
+                       for (TrackViewList::const_iterator i = grouped_add.begin(); i != grouped_add.end(); ++i)
+                               if ( !_editor->selection->tracks.contains ( *i ) )
+                                       tracks_to_add.push_back ( *i );
+                       for (TrackViewList::const_iterator i = _editor->selection->tracks.begin(); i != _editor->selection->tracks.end(); ++i)
+                               if ( !grouped_add.contains ( *i ) )
+                                       tracks_to_remove.push_back ( *i );
+                       _editor->selection->add(tracks_to_add);
+                       _editor->selection->remove(tracks_to_remove);
+
                }
        }
        break;
@@ -4357,8 +4389,11 @@ SelectionDrag::finished (GdkEvent* event, bool movement_occurred)
                        if ( s->get_play_range() && s->transport_rolling() ) {
                                s->request_play_range (&_editor->selection->time, true);
                        } else {
-                               if (Config->get_always_play_range() && !s->transport_rolling()) {
-                                       s->request_locate (_editor->get_selection().time.start());
+                               if (Config->get_follow_edits() && !s->transport_rolling()) {
+                                       if (_operation == SelectionEndTrim)
+                                               _editor->maybe_locate_with_edit_preroll( _editor->get_selection().time.end_frame());
+                                       else
+                                               s->request_locate (_editor->get_selection().time.start());
                                }
                        }
                }
@@ -4418,8 +4453,8 @@ RangeMarkerBarDrag::RangeMarkerBarDrag (Editor* e, ArdourCanvas::Item* i, Operat
                                                                      physical_screen_height (_editor->get_window())));
        _drag_rect->hide ();
 
-       _drag_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_RangeDragRect());
-       _drag_rect->set_outline_color (ARDOUR_UI::config()->get_canvasvar_RangeDragRect());
+       _drag_rect->set_fill_color (ARDOUR_UI::config()->color ("range drag rect"));
+       _drag_rect->set_outline_color (ARDOUR_UI::config()->color ("range drag rect"));
 }
 
 void
@@ -4436,6 +4471,7 @@ RangeMarkerBarDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
        }
 
        switch (_operation) {
+       case CreateSkipMarker:
        case CreateRangeMarker:
        case CreateTransportMarker:
        case CreateCDMarker:
@@ -4462,6 +4498,9 @@ RangeMarkerBarDrag::motion (GdkEvent* event, bool first_move)
        ArdourCanvas::Rectangle *crect;
 
        switch (_operation) {
+       case CreateSkipMarker:
+               crect = _editor->range_bar_drag_rect;
+               break;
        case CreateRangeMarker:
                crect = _editor->range_bar_drag_rect;
                break;
@@ -4479,7 +4518,7 @@ RangeMarkerBarDrag::motion (GdkEvent* event, bool first_move)
 
        framepos_t const pf = adjusted_current_frame (event);
 
-       if (_operation == CreateRangeMarker || _operation == CreateTransportMarker || _operation == CreateCDMarker) {
+       if (_operation == CreateSkipMarker || _operation == CreateRangeMarker || _operation == CreateTransportMarker || _operation == CreateCDMarker) {
                framepos_t grab = grab_frame ();
                _editor->snap_to (grab);
 
@@ -4535,17 +4574,24 @@ RangeMarkerBarDrag::finished (GdkEvent* event, bool movement_occurred)
                _drag_rect->hide();
 
                switch (_operation) {
+               case CreateSkipMarker:
                case CreateRangeMarker:
                case CreateCDMarker:
                    {
-                       _editor->begin_reversible_command (_("new range marker"));
                        XMLNode &before = _editor->session()->locations()->get_state();
-                       _editor->session()->locations()->next_available_name(rangename,"unnamed");
-                       if (_operation == CreateCDMarker) {
+                       if (_operation == CreateSkipMarker) {
+                               _editor->begin_reversible_command (_("new skip marker"));
+                               _editor->session()->locations()->next_available_name(rangename,_("skip"));
+                               flags = Location::IsRangeMarker | Location::IsSkip;
+                               _editor->range_bar_drag_rect->hide();
+                       } else if (_operation == CreateCDMarker) {
+                               _editor->session()->locations()->next_available_name(rangename, _("CD"));
+                               _editor->begin_reversible_command (_("new CD marker"));
                                flags = Location::IsRangeMarker | Location::IsCDMarker;
                                _editor->cd_marker_bar_drag_rect->hide();
-                       }
-                       else {
+                       } else {
+                               _editor->begin_reversible_command (_("new skip marker"));
+                               _editor->session()->locations()->next_available_name(rangename, _("unnamed"));
                                flags = Location::IsRangeMarker;
                                _editor->range_bar_drag_rect->hide();
                        }
@@ -4581,7 +4627,7 @@ RangeMarkerBarDrag::finished (GdkEvent* event, bool movement_occurred)
                        /* didn't drag, but mark is already created so do
                         * nothing */
 
-               } else { /* operation == CreateRangeMarker */
+               } else { /* operation == CreateRangeMarker || CreateSkipMarker */
                        
 
                        framepos_t start;
@@ -4633,88 +4679,6 @@ RangeMarkerBarDrag::update_item (Location* location)
        _drag_rect->set_x1 (x2);
 }
 
-MouseZoomDrag::MouseZoomDrag (Editor* e, ArdourCanvas::Item* i)
-       : Drag (e, i)
-       , _zoom_out (false)
-{
-       DEBUG_TRACE (DEBUG::Drags, "New MouseZoomDrag\n");
-}
-
-void
-MouseZoomDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
-{
-       if (Keyboard::the_keyboard().key_is_down (GDK_Control_L)) {
-               Drag::start_grab (event, _editor->cursors()->zoom_out);
-               _zoom_out = true;
-       } else {
-               Drag::start_grab (event, _editor->cursors()->zoom_in);
-               _zoom_out = false;
-       }
-
-       show_verbose_cursor_time (adjusted_current_frame (event));
-}
-
-void
-MouseZoomDrag::motion (GdkEvent* event, bool first_move)
-{
-       framepos_t start;
-       framepos_t end;
-
-       framepos_t const pf = adjusted_current_frame (event);
-
-       framepos_t grab = grab_frame ();
-       _editor->snap_to_with_modifier (grab, event);
-
-       /* base start and end on initial click position */
-       if (pf < grab) {
-               start = pf;
-               end = grab;
-       } else {
-               end = pf;
-               start = grab;
-       }
-
-       if (start != end) {
-
-               if (first_move) {
-                       _editor->zoom_rect->show();
-                       _editor->zoom_rect->raise_to_top();
-               }
-
-               _editor->reposition_zoom_rect(start, end);
-
-               show_verbose_cursor_time (pf);
-       }
-}
-
-void
-MouseZoomDrag::finished (GdkEvent* event, bool movement_occurred)
-{
-       if (movement_occurred) {
-               motion (event, false);
-
-               if (grab_frame() < last_pointer_frame()) {
-                       _editor->temporal_zoom_by_frame (grab_frame(), last_pointer_frame());
-               } else {
-                       _editor->temporal_zoom_by_frame (last_pointer_frame(), grab_frame());
-               }
-       } else {
-               if (Keyboard::the_keyboard().key_is_down (GDK_Shift_L)) {
-                       _editor->tav_zoom_step (_zoom_out);
-               } else {
-                       _editor->temporal_zoom_to_frame (_zoom_out, grab_frame());
-               }
-       }
-
-       _editor->zoom_rect->hide();
-}
-
-void
-MouseZoomDrag::aborted (bool)
-{
-       _editor->zoom_rect->hide ();
-}
-
 NoteDrag::NoteDrag (Editor* e, ArdourCanvas::Item* i)
        : Drag (e, i)
        , _cumulative_dx (0)
@@ -4981,8 +4945,8 @@ AutomationRangeDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
                                double const p = j->line->time_converter().from (i->start - j->line->time_converter().origin_b ());
                                double const q = j->line->time_converter().from (a - j->line->time_converter().origin_b ());
 
-                               the_list->add (p, the_list->eval (p));
-                               the_list->add (q, the_list->eval (q));
+                               the_list->editor_add (p, the_list->eval (p));
+                               the_list->editor_add (q, the_list->eval (q));
                        }
 
                        /* same thing for the end */
@@ -5007,8 +4971,8 @@ AutomationRangeDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
                                double const p = j->line->time_converter().from (b - j->line->time_converter().origin_b ());
                                double const q = j->line->time_converter().from (i->end - j->line->time_converter().origin_b ());
 
-                               the_list->add (p, the_list->eval (p));
-                               the_list->add (q, the_list->eval (q));
+                               the_list->editor_add (p, the_list->eval (p));
+                               the_list->editor_add (q, the_list->eval (q));
                        }
                }
 
@@ -5171,21 +5135,9 @@ MidiRubberbandSelectDrag::MidiRubberbandSelectDrag (Editor* e, MidiRegionView* r
 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->sample_to_pixel (x1),
-               _editor->sample_to_pixel (x2),
-               y1,
-               y2,
-               Keyboard::modifier_state_contains (button_state, Keyboard::TertiaryModifier)
-               );
+               x1, x2, y1, y2,
+               Keyboard::modifier_state_contains (button_state, Keyboard::TertiaryModifier));
 }
 
 void
@@ -5259,7 +5211,7 @@ NoteCreateDrag::NoteCreateDrag (Editor* e, ArdourCanvas::Item* i, MidiRegionView
        , _region_view (rv)
        , _drag_rect (0)
 {
-       
+       _note[0] = _note[1] = 0;
 }
 
 NoteCreateDrag::~NoteCreateDrag ()
@@ -5273,7 +5225,7 @@ 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;
+               grid_beats = Evoral::MusicalTime(1);
        }
 
        return _region_view->region_beats_to_region_frames (grid_beats);
@@ -5297,6 +5249,7 @@ NoteCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
        }
 
        _note[0] = adjusted_frame (pf, event) - _region_view->region()->position ();
+       _note[1] = _note[0];
 
        MidiStreamView* sv = _region_view->midi_stream_view ();
        double const x = _editor->sample_to_pixel (_note[0]);
@@ -5312,12 +5265,10 @@ void
 NoteCreateDrag::motion (GdkEvent* event, bool)
 {
        _note[1] = max ((framepos_t)0, adjusted_current_frame (event) - _region_view->region()->position ());
-       double const x = _editor->sample_to_pixel (_note[1]);
-       if (_note[1] > _note[0]) {
-               _drag_rect->set_x1 (x);
-       } else {
-               _drag_rect->set_x0 (x);
-       }
+       double const x0 = _editor->sample_to_pixel (_note[0]);
+       double const x1 = _editor->sample_to_pixel (_note[1]);
+       _drag_rect->set_x0 (std::min(x0, x1));
+       _drag_rect->set_x1 (std::max(x0, x1));
 }
 
 void
@@ -5331,13 +5282,14 @@ NoteCreateDrag::finished (GdkEvent*, bool had_movement)
        framecnt_t length = (framecnt_t) fabs ((double)(_note[0] - _note[1]));
 
        framecnt_t const g = grid_frames (start);
-       double const one_tick = 1 / Timecode::BBT_Time::ticks_per_beat;
+       Evoral::MusicalTime const one_tick = Evoral::MusicalTime::ticks(1);
        
        if (_editor->snap_mode() == SnapNormal && length < g) {
-               length = g - one_tick;
+               length = g;
        }
 
-       double const length_beats = max (one_tick, _region_view->region_frames_to_region_beats (length));
+       Evoral::MusicalTime length_beats = max (
+               one_tick, _region_view->region_frames_to_region_beats (length) - one_tick);
 
        _region_view->create_note_at (start, _drag_rect->y0(), length_beats, false);
 }
@@ -5452,3 +5404,47 @@ CrossfadeEdgeDrag::aborted (bool)
        }
 }
 
+RegionCutDrag::RegionCutDrag (Editor* e, ArdourCanvas::Item* item, framepos_t pos)
+       : Drag (e, item, true)
+       , line (new EditorCursor (*e))
+{
+       line->set_position (pos);
+       line->show ();
+}
+
+RegionCutDrag::~RegionCutDrag ()
+{
+       delete line;
+}
+
+void
+RegionCutDrag::motion (GdkEvent*, bool)
+{
+       framepos_t where = _drags->current_pointer_frame();
+       _editor->snap_to (where);
+
+       line->set_position (where);
+}
+
+void
+RegionCutDrag::finished (GdkEvent*, bool)
+{
+       _editor->get_track_canvas()->canvas()->re_enter();
+
+       framepos_t pos = _drags->current_pointer_frame();
+       
+       line->hide ();
+
+       RegionSelection rs = _editor->get_regions_from_selection_and_mouse (pos);
+
+       if (rs.empty()) {
+               return;
+       }
+
+       _editor->split_regions_at (pos, rs);
+}
+
+void
+RegionCutDrag::aborted (bool)
+{
+}