X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Feditor_mouse.cc;h=d75dce80791f640ce2eb03a10f3d08d463be638f;hb=129ace60e24aa7b5297563d389edbae1d70a3a80;hp=aea06d6410686f0a3ee2a42779e44135c3d12559;hpb=3ae28868ff02abf44102fff9954e7e8d6359867f;p=ardour.git diff --git a/gtk2_ardour/editor_mouse.cc b/gtk2_ardour/editor_mouse.cc index aea06d6410..d75dce8079 100644 --- a/gtk2_ardour/editor_mouse.cc +++ b/gtk2_ardour/editor_mouse.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2001 Paul Davis + Copyright (C) 2000-2001 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -31,6 +31,7 @@ #include #include "pbd/memento_command.h" #include "pbd/basename.h" +#include "pbd/stateful_diff_command.h" #include "ardour_ui.h" #include "actions.h" @@ -67,6 +68,7 @@ #include "ardour/utils.h" #include "ardour/region_factory.h" #include "ardour/source_factory.h" +#include "ardour/session.h" #include @@ -75,9 +77,9 @@ using namespace std; using namespace ARDOUR; using namespace PBD; -using namespace sigc; using namespace Gtk; using namespace Editing; +using Gtkmm2ext::Keyboard; bool Editor::mouse_frame (nframes64_t& where, bool& in_track_canvas) const @@ -91,7 +93,7 @@ Editor::mouse_frame (nframes64_t& where, bool& in_track_canvas) const if (!canvas_window) { return false; } - + pointer_window = canvas_window->get_pointer (x, y, mask); if (pointer_window == track_canvas->get_bin_window()) { @@ -108,7 +110,7 @@ Editor::mouse_frame (nframes64_t& where, bool& in_track_canvas) const event.type = GDK_BUTTON_RELEASE; event.button.x = wx; event.button.y = wy; - + where = event_frame (&event, 0, 0); return true; } @@ -133,13 +135,11 @@ Editor::event_frame (GdkEvent const * event, double* pcx, double* pcy) const case GDK_BUTTON_PRESS: case GDK_2BUTTON_PRESS: case GDK_3BUTTON_PRESS: - *pcx = event->button.x; *pcy = event->button.y; _trackview_group->w2i(*pcx, *pcy); break; case GDK_MOTION_NOTIFY: - *pcx = event->motion.x; *pcy = event->motion.y; _trackview_group->w2i(*pcx, *pcy); @@ -161,7 +161,7 @@ Editor::event_frame (GdkEvent const * event, double* pcx, double* pcy) const position is negative (as can be the case with motion events in particular), the frame location is always positive. */ - + return pixel_to_frame (*pcx); } @@ -172,14 +172,14 @@ Editor::which_grabber_cursor () if (_internal_editing) { switch (mouse_mode) { - case MouseObject: + case MouseRange: c = midi_pencil_cursor; break; - - case MouseRange: - c = midi_select_cursor; + + case MouseObject: + c = grabber_cursor; break; - + case MouseTimeFX: c = midi_resize_cursor; break; @@ -208,14 +208,14 @@ Editor::set_canvas_cursor () if (_internal_editing) { switch (mouse_mode) { - case MouseObject: + case MouseRange: current_canvas_cursor = midi_pencil_cursor; break; - - case MouseRange: - current_canvas_cursor = midi_select_cursor; + + case MouseObject: + current_canvas_cursor = which_grabber_cursor(); break; - + case MouseTimeFX: current_canvas_cursor = midi_resize_cursor; break; @@ -230,29 +230,40 @@ Editor::set_canvas_cursor () case MouseRange: current_canvas_cursor = selector_cursor; break; - + case MouseObject: current_canvas_cursor = which_grabber_cursor(); break; - + case MouseGain: current_canvas_cursor = cross_hair_cursor; break; - + case MouseZoom: current_canvas_cursor = zoom_cursor; break; - + case MouseTimeFX: current_canvas_cursor = time_fx_cursor; // just use playhead break; - + case MouseAudition: current_canvas_cursor = speaker_cursor; break; } } + switch (_join_object_range_state) { + case JOIN_OBJECT_RANGE_NONE: + break; + case JOIN_OBJECT_RANGE_OBJECT: + current_canvas_cursor = which_grabber_cursor (); + break; + case JOIN_OBJECT_RANGE_RANGE: + current_canvas_cursor = selector_cursor; + break; + } + if (is_drawable()) { track_canvas->get_window()->set_cursor(*current_canvas_cursor); } @@ -261,7 +272,7 @@ Editor::set_canvas_cursor () void Editor::set_mouse_mode (MouseMode m, bool force) { - if (_drag) { + if (_drags->active ()) { return; } @@ -301,6 +312,9 @@ Editor::set_mouse_mode (MouseMode m, bool force) Glib::RefPtr tact = Glib::RefPtr::cast_dynamic (act); assert (tact); + + /* go there and back to ensure that the toggled handler is called to set up mouse_mode */ + tact->set_active (false); tact->set_active (true); } @@ -311,9 +325,9 @@ Editor::mouse_mode_toggled (MouseMode m) instant_save (); - if (mouse_mode != MouseRange) { + if (mouse_mode != MouseRange && _join_object_range_state == JOIN_OBJECT_RANGE_NONE) { - /* in all modes except range, hide the range selection, + /* in all modes except range and joined object/range, hide the range selection, show the object (region) selection. */ @@ -326,14 +340,12 @@ Editor::mouse_mode_toggled (MouseMode m) } else { - /* - in range mode,show the range selection. + /* + in range or object/range mode, show the range selection. */ for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) { - if ((*i)->get_selected()) { - (*i)->show_selection (selection->time); - } + (*i)->show_selection (selection->time); } } @@ -376,12 +388,12 @@ Editor::step_mouse_mode (bool next) } } break; - + case MouseGain: if (next) set_mouse_mode (MouseTimeFX); else set_mouse_mode (MouseZoom); break; - + case MouseTimeFX: if (next) { set_mouse_mode (MouseAudition); @@ -414,45 +426,51 @@ Editor::button_selection (ArdourCanvas::Item* /*item*/, GdkEvent* event, ItemTyp */ if (((mouse_mode != MouseObject) && + (_join_object_range_state != JOIN_OBJECT_RANGE_OBJECT) && (mouse_mode != MouseAudition || item_type != RegionItem) && (mouse_mode != MouseTimeFX || item_type != RegionItem) && (mouse_mode != MouseGain) && (mouse_mode != MouseRange)) || ((event->type != GDK_BUTTON_PRESS && event->type != GDK_BUTTON_RELEASE) || event->button.button > 3)) { - + return; } if (event->type == GDK_BUTTON_PRESS || event->type == GDK_BUTTON_RELEASE) { if ((event->button.state & Keyboard::RelevantModifierKeyMask) && event->button.button != 1) { - + /* almost no selection action on modified button-2 or button-3 events */ - + if (item_type != RegionItem && event->button.button != 2) { return; } } } - Selection::Operation op = Keyboard::selection_type (event->button.state); + Selection::Operation op = ArdourKeyboard::selection_type (event->button.state); bool press = (event->type == GDK_BUTTON_PRESS); // begin_reversible_command (_("select on click")); - + switch (item_type) { case RegionItem: - if (mouse_mode != MouseRange) { + if (mouse_mode != MouseRange || _join_object_range_state == JOIN_OBJECT_RANGE_OBJECT) { set_selected_regionview_from_click (press, op, true); } else if (event->type == GDK_BUTTON_PRESS) { - set_selected_track_as_side_effect (); + selection->clear_tracks (); + set_selected_track_as_side_effect (true); } + if (_join_object_range_state == JOIN_OBJECT_RANGE_OBJECT && !selection->regions.empty()) { + clicked_selection = select_range_around_region (selection->regions.front()); + } + break; - + case RegionViewNameHighlight: case RegionViewName: - if (mouse_mode != MouseRange) { + if (mouse_mode != MouseRange || _join_object_range_state == JOIN_OBJECT_RANGE_OBJECT) { set_selected_regionview_from_click (press, op, true); } else if (event->type == GDK_BUTTON_PRESS) { set_selected_track_as_side_effect (); @@ -464,7 +482,7 @@ Editor::button_selection (ArdourCanvas::Item* /*item*/, GdkEvent* event, ItemTyp case FadeInItem: case FadeOutHandleItem: case FadeOutItem: - if (mouse_mode != MouseRange) { + if (mouse_mode != MouseRange || _join_object_range_state == JOIN_OBJECT_RANGE_OBJECT) { set_selected_regionview_from_click (press, op, true); } else if (event->type == GDK_BUTTON_PRESS) { set_selected_track_as_side_effect (); @@ -473,486 +491,465 @@ Editor::button_selection (ArdourCanvas::Item* /*item*/, GdkEvent* event, ItemTyp case ControlPointItem: set_selected_track_as_side_effect (); - if (mouse_mode != MouseRange) { + if (mouse_mode != MouseRange || _join_object_range_state == JOIN_OBJECT_RANGE_OBJECT) { set_selected_control_point_from_click (op, false); } break; - + case StreamItem: - /* for context click or range selection, select track */ + /* for context click, select track */ if (event->button.button == 3) { - set_selected_track_as_side_effect (); - } else if (event->type == GDK_BUTTON_PRESS && mouse_mode == MouseRange) { - set_selected_track_as_side_effect (); + selection->clear_tracks (); + set_selected_track_as_side_effect (true); } break; - + case AutomationTrackItem: set_selected_track_as_side_effect (true); break; - + default: break; } } bool -Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type) +Editor::button_press_handler_1 (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type) { - Glib::RefPtr canvas_window = const_cast(this)->track_canvas->get_window(); + if (_drags->active ()) { + _drags->abort (); + } - if (canvas_window) { - Glib::RefPtr pointer_window; - int x, y; - double wx, wy; - Gdk::ModifierType mask; + /* single mouse clicks on any of these item types operate + independent of mouse mode, mostly because they are + not on the main track canvas or because we want + them to be modeless. + */ - pointer_window = canvas_window->get_pointer (x, y, mask); - - if (pointer_window == track_canvas->get_bin_window()) { - track_canvas->window_to_world (x, y, wx, wy); - allow_vertical_scroll = true; + switch (item_type) { + case PlayheadCursorItem: + _drags->set (new CursorDrag (this, item, true), event); + return true; + + case MarkerItem: + if (Keyboard::modifier_state_equals (event->button.state, Keyboard::ModifierMask(Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) { + hide_marker (item, event); } else { - allow_vertical_scroll = false; + _drags->set (new MarkerDrag (this, item), event); } - } + return true; - track_canvas->grab_focus(); + case TempoMarkerItem: + _drags->set ( + new TempoMarkerDrag ( + this, + item, + Keyboard::modifier_state_contains (event->button.state, Keyboard::CopyModifier) + ), + event + ); + return true; - if (session && session->actively_recording()) { + case MeterMarkerItem: + _drags->set ( + new MeterMarkerDrag ( + this, + item, + Keyboard::modifier_state_contains (event->button.state, Keyboard::CopyModifier) + ), + event + ); return true; - } - button_selection (item, event, item_type); + case MarkerBarItem: + case TempoBarItem: + case MeterBarItem: + if (!Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) { + _drags->set (new CursorDrag (this, &playhead_cursor->canvas_item, false), event); + } + return true; + break; - if (_drag == 0 && - (Keyboard::is_delete_event (&event->button) || - Keyboard::is_context_menu_event (&event->button) || - Keyboard::is_edit_event (&event->button))) { - - /* handled by button release */ + + case RangeMarkerBarItem: + if (!Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) { + _drags->set (new CursorDrag (this, &playhead_cursor->canvas_item, false), event); + } else { + _drags->set (new RangeMarkerBarDrag (this, item, RangeMarkerBarDrag::CreateRangeMarker), event); + } + return true; + break; + + case CdMarkerBarItem: + if (!Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) { + _drags->set (new CursorDrag (this, &playhead_cursor->canvas_item, false), event); + } else { + _drags->set (new RangeMarkerBarDrag (this, item, RangeMarkerBarDrag::CreateCDMarker), event); + } return true; + break; + + case TransportMarkerBarItem: + if (!Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) { + _drags->set (new CursorDrag (this, &playhead_cursor->canvas_item, false), event); + } else { + _drags->set (new RangeMarkerBarDrag (this, item, RangeMarkerBarDrag::CreateTransportMarker), event); + } + return true; + break; + + default: + break; } - switch (event->button.button) { - case 1: + if (_join_object_range_state == JOIN_OBJECT_RANGE_OBJECT) { + /* special case: allow trim of range selections in joined object mode; + in theory eff should equal MouseRange in this case, but it doesn't + because entering the range selection canvas item results in entered_regionview + being set to 0, so update_join_object_range_location acts as if we aren't + over a region. + */ + if (item_type == StartSelectionTrimItem) { + _drags->set (new SelectionDrag (this, item, SelectionDrag::SelectionStartTrim), event); + } else if (item_type == EndSelectionTrimItem) { + _drags->set (new SelectionDrag (this, item, SelectionDrag::SelectionEndTrim), event); + } + } - if (event->type == GDK_BUTTON_PRESS) { + Editing::MouseMode eff = effective_mouse_mode (); + + /* special case: allow drag of region fade in/out in object mode with join object/range enabled */ + if (item_type == FadeInHandleItem || item_type == FadeOutHandleItem) { + eff = MouseObject; + } + + switch (eff) { + case MouseRange: + switch (item_type) { + case StartSelectionTrimItem: + _drags->set (new SelectionDrag (this, item, SelectionDrag::SelectionStartTrim), event); + break; + + case EndSelectionTrimItem: + _drags->set (new SelectionDrag (this, item, SelectionDrag::SelectionEndTrim), event); + break; + + case SelectionItem: + if (Keyboard::modifier_state_contains + (event->button.state, Keyboard::ModifierMask(Keyboard::PrimaryModifier))) { + // contains and not equals because I can't use alt as a modifier alone. + start_selection_grab (item, event); + } else if (Keyboard::modifier_state_equals (event->button.state, Keyboard::SecondaryModifier)) { + /* grab selection for moving */ + _drags->set (new SelectionDrag (this, item, SelectionDrag::SelectionMove), event); + } else { + double const y = event->button.y + vertical_adjustment.get_value() - canvas_timebars_vsize; + pair tvp = trackview_by_y_position (y); + if (tvp.first) { + AutomationTimeAxisView* atv = dynamic_cast (tvp.first); + if (join_object_range_button.get_active() && atv) { + /* smart "join" mode: drag automation */ + _drags->set (new AutomationRangeDrag (this, atv->base_item(), selection->time), event); + } else { + /* this was debated, but decided the more common action was to + make a new selection */ + _drags->set (new SelectionDrag (this, item, SelectionDrag::CreateSelection), event); + } + } + } + break; + + default: + _drags->set (new SelectionDrag (this, item, SelectionDrag::CreateSelection), event); + } + return true; + break; - if (_drag) { - _drag->item()->ungrab (event->button.time); + case MouseObject: + switch (item_type) { + case NoteItem: + if (internal_editing()) { + /* Note: we don't get here if not in internal_editing() mode */ + _drags->set (new NoteDrag (this, item), event); + return true; } + break; + + default: + break; + } - /* single mouse clicks on any of these item types operate - independent of mouse mode, mostly because they are - not on the main track canvas or because we want - them to be modeless. - */ + if (Keyboard::modifier_state_contains (event->button.state, Keyboard::ModifierMask(Keyboard::PrimaryModifier|Keyboard::SecondaryModifier)) && + event->type == GDK_BUTTON_PRESS) { + + _drags->set (new RubberbandSelectDrag (this, item), event); + + } else if (event->type == GDK_BUTTON_PRESS) { switch (item_type) { - case PlayheadCursorItem: - assert (_drag == 0); - _drag = new CursorDrag (this, item, true); - _drag->start_grab (event); + case FadeInHandleItem: + { + RegionSelection s = get_equivalent_regions (selection->regions, Properties::edit.property_id); + _drags->set (new FadeInDrag (this, item, reinterpret_cast (item->get_data("regionview")), s), event); return true; + } - case MarkerItem: - if (Keyboard::modifier_state_equals (event->button.state, Keyboard::ModifierMask(Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) { - hide_marker (item, event); + case FadeOutHandleItem: + { + RegionSelection s = get_equivalent_regions (selection->regions, Properties::edit.property_id); + _drags->set (new FadeOutDrag (this, item, reinterpret_cast (item->get_data("regionview")), s), event); + return true; + } + + case RegionItem: + if (Keyboard::modifier_state_contains (event->button.state, Keyboard::CopyModifier)) { + add_region_copy_drag (item, event, clicked_regionview); + } else if (Keyboard::the_keyboard().key_is_down (GDK_b)) { + add_region_brush_drag (item, event, clicked_regionview); } else { - assert (_drag == 0); - _drag = new MarkerDrag (this, item); - _drag->start_grab (event); + add_region_drag (item, event, clicked_regionview); } - return true; - case TempoMarkerItem: - assert (_drag == 0); - _drag = new TempoMarkerDrag ( - this, - item, - Keyboard::modifier_state_contains (event->button.state, Keyboard::CopyModifier) - ); - _drag->start_grab (event); - return true; + if (_join_object_range_state == JOIN_OBJECT_RANGE_OBJECT && !selection->regions.empty()) { + _drags->add (new SelectionDrag (this, clicked_axisview->get_selection_rect (clicked_selection)->rect, SelectionDrag::SelectionMove)); + } - case MeterMarkerItem: - assert (_drag == 0); + _drags->start_grab (event); + break; - _drag = new MeterMarkerDrag ( - this, - item, - Keyboard::modifier_state_contains (event->button.state, Keyboard::CopyModifier) - ); - - _drag->start_grab (event); + case RegionViewNameHighlight: + { + RegionSelection s = get_equivalent_regions (selection->regions, Properties::edit.property_id); + _drags->set (new TrimDrag (this, item, clicked_regionview, s.by_layer()), event); return true; + break; + } - case MarkerBarItem: - case TempoBarItem: - case MeterBarItem: - if (!Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) { - assert (_drag == 0); - _drag = new CursorDrag (this, &playhead_cursor->canvas_item, false); - _drag->start_grab (event); - } + case RegionViewName: + { + /* rename happens on edit clicks */ + RegionSelection s = get_equivalent_regions (selection->regions, Properties::edit.property_id); + _drags->set (new TrimDrag (this, clicked_regionview->get_name_highlight(), clicked_regionview, s.by_layer()), event); return true; break; + } - - case RangeMarkerBarItem: - assert (_drag == 0); - if (!Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) { - _drag = new CursorDrag (this, &playhead_cursor->canvas_item, false); - } else { - _drag = new RangeMarkerBarDrag (this, item, RangeMarkerBarDrag::CreateRangeMarker); - } - _drag->start_grab (event); + case ControlPointItem: + _drags->set (new ControlPointDrag (this, item), event); return true; break; - case CdMarkerBarItem: - assert (_drag == 0); - if (!Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) { - _drag = new CursorDrag (this, &playhead_cursor->canvas_item, false); - } else { - _drag = new RangeMarkerBarDrag (this, item, RangeMarkerBarDrag::CreateCDMarker); - } - _drag->start_grab (event); + case AutomationLineItem: + _drags->set (new LineDrag (this, item), event); return true; break; - case TransportMarkerBarItem: - assert (_drag == 0); - if (!Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) { - _drag = new CursorDrag (this, &playhead_cursor->canvas_item, false); + case StreamItem: + if (internal_editing()) { + _drags->set (new RegionCreateDrag (this, item, clicked_axisview), event); + return true; } else { - _drag = new RangeMarkerBarDrag (this, item, RangeMarkerBarDrag::CreateTransportMarker); + _drags->set (new RubberbandSelectDrag (this, item), event); } - _drag->start_grab (event); - return true; break; - default: + case AutomationTrackItem: + /* rubberband drag to select automation points */ + _drags->set (new RubberbandSelectDrag (this, item), event); break; - } - } - if (internal_editing()) { - assert (_drag == 0); - _drag = new RegionCreateDrag (this, item, clicked_axisview); - _drag->start_grab (event); - cerr << "--- DRAG START FOR RCD\n"; - } else { - switch (mouse_mode) { - case MouseRange: - switch (item_type) { - case StartSelectionTrimItem: - assert (_drag == 0); - _drag = new SelectionDrag (this, item, SelectionDrag::SelectionStartTrim); - _drag->start_grab (event); - break; - - case EndSelectionTrimItem: - assert (_drag == 0); - _drag = new SelectionDrag (this, item, SelectionDrag::SelectionEndTrim); - _drag->start_grab (event); - break; + case SelectionItem: + { + if (join_object_range_button.get_active()) { + /* we're in "smart" joined mode, and we've clicked on a Selection */ + double const y = event->button.y + vertical_adjustment.get_value() - canvas_timebars_vsize; + pair tvp = trackview_by_y_position (y); + if (tvp.first) { + /* if we're over an automation track, start a drag of its data */ + AutomationTimeAxisView* atv = dynamic_cast (tvp.first); + if (atv) { + _drags->set (new AutomationRangeDrag (this, atv->base_item(), selection->time), event); + } - case SelectionItem: - if (Keyboard::modifier_state_contains - (event->button.state, Keyboard::ModifierMask(Keyboard::SecondaryModifier))) { - // contains and not equals because I can't use alt as a modifier alone. - start_selection_grab (item, event); - } else if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) { - /* grab selection for moving */ - assert (_drag == 0); - _drag = new SelectionDrag (this, item, SelectionDrag::SelectionMove); - _drag->start_grab (event); - } else { - /* this was debated, but decided the more common action was to - make a new selection */ - assert (_drag == 0); - _drag = new SelectionDrag (this, item, SelectionDrag::CreateSelection); - _drag->start_grab (event); + /* if we're over a track and a region, and in the `object' part of a region, + put a selection around the region and drag both + */ + RouteTimeAxisView* rtv = dynamic_cast (tvp.first); + if (rtv && _join_object_range_state == JOIN_OBJECT_RANGE_OBJECT) { + boost::shared_ptr t = boost::dynamic_pointer_cast (rtv->route ()); + if (t) { + boost::shared_ptr pl = t->playlist (); + if (pl) { + + boost::shared_ptr r = pl->top_region_at (event_frame (event)); + if (r) { + RegionView* rv = rtv->view()->find_view (r); + clicked_selection = select_range_around_region (rv); + _drags->add (new SelectionDrag (this, item, SelectionDrag::SelectionMove)); + list rvs; + rvs.push_back (rv); + _drags->add (new RegionMoveDrag (this, item, rv, rvs, false, false)); + _drags->start_grab (event); + } + } + } + } } - break; - - default: - assert (_drag == 0); - _drag = new SelectionDrag (this, item, SelectionDrag::CreateSelection); - _drag->start_grab (event); } - return true; break; - - case MouseObject: - if (Keyboard::modifier_state_contains (event->button.state, Keyboard::ModifierMask(Keyboard::PrimaryModifier|Keyboard::SecondaryModifier)) && - event->type == GDK_BUTTON_PRESS) { - - assert (_drag == 0); - _drag = new RubberbandSelectDrag (this, item); - _drag->start_grab (event); - - } else if (event->type == GDK_BUTTON_PRESS) { - - switch (item_type) { - case FadeInHandleItem: - { - assert (_drag == 0); - RegionSelection s = get_equivalent_regions (selection->regions, RouteGroup::Edit); - _drag = new FadeInDrag (this, item, reinterpret_cast (item->get_data("regionview")), s); - _drag->start_grab (event); - return true; - } - - case FadeOutHandleItem: - { - assert (_drag == 0); - RegionSelection s = get_equivalent_regions (selection->regions, RouteGroup::Edit); - _drag = new FadeOutDrag (this, item, reinterpret_cast (item->get_data("regionview")), s); - _drag->start_grab (event); - return true; - } - - case RegionItem: - if (Keyboard::modifier_state_contains (event->button.state, Keyboard::CopyModifier)) { - start_region_copy_grab (item, event, clicked_regionview); - } else if (Keyboard::the_keyboard().key_is_down (GDK_b)) { - start_region_brush_grab (item, event, clicked_regionview); - } else { - start_region_grab (item, event, clicked_regionview); - } - break; - - case RegionViewNameHighlight: - { - assert (_drag == 0); - RegionSelection s = get_equivalent_regions (selection->regions, RouteGroup::Edit); - _drag = new TrimDrag (this, item, clicked_regionview, s.by_layer()); - _drag->start_grab (event); - return true; - break; - } - - case RegionViewName: - { - /* rename happens on edit clicks */ - assert (_drag == 0); - RegionSelection s = get_equivalent_regions (selection->regions, RouteGroup::Edit); - _drag = new TrimDrag (this, clicked_regionview->get_name_highlight(), clicked_regionview, s.by_layer()); - _drag->start_grab (event); - return true; - break; - } + } - case ControlPointItem: - assert (_drag == 0); - _drag = new ControlPointDrag (this, item); - _drag->start_grab (event); - return true; - break; - - case AutomationLineItem: - assert (_drag == 0); - _drag = new LineDrag (this, item); - _drag->start_grab (event); - return true; - break; - - case StreamItem: - case AutomationTrackItem: - assert (_drag == 0); - _drag = new RubberbandSelectDrag (this, item); - _drag->start_grab (event); - break; - #ifdef WITH_CMT - case ImageFrameHandleStartItem: - imageframe_start_handle_op(item, event) ; - return(true) ; - break ; - case ImageFrameHandleEndItem: - imageframe_end_handle_op(item, event) ; - return(true) ; - break ; - case MarkerViewHandleStartItem: - markerview_item_start_handle_op(item, event) ; - return(true) ; - break ; - case MarkerViewHandleEndItem: - markerview_item_end_handle_op(item, event) ; - return(true) ; - break ; - case MarkerViewItem: - start_markerview_grab(item, event) ; - break ; - case ImageFrameItem: - start_imageframe_grab(item, event) ; - break ; + case ImageFrameHandleStartItem: + imageframe_start_handle_op(item, event) ; + return(true) ; + break ; + case ImageFrameHandleEndItem: + imageframe_end_handle_op(item, event) ; + return(true) ; + break ; + case MarkerViewHandleStartItem: + markerview_item_start_handle_op(item, event) ; + return(true) ; + break ; + case MarkerViewHandleEndItem: + markerview_item_end_handle_op(item, event) ; + return(true) ; + break ; + case MarkerViewItem: + start_markerview_grab(item, event) ; + break ; + case ImageFrameItem: + start_imageframe_grab(item, event) ; + break ; #endif - case MarkerBarItem: - - break; + case MarkerBarItem: - default: - break; - } - } - return true; break; - - case MouseGain: - switch (item_type) { - case RegionItem: - /* start a grab so that if we finish after moving - we can tell what happened. - */ - assert (_drag == 0); - _drag = new RegionGainDrag (this, item); - _drag->start_grab (event, current_canvas_cursor); - break; - case GainLineItem: - assert (_drag == 0); - _drag = new LineDrag (this, item); - _drag->start_grab (event); - return true; + default: + break; + } + } + return true; + break; - case ControlPointItem: - assert (_drag == 0); - _drag = new ControlPointDrag (this, item); - _drag->start_grab (event); - return true; - break; + case MouseGain: + switch (item_type) { + case RegionItem: + /* start a grab so that if we finish after moving + we can tell what happened. + */ + _drags->set (new RegionGainDrag (this, item), event, current_canvas_cursor); + break; - default: - break; - } - return true; - break; + case GainLineItem: + _drags->set (new LineDrag (this, item), event); + return true; - switch (item_type) { - case ControlPointItem: - assert (_drag == 0); - _drag = new ControlPointDrag (this, item); - _drag->start_grab (event); - break; + case ControlPointItem: + _drags->set (new ControlPointDrag (this, item), event); + return true; + break; - case AutomationLineItem: - assert (_drag == 0); - _drag = new LineDrag (this, item); - _drag->start_grab (event); - break; + default: + break; + } + return true; + break; - case RegionItem: - // XXX need automation mode to identify which - // line to use - // start_line_grab_from_regionview (item, event); - break; + switch (item_type) { + case ControlPointItem: + _drags->set (new ControlPointDrag (this, item), event); + break; - default: - break; - } - return true; - break; + case AutomationLineItem: + _drags->set (new LineDrag (this, item), event); + break; - case MouseZoom: - if (event->type == GDK_BUTTON_PRESS) { - assert (_drag == 0); - _drag = new MouseZoomDrag (this, item); - _drag->start_grab (event); - } + case RegionItem: + // XXX need automation mode to identify which + // line to use + // start_line_grab_from_regionview (item, event); + break; - return true; - break; + default: + break; + } + return true; + break; - case MouseTimeFX: - if (item_type == RegionItem) { - assert (_drag == 0); - _drag = new TimeFXDrag (this, item, clicked_regionview, selection->regions.by_layer()); - _drag->start_grab (event); - } - break; + case MouseZoom: + if (event->type == GDK_BUTTON_PRESS) { + _drags->set (new MouseZoomDrag (this, item), event); + } - case MouseAudition: - _drag = new ScrubDrag (this, item); - _drag->start_grab (event); - scrub_reversals = 0; - scrub_reverse_distance = 0; - last_scrub_x = event->button.x; - scrubbing_direction = 0; - track_canvas->get_window()->set_cursor (*transparent_cursor); - break; + return true; + break; - default: - break; - } + case MouseTimeFX: + if (internal_editing() && item_type == NoteItem) { + /* drag notes if we're in internal edit mode */ + _drags->set (new NoteResizeDrag (this, item), event); + return true; + } else if (!internal_editing() || dynamic_cast (clicked_regionview)) { + /* do time-FX if we're not in internal edit mode, or we are but we clicked on an audio region */ + _drags->set (new TimeFXDrag (this, item, clicked_regionview, selection->regions.by_layer()), event); + return true; } break; - case 2: - switch (mouse_mode) { - case MouseObject: - if (event->type == GDK_BUTTON_PRESS) { - switch (item_type) { - case RegionItem: - if (Keyboard::modifier_state_contains (event->button.state, Keyboard::CopyModifier)) { - start_region_copy_grab (item, event, clicked_regionview); - } else { - start_region_grab (item, event, clicked_regionview); - } - return true; - break; - case ControlPointItem: - assert (_drag == 0); - _drag = new ControlPointDrag (this, item); - _drag->start_grab (event); - return true; - break; - - default: - break; - } - } - - - switch (item_type) { - case RegionViewNameHighlight: - assert (_drag == 0); - _drag = new TrimDrag (this, item, clicked_regionview, selection->regions.by_layer()); - _drag->start_grab (event); - return true; - break; - - case RegionViewName: - assert (_drag == 0); - _drag = new TrimDrag (this, clicked_regionview->get_name_highlight(), clicked_regionview, selection->regions.by_layer()); - _drag->start_grab (event); - return true; - break; - - default: - break; + case MouseAudition: + _drags->set (new ScrubDrag (this, item), event); + scrub_reversals = 0; + scrub_reverse_distance = 0; + last_scrub_x = event->button.x; + scrubbing_direction = 0; + track_canvas->get_window()->set_cursor (*transparent_cursor); + return true; + break; + + default: + break; + } + + return false; +} + +bool +Editor::button_press_handler_2 (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type) +{ + Editing::MouseMode const eff = effective_mouse_mode (); + switch (eff) { + case MouseObject: + switch (item_type) { + case RegionItem: + if (Keyboard::modifier_state_contains (event->button.state, Keyboard::CopyModifier)) { + add_region_copy_drag (item, event, clicked_regionview); + } else { + add_region_drag (item, event, clicked_regionview); } - + _drags->start_grab (event); + return true; + break; + case ControlPointItem: + _drags->set (new ControlPointDrag (this, item), event); + return true; break; - case MouseRange: - if (event->type == GDK_BUTTON_PRESS) { - /* relax till release */ - } + default: + break; + } + + switch (item_type) { + case RegionViewNameHighlight: + _drags->set (new TrimDrag (this, item, clicked_regionview, selection->regions.by_layer()), event); return true; break; - - - case MouseZoom: - if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) { - temporal_zoom_session(); - } else { - temporal_zoom_to_frame (true, event_frame(event)); - } + + case RegionViewName: + _drags->set (new TrimDrag (this, clicked_regionview->get_name_highlight(), clicked_regionview, selection->regions.by_layer()), event); return true; break; @@ -962,6 +959,79 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp break; + case MouseRange: + /* relax till release */ + return true; + break; + + + case MouseZoom: + if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) { + temporal_zoom_session(); + } else { + temporal_zoom_to_frame (true, event_frame(event)); + } + return true; + break; + + default: + break; + } + + return false; +} + +bool +Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type) +{ + if (event->type != GDK_BUTTON_PRESS) { + return false; + } + + Glib::RefPtr canvas_window = const_cast(this)->track_canvas->get_window(); + + if (canvas_window) { + Glib::RefPtr pointer_window; + int x, y; + double wx, wy; + Gdk::ModifierType mask; + + pointer_window = canvas_window->get_pointer (x, y, mask); + + if (pointer_window == track_canvas->get_bin_window()) { + track_canvas->window_to_world (x, y, wx, wy); + allow_vertical_scroll = true; + } else { + allow_vertical_scroll = false; + } + } + + track_canvas->grab_focus(); + + if (_session && _session->actively_recording()) { + return true; + } + + button_selection (item, event, item_type); + + if (!_drags->active () && + (Keyboard::is_delete_event (&event->button) || + Keyboard::is_context_menu_event (&event->button) || + Keyboard::is_edit_event (&event->button))) { + + /* handled by button release */ + return true; + } + + switch (event->button.button) { + case 1: + return button_press_handler_1 (item, event, item_type); + break; + + case 2: + return button_press_handler_2 (item, event, item_type); + break; + case 3: break; @@ -978,21 +1048,18 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT { nframes64_t where = event_frame (event, 0, 0); AutomationTimeAxisView* atv = 0; - + /* no action if we're recording */ - - if (session && session->actively_recording()) { + + if (_session && _session->actively_recording()) { return true; } /* first, see if we're finishing a drag ... */ bool were_dragging = false; - if (_drag) { - bool const r = _drag->end_grab (event); - delete _drag; - _drag = 0; - cerr << "DRAG DONE, r = " << r << endl; + if (_drags->active ()) { + bool const r = _drags->end_grab (event); if (r) { /* grab dragged, so do nothing else */ return true; @@ -1000,12 +1067,12 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT were_dragging = true; } - + button_selection (item, event, item_type); /* edit events get handled here */ - if (_drag == 0 && Keyboard::is_edit_event (&event->button)) { + if (!_drags->active () && Keyboard::is_edit_event (&event->button)) { switch (item_type) { case RegionItem: edit_region (); @@ -1014,11 +1081,11 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT case TempoMarkerItem: edit_tempo_marker (item); break; - + case MeterMarkerItem: edit_meter_marker (item); break; - + case RegionViewName: if (clicked_regionview->name_active()) { return mouse_rename_region (item, event); @@ -1039,7 +1106,7 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT if (Keyboard::is_context_menu_event (&event->button)) { - if (_drag == 0) { + if (!_drags->active ()) { /* no matter which button pops up the context menu, tell the menu widget to use button 1 to drive menu selection. @@ -1052,17 +1119,17 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT case FadeOutHandleItem: popup_fade_context_menu (1, event->button.time, item, item_type); break; - + case StreamItem: popup_track_context_menu (1, event->button.time, item_type, false, where); break; - + case RegionItem: case RegionViewNameHighlight: case RegionViewName: popup_track_context_menu (1, event->button.time, item_type, false, where); break; - + case SelectionItem: popup_track_context_menu (1, event->button.time, item_type, true, where); break; @@ -1071,8 +1138,8 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT popup_track_context_menu (1, event->button.time, item_type, false, where); break; - case MarkerBarItem: - case RangeMarkerBarItem: + case MarkerBarItem: + case RangeMarkerBarItem: case TransportMarkerBarItem: case CdMarkerBarItem: case TempoBarItem: @@ -1085,13 +1152,13 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT break; case TempoMarkerItem: - tm_marker_context_menu (&event->button, item); + tempo_or_meter_marker_context_menu (&event->button, item); break; - + case MeterMarkerItem: - tm_marker_context_menu (&event->button, item); + tempo_or_meter_marker_context_menu (&event->button, item); break; - + case CrossfadeViewItem: popup_track_context_menu (1, event->button.time, item_type, false, where); break; @@ -1110,7 +1177,7 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT popup_marker_time_axis_edit_menu(1, event->button.time, item, false) ; break ; #endif - + default: break; } @@ -1121,13 +1188,15 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT /* delete events get handled here */ - if (_drag == 0 && Keyboard::is_delete_event (&event->button)) { + Editing::MouseMode const eff = effective_mouse_mode (); + + if (!_drags->active () && Keyboard::is_delete_event (&event->button)) { switch (item_type) { case TempoMarkerItem: remove_tempo_marker (item); break; - + case MeterMarkerItem: remove_meter_marker (item); break; @@ -1137,13 +1206,13 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT break; case RegionItem: - if (mouse_mode == MouseObject) { + if (eff == MouseObject) { remove_clicked_region (); } break; - + case ControlPointItem: - if (mouse_mode == MouseGain) { + if (eff == MouseGain) { remove_gain_control_point (item, event); } else { remove_control_point (item, event); @@ -1171,9 +1240,7 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT case MarkerBarItem: if (!_dragging_playhead) { - if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) { - snap_to (where, 0, true); - } + snap_to_with_modifier (where, event, 0, true); mouse_add_new_marker (where); } return true; @@ -1181,45 +1248,40 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT case CdMarkerBarItem: if (!_dragging_playhead) { // if we get here then a dragged range wasn't done - if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) { - snap_to (where, 0, true); - } + snap_to_with_modifier (where, event, 0, true); mouse_add_new_marker (where, true); } return true; case TempoBarItem: if (!_dragging_playhead) { - if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) { - snap_to (where); - } + snap_to_with_modifier (where, event); mouse_add_new_tempo_event (where); } return true; - + case MeterBarItem: if (!_dragging_playhead) { mouse_add_new_meter_event (pixel_to_frame (event->button.x)); - } + } return true; break; default: break; } - - switch (mouse_mode) { + + switch (eff) { case MouseObject: switch (item_type) { case AutomationTrackItem: atv = dynamic_cast(clicked_axisview); if (atv) { atv->add_automation_event (item, event, where, event->button.y); - } + } return true; - break; - + default: break; } @@ -1243,7 +1305,7 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT } return true; break; - + case AutomationTrackItem: dynamic_cast(clicked_axisview)-> add_automation_event (item, event, where, event->button.y); @@ -1253,7 +1315,7 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT break; } break; - + case MouseAudition: track_canvas->get_window()->set_cursor (*current_canvas_cursor); if (scrubbing_direction == 0) { @@ -1267,10 +1329,10 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT } } else { /* make sure we stop */ - session->request_transport_speed (0.0); - } + _session->request_transport_speed (0.0); + } break; - + default: break; @@ -1281,8 +1343,8 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT case 2: - switch (mouse_mode) { - + switch (eff) { + case MouseObject: switch (item_type) { case RegionItem: @@ -1294,29 +1356,29 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT // Button2 click is unused } return true; - + break; - + default: break; } break; - + case MouseRange: - + // x_style_paste (where, 1.0); return true; break; - + default: break; } break; - + case 3: break; - + default: break; } @@ -1324,12 +1386,12 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT } bool -Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* /*event*/, ItemType item_type) +Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type) { ControlPoint* cp; Marker * marker; double fraction; - + if (last_item_entered != item) { last_item_entered = item; last_item_entered_n = 0; @@ -1344,13 +1406,13 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* /*event*/, ItemType i double at_x, at_y; at_x = cp->get_x(); at_y = cp->get_y (); - cp->item()->i2w (at_x, at_y); + cp->i2w (at_x, at_y); at_x += 10.0; at_y += 10.0; fraction = 1.0 - (cp->get_y() / cp->line().height()); - if (is_drawable() && dynamic_cast (_drag) == 0) { + if (is_drawable() && !_drags->active ()) { track_canvas->get_window()->set_cursor (*fader_cursor); } @@ -1372,7 +1434,7 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* /*event*/, ItemType i } } break; - + case AutomationLineItem: if (mouse_mode == MouseGain || mouse_mode == MouseObject) { { @@ -1385,7 +1447,7 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* /*event*/, ItemType i } } break; - + case RegionViewNameHighlight: if (is_drawable() && mouse_mode == MouseObject) { track_canvas->get_window()->set_cursor (*trimmer_cursor); @@ -1421,14 +1483,14 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* /*event*/, ItemType i break; case RegionViewName: - + /* when the name is not an active item, the entire name highlight is for trimming */ if (!reinterpret_cast (item->get_data ("regionview"))->name_active()) { if (mouse_mode == MouseObject && is_drawable()) { track_canvas->get_window()->set_cursor (*trimmer_cursor); } - } + } break; @@ -1489,6 +1551,7 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* /*event*/, ItemType i rect->property_fill_color_rgba() = 0; rect->property_outline_pixels() = 1; } + track_canvas->get_window()->set_cursor (*grabber_cursor); } break; @@ -1520,7 +1583,7 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* /*event*/, ItemType i } bool -Editor::leave_handler (ArdourCanvas::Item* item, GdkEvent* /*event*/, ItemType item_type) +Editor::leave_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type) { AutomationLine* al; ControlPoint* cp; @@ -1537,14 +1600,14 @@ Editor::leave_handler (ArdourCanvas::Item* item, GdkEvent* /*event*/, ItemType i cp->set_visible (false); } } - + if (is_drawable()) { track_canvas->get_window()->set_cursor (*current_canvas_cursor); } hide_verbose_canvas_cursor (); break; - + case RegionViewNameHighlight: case StartSelectionTrimItem: case EndSelectionTrimItem: @@ -1594,7 +1657,7 @@ Editor::leave_handler (ArdourCanvas::Item* item, GdkEvent* /*event*/, ItemType i track_canvas->get_window()->set_cursor (*current_canvas_cursor); } break; - + case MarkerItem: if ((marker = static_cast (item->get_data ("marker"))) == 0) { break; @@ -1606,7 +1669,7 @@ Editor::leave_handler (ArdourCanvas::Item* item, GdkEvent* /*event*/, ItemType i // fall through case MeterMarkerItem: case TempoMarkerItem: - + if (is_drawable()) { track_canvas->get_window()->set_cursor (*timebar_cursor); } @@ -1623,16 +1686,17 @@ Editor::leave_handler (ArdourCanvas::Item* item, GdkEvent* /*event*/, ItemType i rect->property_outline_pixels() = 0; } } + track_canvas->get_window()->set_cursor (*current_canvas_cursor); break; case AutomationTrackItem: if (is_drawable()) { track_canvas->get_window()->set_cursor (*current_canvas_cursor); clear_entered_track = true; - Glib::signal_idle().connect (mem_fun(*this, &Editor::left_automation_track)); + Glib::signal_idle().connect (sigc::mem_fun(*this, &Editor::left_automation_track)); } break; - + default: break; } @@ -1651,82 +1715,82 @@ Editor::left_automation_track () } void -Editor::scrub () +Editor::scrub (nframes64_t frame, double current_x) { double delta; - + if (scrubbing_direction == 0) { /* first move */ - session->request_locate (_drag->current_pointer_frame(), false); - session->request_transport_speed (0.1); + _session->request_locate (frame, false); + _session->request_transport_speed (0.1); scrubbing_direction = 1; - + } else { - - if (last_scrub_x > _drag->current_pointer_x()) { - + + if (last_scrub_x > current_x) { + /* pointer moved to the left */ - + if (scrubbing_direction > 0) { - + /* we reversed direction to go backwards */ - + scrub_reversals++; - scrub_reverse_distance += (int) (last_scrub_x - _drag->current_pointer_x()); - + scrub_reverse_distance += (int) (last_scrub_x - current_x); + } else { - + /* still moving to the left (backwards) */ - + scrub_reversals = 0; scrub_reverse_distance = 0; - - delta = 0.01 * (last_scrub_x - _drag->current_pointer_x()); - session->request_transport_speed (session->transport_speed() - delta); + + delta = 0.01 * (last_scrub_x - current_x); + _session->request_transport_speed (_session->transport_speed() - delta); } - + } else { /* pointer moved to the right */ - + if (scrubbing_direction < 0) { /* we reversed direction to go forward */ - + scrub_reversals++; - scrub_reverse_distance += (int) (_drag->current_pointer_x() - last_scrub_x); - + scrub_reverse_distance += (int) (current_x - last_scrub_x); + } else { /* still moving to the right */ - + scrub_reversals = 0; scrub_reverse_distance = 0; - - delta = 0.01 * (_drag->current_pointer_x() - last_scrub_x); - session->request_transport_speed (session->transport_speed() + delta); + + delta = 0.01 * (current_x - last_scrub_x); + _session->request_transport_speed (_session->transport_speed() + delta); } } - + /* if there have been more than 2 opposite motion moves detected, or one that moves back more than 10 pixels, reverse direction */ - + if (scrub_reversals >= 2 || scrub_reverse_distance > 10) { - + if (scrubbing_direction > 0) { /* was forwards, go backwards */ - session->request_transport_speed (-0.1); + _session->request_transport_speed (-0.1); scrubbing_direction = -1; } else { /* was backwards, go forwards */ - session->request_transport_speed (0.1); + _session->request_transport_speed (0.1); scrubbing_direction = 1; } - + scrub_reverse_distance = 0; scrub_reversals = 0; } } - - last_scrub_x = _drag->current_pointer_x(); + + last_scrub_x = current_x; } bool @@ -1734,18 +1798,18 @@ Editor::motion_handler (ArdourCanvas::Item* /*item*/, GdkEvent* event, bool from { if (event->motion.is_hint) { gint x, y; - + /* We call this so that MOTION_NOTIFY events continue to be delivered to the canvas. We need to do this because we set Gdk::POINTER_MOTION_HINT_MASK on the canvas. This reduces the density of the events, at the expense of a round-trip to the server. Given that this will mostly occur on cases where DISPLAY = :0.0, and given the cost of what the motion - event might do, its a good tradeoff. + event might do, its a good tradeoff. */ track_canvas->get_pointer (x, y); - } + } if (current_stepping_trackview) { /* don't keep the persistent stepped trackview if the mouse moves */ @@ -1753,14 +1817,20 @@ Editor::motion_handler (ArdourCanvas::Item* /*item*/, GdkEvent* event, bool from step_timeout.disconnect (); } - if (session && session->actively_recording()) { + if (_session && _session->actively_recording()) { /* Sorry. no dragging stuff around while we record */ return true; } + JoinObjectRangeState const old = _join_object_range_state; + update_join_object_range_location (event->motion.x, event->motion.y); + if (_join_object_range_state != old) { + set_canvas_cursor (); + } + bool handled = false; - if (_drag) { - handled = _drag->motion_handler (event, from_autoscroll); + if (_drags->active ()) { + handled = _drags->motion_handler (event, from_autoscroll); } if (!handled) { @@ -1783,7 +1853,7 @@ Editor::remove_gain_control_point (ArdourCanvas::Item*item, GdkEvent* /*event*/) // We shouldn't remove the first or last gain point if (control_point->line().is_last_point(*control_point) || - control_point->line().is_first_point(*control_point)) { + control_point->line().is_first_point(*control_point)) { return; } @@ -1830,17 +1900,17 @@ Editor::visible_order_range (int* low, int* high) const { *low = TimeAxisView::max_order (); *high = 0; - + for (TrackViewList::const_iterator i = track_views.begin(); i != track_views.end(); ++i) { RouteTimeAxisView* rtv = dynamic_cast (*i); - + if (!rtv->hidden()) { - + if (*high < rtv->order()) { *high = rtv->order (); } - + if (*low > rtv->order()) { *low = rtv->order (); } @@ -1854,13 +1924,13 @@ Editor::region_view_item_click (AudioRegionView& rv, GdkEventButton* event) /* Either add to or set the set the region selection, unless this is an alignment click (control used) */ - + if (Keyboard::modifier_state_contains (event->state, Keyboard::PrimaryModifier)) { TimeAxisView* tv = &rv.get_time_axis_view(); RouteTimeAxisView* rtv = dynamic_cast(tv); double speed = 1.0; if (rtv && rtv->is_track()) { - speed = rtv->get_diskstream()->speed(); + speed = rtv->track()->speed(); } nframes64_t where = get_preferred_edit_position(); @@ -1868,15 +1938,15 @@ Editor::region_view_item_click (AudioRegionView& rv, GdkEventButton* event) if (where >= 0) { if (Keyboard::modifier_state_equals (event->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::SecondaryModifier))) { - + align_region (rv.region(), SyncPoint, (nframes64_t) (where * speed)); - + } else if (Keyboard::modifier_state_equals (event->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) { - + align_region (rv.region(), End, (nframes64_t) (where * speed)); - + } else { - + align_region (rv.region(), Start, (nframes64_t) (where * speed)); } } @@ -1884,16 +1954,16 @@ Editor::region_view_item_click (AudioRegionView& rv, GdkEventButton* event) } void -Editor::show_verbose_time_cursor (nframes64_t frame, double offset, double xpos, double ypos) +Editor::show_verbose_time_cursor (nframes64_t frame, double offset, double xpos, double ypos) { char buf[128]; - SMPTE::Time smpte; + Timecode::Time timecode; BBT_Time bbt; int hours, mins; nframes64_t frame_rate; float secs; - if (session == 0) { + if (_session == 0) { return; } @@ -1907,18 +1977,18 @@ Editor::show_verbose_time_cursor (nframes64_t frame, double offset, double xpos, switch (m) { case AudioClock::BBT: - session->bbt_time (frame, bbt); + _session->bbt_time (frame, bbt); snprintf (buf, sizeof (buf), "%02" PRIu32 "|%02" PRIu32 "|%02" PRIu32, bbt.bars, bbt.beats, bbt.ticks); break; - - case AudioClock::SMPTE: - session->smpte_time (frame, smpte); - snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%02" PRId32 ":%02" PRId32, smpte.hours, smpte.minutes, smpte.seconds, smpte.frames); + + case AudioClock::Timecode: + _session->timecode_time (frame, timecode); + snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%02" PRId32 ":%02" PRId32, timecode.hours, timecode.minutes, timecode.seconds, timecode.frames); break; case AudioClock::MinSec: /* XXX this is copied from show_verbose_duration_cursor() */ - frame_rate = session->frame_rate(); + frame_rate = _session->frame_rate(); hours = frame / (frame_rate * 3600); frame = frame % (frame_rate * 3600); mins = frame / (frame_rate * 60); @@ -1934,26 +2004,25 @@ Editor::show_verbose_time_cursor (nframes64_t frame, double offset, double xpos, if (xpos >= 0 && ypos >=0) { set_verbose_canvas_cursor (buf, xpos + offset, ypos + offset); - } - else { - set_verbose_canvas_cursor (buf, _drag->current_pointer_x() + offset - horizontal_adjustment.get_value(), _drag->current_pointer_y() + offset - vertical_adjustment.get_value() + canvas_timebars_vsize); + } else { + set_verbose_canvas_cursor (buf, _drags->current_pointer_x() + offset - horizontal_adjustment.get_value(), _drags->current_pointer_y() + offset - vertical_adjustment.get_value() + canvas_timebars_vsize); } show_verbose_canvas_cursor (); } void -Editor::show_verbose_duration_cursor (nframes64_t start, nframes64_t end, double offset, double xpos, double ypos) +Editor::show_verbose_duration_cursor (nframes64_t start, nframes64_t end, double offset, double xpos, double ypos) { char buf[128]; - SMPTE::Time smpte; + Timecode::Time timecode; BBT_Time sbbt; BBT_Time ebbt; int hours, mins; nframes64_t distance, frame_rate; float secs; - Meter meter_at_start(session->tempo_map().meter_at(start)); + Meter meter_at_start(_session->tempo_map().meter_at(start)); - if (session == 0) { + if (_session == 0) { return; } @@ -1967,8 +2036,8 @@ Editor::show_verbose_duration_cursor (nframes64_t start, nframes64_t end, double switch (m) { case AudioClock::BBT: - session->bbt_time (start, sbbt); - session->bbt_time (end, ebbt); + _session->bbt_time (start, sbbt); + _session->bbt_time (end, ebbt); /* subtract */ /* XXX this computation won't work well if the @@ -1988,19 +2057,19 @@ Editor::show_verbose_duration_cursor (nframes64_t start, nframes64_t end, double ebbt.beats--; ebbt.ticks = int(Meter::ticks_per_beat) + ebbt.ticks - sbbt.ticks; } - + snprintf (buf, sizeof (buf), "%02" PRIu32 "|%02" PRIu32 "|%02" PRIu32, ebbt.bars, ebbt.beats, ebbt.ticks); break; - - case AudioClock::SMPTE: - session->smpte_duration (end - start, smpte); - snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%02" PRId32 ":%02" PRId32, smpte.hours, smpte.minutes, smpte.seconds, smpte.frames); + + case AudioClock::Timecode: + _session->timecode_duration (end - start, timecode); + snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%02" PRId32 ":%02" PRId32, timecode.hours, timecode.minutes, timecode.seconds, timecode.frames); break; case AudioClock::MinSec: /* XXX this stuff should be elsewhere.. */ distance = end - start; - frame_rate = session->frame_rate(); + frame_rate = _session->frame_rate(); hours = distance / (frame_rate * 3600); distance = distance % (frame_rate * 3600); mins = distance / (frame_rate * 60); @@ -2018,7 +2087,7 @@ Editor::show_verbose_duration_cursor (nframes64_t start, nframes64_t end, double set_verbose_canvas_cursor (buf, xpos + offset, ypos + offset); } else { - set_verbose_canvas_cursor (buf, _drag->current_pointer_x() + offset, _drag->current_pointer_y() + offset); + set_verbose_canvas_cursor (buf, _drags->current_pointer_x() + offset, _drags->current_pointer_y() + offset); } show_verbose_canvas_cursor (); @@ -2046,11 +2115,11 @@ Editor::cancel_selection () selection->clear (); clicked_selection = 0; -} +} void -Editor::single_contents_trim (RegionView& rv, nframes64_t frame_delta, bool left_direction, bool swap_direction, bool obey_snap) +Editor::single_contents_trim (RegionView& rv, nframes64_t frame_delta, bool left_direction, bool swap_direction) { boost::shared_ptr region (rv.region()); @@ -2065,9 +2134,9 @@ Editor::single_contents_trim (RegionView& rv, nframes64_t frame_delta, bool left RouteTimeAxisView* tv = dynamic_cast(tvp); if (tv && tv->is_track()) { - speed = tv->get_diskstream()->speed(); + speed = tv->track()->speed(); } - + if (left_direction) { if (swap_direction) { new_bound = (nframes64_t) (region->position()/speed) + frame_delta; @@ -2082,51 +2151,36 @@ Editor::single_contents_trim (RegionView& rv, nframes64_t frame_delta, bool left } } - if (obey_snap) { - snap_to (new_bound); - } - region->trim_start ((nframes64_t) (new_bound * speed), this); - rv.region_changed (StartChanged); + region->trim_start ((nframes64_t) (new_bound * speed), this); + rv.region_changed (PropertyChange (ARDOUR::Properties::start)); } void -Editor::single_start_trim (RegionView& rv, nframes64_t frame_delta, bool left_direction, bool obey_snap, bool no_overlap) +Editor::single_start_trim (RegionView& rv, nframes64_t new_bound, bool no_overlap) { - boost::shared_ptr region (rv.region()); + boost::shared_ptr region (rv.region()); if (region->locked()) { return; } - nframes64_t new_bound; - double speed = 1.0; TimeAxisView* tvp = clicked_axisview; RouteTimeAxisView* tv = dynamic_cast(tvp); if (tv && tv->is_track()) { - speed = tv->get_diskstream()->speed(); - } - - if (left_direction) { - new_bound = (nframes64_t) (region->position()/speed) - frame_delta; - } else { - new_bound = (nframes64_t) (region->position()/speed) + frame_delta; + speed = tv->track()->speed(); } - if (obey_snap) { - snap_to (new_bound, (left_direction ? 0 : 1)); - } - nframes64_t pre_trim_first_frame = region->first_frame(); region->trim_front ((nframes64_t) (new_bound * speed), this); - + if (no_overlap) { //Get the next region on the left of this region and shrink/expand it. boost::shared_ptr playlist (region->playlist()); boost::shared_ptr region_left = playlist->find_next_region (pre_trim_first_frame, End, 0); - + bool regions_touching = false; if (region_left != 0 && (pre_trim_first_frame == region_left->last_frame() + 1)){ @@ -2134,20 +2188,18 @@ Editor::single_start_trim (RegionView& rv, nframes64_t frame_delta, bool left_di } //Only trim region on the left if the first frame has gone beyond the left region's last frame. - if (region_left != 0 && - (region_left->last_frame() > region->first_frame() || regions_touching)) + if (region_left != 0 && + (region_left->last_frame() > region->first_frame() || regions_touching)) { - region_left->trim_end(region->first_frame(), this); + region_left->trim_end(region->first_frame() - 1, this); } } - - - rv.region_changed (Change (LengthChanged|PositionChanged|StartChanged)); + rv.region_changed (ARDOUR::bounds_change); } void -Editor::single_end_trim (RegionView& rv, nframes64_t frame_delta, bool left_direction, bool obey_snap, bool no_overlap) +Editor::single_end_trim (RegionView& rv, nframes64_t new_bound, bool no_overlap) { boost::shared_ptr region (rv.region()); @@ -2155,24 +2207,12 @@ Editor::single_end_trim (RegionView& rv, nframes64_t frame_delta, bool left_dire return; } - nframes64_t new_bound; - double speed = 1.0; TimeAxisView* tvp = clicked_axisview; RouteTimeAxisView* tv = dynamic_cast(tvp); if (tv && tv->is_track()) { - speed = tv->get_diskstream()->speed(); - } - - if (left_direction) { - new_bound = (nframes64_t) ((region->last_frame() + 1)/speed) - frame_delta; - } else { - new_bound = (nframes64_t) ((region->last_frame() + 1)/speed) + frame_delta; - } - - if (obey_snap) { - snap_to (new_bound); + speed = tv->track()->speed(); } nframes64_t pre_trim_last_frame = region->last_frame(); @@ -2186,36 +2226,30 @@ Editor::single_end_trim (RegionView& rv, nframes64_t frame_delta, bool left_dire bool regions_touching = false; - if (region_right != 0 && (pre_trim_last_frame == region_right->first_frame() - 1)){ - regions_touching = true; + if (region_right != 0 && (pre_trim_last_frame == region_right->first_frame() - 1)) { + regions_touching = true; } //Only trim region on the right if the last frame has gone beyond the right region's first frame. if (region_right != 0 && - (region_right->first_frame() < region->last_frame() || regions_touching)) + (region_right->first_frame() < region->last_frame() || regions_touching)) { region_right->trim_front(region->last_frame() + 1, this); } - - rv.region_changed (Change (LengthChanged|PositionChanged|StartChanged)); - } - else { - rv.region_changed (LengthChanged); + + rv.region_changed (ARDOUR::bounds_change); + + } else { + rv.region_changed (PropertyChange (ARDOUR::Properties::length)); } } void -Editor::point_trim (GdkEvent* event) +Editor::point_trim (GdkEvent* event, nframes64_t new_bound) { RegionView* rv = clicked_regionview; - nframes64_t new_bound = _drag->current_pointer_frame(); - - if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) { - snap_to (new_bound); - } - /* Choose action dependant on which button was pressed */ switch (event->button.button) { case 1: @@ -2230,58 +2264,48 @@ Editor::point_trim (GdkEvent* event) } if (!(*i)->region()->locked()) { - boost::shared_ptr pl = (*i)->region()->playlist(); - XMLNode &before = pl->get_state(); - + (*i)->region()->clear_history (); (*i)->region()->trim_front (new_bound, this); - - XMLNode &after = pl->get_state(); - session->add_command(new MementoCommand(*pl.get(), &before, &after)); + _session->add_command(new StatefulDiffCommand ((*i)->region())); } } } else { if (!rv->region()->locked()) { - boost::shared_ptr pl = rv->region()->playlist(); - XMLNode &before = pl->get_state(); + rv->region()->clear_history (); rv->region()->trim_front (new_bound, this); - XMLNode &after = pl->get_state(); - session->add_command(new MementoCommand(*pl.get(), &before, &after)); + _session->add_command(new StatefulDiffCommand (rv->region())); } } commit_reversible_command(); - + break; case 2: begin_reversible_command (_("End point trim")); if (selection->selected (rv)) { - + for (list::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ++i) { if (!(*i)->region()->locked()) { - boost::shared_ptr pl = (*i)->region()->playlist(); - XMLNode &before = pl->get_state(); + (*i)->region()->clear_history(); (*i)->region()->trim_end (new_bound, this); - XMLNode &after = pl->get_state(); - session->add_command(new MementoCommand(*pl.get(), &before, &after)); + _session->add_command(new StatefulDiffCommand ((*i)->region())); } } } else { if (!rv->region()->locked()) { - boost::shared_ptr pl = rv->region()->playlist(); - XMLNode &before = pl->get_state(); + rv->region()->clear_history (); rv->region()->trim_end (new_bound, this); - XMLNode &after = pl->get_state(); - session->add_command (new MementoCommand(*pl.get(), &before, &after)); + _session->add_command (new StatefulDiffCommand (rv->region())); } } commit_reversible_command(); - + break; default: break; @@ -2297,10 +2321,10 @@ Editor::thaw_region_after_trim (RegionView& rv) return; } - region->thaw (_("trimmed region")); + region->resume_property_changes (); AudioRegionView* arv = dynamic_cast(&rv); - + if (arv) { arv->unhide_envelope (); } @@ -2317,7 +2341,7 @@ Editor::hide_marker (ArdourCanvas::Item* item, GdkEvent* /*event*/) /*NOTREACHED*/ } - Location* location = find_location_from_marker (marker, is_start); + Location* location = find_location_from_marker (marker, is_start); location->set_hidden (true, this); } @@ -2366,14 +2390,14 @@ Editor::mouse_brush_insert_region (RegionView* rv, nframes64_t pos) { /* no brushing without a useful snap setting */ - switch (snap_mode) { + switch (_snap_mode) { case SnapMagnetic: return; /* can't work because it allows region to be placed anywhere */ default: break; /* OK */ } - switch (snap_type) { + switch (_snap_type) { case SnapToMark: return; @@ -2382,7 +2406,7 @@ Editor::mouse_brush_insert_region (RegionView* rv, nframes64_t pos) } /* don't brush a copy over the original */ - + if (pos == rv->region()->position()) { return; } @@ -2394,16 +2418,16 @@ Editor::mouse_brush_insert_region (RegionView* rv, nframes64_t pos) } boost::shared_ptr playlist = rtv->playlist(); - double speed = rtv->get_diskstream()->speed(); - - XMLNode &before = playlist->get_state(); - playlist->add_region (RegionFactory::create (rv->region()), (nframes64_t) (pos * speed)); - XMLNode &after = playlist->get_state(); - session->add_command(new MementoCommand(*playlist.get(), &before, &after)); - - // playlist is frozen, so we have to update manually - - playlist->Modified(); /* EMIT SIGNAL */ + double speed = rtv->track()->speed(); + + playlist->clear_history (); + boost::shared_ptr new_region (RegionFactory::create (rv->region())); + playlist->add_region (new_region, (nframes64_t) (pos * speed)); + _session->add_command (new StatefulDiffCommand (playlist)); + + // playlist is frozen, so we have to update manually XXX this is disgusting + + playlist->RegionAdded (new_region); /* EMIT SIGNAL */ } gint @@ -2417,56 +2441,46 @@ Editor::track_height_step_timeout () } void -Editor::start_region_grab (ArdourCanvas::Item* item, GdkEvent* event, RegionView* region_view) +Editor::add_region_drag (ArdourCanvas::Item* item, GdkEvent* event, RegionView* region_view) { assert (region_view); _region_motion_group->raise_to_top (); - - assert (_drag == 0); - + if (Config->get_edit_mode() == Splice) { - _drag = new RegionSpliceDrag (this, item, region_view, selection->regions.by_layer()); + _drags->add (new RegionSpliceDrag (this, item, region_view, selection->regions.by_layer())); } else { - RegionSelection s = get_equivalent_regions (selection->regions, RouteGroup::Edit); - _drag = new RegionMoveDrag (this, item, region_view, s.by_layer(), false, false); + RegionSelection s = get_equivalent_regions (selection->regions, ARDOUR::Properties::edit.property_id); + _drags->add (new RegionMoveDrag (this, item, region_view, s.by_layer(), false, false)); } - - _drag->start_grab (event); - - begin_reversible_command (_("move region(s)")); /* sync the canvas to what we think is its current state */ update_canvas_now(); } void -Editor::start_region_copy_grab (ArdourCanvas::Item* item, GdkEvent* event, RegionView* region_view) +Editor::add_region_copy_drag (ArdourCanvas::Item* item, GdkEvent* event, RegionView* region_view) { assert (region_view); - assert (_drag == 0); - + _region_motion_group->raise_to_top (); - RegionSelection s = get_equivalent_regions (selection->regions, RouteGroup::Edit); - _drag = new RegionMoveDrag (this, item, region_view, s.by_layer(), false, true); - _drag->start_grab(event); + RegionSelection s = get_equivalent_regions (selection->regions, ARDOUR::Properties::edit.property_id); + _drags->add (new RegionMoveDrag (this, item, region_view, s.by_layer(), false, true)); } void -Editor::start_region_brush_grab (ArdourCanvas::Item* item, GdkEvent* event, RegionView* region_view) +Editor::add_region_brush_drag (ArdourCanvas::Item* item, GdkEvent* event, RegionView* region_view) { assert (region_view); - assert (_drag == 0); - + if (Config->get_edit_mode() == Splice) { return; } - RegionSelection s = get_equivalent_regions (selection->regions, RouteGroup::Edit); - _drag = new RegionMoveDrag (this, item, region_view, s.by_layer(), true, false); - _drag->start_grab (event); - + RegionSelection s = get_equivalent_regions (selection->regions, ARDOUR::Properties::edit.property_id); + _drags->add (new RegionMoveDrag (this, item, region_view, s.by_layer(), true, false)); + begin_reversible_command (_("Drag region brush")); } @@ -2491,7 +2505,7 @@ Editor::start_selection_grab (ArdourCanvas::Item* /*item*/, GdkEvent* event) } /* XXX fix me one day to use all new regions */ - + boost::shared_ptr region (new_regions.front()); /* add it to the current stream/playlist. @@ -2500,11 +2514,11 @@ Editor::start_selection_grab (ArdourCanvas::Item* /*item*/, GdkEvent* event) catch the signal it sends when it creates the regionview to set the regionview we want to then drag. */ - + latest_regionviews.clear(); - sigc::connection c = clicked_routeview->view()->RegionViewAdded.connect (mem_fun(*this, &Editor::collect_new_region_view)); - - /* A selection grab currently creates two undo/redo operations, one for + sigc::connection c = clicked_routeview->view()->RegionViewAdded.connect (sigc::mem_fun(*this, &Editor::collect_new_region_view)); + + /* A selection grab currently creates two undo/redo operations, one for creating the new region and another for moving it. */ @@ -2512,35 +2526,34 @@ Editor::start_selection_grab (ArdourCanvas::Item* /*item*/, GdkEvent* event) boost::shared_ptr playlist = clicked_axisview->playlist(); - XMLNode *before = &(playlist->get_state()); + playlist->clear_history (); clicked_routeview->playlist()->add_region (region, selection->time[clicked_selection].start); - XMLNode *after = &(playlist->get_state()); - session->add_command(new MementoCommand(*playlist, before, after)); + _session->add_command(new StatefulDiffCommand (playlist)); commit_reversible_command (); - + c.disconnect (); - + if (latest_regionviews.empty()) { /* something went wrong */ return; } /* we need to deselect all other regionviews, and select this one - i'm ignoring undo stuff, because the region creation will take care of it + i'm ignoring undo stuff, because the region creation will take care of it */ selection->set (latest_regionviews); - - assert (_drag == 0); - _drag = new RegionMoveDrag (this, latest_regionviews.front()->get_canvas_group(), latest_regionviews.front(), latest_regionviews, false, false); - _drag->start_grab (event); + + _drags->set (new RegionMoveDrag (this, latest_regionviews.front()->get_canvas_group(), latest_regionviews.front(), latest_regionviews, false, false), event); } void -Editor::break_drag () +Editor::escape () { - if (_drag) { - _drag->break_drag (); + if (_drags->active ()) { + _drags->abort (); + } else { + selection->clear (); } } @@ -2548,5 +2561,87 @@ void Editor::set_internal_edit (bool yn) { _internal_editing = yn; + + if (yn) { + mouse_select_button.set_image (*(manage (new Image (::get_icon("midi_tool_pencil"))))); + mouse_select_button.get_image ()->show (); + + for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) { + MidiTimeAxisView* mtv = dynamic_cast (*i); + if (mtv) { + mtv->start_step_editing (); + } + } + start_step_editing (); + + } else { + + mouse_select_button.set_image (*(manage (new Image (::get_icon("tool_range"))))); + mouse_select_button.get_image ()->show (); + stop_step_editing (); + + for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) { + MidiTimeAxisView* mtv = dynamic_cast (*i); + if (mtv) { + mtv->stop_step_editing (); + } + } + } + set_canvas_cursor (); + + +} + +/** Update _join_object_range_state which indicate whether we are over the top or bottom half of a region view, + * used by the `join object/range' tool mode. + */ +void +Editor::update_join_object_range_location (double x, double y) +{ + /* XXX: actually, this decides based on whether the mouse is in the top or bottom half of a RouteTimeAxisView; + entered_{track,regionview} is not always setup (e.g. if the mouse is over a TimeSelection), and to get a Region + that we're over requires searching the playlist. + */ + + if (join_object_range_button.get_active() == false || (mouse_mode != MouseRange && mouse_mode != MouseObject)) { + _join_object_range_state = JOIN_OBJECT_RANGE_NONE; + return; + } + + if (mouse_mode == MouseObject) { + _join_object_range_state = JOIN_OBJECT_RANGE_OBJECT; + } else if (mouse_mode == MouseRange) { + _join_object_range_state = JOIN_OBJECT_RANGE_RANGE; + } + + /* XXX: maybe we should make entered_track work in all cases, rather than resorting to this */ + pair tvp = trackview_by_y_position (y + vertical_adjustment.get_value() - canvas_timebars_vsize); + + if (tvp.first) { + + RouteTimeAxisView* rtv = dynamic_cast (tvp.first); + if (rtv) { + + double cx = 0; + double cy = y; + rtv->canvas_display()->w2i (cx, cy); + + bool const top_half = cy < rtv->current_height () / 2; + + _join_object_range_state = top_half ? JOIN_OBJECT_RANGE_RANGE : JOIN_OBJECT_RANGE_OBJECT; + } + } +} + +Editing::MouseMode +Editor::effective_mouse_mode () const +{ + if (_join_object_range_state == JOIN_OBJECT_RANGE_OBJECT) { + return MouseObject; + } else if (_join_object_range_state == JOIN_OBJECT_RANGE_RANGE) { + return MouseRange; + } + + return mouse_mode; }