no more edit point clock (except SAE version, but who knows why or even if)
[ardour.git] / gtk2_ardour / editor_mouse.cc
index a3585d2872ece1e8fe030c2da7b143c85882ae85..490112d43010ceee2518190843d8d976a402b0e5 100644 (file)
@@ -336,8 +336,15 @@ Editor::step_mouse_mode (bool next)
 {
        switch (current_mouse_mode()) {
        case MouseObject:
-               if (next) set_mouse_mode (MouseRange);
-               else set_mouse_mode (MouseTimeFX);
+               if (next) {
+                       if (Profile->get_sae()) {
+                               set_mouse_mode (MouseZoom);
+                       } else {
+                               set_mouse_mode (MouseRange);
+                       }
+               } else {
+                       set_mouse_mode (MouseTimeFX);
+               }
                break;
 
        case MouseRange:
@@ -346,8 +353,19 @@ Editor::step_mouse_mode (bool next)
                break;
 
        case MouseZoom:
-               if (next) set_mouse_mode (MouseGain);
-               else set_mouse_mode (MouseRange);
+               if (next) {
+                       if (Profile->get_sae()) {
+                               set_mouse_mode (MouseTimeFX);
+                       } else {
+                               set_mouse_mode (MouseGain);
+                       }
+               } else {
+                       if (Profile->get_sae()) {
+                               set_mouse_mode (MouseObject);
+                       } else {
+                               set_mouse_mode (MouseRange);
+                       }
+               }
                break;
        
        case MouseGain:
@@ -356,8 +374,15 @@ Editor::step_mouse_mode (bool next)
                break;
        
        case MouseTimeFX:
-               if (next) set_mouse_mode (MouseAudition);
-               else set_mouse_mode (MouseGain);
+               if (next) {
+                       set_mouse_mode (MouseAudition);
+               } else {
+                       if (Profile->get_sae()) {
+                               set_mouse_mode (MouseZoom);
+                       } else {
+                               set_mouse_mode (MouseGain);
+                       }
+               }
                break;
 
        case MouseAudition:
@@ -370,10 +395,11 @@ Editor::step_mouse_mode (bool next)
 void
 Editor::button_selection (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type)
 {
-       /* in object/audition/timefx mode, any button press sets
-          the selection if the object can be selected. this is a
-          bit of hack, because we want to avoid this if the
-          mouse operation is a region alignment.
+       /* in object/audition/timefx/gain-automation mode,
+          any button press sets the selection if the object
+          can be selected. this is a bit of hack, because
+          we want to avoid this if the mouse operation is a
+          region alignment.
 
           note: not dbl-click or triple-click
        */
@@ -381,6 +407,7 @@ Editor::button_selection (ArdourCanvas::Item* item, GdkEvent* event, ItemType it
        if (((mouse_mode != MouseObject) &&
             (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)) {
@@ -399,7 +426,7 @@ Editor::button_selection (ArdourCanvas::Item* item, GdkEvent* event, ItemType it
                        }
                }
        }
-           
+
        Selection::Operation op = Keyboard::selection_type (event->button.state);
        bool press = (event->type == GDK_BUTTON_PRESS);
 
@@ -492,6 +519,24 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp
 
        button_selection (item, event, item_type);
 
+       //ctrl-drag or right-click-drag on a "range" ruler should start a range drag
+       if (event->type == GDK_BUTTON_PRESS) {
+               if (event->button.button == 3 || ( (event->button.button == 1) && (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier) ))) {
+                       if (item_type == TransportMarkerBarItem) {
+                               start_range_markerbar_op (item, event, CreateTransportMarker);
+                               return true;
+                       }
+                       if (item_type == RangeMarkerBarItem) {
+                               start_range_markerbar_op (item, event, CreateRangeMarker);
+                               return true;
+                       }
+                       if (item_type == CdMarkerBarItem) {
+                               start_range_markerbar_op (item, event, CreateCDMarker);
+                               return true;
+                       }
+               }
+       }
+
        if (drag_info.item == 0 &&
            (Keyboard::is_delete_event (&event->button) ||
             Keyboard::is_context_menu_event (&event->button) ||
@@ -545,24 +590,15 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp
                                }
                                return true;
 
+                       case MarkerBarItem:
                        case TempoBarItem:
-                               return true;
-
                        case MeterBarItem:
-                               return true;
-                               
+                       case TransportMarkerBarItem:
                        case RangeMarkerBarItem:
-                               start_range_markerbar_op (item, event, CreateRangeMarker); 
-                               return true;
-                               break;
-
                        case CdMarkerBarItem:
-                               start_range_markerbar_op (item, event, CreateCDMarker); 
-                               return true;
-                               break;
-
-                       case TransportMarkerBarItem:
-                               start_range_markerbar_op (item, event, CreateTransportMarker); 
+                               if (!Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
+                                       start_cursor_grab_no_stop(&playhead_cursor->canvas_item, event);
+                               }
                                return true;
                                break;
 
@@ -957,7 +993,7 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT
                        case CdMarkerBarItem:
                        case TempoBarItem:
                        case MeterBarItem:
-                               popup_ruler_menu (pixel_to_frame(event->button.x), item_type);
+                               popup_ruler_menu (where, item_type);
                                break;
 
                        case MarkerItem:
@@ -1057,36 +1093,44 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT
                        return true;
 
                case MarkerBarItem:
-                       if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
-                               snap_to (where, 0, true);
+                       if (!_dragging_playhead) {
+                               if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
+                                       snap_to (where, 0, true);
+                               }
+                               mouse_add_new_marker (where);
                        }
-                       mouse_add_new_marker (where);
                        return true;
 
                case CdMarkerBarItem:
-                       // 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);
+                       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);
+                               }
+                               mouse_add_new_marker (where, true);
                        }
-                       mouse_add_new_marker (where, true);
                        return true;
 
                case TempoBarItem:
-                       if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
-                               snap_to (where);
+                       if (!_dragging_playhead) {
+                               if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) {
+                                       snap_to (where);
+                               }
+                               mouse_add_new_tempo_event (where);
                        }
-                       mouse_add_new_tempo_event (where);
                        return true;
                        
                case MeterBarItem:
-                       mouse_add_new_meter_event (pixel_to_frame (event->button.x));
+                       if (!_dragging_playhead) {
+                               mouse_add_new_meter_event (pixel_to_frame (event->button.x));
+                       } 
                        return true;
                        break;
 
                default:
                        break;
                }
-
+               
                switch (mouse_mode) {
                case MouseObject:
                        switch (item_type) {
@@ -1715,6 +1759,9 @@ Editor::motion_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item
        switch (item_type) {
        case PlayheadCursorItem:
        case MarkerItem:
+       case MarkerBarItem:
+       case TempoBarItem:
+       case MeterBarItem:
        case RangeMarkerBarItem:
        case TransportMarkerBarItem:
        case CdMarkerBarItem:
@@ -1741,6 +1788,7 @@ Editor::motion_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item
        case MarkerViewHandleEndItem:
        /* </CMT Additions> */
          if (drag_info.item && (event->motion.state & Gdk::BUTTON1_MASK ||
+                                (event->motion.state & Gdk::BUTTON3_MASK) ||
                                 (event->motion.state & Gdk::BUTTON2_MASK))) {
                  if (!from_autoscroll) {
                          maybe_autoscroll_horizontally (&event->motion);
@@ -1850,7 +1898,7 @@ Editor::start_grab (GdkEvent* event, Gdk::Cursor *cursor)
 
         // if dragging with button2, the motion is x constrained, with Alt-button2 it is y constrained
 
-       if (event->button.button == 2) {
+       if (Keyboard::is_button2_event (&event->button)) {
                if (Keyboard::modifier_state_equals (event->button.state, Keyboard::SecondaryModifier)) {
                        drag_info.y_constrained = true;
                        drag_info.x_constrained = false;
@@ -1929,9 +1977,9 @@ Editor::end_grab (ArdourCanvas::Item* item, GdkEvent* event)
                return false;
        }
        
-       drag_info.item->ungrab (event->button.time);
+       drag_info.item->ungrab (event ? event->button.time : 0);
 
-       if (drag_info.finished_callback) {
+       if (drag_info.finished_callback && event) {
                drag_info.last_pointer_x = drag_info.current_pointer_x;
                drag_info.last_pointer_y = drag_info.current_pointer_y;
                (this->*(drag_info.finished_callback)) (item, event);
@@ -2212,6 +2260,39 @@ Editor::start_cursor_grab (ArdourCanvas::Item* item, GdkEvent* event)
        show_verbose_time_cursor (cursor->current_frame, 10);
 }
 
+void
+Editor::start_cursor_grab_no_stop (ArdourCanvas::Item* item, GdkEvent* event)
+{
+       drag_info.item = item;
+       drag_info.motion_callback = &Editor::cursor_drag_motion_callback;
+       drag_info.finished_callback = &Editor::cursor_drag_finished_ensure_locate_callback;
+
+       start_grab (event);
+
+       if ((drag_info.data = (item->get_data ("cursor"))) == 0) {
+               fatal << _("programming error: cursor canvas item has no cursor data pointer!") << endmsg;
+               /*NOTREACHED*/
+       }
+
+       Cursor* cursor = (Cursor *) drag_info.data;
+       nframes64_t where = event_frame (event, 0, 0);
+
+       snap_to(where);
+       playhead_cursor->set_position (where);
+
+       if (cursor == playhead_cursor) {
+               _dragging_playhead = true;
+
+               if (session && session->is_auditioning()) {
+                       session->cancel_audition ();
+               }
+       }
+
+       drag_info.pointer_frame_offset = drag_info.grab_frame - cursor->current_frame;  
+       
+       show_verbose_time_cursor (cursor->current_frame, 10);
+}
+
 void
 Editor::cursor_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
 {
@@ -2249,12 +2330,28 @@ Editor::cursor_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
 void
 Editor::cursor_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event)
 {
-       if (drag_info.first_move) return;
+       _dragging_playhead = false;
+
+       if (drag_info.first_move) {
+               return;
+       }
        
        cursor_drag_motion_callback (item, event);
+       
+       if (item == &playhead_cursor->canvas_item) {
+               if (session) {
+                       session->request_locate (playhead_cursor->current_frame, drag_info.was_rolling);
+               }
+       } 
+}
 
+void
+Editor::cursor_drag_finished_ensure_locate_callback (ArdourCanvas::Item* item, GdkEvent* event)
+{
        _dragging_playhead = false;
        
+       cursor_drag_motion_callback (item, event);
+       
        if (item == &playhead_cursor->canvas_item) {
                if (session) {
                        session->request_locate (playhead_cursor->current_frame, drag_info.was_rolling);
@@ -2530,7 +2627,9 @@ Editor::marker_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
                abort();
        }
 
-       edit_point_clock.set (drag_info.copied_locations.front()->start());
+       if (Profile->get_sae()) {
+               edit_point_clock.set (drag_info.copied_locations.front()->start());
+       }
        show_verbose_time_cursor (newframe, 10);
 
 #ifdef GTKOSX
@@ -3102,24 +3201,11 @@ Editor::line_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
 
        double cy = drag_info.grab_y + drag_info.cumulative_y_drag + dy;
 
-       // calculate zero crossing point. back off by .01 to stay on the
-       // positive side of zero
-       double zero_gain_y = (1.0 - ZERO_GAIN_FRACTION) * line->height() - .01;
-
-       // line->parent_group().i2w(_unused, zero_gain_y);
-
-       // make sure we hit zero when passing through
-       if ((cy < zero_gain_y and (cy - dy) > zero_gain_y)
-                       or (cy > zero_gain_y and (cy - dy) < zero_gain_y)) {
-               cy = zero_gain_y;
-       }
-
        drag_info.cumulative_y_drag = cy - drag_info.grab_y;
 
        cy = max (0.0, cy);
        cy = min ((double) line->height(), cy);
 
-
        double fraction = 1.0 - (cy / line->height());
 
        bool push;
@@ -3446,7 +3532,7 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
 
                int32_t children = 0, numtracks = 0;
                // XXX hard coding track limit, oh my, so very very bad
-               bitset <1024> tracks (0x00);
+               bitset <1024> tracks (0x00ul);
                /* get a bitmask representing the visible tracks */
 
                for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
@@ -3643,12 +3729,7 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
                bool x_move_allowed;
                
                if (Config->get_edit_mode() == Lock) {
-                       if (drag_info.copy) {
-                               x_move_allowed = !drag_info.x_constrained;
-                       } else {
-                               /* in locked edit mode, reverse the usual meaning of x_constrained */
-                               x_move_allowed = drag_info.x_constrained;
-                       }
+                       x_move_allowed = drag_info.x_constrained;
                } else {
                        x_move_allowed = !drag_info.x_constrained;
                }
@@ -3895,7 +3976,7 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event
           the drag.
        */
        
-       if (Config->get_edit_mode() == Lock && !drag_info.copy) {
+       if (Config->get_edit_mode() == Lock) {
                drag_info.x_constrained = !drag_info.x_constrained;
        }