X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Feditor_mouse.cc;h=ed7f46df082a80311c4eb99c54d18f1bb87d4f7e;hb=6f8cd634501efd70711b148b4ac0e0ce2aa5cc95;hp=bcbb806b79eb944d988447db7d9e951d28b15915;hpb=24ccaac67e9d416b3f3c564a441934313f3e9a21;p=ardour.git diff --git a/gtk2_ardour/editor_mouse.cc b/gtk2_ardour/editor_mouse.cc index bcbb806b79..ed7f46df08 100644 --- a/gtk2_ardour/editor_mouse.cc +++ b/gtk2_ardour/editor_mouse.cc @@ -1,3 +1,4 @@ + /* Copyright (C) 2000-2001 Paul Davis @@ -28,6 +29,7 @@ #include #include #include +#include #include "ardour_ui.h" #include "editor.h" @@ -39,6 +41,7 @@ #include "streamview.h" #include "region_gain_line.h" #include "automation_time_axis.h" +#include "control_point.h" #include "prompter.h" #include "utils.h" #include "selection.h" @@ -51,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -58,6 +62,7 @@ #include #include #include +#include #include @@ -70,8 +75,44 @@ using namespace sigc; using namespace Gtk; using namespace Editing; -nframes_t -Editor::event_frame (GdkEvent* event, double* pcx, double* pcy) +const static double ZERO_GAIN_FRACTION = gain_to_slider_position(dB_to_coefficient(0.0)); + +bool +Editor::mouse_frame (nframes64_t& where, bool& in_track_canvas) const +{ + int x, y; + double wx, wy; + Gdk::ModifierType mask; + Glib::RefPtr canvas_window = const_cast(this)->track_canvas->get_window(); + Glib::RefPtr pointer_window; + + if (!canvas_window) { + return false; + } + + pointer_window = canvas_window->get_pointer (x, y, mask); + + if (pointer_window == track_canvas->get_bin_window()) { + wx = x; + wy = y; + in_track_canvas = true; + + } else { + in_track_canvas = false; + return false; + } + + GdkEvent event; + event.type = GDK_BUTTON_RELEASE; + event.button.x = wx; + event.button.y = wy; + + where = event_frame (&event, 0, 0); + return true; +} + +nframes64_t +Editor::event_frame (GdkEvent* event, double* pcx, double* pcy) const { double cx, cy; @@ -90,18 +131,24 @@ Editor::event_frame (GdkEvent* event, double* pcx, double* pcy) case GDK_BUTTON_PRESS: case GDK_2BUTTON_PRESS: case GDK_3BUTTON_PRESS: - track_canvas.w2c(event->button.x, event->button.y, *pcx, *pcy); + + *pcx = event->button.x; + *pcy = event->button.y; + _trackview_group->w2i(*pcx, *pcy); break; case GDK_MOTION_NOTIFY: - track_canvas.w2c(event->motion.x, event->motion.y, *pcx, *pcy); + + *pcx = event->motion.x; + *pcy = event->motion.y; + _trackview_group->w2i(*pcx, *pcy); break; case GDK_ENTER_NOTIFY: case GDK_LEAVE_NOTIFY: - track_canvas.w2c(event->crossing.x, event->crossing.y, *pcx, *pcy); + track_canvas->w2c(event->crossing.x, event->crossing.y, *pcx, *pcy); break; case GDK_KEY_PRESS: case GDK_KEY_RELEASE: - // track_canvas.w2c(event->key.x, event->key.y, *pcx, *pcy); + // track_canvas->w2c(event->key.x, event->key.y, *pcx, *pcy); break; default: warning << string_compose (_("Editor::event_frame() used on unhandled event type %1"), event->type) << endmsg; @@ -159,12 +206,69 @@ Editor::mouse_mode_toggled (MouseMode m) set_mouse_mode (m); } break; + + case MouseNote: + if (mouse_note_button.get_active()) { + set_mouse_mode (m); + } + break; default: break; } } +Gdk::Cursor* +Editor::which_grabber_cursor () +{ + switch (_edit_point) { + case EditAtMouse: + return grabber_edit_point_cursor; + break; + default: + break; + } + return grabber_cursor; +} + +void +Editor::set_canvas_cursor () +{ + switch (mouse_mode) { + 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; + + case MouseNote: + set_midi_edit_cursor (current_midi_edit_mode()); + break; + } + + if (is_drawable()) { + track_canvas->get_window()->set_cursor(*current_canvas_cursor); + } +} + void Editor::set_mouse_mode (MouseMode m, bool force) { @@ -206,7 +310,7 @@ Editor::set_mouse_mode (MouseMode m, bool force) } } - /* XXX the hack of unsetting all other buttongs should go + /* XXX the hack of unsetting all other buttons should go away once GTK2 allows us to use regular radio buttons drawn like normal buttons, rather than my silly GroupedButton hack. */ @@ -216,40 +320,42 @@ Editor::set_mouse_mode (MouseMode m, bool force) switch (mouse_mode) { case MouseRange: mouse_select_button.set_active (true); - current_canvas_cursor = selector_cursor; break; case MouseObject: mouse_move_button.set_active (true); - current_canvas_cursor = grabber_cursor; break; case MouseGain: mouse_gain_button.set_active (true); - current_canvas_cursor = cross_hair_cursor; break; case MouseZoom: mouse_zoom_button.set_active (true); - current_canvas_cursor = zoom_cursor; break; case MouseTimeFX: mouse_timefx_button.set_active (true); - current_canvas_cursor = time_fx_cursor; // just use playhead break; case MouseAudition: mouse_audition_button.set_active (true); - current_canvas_cursor = speaker_cursor; + break; + + case MouseNote: + mouse_note_button.set_active (true); + set_midi_edit_cursor (current_midi_edit_mode()); break; } - ignore_mouse_mode_toggle = false; + if (mouse_mode == MouseNote) + midi_toolbar_frame.show(); + else + midi_toolbar_frame.hide(); - if (is_drawable()) { - track_canvas.get_window()->set_cursor(*current_canvas_cursor); - } + ignore_mouse_mode_toggle = false; + + set_canvas_cursor (); } void @@ -285,14 +391,119 @@ Editor::step_mouse_mode (bool next) if (next) set_mouse_mode (MouseObject); else set_mouse_mode (MouseTimeFX); break; + + case MouseNote: + if (next) set_mouse_mode (MouseObject); + else set_mouse_mode (MouseAudition); + break; } } void -Editor::button_selection (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type) +Editor::midi_edit_mode_toggled (MidiEditMode m) +{ + if (ignore_midi_edit_mode_toggle) { + return; + } + + switch (m) { + case MidiEditPencil: + if (midi_tool_pencil_button.get_active()) + set_midi_edit_mode (m); + break; + + case MidiEditSelect: + if (midi_tool_select_button.get_active()) + set_midi_edit_mode (m); + break; + + case MidiEditResize: + if (midi_tool_resize_button.get_active()) + set_midi_edit_mode (m); + break; + + case MidiEditErase: + if (midi_tool_erase_button.get_active()) + set_midi_edit_mode (m); + break; + + default: + break; + } + + set_midi_edit_cursor(m); +} + + +void +Editor::set_midi_edit_mode (MidiEditMode m, bool force) +{ + if (drag_info.item) { + return; + } + + if (!force && m == midi_edit_mode) { + return; + } + + midi_edit_mode = m; + + instant_save (); + + ignore_midi_edit_mode_toggle = true; + + switch (midi_edit_mode) { + case MidiEditPencil: + midi_tool_pencil_button.set_active (true); + break; + + case MidiEditSelect: + midi_tool_select_button.set_active (true); + break; + + case MidiEditResize: + midi_tool_resize_button.set_active (true); + break; + + case MidiEditErase: + midi_tool_erase_button.set_active (true); + break; + } + + ignore_midi_edit_mode_toggle = false; + + set_midi_edit_cursor (current_midi_edit_mode()); + + if (is_drawable()) { + track_canvas->get_window()->set_cursor(*current_canvas_cursor); + } +} + +void +Editor::set_midi_edit_cursor (MidiEditMode m) { - bool commit = false; + switch (midi_edit_mode) { + case MidiEditPencil: + current_canvas_cursor = midi_pencil_cursor; + break; + + case MidiEditSelect: + current_canvas_cursor = midi_select_cursor; + break; + + case MidiEditResize: + current_canvas_cursor = midi_resize_cursor; + break; + + case MidiEditErase: + current_canvas_cursor = midi_erase_cursor; + break; + } +} +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 @@ -306,7 +517,7 @@ Editor::button_selection (ArdourCanvas::Item* item, GdkEvent* event, ItemType it (mouse_mode != MouseTimeFX || item_type != RegionItem) && (mouse_mode != MouseRange)) || - (event->type != GDK_BUTTON_PRESS && event->type != GDK_BUTTON_RELEASE || event->button.button > 3)) { + ((event->type != GDK_BUTTON_PRESS && event->type != GDK_BUTTON_RELEASE) || event->button.button > 3)) { return; } @@ -330,59 +541,81 @@ Editor::button_selection (ArdourCanvas::Item* item, GdkEvent* event, ItemType it switch (item_type) { case RegionItem: - case RegionViewNameHighlight: - case RegionViewName: + if (mouse_mode != MouseRange) { + set_selected_regionview_from_click (press, op, true); + } else if (event->type == GDK_BUTTON_PRESS) { + set_selected_track_as_side_effect (); + } + break; + + case RegionViewNameHighlight: + case RegionViewName: + if (mouse_mode != MouseRange) { + set_selected_regionview_from_click (press, op, true); + } else if (event->type == GDK_BUTTON_PRESS) { + set_selected_track_as_side_effect (); + } + break; + + case FadeInHandleItem: case FadeInItem: case FadeOutHandleItem: case FadeOutItem: if (mouse_mode != MouseRange) { - commit = set_selected_regionview_from_click (press, op, true); + set_selected_regionview_from_click (press, op, true); } else if (event->type == GDK_BUTTON_PRESS) { - commit = set_selected_track_from_click (press, op, false); + set_selected_track_as_side_effect (); } break; - case CrossfadeViewItem: - commit = set_selected_track_from_click (press, op, false); - break; - - case GainAutomationControlPointItem: - case PanAutomationControlPointItem: - case RedirectAutomationControlPointItem: - case MidiCCAutomationControlPointItem: - commit = set_selected_track_from_click (press, op, true); + case ControlPointItem: + set_selected_track_as_side_effect (); if (mouse_mode != MouseRange) { - commit |= set_selected_control_point_from_click (op, false); + set_selected_control_point_from_click (op, false); } break; case StreamItem: /* for context click or range selection, select track */ if (event->button.button == 3) { - commit = set_selected_track_from_click (press, op, true); + set_selected_track_as_side_effect (); } else if (event->type == GDK_BUTTON_PRESS && mouse_mode == MouseRange) { - commit = set_selected_track_from_click (press, op, false); + set_selected_track_as_side_effect (); } break; case AutomationTrackItem: - commit = set_selected_track_from_click (press, op, true); + set_selected_track_as_side_effect (true); break; default: break; } - -// if (commit) { -// commit_reversible_command (); -// } } bool Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type) { - track_canvas.grab_focus(); + 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; @@ -415,14 +648,12 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp */ switch (item_type) { - case EditCursorItem: case PlayheadCursorItem: start_cursor_grab (item, event); return true; case MarkerItem: - if (Keyboard::modifier_state_equals (event->button.state, - Keyboard::ModifierMask(Keyboard::Control|Keyboard::Shift))) { + if (Keyboard::modifier_state_equals (event->button.state, Keyboard::ModifierMask(Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) { hide_marker (item, event); } else { start_marker_grab (item, event); @@ -430,7 +661,7 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp return true; case TempoMarkerItem: - if (Keyboard::modifier_state_contains (event->button.state, Keyboard::Control)) { + if (Keyboard::modifier_state_contains (event->button.state, Keyboard::CopyModifier)) { start_tempo_marker_copy_grab (item, event); } else { start_tempo_marker_grab (item, event); @@ -438,7 +669,7 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp return true; case MeterMarkerItem: - if (Keyboard::modifier_state_contains (event->button.state, Keyboard::Control)) { + if (Keyboard::modifier_state_contains (event->button.state, Keyboard::CopyModifier)) { start_meter_marker_copy_grab (item, event); } else { start_meter_marker_grab (item, event); @@ -456,6 +687,11 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp return true; break; + case CdMarkerBarItem: + start_range_markerbar_op (item, event, CreateCDMarker); + return true; + break; + case TransportMarkerBarItem: start_range_markerbar_op (item, event, CreateTransportMarker); return true; @@ -479,14 +715,13 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp case SelectionItem: if (Keyboard::modifier_state_contains - (event->button.state, Keyboard::ModifierMask(Keyboard::Alt))) { + (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::Control)) { + } else if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) { /* grab selection for moving */ start_selection_op (item, event, SelectionMove); - } - else { + } else { /* this was debated, but decided the more common action was to make a new selection */ start_selection_op (item, event, CreateSelection); @@ -500,7 +735,7 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp break; case MouseObject: - if (Keyboard::modifier_state_contains (event->button.state, Keyboard::ModifierMask(Keyboard::Control|Keyboard::Alt)) && + if (Keyboard::modifier_state_contains (event->button.state, Keyboard::ModifierMask(Keyboard::PrimaryModifier|Keyboard::SecondaryModifier)) && event->type == GDK_BUTTON_PRESS) { start_rubberband_select (item, event); @@ -517,7 +752,7 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp return true; case RegionItem: - if (Keyboard::modifier_state_contains (event->button.state, Keyboard::Control)) { + if (Keyboard::modifier_state_contains (event->button.state, Keyboard::CopyModifier)) { start_region_copy_grab (item, event); } else if (Keyboard::the_keyboard().key_is_down (GDK_b)) { start_region_brush_grab (item, event); @@ -533,22 +768,16 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp case RegionViewName: /* rename happens on edit clicks */ - start_trim (clicked_regionview->get_name_highlight(), event); - return true; + start_trim (clicked_regionview->get_name_highlight(), event); + return true; break; - case GainAutomationControlPointItem: - case PanAutomationControlPointItem: - case RedirectAutomationControlPointItem: - case MidiCCAutomationControlPointItem: + case ControlPointItem: start_control_point_grab (item, event); return true; break; - case GainAutomationLineItem: - case PanAutomationLineItem: - case ProcessorAutomationLineItem: - case MidiCCAutomationLineItem: + case AutomationLineItem: start_line_grab_from_line (item, event); return true; break; @@ -600,18 +829,11 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp // start_line_grab_from_regionview (item, event); break; - case GainControlPointItem: - start_control_point_grab (item, event); - return true; - case GainLineItem: start_line_grab_from_line (item, event); return true; - case GainAutomationControlPointItem: - case PanAutomationControlPointItem: - case RedirectAutomationControlPointItem: - case MidiCCAutomationControlPointItem: + case ControlPointItem: start_control_point_grab (item, event); return true; break; @@ -623,17 +845,11 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp break; switch (item_type) { - case GainAutomationControlPointItem: - case PanAutomationControlPointItem: - case RedirectAutomationControlPointItem: - case MidiCCAutomationControlPointItem: + case ControlPointItem: start_control_point_grab (item, event); break; - case GainAutomationLineItem: - case PanAutomationLineItem: - case ProcessorAutomationLineItem: - case MidiCCAutomationLineItem: + case AutomationLineItem: start_line_grab_from_line (item, event); break; @@ -664,9 +880,19 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp break; case MouseAudition: - /* handled in release */ + _scrubbing = true; + scrub_reversals = 0; + scrub_reverse_distance = 0; + last_scrub_x = event->button.x; + scrubbing_direction = 0; + track_canvas->get_window()->set_cursor (*transparent_cursor); + /* rest handled in motion & release */ break; + case MouseNote: + start_create_region_grab (item, event); + break; + default: break; } @@ -678,17 +904,14 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp if (event->type == GDK_BUTTON_PRESS) { switch (item_type) { case RegionItem: - if (Keyboard::modifier_state_contains (event->button.state, Keyboard::Control)) { + if (Keyboard::modifier_state_contains (event->button.state, Keyboard::CopyModifier)) { start_region_copy_grab (item, event); } else { start_region_grab (item, event); } - + return true; break; - case GainAutomationControlPointItem: - case PanAutomationControlPointItem: - case RedirectAutomationControlPointItem: - case MidiCCAutomationControlPointItem: + case ControlPointItem: start_control_point_grab (item, event); return true; break; @@ -725,7 +948,7 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp case MouseZoom: - if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Control)) { + if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) { temporal_zoom_session(); } else { temporal_zoom_to_frame (true, event_frame(event)); @@ -753,7 +976,8 @@ Editor::button_press_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemTyp bool Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type) { - nframes_t where = event_frame (event, 0, 0); + nframes64_t where = event_frame (event, 0, 0); + AutomationTimeAxisView* atv = 0; /* no action if we're recording */ @@ -817,20 +1041,29 @@ 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; + case AutomationTrackItem: - case CrossfadeViewItem: - popup_track_context_menu (1, event->button.time, where); + popup_track_context_menu (1, event->button.time, item_type, false, where); break; case MarkerBarItem: case RangeMarkerBarItem: - case TransportMarkerBarItem: + case TransportMarkerBarItem: + case CdMarkerBarItem: case TempoBarItem: case MeterBarItem: popup_ruler_menu (pixel_to_frame(event->button.x), item_type); @@ -847,6 +1080,10 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT case MeterMarkerItem: tm_marker_context_menu (&event->button, item); break; + + case CrossfadeViewItem: + popup_track_context_menu (1, event->button.time, item_type, false, where); + break; #ifdef WITH_CMT case ImageFrameItem: @@ -894,19 +1131,14 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT } break; - case GainControlPointItem: + case ControlPointItem: if (mouse_mode == MouseGain) { remove_gain_control_point (item, event); + } else { + remove_control_point (item, event); } break; - case GainAutomationControlPointItem: - case PanAutomationControlPointItem: - case RedirectAutomationControlPointItem: - case MidiCCAutomationControlPointItem: - remove_control_point (item, event); - break; - default: break; } @@ -918,14 +1150,10 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT switch (item_type) { /* see comments in button_press_handler */ - case EditCursorItem: case PlayheadCursorItem: case MarkerItem: case GainLineItem: - case GainAutomationLineItem: - case PanAutomationLineItem: - case ProcessorAutomationLineItem: - case MidiCCAutomationLineItem: + case AutomationLineItem: case StartSelectionTrimItem: case EndSelectionTrimItem: return true; @@ -937,6 +1165,14 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT 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); + } + mouse_add_new_marker (where, true); + return true; + case TempoBarItem: if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) { snap_to (where); @@ -957,14 +1193,14 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT case MouseObject: switch (item_type) { case AutomationTrackItem: - dynamic_cast(clicked_axisview)->add_automation_event - (item, - event, - where, - event->button.y); + atv = dynamic_cast(clicked_routeview); + if (atv) { + atv->add_automation_event (item, event, where, event->button.y); + } return true; + break; - + default: break; } @@ -994,15 +1230,23 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT break; case MouseAudition: - switch (item_type) { - case RegionItem: - audition_selected_region (); - break; - default: - break; - } + _scrubbing = false; + track_canvas->get_window()->set_cursor (*current_canvas_cursor); + if (scrubbing_direction == 0) { + /* no drag, just a click */ + switch (item_type) { + case RegionItem: + play_selected_region (); + break; + default: + break; + } + } else { + /* make sure we stop */ + session->request_transport_speed (0.0); + } break; - + default: break; @@ -1015,6 +1259,25 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT case 2: switch (mouse_mode) { + case MouseObject: + switch (item_type) { + case RegionItem: + if (Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) { + raise_region (); + } else if (Keyboard::modifier_state_equals (event->button.state, Keyboard::ModifierMask (Keyboard::TertiaryModifier|Keyboard::SecondaryModifier))) { + lower_region (); + } else { + // Button2 click is unused + } + return true; + + break; + + default: + break; + } + break; + case MouseRange: // x_style_paste (where, 1.0); @@ -1043,34 +1306,13 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_ Marker * marker; double fraction; - switch (item_type) { - case GainControlPointItem: - if (mouse_mode == MouseGain) { - cp = static_cast(item->get_data ("control_point")); - cp->set_visible (true); - - double at_x, at_y; - at_x = cp->get_x(); - at_y = cp->get_y (); - cp->item->i2w (at_x, at_y); - at_x += 20.0; - at_y += 20.0; - - fraction = 1.0 - ((cp->get_y() - cp->line.y_position()) / cp->line.height()); - - set_verbose_canvas_cursor (cp->line.get_verbose_cursor_string (fraction), at_x, at_y); - show_verbose_canvas_cursor (); - - if (is_drawable()) { - track_canvas.get_window()->set_cursor (*fader_cursor); - } - } - break; + if (last_item_entered != item) { + last_item_entered = item; + last_item_entered_n = 0; + } - case GainAutomationControlPointItem: - case PanAutomationControlPointItem: - case RedirectAutomationControlPointItem: - case MidiCCAutomationControlPointItem: + switch (item_type) { + case ControlPointItem: if (mouse_mode == MouseGain || mouse_mode == MouseObject) { cp = static_cast(item->get_data ("control_point")); cp->set_visible (true); @@ -1078,51 +1320,51 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_ double at_x, at_y; at_x = cp->get_x(); at_y = cp->get_y (); - cp->item->i2w (at_x, at_y); + cp->item()->i2w (at_x, at_y); at_x += 20.0; at_y += 20.0; - fraction = 1.0 - (cp->get_y() / cp->line.height()); + fraction = 1.0 - (cp->get_y() / cp->line().height()); - set_verbose_canvas_cursor (cp->line.get_verbose_cursor_string (fraction), at_x, at_y); - show_verbose_canvas_cursor (); + if (is_drawable() && !_scrubbing) { + track_canvas->get_window()->set_cursor (*fader_cursor); + } - if (is_drawable()) { - track_canvas.get_window()->set_cursor (*fader_cursor); + last_item_entered_n++; + set_verbose_canvas_cursor (cp->line().get_verbose_cursor_string (fraction), at_x, at_y); + if (last_item_entered_n < 10) { + show_verbose_canvas_cursor (); } } break; - + case GainLineItem: if (mouse_mode == MouseGain) { ArdourCanvas::Line *line = dynamic_cast (item); if (line) - line->property_fill_color_rgba() = Config->canvasvar_EnteredGainLine.get(); + line->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_EnteredGainLine.get(); if (is_drawable()) { - track_canvas.get_window()->set_cursor (*fader_cursor); + track_canvas->get_window()->set_cursor (*fader_cursor); } } break; - case GainAutomationLineItem: - case ProcessorAutomationLineItem: - case MidiCCAutomationLineItem: - case PanAutomationLineItem: + case AutomationLineItem: if (mouse_mode == MouseGain || mouse_mode == MouseObject) { { ArdourCanvas::Line *line = dynamic_cast (item); if (line) - line->property_fill_color_rgba() = Config->canvasvar_EnteredAutomationLine.get(); + line->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_EnteredAutomationLine.get(); } if (is_drawable()) { - track_canvas.get_window()->set_cursor (*fader_cursor); + track_canvas->get_window()->set_cursor (*fader_cursor); } } break; case RegionViewNameHighlight: if (is_drawable() && mouse_mode == MouseObject) { - track_canvas.get_window()->set_cursor (*trimmer_cursor); + track_canvas->get_window()->set_cursor (*trimmer_cursor); } break; @@ -1137,24 +1379,30 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_ #endif if (is_drawable()) { - track_canvas.get_window()->set_cursor (*trimmer_cursor); + track_canvas->get_window()->set_cursor (*trimmer_cursor); } break; - case EditCursorItem: case PlayheadCursorItem: if (is_drawable()) { - track_canvas.get_window()->set_cursor (*grabber_cursor); - } - break; - + switch (_edit_point) { + case EditAtMouse: + track_canvas->get_window()->set_cursor (*grabber_edit_point_cursor); + break; + default: + track_canvas->get_window()->set_cursor (*grabber_cursor); + break; + } + } + 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); + track_canvas->get_window()->set_cursor (*trimmer_cursor); } } break; @@ -1162,7 +1410,7 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_ case AutomationTrackItem: if (is_drawable()) { - Gdk::Cursor *cursor; + Gdk::Cursor *cursor; switch (mouse_mode) { case MouseRange: cursor = selector_cursor; @@ -1175,7 +1423,7 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_ break; } - track_canvas.get_window()->set_cursor (*cursor); + track_canvas->get_window()->set_cursor (*cursor); AutomationTimeAxisView* atv; if ((atv = static_cast(item->get_data ("trackview"))) != 0) { @@ -1188,10 +1436,11 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_ case MarkerBarItem: case RangeMarkerBarItem: case TransportMarkerBarItem: + case CdMarkerBarItem: case MeterBarItem: case TempoBarItem: if (is_drawable()) { - time_canvas.get_window()->set_cursor (*timebar_cursor); + track_canvas->get_window()->set_cursor (*timebar_cursor); } break; @@ -1199,12 +1448,13 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_ if ((marker = static_cast (item->get_data ("marker"))) == 0) { break; } - marker->set_color_rgba (Config->canvasvar_EnteredMarker.get()); + entered_marker = marker; + marker->set_color_rgba (ARDOUR_UI::config()->canvasvar_EnteredMarker.get()); // fall through case MeterMarkerItem: case TempoMarkerItem: if (is_drawable()) { - time_canvas.get_window()->set_cursor (*timebar_cursor); + track_canvas->get_window()->set_cursor (*timebar_cursor); } break; case FadeInHandleItem: @@ -1227,15 +1477,8 @@ Editor::enter_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_ switch (item_type) { case GainLineItem: - case GainAutomationLineItem: - case ProcessorAutomationLineItem: - case MidiCCAutomationLineItem: - case PanAutomationLineItem: - case GainControlPointItem: - case GainAutomationControlPointItem: - case PanAutomationControlPointItem: - case RedirectAutomationControlPointItem: - case MidiCCAutomationControlPointItem: + case AutomationLineItem: + case ControlPointItem: /* these do not affect the current entered track state */ clear_entered_track = false; break; @@ -1263,20 +1506,16 @@ Editor::leave_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_ bool is_start; switch (item_type) { - case GainControlPointItem: - case GainAutomationControlPointItem: - case PanAutomationControlPointItem: - case RedirectAutomationControlPointItem: - case MidiCCAutomationControlPointItem: + case ControlPointItem: cp = reinterpret_cast(item->get_data ("control_point")); - if (cp->line.npoints() > 1) { - if (!cp->selected) { + if (cp->line().the_list()->interpolation() != AutomationList::Discrete) { + if (cp->line().npoints() > 1 && !cp->selected()) { cp->set_visible (false); } } if (is_drawable()) { - track_canvas.get_window()->set_cursor (*current_canvas_cursor); + track_canvas->get_window()->set_cursor (*current_canvas_cursor); } hide_verbose_canvas_cursor (); @@ -1285,7 +1524,6 @@ Editor::leave_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_ case RegionViewNameHighlight: case StartSelectionTrimItem: case EndSelectionTrimItem: - case EditCursorItem: case PlayheadCursorItem: #ifdef WITH_CMT @@ -1296,15 +1534,12 @@ Editor::leave_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_ #endif if (is_drawable()) { - track_canvas.get_window()->set_cursor (*current_canvas_cursor); + track_canvas->get_window()->set_cursor (*current_canvas_cursor); } break; case GainLineItem: - case GainAutomationLineItem: - case ProcessorAutomationLineItem: - case MidiCCAutomationLineItem: - case PanAutomationLineItem: + case AutomationLineItem: al = reinterpret_cast (item->get_data ("line")); { ArdourCanvas::Line *line = dynamic_cast (item); @@ -1312,7 +1547,7 @@ Editor::leave_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_ line->property_fill_color_rgba() = al->get_line_color(); } if (is_drawable()) { - track_canvas.get_window()->set_cursor (*current_canvas_cursor); + track_canvas->get_window()->set_cursor (*current_canvas_cursor); } break; @@ -1320,18 +1555,19 @@ Editor::leave_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_ /* see enter_handler() for notes */ if (!reinterpret_cast (item->get_data ("regionview"))->name_active()) { if (is_drawable() && mouse_mode == MouseObject) { - track_canvas.get_window()->set_cursor (*current_canvas_cursor); + track_canvas->get_window()->set_cursor (*current_canvas_cursor); } } break; case RangeMarkerBarItem: case TransportMarkerBarItem: + case CdMarkerBarItem: case MeterBarItem: case TempoBarItem: case MarkerBarItem: if (is_drawable()) { - time_canvas.get_window()->set_cursor (*timebar_cursor); + track_canvas->get_window()->set_cursor (*timebar_cursor); } break; @@ -1339,14 +1575,16 @@ Editor::leave_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_ if ((marker = static_cast (item->get_data ("marker"))) == 0) { break; } - loc = find_location_from_marker (marker, is_start); - if (loc) location_flags_changed (loc, this); + entered_marker = 0; + if ((loc = find_location_from_marker (marker, is_start)) != 0) { + location_flags_changed (loc, this); + } // fall through case MeterMarkerItem: case TempoMarkerItem: if (is_drawable()) { - time_canvas.get_window()->set_cursor (*timebar_cursor); + track_canvas->get_window()->set_cursor (*timebar_cursor); } break; @@ -1365,7 +1603,7 @@ Editor::leave_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_ case AutomationTrackItem: if (is_drawable()) { - track_canvas.get_window()->set_cursor (*current_canvas_cursor); + track_canvas->get_window()->set_cursor (*current_canvas_cursor); clear_entered_track = true; Glib::signal_idle().connect (mem_fun(*this, &Editor::left_automation_track)); } @@ -1388,21 +1626,102 @@ Editor::left_automation_track () return false; } +void +Editor::scrub () +{ + double delta; + + if (scrubbing_direction == 0) { + /* first move */ + session->request_locate (drag_info.current_pointer_frame, false); + session->request_transport_speed (0.1); + scrubbing_direction = 1; + + } else { + + if (last_scrub_x > drag_info.current_pointer_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_info.current_pointer_x); + + } else { + + /* still moving to the left (backwards) */ + + scrub_reversals = 0; + scrub_reverse_distance = 0; + + delta = 0.01 * (last_scrub_x - drag_info.current_pointer_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_info.current_pointer_x - last_scrub_x); + + } else { + /* still moving to the right */ + + scrub_reversals = 0; + scrub_reverse_distance = 0; + + delta = 0.01 * (drag_info.current_pointer_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); + scrubbing_direction = -1; + } else { + /* was backwards, go forwards */ + session->request_transport_speed (0.1); + scrubbing_direction = 1; + } + + scrub_reverse_distance = 0; + scrub_reversals = 0; + } + } + + last_scrub_x = drag_info.current_pointer_x; +} + bool Editor::motion_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type, bool from_autoscroll) { - 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. - */ + 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. + */ - track_canvas.get_pointer (x, y); + track_canvas->get_pointer (x, y); + } if (current_stepping_trackview) { /* don't keep the persistent stepped trackview if the mouse moves */ @@ -1416,16 +1735,31 @@ Editor::motion_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item } drag_info.item_type = item_type; + drag_info.last_pointer_x = drag_info.current_pointer_x; + drag_info.last_pointer_y = drag_info.current_pointer_y; drag_info.current_pointer_frame = event_frame (event, &drag_info.current_pointer_x, &drag_info.current_pointer_y); + + switch (mouse_mode) { + case MouseAudition: + if (_scrubbing) { + scrub (); + } + break; + + default: + break; + } + + if (!from_autoscroll && drag_info.item) { /* item != 0 is the best test i can think of for dragging. */ if (!drag_info.move_threshold_passed) { - bool x_threshold_passed = (abs ((nframes64_t) (drag_info.current_pointer_x - drag_info.grab_x)) > 4LL); - bool y_threshold_passed = (abs ((nframes64_t) (drag_info.current_pointer_y - drag_info.grab_y)) > 4LL); + bool x_threshold_passed = (::llabs ((nframes64_t) (drag_info.current_pointer_x - drag_info.grab_x)) > 4LL); + bool y_threshold_passed = (::llabs ((nframes64_t) (drag_info.current_pointer_y - drag_info.grab_y)) > 4LL); drag_info.move_threshold_passed = (x_threshold_passed || y_threshold_passed); @@ -1443,13 +1777,11 @@ Editor::motion_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item switch (item_type) { case PlayheadCursorItem: - case EditCursorItem: case MarkerItem: - case GainControlPointItem: - case RedirectAutomationControlPointItem: - case MidiCCAutomationControlPointItem: - case GainAutomationControlPointItem: - case PanAutomationControlPointItem: + case ControlPointItem: + case RangeMarkerBarItem: + case TransportMarkerBarItem: + case CdMarkerBarItem: case TempoMarkerItem: case MeterMarkerItem: case RegionViewNameHighlight: @@ -1457,10 +1789,7 @@ Editor::motion_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item case EndSelectionTrimItem: case SelectionItem: case GainLineItem: - case ProcessorAutomationLineItem: - case MidiCCAutomationLineItem: - case GainAutomationLineItem: - case PanAutomationLineItem: + case AutomationLineItem: case FadeInHandleItem: case FadeOutHandleItem: @@ -1474,13 +1803,13 @@ Editor::motion_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item if (drag_info.item && (event->motion.state & Gdk::BUTTON1_MASK || (event->motion.state & Gdk::BUTTON2_MASK))) { if (!from_autoscroll) { - maybe_autoscroll (event); + maybe_autoscroll_horizontally (&event->motion); } (this->*(drag_info.motion_callback)) (item, event); goto handled; } goto not_handled; - + break; default: break; } @@ -1490,10 +1819,11 @@ Editor::motion_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item case MouseRange: case MouseZoom: case MouseTimeFX: + case MouseNote: if (drag_info.item && (event->motion.state & GDK_BUTTON1_MASK || (event->motion.state & GDK_BUTTON2_MASK))) { if (!from_autoscroll) { - maybe_autoscroll (event); + maybe_autoscroll (&event->motion); } (this->*(drag_info.motion_callback)) (item, event); goto handled; @@ -1514,6 +1844,44 @@ Editor::motion_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemType item return false; } +void +Editor::break_drag () +{ + stop_canvas_autoscroll (); + hide_verbose_canvas_cursor (); + + if (drag_info.item) { + drag_info.item->ungrab (0); + + /* put it back where it came from */ + + double cxw, cyw; + cxw = 0; + cyw = 0; + drag_info.item->i2w (cxw, cyw); + drag_info.item->move (drag_info.original_x - cxw, drag_info.original_y - cyw); + } + + finalize_drag (); +} + +void +Editor::finalize_drag () +{ + drag_info.item = 0; + drag_info.copy = false; + drag_info.motion_callback = 0; + drag_info.finished_callback = 0; + drag_info.dest_trackview = 0; + drag_info.source_trackview = 0; + drag_info.last_frame_position = 0; + drag_info.grab_frame = 0; + drag_info.last_pointer_frame = 0; + drag_info.current_pointer_frame = 0; + drag_info.brushing = false; + drag_info.clear_copied_locations (); +} + void Editor::start_grab (GdkEvent* event, Gdk::Cursor *cursor) { @@ -1524,13 +1892,13 @@ Editor::start_grab (GdkEvent* event, Gdk::Cursor *cursor) } if (cursor == 0) { - cursor = grabber_cursor; + cursor = which_grabber_cursor (); } - // if dragging with button2, the motion is x constrained, with Alt-button2 it is y constrained + // if dragging with button2, the motion is x constrained, with Alt-button2 it is y constrained if (event->button.button == 2) { - if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Alt)) { + if (Keyboard::modifier_state_equals (event->button.state, Keyboard::SecondaryModifier)) { drag_info.y_constrained = true; drag_info.x_constrained = false; } else { @@ -1547,6 +1915,8 @@ Editor::start_grab (GdkEvent* event, Gdk::Cursor *cursor) drag_info.current_pointer_frame = drag_info.grab_frame; drag_info.current_pointer_x = drag_info.grab_x; drag_info.current_pointer_y = drag_info.grab_y; + drag_info.last_pointer_x = drag_info.current_pointer_x; + drag_info.last_pointer_y = drag_info.current_pointer_y; drag_info.cumulative_x_drag = 0; drag_info.cumulative_y_drag = 0; drag_info.first_move = true; @@ -1554,7 +1924,11 @@ Editor::start_grab (GdkEvent* event, Gdk::Cursor *cursor) drag_info.want_move_threshold = false; drag_info.pointer_frame_offset = 0; drag_info.brushing = false; - drag_info.copied_location = 0; + drag_info.clear_copied_locations (); + + drag_info.original_x = 0; + drag_info.original_y = 0; + drag_info.item->i2w (drag_info.original_x, drag_info.original_y); drag_info.item->grab (Gdk::POINTER_MOTION_MASK|Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK, *cursor, @@ -1585,7 +1959,7 @@ Editor::swap_grab (ArdourCanvas::Item* new_item, Gdk::Cursor* cursor, uint32_t t drag_info.item = new_item; if (cursor == 0) { - cursor = grabber_cursor; + cursor = which_grabber_cursor (); } drag_info.item->grab (Gdk::POINTER_MOTION_MASK|Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK, *cursor, time); @@ -1605,6 +1979,8 @@ Editor::end_grab (ArdourCanvas::Item* item, GdkEvent* event) drag_info.item->ungrab (event->button.time); if (drag_info.finished_callback) { + 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); } @@ -1612,54 +1988,11 @@ Editor::end_grab (ArdourCanvas::Item* item, GdkEvent* event) hide_verbose_canvas_cursor(); - drag_info.item = 0; - drag_info.copy = false; - drag_info.motion_callback = 0; - drag_info.finished_callback = 0; - drag_info.last_trackview = 0; - drag_info.last_frame_position = 0; - drag_info.grab_frame = 0; - drag_info.last_pointer_frame = 0; - drag_info.current_pointer_frame = 0; - drag_info.brushing = false; - - if (drag_info.copied_location) { - delete drag_info.copied_location; - drag_info.copied_location = 0; - } + finalize_drag (); return did_drag; } -void -Editor::set_edit_cursor (GdkEvent* event) -{ - nframes_t pointer_frame = event_frame (event); - - if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) { - if (snap_type != SnapToEditCursor) { - snap_to (pointer_frame); - } - } - - edit_cursor->set_position (pointer_frame); - edit_cursor_clock.set (pointer_frame); -} - -void -Editor::set_playhead_cursor (GdkEvent* event) -{ - nframes_t pointer_frame = event_frame (event); - - if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) { - snap_to (pointer_frame); - } - - if (session) { - session->request_locate (pointer_frame, session->transport_rolling()); - } -} - void Editor::start_fade_in_grab (ArdourCanvas::Item* item, GdkEvent* event) { @@ -1676,15 +2009,16 @@ Editor::start_fade_in_grab (ArdourCanvas::Item* item, GdkEvent* event) AudioRegionView* arv = static_cast(drag_info.data); - drag_info.pointer_frame_offset = drag_info.grab_frame - ((nframes_t) arv->audio_region()->fade_in()->back()->when + arv->region()->position()); + + drag_info.pointer_frame_offset = drag_info.grab_frame - ((nframes64_t) arv->audio_region()->fade_in()->back()->when + arv->region()->position()); } void Editor::fade_in_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) { AudioRegionView* arv = static_cast(drag_info.data); - nframes_t pos; - nframes_t fade_length; + nframes64_t pos; + nframes64_t fade_length; if (drag_info.current_pointer_frame > drag_info.pointer_frame_offset) { pos = drag_info.current_pointer_frame - drag_info.pointer_frame_offset; @@ -1726,8 +2060,8 @@ void Editor::fade_in_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event) { AudioRegionView* arv = static_cast(drag_info.data); - nframes_t pos; - nframes_t fade_length; + nframes64_t pos; + nframes64_t fade_length; if (drag_info.first_move) return; @@ -1759,6 +2093,7 @@ Editor::fade_in_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* even XMLNode &before = alist->get_state(); tmp->audio_region()->set_fade_in_length (fade_length); + tmp->audio_region()->set_fade_in_active (true); XMLNode &after = alist->get_state(); session->add_command(new MementoCommand(*alist.get(), &before, &after)); @@ -1783,15 +2118,15 @@ Editor::start_fade_out_grab (ArdourCanvas::Item* item, GdkEvent* event) AudioRegionView* arv = static_cast(drag_info.data); - drag_info.pointer_frame_offset = drag_info.grab_frame - (arv->region()->length() - (nframes_t) arv->audio_region()->fade_out()->back()->when + arv->region()->position()); + drag_info.pointer_frame_offset = drag_info.grab_frame - (arv->region()->length() - (nframes64_t) arv->audio_region()->fade_out()->back()->when + arv->region()->position()); } void Editor::fade_out_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) { AudioRegionView* arv = static_cast(drag_info.data); - nframes_t pos; - nframes_t fade_length; + nframes64_t pos; + nframes64_t fade_length; if (drag_info.current_pointer_frame > drag_info.pointer_frame_offset) { pos = drag_info.current_pointer_frame - drag_info.pointer_frame_offset; @@ -1837,8 +2172,8 @@ Editor::fade_out_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* eve if (drag_info.first_move) return; AudioRegionView* arv = static_cast(drag_info.data); - nframes_t pos; - nframes_t fade_length; + nframes64_t pos; + nframes64_t fade_length; if (drag_info.current_pointer_frame > drag_info.pointer_frame_offset) { pos = drag_info.current_pointer_frame - drag_info.pointer_frame_offset; @@ -1875,6 +2210,7 @@ Editor::fade_out_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* eve XMLNode &before = alist->get_state(); tmp->audio_region()->set_fade_out_length (fade_length); + tmp->audio_region()->set_fade_out_active (true); XMLNode &after = alist->get_state(); session->add_command(new MementoCommand(*alist.get(), &before, &after)); @@ -1920,7 +2256,7 @@ void Editor::cursor_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) { Cursor* cursor = (Cursor *) drag_info.data; - nframes_t adjusted_frame; + nframes64_t adjusted_frame; if (drag_info.current_pointer_frame > drag_info.pointer_frame_offset) { adjusted_frame = drag_info.current_pointer_frame - drag_info.pointer_frame_offset; @@ -1930,7 +2266,7 @@ Editor::cursor_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) } if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) { - if (cursor != edit_cursor || snap_type != SnapToEditCursor) { + if (cursor == playhead_cursor) { snap_to (adjusted_frame); } } @@ -1939,11 +2275,7 @@ Editor::cursor_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) cursor->set_position (adjusted_frame); - if (cursor == edit_cursor) { - edit_cursor_clock.set (cursor->current_frame); - } else { - UpdateAllTransportClocks (cursor->current_frame); - } + UpdateAllTransportClocks (cursor->current_frame); show_verbose_time_cursor (cursor->current_frame, 10); @@ -1964,9 +2296,6 @@ Editor::cursor_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event if (session) { session->request_locate (playhead_cursor->current_frame, drag_info.was_rolling); } - } else if (item == &edit_cursor->canvas_item) { - edit_cursor->set_position (edit_cursor->current_frame); - edit_cursor_clock.set (edit_cursor->current_frame); } } @@ -1977,7 +2306,7 @@ Editor::update_marker_drag_item (Location *location) double x2 = frame_to_pixel (location->end()); if (location->is_mark()) { - marker_drag_line_points.front().set_x(x1); + marker_drag_line_points.front().set_x(x1); marker_drag_line_points.back().set_x(x1); marker_drag_line->property_points() = marker_drag_line_points; } @@ -1987,6 +2316,7 @@ Editor::update_marker_drag_item (Location *location) } } + void Editor::start_marker_grab (ArdourCanvas::Item* item, GdkEvent* event) { @@ -2008,43 +2338,101 @@ Editor::start_marker_grab (ArdourCanvas::Item* item, GdkEvent* event) start_grab (event); - drag_info.copied_location = new Location (*location); + _dragging_edit_point = true; + drag_info.pointer_frame_offset = drag_info.grab_frame - (is_start ? location->start() : location->end()); update_marker_drag_item (location); if (location->is_mark()) { - marker_drag_line->show(); - marker_drag_line->raise_to_top(); - } - else { + // marker_drag_line->show(); + // marker_drag_line->raise_to_top(); + } else { range_marker_drag_rect->show(); - range_marker_drag_rect->raise_to_top(); + //range_marker_drag_rect->raise_to_top(); + } + + if (is_start) { + show_verbose_time_cursor (location->start(), 10); + } else { + show_verbose_time_cursor (location->end(), 10); + } + + Selection::Operation op = Keyboard::selection_type (event->button.state); + + switch (op) { + case Selection::Toggle: + selection->toggle (marker); + break; + case Selection::Set: + if (!selection->selected (marker)) { + selection->set (marker); + } + break; + case Selection::Extend: + { + Locations::LocationList ll; + list to_add; + nframes64_t s, e; + selection->markers.range (s, e); + s = min (marker->position(), s); + e = max (marker->position(), e); + s = min (s, e); + e = max (s, e); + if (e < max_frames) { + ++e; + } + session->locations()->find_all_between (s, e, ll, Location::Flags (0)); + for (Locations::LocationList::iterator i = ll.begin(); i != ll.end(); ++i) { + LocationMarkers* lm = find_location_markers (*i); + if (lm) { + if (lm->start) { + to_add.push_back (lm->start); + } + if (lm->end) { + to_add.push_back (lm->end); + } + } + } + if (!to_add.empty()) { + selection->add (to_add); + } + break; + } + case Selection::Add: + selection->add (marker); + break; + } + + /* set up copies for us to manipulate during the drag */ + + drag_info.clear_copied_locations (); + + for (MarkerSelection::iterator i = selection->markers.begin(); i != selection->markers.end(); ++i) { + Location *l = find_location_from_marker (*i, is_start); + drag_info.copied_locations.push_back (new Location (*l)); } - - if (is_start) show_verbose_time_cursor (location->start(), 10); - else show_verbose_time_cursor (location->end(), 10); } void Editor::marker_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) { - nframes_t f_delta; - Marker* marker = (Marker *) drag_info.data; - Location *real_location; - Location *copy_location; + nframes64_t f_delta; + nframes64_t newframe; bool is_start; bool move_both = false; + Marker* dragged_marker = (Marker*) drag_info.data; + Marker* marker; + Location *real_location; + Location *copy_location; - - nframes_t newframe; if (drag_info.pointer_frame_offset <= drag_info.current_pointer_frame) { newframe = drag_info.current_pointer_frame - drag_info.pointer_frame_offset; } else { newframe = 0; } - nframes_t next = newframe; + nframes64_t next = newframe; if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) { snap_to (newframe, 0, true); @@ -2054,89 +2442,196 @@ Editor::marker_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) return; } - /* call this to find out if its the start or end */ - - real_location = find_location_from_marker (marker, is_start); + if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) { + move_both = true; + } - /* use the copy that we're "dragging" around */ - - copy_location = drag_info.copied_location; + MarkerSelection::iterator i; + list::iterator x; - f_delta = copy_location->end() - copy_location->start(); - - if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Control)) { - move_both = true; + /* find the marker we're dragging, and compute the delta */ + + for (i = selection->markers.begin(), x = drag_info.copied_locations.begin(); + x != drag_info.copied_locations.end() && i != selection->markers.end(); + ++i, ++x) { + + copy_location = *x; + marker = *i; + + if (marker == dragged_marker) { + + if ((real_location = find_location_from_marker (marker, is_start)) == 0) { + /* que pasa ?? */ + return; + } + + if (real_location->is_mark()) { + f_delta = newframe - copy_location->start(); + } else { + + + switch (marker->type()) { + case Marker::Start: + case Marker::LoopStart: + case Marker::PunchIn: + f_delta = newframe - copy_location->start(); + break; + + case Marker::End: + case Marker::LoopEnd: + case Marker::PunchOut: + f_delta = newframe - copy_location->end(); + break; + default: + /* what kind of marker is this ? */ + return; + } + } + break; + } } - if (copy_location->is_mark()) { - /* just move it */ + if (i == selection->markers.end()) { + /* hmm, impossible - we didn't find the dragged marker */ + return; + } - copy_location->set_start (newframe); + /* now move them all */ - } else { + for (i = selection->markers.begin(), x = drag_info.copied_locations.begin(); + x != drag_info.copied_locations.end() && i != selection->markers.end(); + ++i, ++x) { + + copy_location = *x; + marker = *i; - if (is_start) { // start-of-range marker + /* call this to find out if its the start or end */ + + if ((real_location = find_location_from_marker (marker, is_start)) == 0) { + continue; + } + + if (real_location->locked()) { + continue; + } + + if (copy_location->is_mark()) { + + /* just move it */ - if (move_both) { - copy_location->set_start (newframe); - copy_location->set_end (newframe + f_delta); - } else if (newframe < copy_location->end()) { - copy_location->set_start (newframe); - } else { - snap_to (next, 1, true); - copy_location->set_end (next); - copy_location->set_start (newframe); - } + copy_location->set_start (copy_location->start() + f_delta); + + } else { - } else { // end marker + nframes64_t new_start = copy_location->start() + f_delta; + nframes64_t new_end = copy_location->end() + f_delta; - if (move_both) { - copy_location->set_end (newframe); - copy_location->set_start (newframe - f_delta); - } else if (newframe > copy_location->start()) { - copy_location->set_end (newframe); + if (is_start) { // start-of-range marker - } else if (newframe > 0) { - snap_to (next, -1, true); - copy_location->set_start (next); - copy_location->set_end (newframe); + if (move_both) { + copy_location->set_start (new_start); + copy_location->set_end (new_end); + } else if (new_start < copy_location->end()) { + copy_location->set_start (new_start); + } else { + snap_to (next, 1, true); + copy_location->set_end (next); + copy_location->set_start (newframe); + } + + } else { // end marker + + if (move_both) { + copy_location->set_end (new_end); + copy_location->set_start (new_start); + } else if (new_end > copy_location->start()) { + copy_location->set_end (new_end); + } else if (newframe > 0) { + snap_to (next, -1, true); + copy_location->set_start (next); + copy_location->set_end (newframe); + } } } + update_marker_drag_item (copy_location); + + LocationMarkers* lm = find_location_markers (real_location); + + if (lm) { + lm->set_position (copy_location->start(), copy_location->end()); + } } drag_info.last_pointer_frame = drag_info.current_pointer_frame; drag_info.first_move = false; - update_marker_drag_item (copy_location); + if (drag_info.copied_locations.empty()) { + abort(); + } - LocationMarkers* lm = find_location_markers (real_location); - lm->set_position (copy_location->start(), copy_location->end()); - + edit_point_clock.set (drag_info.copied_locations.front()->start()); show_verbose_time_cursor (newframe, 10); + +#ifdef GTKOSX + track_canvas->update_now (); +#endif } void Editor::marker_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event) { if (drag_info.first_move) { - marker_drag_motion_callback (item, event); + /* just a click, do nothing but finish + off the selection process + */ + + Selection::Operation op = Keyboard::selection_type (event->button.state); + Marker* marker = (Marker *) drag_info.data; + + switch (op) { + case Selection::Set: + if (selection->selected (marker) && selection->markers.size() > 1) { + selection->set (marker); + } + break; + + case Selection::Toggle: + case Selection::Extend: + case Selection::Add: + break; + } + + return; } - - Marker* marker = (Marker *) drag_info.data; - bool is_start; + _dragging_edit_point = false; + begin_reversible_command ( _("move marker") ); XMLNode &before = session->locations()->get_state(); + + MarkerSelection::iterator i; + list::iterator x; + bool is_start; + + for (i = selection->markers.begin(), x = drag_info.copied_locations.begin(); + x != drag_info.copied_locations.end() && i != selection->markers.end(); + ++i, ++x) { - Location * location = find_location_from_marker (marker, is_start); - - if (location) { - if (location->is_mark()) { - location->set_start (drag_info.copied_location->start()); - } else { - location->set (drag_info.copied_location->start(), drag_info.copied_location->end()); + Location * location = find_location_from_marker ((*i), is_start); + + if (location) { + + if (location->locked()) { + return; + } + + if (location->is_mark()) { + location->set_start ((*x)->start()); + } else { + location->set ((*x)->start(), (*x)->end()); + } } } @@ -2168,6 +2663,7 @@ Editor::start_meter_marker_grab (ArdourCanvas::Item* item, GdkEvent* event) } drag_info.item = item; + drag_info.copy = false; drag_info.data = marker; drag_info.motion_callback = &Editor::meter_marker_drag_motion_callback; drag_info.finished_callback = &Editor::meter_marker_drag_finished_callback; @@ -2196,7 +2692,7 @@ Editor::start_meter_marker_copy_grab (ArdourCanvas::Item* item, GdkEvent* event) // The actual copying is not done before we reach the finish callback. char name[64]; snprintf (name, sizeof(name), "%g/%g", meter_marker->meter().beats_per_bar(), meter_marker->meter().note_divisor ()); - MeterMarker* new_marker = new MeterMarker(*this, *meter_group, Config->canvasvar_MeterMarker.get(), name, + MeterMarker* new_marker = new MeterMarker(*this, *meter_group, ARDOUR_UI::config()->canvasvar_MeterMarker.get(), name, *new MeterSection(meter_marker->meter())); drag_info.item = &new_marker->the_item(); @@ -2216,7 +2712,7 @@ void Editor::meter_marker_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) { MeterMarker* marker = (MeterMarker *) drag_info.data; - nframes_t adjusted_frame; + nframes64_t adjusted_frame; if (drag_info.current_pointer_frame > drag_info.pointer_frame_offset) { adjusted_frame = drag_info.current_pointer_frame - drag_info.pointer_frame_offset; @@ -2255,12 +2751,12 @@ Editor::meter_marker_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* if (drag_info.copy == true) { begin_reversible_command (_("copy meter mark")); - XMLNode &before = map.get_state(); + XMLNode &before = map.get_state(); map.add_meter (marker->meter(), when); XMLNode &after = map.get_state(); - session->add_command(new MementoCommand(map, &before, &after)); + session->add_command(new MementoCommand(map, &before, &after)); commit_reversible_command (); - + // delete the dummy marker we used for visual representation of copying. // a new visual marker will show up automatically. delete marker; @@ -2269,7 +2765,7 @@ Editor::meter_marker_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* XMLNode &before = map.get_state(); map.move_meter (marker->meter(), when); XMLNode &after = map.get_state(); - session->add_command(new MementoCommand(map, &before, &after)); + session->add_command(new MementoCommand(map, &before, &after)); commit_reversible_command (); } } @@ -2297,6 +2793,7 @@ Editor::start_tempo_marker_grab (ArdourCanvas::Item* item, GdkEvent* event) } drag_info.item = item; + drag_info.copy = false; drag_info.data = marker; drag_info.motion_callback = &Editor::tempo_marker_drag_motion_callback; drag_info.finished_callback = &Editor::tempo_marker_drag_finished_callback; @@ -2327,7 +2824,7 @@ Editor::start_tempo_marker_copy_grab (ArdourCanvas::Item* item, GdkEvent* event) // The actual copying is not done before we reach the finish callback. char name[64]; snprintf (name, sizeof (name), "%.2f", tempo_marker->tempo().beats_per_minute()); - TempoMarker* new_marker = new TempoMarker(*this, *tempo_group, Config->canvasvar_TempoMarker.get(), name, + TempoMarker* new_marker = new TempoMarker(*this, *tempo_group, ARDOUR_UI::config()->canvasvar_TempoMarker.get(), name, *new TempoSection(tempo_marker->tempo())); drag_info.item = &new_marker->the_item(); @@ -2347,7 +2844,7 @@ void Editor::tempo_marker_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) { TempoMarker* marker = (TempoMarker *) drag_info.data; - nframes_t adjusted_frame; + nframes64_t adjusted_frame; if (drag_info.current_pointer_frame > drag_info.pointer_frame_offset) { adjusted_frame = drag_info.current_pointer_frame - drag_info.pointer_frame_offset; @@ -2398,10 +2895,10 @@ Editor::tempo_marker_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* delete marker; } else { begin_reversible_command (_("move tempo mark")); - XMLNode &before = map.get_state(); + XMLNode &before = map.get_state(); map.move_tempo (marker->tempo(), when); - XMLNode &after = map.get_state(); - session->add_command (new MementoCommand(map, &before, &after)); + XMLNode &after = map.get_state(); + session->add_command (new MementoCommand(map, &before, &after)); commit_reversible_command (); } } @@ -2417,16 +2914,16 @@ 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)) { + if (control_point->line().is_last_point(*control_point) || + control_point->line().is_first_point(*control_point)) { return; } - control_point->line.remove_point (*control_point); + control_point->line().remove_point (*control_point); } void -Editor::remove_control_point (ArdourCanvas::Item*item, GdkEvent* event) +Editor::remove_control_point (ArdourCanvas::Item* item, GdkEvent* event) { ControlPoint* control_point; @@ -2435,7 +2932,7 @@ Editor::remove_control_point (ArdourCanvas::Item*item, GdkEvent* event) /*NOTREACHED*/ } - control_point->line.remove_point (*control_point); + control_point->line().remove_point (*control_point); } void @@ -2455,10 +2952,20 @@ Editor::start_control_point_grab (ArdourCanvas::Item* item, GdkEvent* event) start_grab (event, fader_cursor); - control_point->line.start_drag (control_point, drag_info.grab_frame, 0); + // start the grab at the center of the control point so + // the point doesn't 'jump' to the mouse after the first drag + drag_info.grab_x = control_point->get_x(); + drag_info.grab_y = control_point->get_y(); + + control_point->line().parent_group().i2w(drag_info.grab_x, drag_info.grab_y); + track_canvas->w2c(drag_info.grab_x, drag_info.grab_y, drag_info.grab_x, drag_info.grab_y); + + drag_info.grab_frame = pixel_to_frame(drag_info.grab_x); + + control_point->line().start_drag (control_point, drag_info.grab_frame, 0); - float fraction = 1.0 - ((control_point->get_y() - control_point->line.y_position()) / control_point->line.height()); - set_verbose_canvas_cursor (control_point->line.get_verbose_cursor_string (fraction), + double fraction = 1.0 - ((control_point->get_y() - control_point->line().y_position()) / (double)control_point->line().height()); + set_verbose_canvas_cursor (control_point->line().get_verbose_cursor_string (fraction), drag_info.current_pointer_x + 20, drag_info.current_pointer_y + 20); show_verbose_canvas_cursor (); @@ -2469,11 +2976,28 @@ Editor::control_point_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* { ControlPoint* cp = reinterpret_cast (drag_info.data); - double cx = drag_info.current_pointer_x; - double cy = drag_info.current_pointer_y; + double dx = drag_info.current_pointer_x - drag_info.last_pointer_x; + double dy = drag_info.current_pointer_y - drag_info.last_pointer_y; + + if (event->button.state & Keyboard::SecondaryModifier) { + dx *= 0.1; + dy *= 0.1; + } - drag_info.cumulative_x_drag = cx - drag_info.grab_x ; - drag_info.cumulative_y_drag = cy - drag_info.grab_y ; + double cx = drag_info.grab_x + drag_info.cumulative_x_drag + dx; + 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 _unused = 0; + double zero_gain_y = (1.0 - ZERO_GAIN_FRACTION) * cp->line().height() - .01; + cp->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; + } if (drag_info.x_constrained) { cx = drag_info.grab_x; @@ -2482,32 +3006,35 @@ Editor::control_point_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* cy = drag_info.grab_y; } - cp->line.parent_group().w2i (cx, cy); + drag_info.cumulative_x_drag = cx - drag_info.grab_x; + drag_info.cumulative_y_drag = cy - drag_info.grab_y; + + cp->line().parent_group().w2i (cx, cy); cx = max (0.0, cx); cy = max (0.0, cy); - cy = min ((double) (cp->line.y_position() + cp->line.height()), cy); + cy = min ((double) (cp->line().y_position() + cp->line().height()), cy); //translate cx to frames - nframes_t cx_frames = unit_to_frame (cx); + nframes64_t cx_frames = unit_to_frame (cx); if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier()) && !drag_info.x_constrained) { snap_to (cx_frames); } - float const fraction = 1.0 - ((cy - cp->line.y_position()) / cp->line.height()); + const double fraction = 1.0 - ((cy - cp->line().y_position()) / (double)cp->line().height()); bool push; - if (Keyboard::modifier_state_contains (event->button.state, Keyboard::Control)) { + if (Keyboard::modifier_state_contains (event->button.state, Keyboard::PrimaryModifier)) { push = true; } else { push = false; } - cp->line.point_drag (*cp, cx_frames , fraction, push); + cp->line().point_drag (*cp, cx_frames , fraction, push); - set_verbose_canvas_cursor_text (cp->line.get_verbose_cursor_string (fraction)); + set_verbose_canvas_cursor_text (cp->line().get_verbose_cursor_string (fraction)); drag_info.first_move = false; } @@ -2521,14 +3048,14 @@ Editor::control_point_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent /* just a click */ - if ((event->type == GDK_BUTTON_RELEASE) && (event->button.button == 1) && Keyboard::modifier_state_equals (event->button.state, Keyboard::Shift)) { + if ((event->type == GDK_BUTTON_RELEASE) && (event->button.button == 1) && Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) { reset_point_selection (); } } else { control_point_drag_motion_callback (item, event); } - cp->line.end_drag (cp); + cp->line().end_drag (cp); } void @@ -2562,7 +3089,7 @@ Editor::start_line_grab (AutomationLine* line, GdkEvent* event) { double cx; double cy; - nframes_t frame_within_region; + nframes64_t frame_within_region; /* need to get x coordinate in terms of parent (TimeAxisItemView) origin. @@ -2571,7 +3098,7 @@ Editor::start_line_grab (AutomationLine* line, GdkEvent* event) cx = event->button.x; cy = event->button.y; line->parent_group().w2i (cx, cy); - frame_within_region = (nframes_t) floor (cx * frames_per_unit); + frame_within_region = (nframes64_t) floor (cx * frames_per_unit); if (!line->control_points_adjacent (frame_within_region, current_line_drag_info.before, current_line_drag_info.after)) { @@ -2586,7 +3113,7 @@ Editor::start_line_grab (AutomationLine* line, GdkEvent* event) start_grab (event, fader_cursor); - double const fraction = 1.0 - ((cy - line->y_position()) / line->height()); + const double fraction = 1.0 - ((cy - line->y_position()) / (double)line->height()); line->start_drag (0, drag_info.grab_frame, fraction); @@ -2599,16 +3126,40 @@ void Editor::line_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) { AutomationLine* line = reinterpret_cast (drag_info.data); + + double dy = drag_info.current_pointer_y - drag_info.last_pointer_y; + + if (event->button.state & Keyboard::SecondaryModifier) { + dy *= 0.1; + } + double cx = drag_info.current_pointer_x; - double cy = drag_info.current_pointer_y; + 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 _unused = 0; + 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; line->parent_group().w2i (cx, cy); - - double const fraction = 1.0 - ((cy - line->y_position()) / line->height()); + + cy = max (0.0, cy); + cy = min ((double) line->height(), cy); + + const double fraction = 1.0 - ((cy - line->y_position()) / (double)line->height()); bool push; - if (Keyboard::modifier_state_contains (event->button.state, Keyboard::Control)) { + if (Keyboard::modifier_state_contains (event->button.state, Keyboard::PrimaryModifier)) { push = false; } else { push = true; @@ -2637,8 +3188,14 @@ Editor::start_region_grab (ArdourCanvas::Item* item, GdkEvent* event) drag_info.copy = false; drag_info.item = item; drag_info.data = clicked_regionview; - drag_info.motion_callback = &Editor::region_drag_motion_callback; - drag_info.finished_callback = &Editor::region_drag_finished_callback; + + if (Config->get_edit_mode() == Splice) { + drag_info.motion_callback = &Editor::region_drag_splice_motion_callback; + drag_info.finished_callback = &Editor::region_drag_splice_finished_callback; + } else { + drag_info.motion_callback = &Editor::region_drag_motion_callback; + drag_info.finished_callback = &Editor::region_drag_finished_callback; + } start_grab (event); @@ -2650,15 +3207,42 @@ Editor::start_region_grab (ArdourCanvas::Item* item, GdkEvent* event) speed = tv->get_diskstream()->speed(); } - drag_info.last_frame_position = (nframes_t) (clicked_regionview->region()->position() / speed); + drag_info.last_frame_position = (nframes64_t) (clicked_regionview->region()->position() / speed); drag_info.pointer_frame_offset = drag_info.grab_frame - drag_info.last_frame_position; - drag_info.last_trackview = &clicked_regionview->get_time_axis_view(); + drag_info.source_trackview = &clicked_regionview->get_time_axis_view(); + drag_info.dest_trackview = drag_info.source_trackview; // we want a move threshold drag_info.want_move_threshold = true; show_verbose_time_cursor (drag_info.last_frame_position, 10); begin_reversible_command (_("move region(s)")); + /* + the group containing moved regions may have been + offset during autoscroll. reset its y offset + (we should really handle this in the same way + we do with the x axis, but a simple way of achieving that + eludes me right now). + */ + + _region_motion_group->property_y() = 0; + + /* sync the canvas to what we think is its current state */ + track_canvas->update_now(); +} + +void +Editor::start_create_region_grab (ArdourCanvas::Item* item, GdkEvent* event) +{ + drag_info.copy = false; + drag_info.item = item; + drag_info.data = clicked_axisview; + drag_info.source_trackview = clicked_axisview; + drag_info.dest_trackview = drag_info.source_trackview; + drag_info.motion_callback = &Editor::create_region_drag_motion_callback; + drag_info.finished_callback = &Editor::create_region_drag_finished_callback; + + start_grab (event); } void @@ -2682,20 +3266,23 @@ Editor::start_region_copy_grab (ArdourCanvas::Item* item, GdkEvent* event) speed = rtv->get_diskstream()->speed(); } - drag_info.last_trackview = &clicked_regionview->get_time_axis_view(); - drag_info.last_frame_position = (nframes_t) (clicked_regionview->region()->position() / speed); + drag_info.source_trackview = &clicked_regionview->get_time_axis_view(); + drag_info.dest_trackview = drag_info.source_trackview; + drag_info.last_frame_position = (nframes64_t) (clicked_regionview->region()->position() / speed); drag_info.pointer_frame_offset = drag_info.grab_frame - drag_info.last_frame_position; // we want a move threshold drag_info.want_move_threshold = true; drag_info.motion_callback = &Editor::region_drag_motion_callback; drag_info.finished_callback = &Editor::region_drag_finished_callback; show_verbose_time_cursor (drag_info.last_frame_position, 10); + + _region_motion_group->property_y() = 0; } void Editor::start_region_brush_grab (ArdourCanvas::Item* item, GdkEvent* event) { - if (selection->regions.empty() || clicked_regionview == 0) { + if (selection->regions.empty() || clicked_regionview == 0 || Config->get_edit_mode() == Splice) { return; } @@ -2715,9 +3302,10 @@ Editor::start_region_brush_grab (ArdourCanvas::Item* item, GdkEvent* event) speed = tv->get_diskstream()->speed(); } - drag_info.last_frame_position = (nframes_t) (clicked_regionview->region()->position() / speed); + drag_info.last_frame_position = (nframes64_t) (clicked_regionview->region()->position() / speed); drag_info.pointer_frame_offset = drag_info.grab_frame - drag_info.last_frame_position; - drag_info.last_trackview = &clicked_regionview->get_time_axis_view(); + drag_info.source_trackview = &clicked_regionview->get_time_axis_view(); + drag_info.dest_trackview = drag_info.source_trackview; // we want a move threshold drag_info.want_move_threshold = true; drag_info.brushing = true; @@ -2726,23 +3314,13 @@ Editor::start_region_brush_grab (ArdourCanvas::Item* item, GdkEvent* event) } void -Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) +Editor::possibly_copy_regions_during_grab (GdkEvent* event) { - double x_delta; - double y_delta = 0; - RegionView* rv = reinterpret_cast (drag_info.data); - nframes_t pending_region_position = 0; - int32_t pointer_y_span = 0, canvas_pointer_y_span = 0, original_pointer_order; - int32_t visible_y_high = 0, visible_y_low = 512; //high meaning higher numbered.. not the height on the screen - bool clamp_y_axis = false; - vector height_list(512) ; - vector::iterator j; - if (drag_info.copy && drag_info.move_threshold_passed && drag_info.want_move_threshold) { drag_info.want_move_threshold = false; // don't copy again - /* duplicate the region(s) */ + /* duplicate the regionview(s) and region(s) */ vector new_regionviews; @@ -2763,8 +3341,10 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) continue; } - nrv->get_canvas_group()->show (); + const boost::shared_ptr original = rv->region(); + boost::shared_ptr region_copy = RegionFactory::create (original); + nrv->get_canvas_group()->show (); new_regionviews.push_back (nrv); } @@ -2772,38 +3352,151 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) return; } - /* reset selection to new regionviews */ - + /* reset selection to new regionviews. This will not set selection visual status for + these regionviews since they don't belong to a track, so do that by hand too. + */ + selection->set (new_regionviews); - + + for (vector::iterator i = new_regionviews.begin(); i != new_regionviews.end(); ++i) { + (*i)->set_selected (true); + } + /* reset drag_info data to reflect the fact that we are dragging the copies */ drag_info.data = new_regionviews.front(); swap_grab (new_regionviews.front()->get_canvas_group (), 0, event->motion.time); + /* + sync the canvas to what we think is its current state + without it, the canvas seems to + "forget" to update properly after the upcoming reparent() + ..only if the mouse is in rapid motion at the time of the grab. + something to do with regionview creation raking so long? + */ + track_canvas->update_now(); } +} +bool +Editor::check_region_drag_possible (RouteTimeAxisView** tv) +{ /* Which trackview is this ? */ TimeAxisView* tvp = trackview_by_y_position (drag_info.current_pointer_y); - RouteTimeAxisView* tv = dynamic_cast(tvp); + (*tv) = dynamic_cast(tvp); /* The region motion is only processed if the pointer is over an audio track. */ - if (!tv || !tv->is_track()) { + if (!(*tv) || !(*tv)->is_track()) { /* To make sure we hide the verbose canvas cursor when the mouse is - not held over a track. + not held over and audiotrack. */ hide_verbose_canvas_cursor (); - return; + return false; } - original_pointer_order = drag_info.last_trackview->order; + return true; +} + +struct RegionSelectionByPosition { + bool operator() (RegionView*a, RegionView* b) { + return a->region()->position () < b->region()->position(); + } +}; + +void +Editor::region_drag_splice_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) +{ + RouteTimeAxisView* tv; + + if (!check_region_drag_possible (&tv)) { + return; + } + + if (!drag_info.move_threshold_passed) { + return; + } + + int dir; + + if (drag_info.current_pointer_x - drag_info.grab_x > 0) { + dir = 1; + } else { + dir = -1; + } + + RegionSelection copy (selection->regions); + + RegionSelectionByPosition cmp; + copy.sort (cmp); + + for (RegionSelection::iterator i = copy.begin(); i != copy.end(); ++i) { + + RouteTimeAxisView* atv = dynamic_cast (&(*i)->get_time_axis_view()); + + if (!atv) { + continue; + } + + boost::shared_ptr playlist; + + if ((playlist = atv->playlist()) == 0) { + continue; + } + + if (!playlist->region_is_shuffle_constrained ((*i)->region())) { + continue; + } + + if (dir > 0) { + if (drag_info.current_pointer_frame < (*i)->region()->last_frame() + 1) { + continue; + } + } else { + if (drag_info.current_pointer_frame > (*i)->region()->first_frame()) { + continue; + } + } + + playlist->shuffle ((*i)->region(), dir); + + drag_info.grab_x = drag_info.current_pointer_x; + } +} + +void +Editor::region_drag_splice_finished_callback (ArdourCanvas::Item* item, GdkEvent* event) +{ +} + +void +Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) +{ + double x_delta; + double y_delta = 0; + RegionView* rv = reinterpret_cast (drag_info.data); + nframes64_t pending_region_position = 0; + int32_t pointer_y_span = 0, canvas_pointer_y_span = 0, original_pointer_order; + int32_t visible_y_high = 0, visible_y_low = 512; //high meaning higher numbered.. not the height on the screen + bool clamp_y_axis = false; + vector height_list(512) ; + vector::iterator j; + RouteTimeAxisView* tv; + + possibly_copy_regions_during_grab (event); + + if (!check_region_drag_possible (&tv)) { + return; + } + + original_pointer_order = drag_info.dest_trackview->order; + /************************************************************ - Y-Delta Computation + Y-Delta Computation ************************************************************/ if (drag_info.brushing) { @@ -2811,8 +3504,8 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) pointer_y_span = 0; goto y_axis_done; } - - if ((pointer_y_span = (drag_info.last_trackview->order - tv->order)) != 0) { + + if ((pointer_y_span = (drag_info.dest_trackview->order - tv->order)) != 0) { int32_t children = 0, numtracks = 0; // XXX hard coding track limit, oh my, so very very bad @@ -2823,7 +3516,7 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) TimeAxisView *tracklist_timeview; tracklist_timeview = (*i); RouteTimeAxisView* rtv2 = dynamic_cast(tracklist_timeview); - list children_list; + TimeAxisView::Children children_list; /* zeroes are audio tracks. ones are other types. */ @@ -2840,12 +3533,13 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) tracks = tracks |= (0x01 << rtv2->order); } - height_list[rtv2->order] = (*i)->height; + height_list[rtv2->order] = (*i)->current_height(); children = 1; + if ((children_list = rtv2->get_child_list()).size() > 0) { - for (list::iterator j = children_list.begin(); j != children_list.end(); ++j) { + for (TimeAxisView::Children::iterator j = children_list.begin(); j != children_list.end(); ++j) { tracks = tracks |= (0x01 << (rtv2->order + children)); - height_list[rtv2->order + children] = (*j)->height; + height_list[rtv2->order + children] = (*j)->current_height(); numtracks++; children++; } @@ -2856,16 +3550,16 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) /* find the actual span according to the canvas */ canvas_pointer_y_span = pointer_y_span; - if (drag_info.last_trackview->order >= tv->order) { + if (drag_info.dest_trackview->order >= tv->order) { int32_t y; - for (y = tv->order; y < drag_info.last_trackview->order; y++) { + for (y = tv->order; y < drag_info.dest_trackview->order; y++) { if (height_list[y] == 0 ) { canvas_pointer_y_span--; } } } else { int32_t y; - for (y = drag_info.last_trackview->order;y <= tv->order; y++) { + for (y = drag_info.dest_trackview->order;y <= tv->order; y++) { if ( height_list[y] == 0 ) { canvas_pointer_y_span++; } @@ -2877,8 +3571,14 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) double ix1, ix2, iy1, iy2; int32_t n = 0; + if (rv2->region()->locked()) { + continue; + } + rv2->get_canvas_frame()->get_bounds (ix1, iy1, ix2, iy2); rv2->get_canvas_group()->i2w (ix1, iy1); + iy1 += vertical_adjustment.get_value() - canvas_timebars_vsize; + TimeAxisView* tvp2 = trackview_by_y_position (iy1); RouteTimeAxisView* rtv2 = dynamic_cast(tvp2); @@ -2948,47 +3648,50 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) } } - } else if (drag_info.last_trackview == tv) { + } else if (drag_info.dest_trackview == tv) { clamp_y_axis = true; } y_axis_done: if (!clamp_y_axis) { - drag_info.last_trackview = tv; + drag_info.dest_trackview = tv; } /************************************************************ - X DELTA COMPUTATION + X DELTA COMPUTATION ************************************************************/ /* compute the amount of pointer motion in frames, and where the region would be if we moved it by that much. */ + if ( drag_info.move_threshold_passed ) { - if (drag_info.move_threshold_passed) { - - if (drag_info.current_pointer_frame > drag_info.pointer_frame_offset) { + if (drag_info.current_pointer_frame >= drag_info.pointer_frame_offset) { - nframes_t sync_frame; - nframes_t sync_offset; + nframes64_t sync_frame; + nframes64_t sync_offset; int32_t sync_dir; - + pending_region_position = drag_info.current_pointer_frame - drag_info.pointer_frame_offset; sync_offset = rv->region()->sync_offset (sync_dir); - sync_frame = rv->region()->adjust_to_sync (pending_region_position); - /* we snap if the snap modifier is not enabled. + /* we don't handle a sync point that lies before zero. */ + if (sync_dir >= 0 || (sync_dir < 0 && pending_region_position >= sync_offset)) { + sync_frame = pending_region_position + (sync_dir*sync_offset); + + /* we snap if the snap modifier is not enabled. + */ - if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) { - snap_to (sync_frame); - } + if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) { + snap_to (sync_frame); + } - if (sync_frame - sync_offset <= sync_frame) { - pending_region_position = sync_frame - (sync_dir*sync_offset); + pending_region_position = rv->region()->adjust_to_sync (sync_frame); + } else { - pending_region_position = 0; + pending_region_position = drag_info.last_frame_position; } } else { @@ -2998,12 +3701,25 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) if (pending_region_position > max_frames - rv->region()->length()) { pending_region_position = drag_info.last_frame_position; } - + // printf ("3: pending_region_position= %lu %lu\n", pending_region_position, drag_info.last_frame_position ); - - if (pending_region_position != drag_info.last_frame_position && !drag_info.x_constrained) { - /* now compute the canvas unit distance we need to move the regiondrag_info.last_trackview->order + 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; + } + } else { + x_move_allowed = !drag_info.x_constrained; + } + + if (( pending_region_position != drag_info.last_frame_position) && x_move_allowed ) { + + /* now compute the canvas unit distance we need to move the regionview to make it appear at the new location. */ @@ -3011,10 +3727,29 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) x_delta = ((double) (pending_region_position - drag_info.last_frame_position) / frames_per_unit); } else { x_delta = -((double) (drag_info.last_frame_position - pending_region_position) / frames_per_unit); - } + for (list::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ++i) { + + RegionView* rv2 = (*i); + + // If any regionview is at zero, we need to know so we can stop further leftward motion. + + double ix1, ix2, iy1, iy2; + rv2->get_canvas_frame()->get_bounds (ix1, iy1, ix2, iy2); + rv2->get_canvas_group()->i2w (ix1, iy1); + + if (-x_delta > ix1 + horizontal_adjustment.get_value()) { + // do_move = false; + cerr << "illegal move" << endl; + x_delta = 0; + pending_region_position = drag_info.last_frame_position; + break; + } + } + } + drag_info.last_frame_position = pending_region_position; - + } else { x_delta = 0; } @@ -3024,9 +3759,9 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) x_delta = 0; } - + /************************************************************* - PREPARE TO MOVE + PREPARE TO MOVE ************************************************************/ if (x_delta == 0 && (pointer_y_span == 0)) { @@ -3034,61 +3769,70 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) trackviews. nothing to do. */ return; - } - - - if (x_delta < 0) { - for (list::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ++i) { - - RegionView* rv2 = (*i); - - // If any regionview is at zero, we need to know so we can stop further leftward motion. - - double ix1, ix2, iy1, iy2; - rv2->get_canvas_frame()->get_bounds (ix1, iy1, ix2, iy2); - rv2->get_canvas_group()->i2w (ix1, iy1); - - if (ix1 <= 1) { - x_delta = 0; - break; - } - } } /************************************************************* - MOTION + MOTION ************************************************************/ - - bool do_move; - + bool do_move = true; if (drag_info.first_move) { - if (drag_info.move_threshold_passed) { - do_move = true; - } else { + if (!drag_info.move_threshold_passed) { do_move = false; } - } else { - do_move = true; } if (do_move) { pair >::iterator,bool> insert_result; const list& layered_regions = selection->regions.by_layer(); + + for (list::const_iterator i = layered_regions.begin(); i != layered_regions.end(); ++i) { + + RegionView* rv = (*i); + double ix1, ix2, iy1, iy2; + int32_t temp_pointer_y_span = pointer_y_span; + + if (rv->region()->locked()) { + continue; + } + + /* get item BBox, which will be relative to parent. so we have + to query on a child, then convert to world coordinates using + the parent. + */ + + rv->get_canvas_frame()->get_bounds (ix1, iy1, ix2, iy2); + rv->get_canvas_group()->i2w (ix1, iy1); + + if (drag_info.first_move) { + + // hide any dependent views + + rv->get_time_axis_view().hide_dependent_views (*rv); + + /* + reparent to a non scrolling group so that we can keep the + region selection above all time axis views. + reparenting means we have to move the rv as the two + parent groups have different coordinates. + */ - for (list::const_iterator i = layered_regions.begin(); i != layered_regions.end(); ++i) { - - RegionView* rv = (*i); - double ix1, ix2, iy1, iy2; - int32_t temp_pointer_y_span = pointer_y_span; + rv->get_canvas_group()->property_y() = iy1 - 1; + rv->get_canvas_group()->reparent(*_region_motion_group); - /* get item BBox, which will be relative to parent. so we have - to query on a child, then convert to world coordinates using - the parent. + rv->fake_set_opaque (true); + } + /* for evaluation of the track position of iy1, we have to adjust + to allow for the vertical scrolling adjustment and the height of the timebars. */ + + cerr << "adjust y from " << iy1 << " using " + << vertical_adjustment.get_value() << " - " + << canvas_timebars_vsize + << endl; + + iy1 += vertical_adjustment.get_value() - canvas_timebars_vsize; - rv->get_canvas_frame()->get_bounds (ix1, iy1, ix2, iy2); - rv->get_canvas_group()->i2w (ix1, iy1); TimeAxisView* tvp2 = trackview_by_y_position (iy1); RouteTimeAxisView* canvas_rtv = dynamic_cast(tvp2); RouteTimeAxisView* temp_rtv; @@ -3119,6 +3863,7 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) y_delta -= (*j); temp_pointer_y_span--; } + while (temp_pointer_y_span < 0) { y_delta += (*j); if (x != original_pointer_order) { @@ -3136,8 +3881,8 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) tvp2 = trackview_by_y_position (iy1 + y_delta); temp_rtv = dynamic_cast(tvp2); - rv->set_y_position_and_height (0, temp_rtv->height); - + rv->set_y_position_and_height (0, temp_rtv->current_height()); + /* if you un-comment the following, the region colours will follow the track colours whilst dragging, personally, i think this can confuse things, but never mind. */ @@ -3149,7 +3894,7 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) x++; } } - + /* prevent the regionview from being moved to before the zero position on the canvas. */ @@ -3163,30 +3908,10 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) x_delta = max_frames - rv->region()->last_frame(); } - - if (drag_info.first_move) { - - /* hide any dependent views */ - - rv->get_time_axis_view().hide_dependent_views (*rv); - - /* this is subtle. raising the regionview itself won't help, - because raise_to_top() just puts the item on the top of - its parent's stack. so, we need to put the trackview canvas_display group - on the top, since its parent is the whole canvas. - */ - - rv->get_canvas_group()->raise_to_top(); - rv->get_time_axis_view().canvas_display->raise_to_top(); - cursor_group->raise_to_top(); - - rv->fake_set_opaque (true); - } - if (drag_info.brushing) { mouse_brush_insert_region (rv, pending_region_position); } else { - rv->move (x_delta, y_delta); + rv->move (x_delta, y_delta); } } /* foreach region */ @@ -3206,15 +3931,17 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) void Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event) { - nframes_t where; - RegionView* rv = reinterpret_cast (drag_info.data); - pair >::iterator,bool> insert_result; bool nocommit = true; - double speed; - RouteTimeAxisView* rtv; - bool regionview_y_movement; - bool regionview_x_movement; vector copies; + RouteTimeAxisView* source_tv; + boost::shared_ptr ds; + boost::shared_ptr from_playlist; + vector new_selection; + typedef set > PlaylistSet; + PlaylistSet modified_playlists; + PlaylistSet frozen_playlists; + list modified_playlist_connections; + pair insert_result, frozen_insert_result; /* first_move is set to false if the regionview has been moved in the motion handler. @@ -3227,11 +3954,17 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event nocommit = false; - /* The regionview has been moved at some stage during the grab so we need + /* XXX is this true??? i can''t tell the difference. + The regionview has been moved at some stage during the grab so we need to account for any mouse movement between this event and the last one. */ - region_drag_motion_callback (item, event); + //region_drag_motion_callback (item, event); + + if (Config->get_edit_mode() == Splice && !pre_drag_region_selection.empty()) { + selection->set (pre_drag_region_selection); + pre_drag_region_selection.clear (); + } if (drag_info.brushing) { /* all changes were made during motion event handlers */ @@ -3245,21 +3978,15 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event goto out; } - /* adjust for track speed */ - speed = 1.0; - - rtv = dynamic_cast (drag_info.last_trackview); - if (rtv && rtv->get_diskstream()) { - speed = rtv->get_diskstream()->speed(); - } - - regionview_x_movement = (drag_info.last_frame_position != (nframes_t) (rv->region()->position()/speed)); - regionview_y_movement = (drag_info.last_trackview != &rv->get_time_axis_view()); + char* op_string; - //printf ("last_frame: %s position is %lu %g\n", rv->get_time_axis_view().name().c_str(), drag_info.last_frame_position, speed); - //printf ("last_rackview: %s \n", drag_info.last_trackview->name().c_str()); + /* reverse this here so that we have the correct logic to finalize + the drag. + */ - char* op_string; + if (Config->get_edit_mode() == Lock && !drag_info.copy) { + drag_info.x_constrained = !drag_info.x_constrained; + } if (drag_info.copy) { if (drag_info.x_constrained) { @@ -3277,71 +4004,147 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event begin_reversible_command (op_string); - if (regionview_y_movement) { + for (list::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ) { + + RegionView* rv = (*i); + double ix1, ix2, iy1, iy2; + rv->get_canvas_frame()->get_bounds (ix1, iy1, ix2, iy2); + rv->get_canvas_group()->i2w (ix1, iy1); + iy1 += vertical_adjustment.get_value() - canvas_timebars_vsize; + + TimeAxisView* dest_tv = trackview_by_y_position (iy1); + RouteTimeAxisView* dest_rtv = dynamic_cast(dest_tv); + double speed; + bool changed_tracks, changed_position; + nframes64_t where; + + if (rv->region()->locked()) { + ++i; + continue; + } + + /* adjust for track speed */ - /* moved to a different audio track. */ + speed = 1.0; - vector new_selection; - - for (list::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ) { - - RegionView* rv = (*i); + if (dest_rtv && dest_rtv->get_diskstream()) { + speed = dest_rtv->get_diskstream()->speed(); + } + + changed_position = (drag_info.last_frame_position != (nframes64_t) (rv->region()->position()/speed)); + changed_tracks = (dest_tv != &rv->get_time_axis_view()); - double ix1, ix2, iy1, iy2; + if (changed_position && !drag_info.x_constrained) { + _master_group->w2i(ix1, iy1); + where = (nframes64_t) (unit_to_frame (ix1) * speed); + } else { + where = rv->region()->position(); + } - rv->get_canvas_frame()->get_bounds (ix1, iy1, ix2, iy2); - rv->get_canvas_group()->i2w (ix1, iy1); - TimeAxisView* tvp2 = trackview_by_y_position (iy1); - RouteTimeAxisView* rtv2 = dynamic_cast(tvp2); + boost::shared_ptr new_region; - boost::shared_ptr from_playlist = rv->region()->playlist(); - boost::shared_ptr to_playlist = rtv2->playlist(); - where = (nframes_t) (unit_to_frame (ix1) * speed); - boost::shared_ptr new_region (RegionFactory::create (rv->region())); + if (drag_info.copy) { + /* we already made a copy */ + new_region = rv->region(); /* undo the previous hide_dependent_views so that xfades don't disappear on copying regions */ + + //rv->get_time_axis_view().reveal_dependent_views (*rv); + + } else if (changed_tracks && dest_rtv->playlist()) { + new_region = RegionFactory::create (rv->region()); + } - rv->get_time_axis_view().reveal_dependent_views (*rv); - - if (!drag_info.copy) { - - /* the region that used to be in the old playlist is not - moved to the new one - we make a copy of it. as a result, - any existing editor for the region should no longer be - visible. - */ - - rv->hide_region_editor(); - rv->fake_set_opaque (false); + if (changed_tracks || drag_info.copy) { - session->add_command (new MementoCommand(*from_playlist, &from_playlist->get_state(), 0)); - from_playlist->remove_region ((rv->region())); - session->add_command (new MementoCommand(*from_playlist, 0, &from_playlist->get_state())); + boost::shared_ptr to_playlist = dest_rtv->playlist(); + if (!to_playlist) { + ++i; + continue; + } - } else { + latest_regionviews.clear (); - /* the regionview we dragged around is a temporary copy, queue it for deletion */ - - copies.push_back (rv); + sigc::connection c = dest_rtv->view()->RegionViewAdded.connect (mem_fun(*this, &Editor::collect_new_region_view)); + + insert_result = modified_playlists.insert (to_playlist); + if (insert_result.second) { + session->add_command (new MementoCommand(*to_playlist, &to_playlist->get_state(), 0)); } - latest_regionview = 0; - - sigc::connection c = rtv2->view()->RegionViewAdded.connect (mem_fun(*this, &Editor::collect_new_region_view)); - session->add_command (new MementoCommand(*to_playlist, &to_playlist->get_state(), 0)); to_playlist->add_region (new_region, where); - session->add_command (new MementoCommand(*to_playlist, 0, &to_playlist->get_state())); + c.disconnect (); - if (latest_regionview) { - new_selection.push_back (latest_regionview); + if (!latest_regionviews.empty()) { + // XXX why just the first one ? we only expect one + // commented out in nick_m's canvas reworking. is that intended? + //dest_atv->reveal_dependent_views (*latest_regionviews.front()); + new_selection.push_back (latest_regionviews.front()); + } + + } else { + /* + motion on the same track. plonk the previously reparented region + back to its original canvas group (its streamview). + No need to do anything for copies as they are fake regions which will be deleted. + */ + + rv->get_canvas_group()->reparent (*dest_rtv->view()->canvas_item()); + rv->get_canvas_group()->property_y() = 0; + + /* just change the model */ + + boost::shared_ptr playlist = dest_rtv->playlist(); + + insert_result = modified_playlists.insert (playlist); + if (insert_result.second) { + session->add_command (new MementoCommand(*playlist, &playlist->get_state(), 0)); + } + /* freeze to avoid lots of relayering in the case of a multi-region drag */ + frozen_insert_result = frozen_playlists.insert(playlist); + if (frozen_insert_result.second) { + playlist->freeze(); + } + + rv->region()->set_position (where, (void*) this); + } + + if (changed_tracks && !drag_info.copy) { + + /* get the playlist where this drag started. we can't use rv->region()->playlist() + because we may have copied the region and it has not been attached to a playlist. + */ + + assert ((source_tv = dynamic_cast (&rv->get_time_axis_view()))); + assert ((ds = source_tv->get_diskstream())); + assert ((from_playlist = ds->playlist())); + + /* moved to a different audio track, without copying */ + + /* the region that used to be in the old playlist is not + moved to the new one - we use a copy of it. as a result, + any existing editor for the region should no longer be + visible. + */ + + rv->hide_region_editor(); + rv->fake_set_opaque (false); + + /* remove the region from the old playlist */ + + insert_result = modified_playlists.insert (from_playlist); + if (insert_result.second) { + session->add_command (new MementoCommand(*from_playlist, &from_playlist->get_state(), 0)); } + from_playlist->remove_region ((rv->region())); + /* OK, this is where it gets tricky. If the playlist was being used by >1 tracks, and the region - was selected in all of them, then removing it from the playlist will have removed all + was selected in all of them, then removing it from a playlist will have removed all trace of it from the selection (i.e. there were N regions selected, we removed 1, but since its the same playlist for N tracks, all N tracks updated themselves, removed the corresponding regionview, and the selection is now empty). @@ -3357,116 +4160,104 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event we can just iterate. */ - if (drag_info.copy) { - ++i; - } else { - if (selection->regions.empty()) { - break; - } else { - i = selection->regions.by_layer().begin(); - } + if (selection->regions.empty()) { + break; + } else { + i = selection->regions.by_layer().begin(); } - } - - selection->set (new_selection); - - } else { - - /* motion within a single track */ - - list regions = selection->regions.by_layer(); + } else { + ++i; + } + + if (drag_info.copy) { + copies.push_back (rv); + } + } + + if (new_selection.empty()) { if (drag_info.copy) { + /* the region(view)s that are selected and being dragged around + are copies and do not belong to any track. remove them + from the selection right here. + */ selection->clear_regions(); } - - for (list::iterator i = regions.begin(); i != regions.end(); ++i) { - - rv = (*i); - - if (!rv->region()->can_move()) { - continue; - } - - if (regionview_x_movement) { - double ownspeed = 1.0; - rtv = dynamic_cast (&(rv->get_time_axis_view())); - - if (rtv && rtv->get_diskstream()) { - ownspeed = rtv->get_diskstream()->speed(); - } - - /* base the new region position on the current position of the regionview.*/ - - double ix1, ix2, iy1, iy2; - - rv->get_canvas_frame()->get_bounds (ix1, iy1, ix2, iy2); - rv->get_canvas_group()->i2w (ix1, iy1); - where = (nframes_t) (unit_to_frame (ix1) * ownspeed); - - } else { - - where = rv->region()->position(); - } + } else { + /* this will clear any existing selection that would have been + cleared in the other clause above + */ + selection->set (new_selection); + } - boost::shared_ptr to_playlist = rv->region()->playlist(); + for (set >::iterator p = frozen_playlists.begin(); p != frozen_playlists.end(); ++p) { + (*p)->thaw(); + } + + out: + if (!nocommit) { + for (set >::iterator p = modified_playlists.begin(); p != modified_playlists.end(); ++p) { + session->add_command (new MementoCommand(*(*p), 0, &(*p)->get_state())); + } + commit_reversible_command (); + } - assert (to_playlist); + for (vector::iterator x = copies.begin(); x != copies.end(); ++x) { + delete *x; + } - /* add the undo */ +} + +void +Editor::create_region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) +{ + if (drag_info.move_threshold_passed) { + if (drag_info.first_move) { + // TODO: create region-create-drag region view here + drag_info.first_move = false; + } - session->add_command (new MementoCommand(*to_playlist, &to_playlist->get_state(), 0)); + // TODO: resize region-create-drag region view here + } +} - if (drag_info.copy) { +void +Editor::create_region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event) +{ + MidiTimeAxisView* mtv = dynamic_cast (drag_info.dest_trackview); + if (!mtv) + return; - boost::shared_ptr newregion; - boost::shared_ptr ar; - boost::shared_ptr mr; + const boost::shared_ptr diskstream = + boost::dynamic_pointer_cast(mtv->view()->trackview().track()->diskstream()); + + if (!diskstream) { + warning << "Cannot create non-MIDI region" << endl; + return; + } - if ((ar = boost::dynamic_pointer_cast(rv->region())) != 0) { - newregion = RegionFactory::create (ar); - } else if ((mr = boost::dynamic_pointer_cast(rv->region())) != 0) { - newregion = RegionFactory::create (mr); - } + if (drag_info.first_move) { + begin_reversible_command (_("create region")); + XMLNode &before = mtv->playlist()->get_state(); - /* add it */ + nframes64_t start = drag_info.grab_frame; + snap_to (start, -1); + const Meter& m = session->tempo_map().meter_at(start); + const Tempo& t = session->tempo_map().tempo_at(start); + double length = floor (m.frames_per_bar(t, session->frame_rate())); - latest_regionview = 0; - sigc::connection c = rtv->view()->RegionViewAdded.connect (mem_fun(*this, &Editor::collect_new_region_view)); - to_playlist->add_region (newregion, (nframes_t) (where * rtv->get_diskstream()->speed())); - c.disconnect (); + boost::shared_ptr src = session->create_midi_source_for_session(*diskstream.get()); - if (latest_regionview) { - rtv->reveal_dependent_views (*latest_regionview); - selection->add (latest_regionview); - } - - } else { - - /* just change the model */ - - rv->region()->set_position (where, (void*) this); - - } - - /* add the redo */ - - session->add_command (new MementoCommand(*to_playlist, 0, &to_playlist->get_state())); - - if (drag_info.copy) { - copies.push_back (rv); - } - } - } - - out: - - if (!nocommit) { - commit_reversible_command (); - } + mtv->playlist()->add_region (boost::dynamic_pointer_cast + (RegionFactory::create(src, 0, (nframes_t) length, + PBD::basename_nosuffix(src->name()))), start); + XMLNode &after = mtv->playlist()->get_state(); + session->add_command(new MementoCommand(*mtv->playlist().get(), &before, &after)); + commit_reversible_command(); - for (vector::iterator x = copies.begin(); x != copies.end(); ++x) { - delete *x; + } else { + create_region_drag_motion_callback (item, event); + // TODO: create region-create-drag region here } } @@ -3477,7 +4268,7 @@ Editor::region_view_item_click (AudioRegionView& rv, GdkEventButton* event) this is an alignment click (control used) */ - if (Keyboard::modifier_state_contains (event->state, Keyboard::Control)) { + 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; @@ -3485,36 +4276,49 @@ Editor::region_view_item_click (AudioRegionView& rv, GdkEventButton* event) speed = rtv->get_diskstream()->speed(); } - if (Keyboard::modifier_state_equals (event->state, Keyboard::ModifierMask (Keyboard::Control|Keyboard::Alt))) { + nframes64_t where = get_preferred_edit_position(); - align_region (rv.region(), SyncPoint, (nframes_t) (edit_cursor->current_frame * speed)); + if (where >= 0) { - } else if (Keyboard::modifier_state_equals (event->state, Keyboard::ModifierMask (Keyboard::Control|Keyboard::Shift))) { - - align_region (rv.region(), End, (nframes_t) (edit_cursor->current_frame * speed)); - - } else { - - align_region (rv.region(), Start, (nframes_t) (edit_cursor->current_frame * speed)); + 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)); + } } } } void -Editor::show_verbose_time_cursor (nframes_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; BBT_Time bbt; int hours, mins; - nframes_t frame_rate; + nframes64_t frame_rate; float secs; if (session == 0) { return; } - switch (Profile->get_small_screen() ? ARDOUR_UI::instance()->primary_clock.mode () : ARDOUR_UI::instance()->secondary_clock.mode ()) { + AudioClock::Mode m; + + if (Profile->get_sae() || Profile->get_small_screen()) { + m = ARDOUR_UI::instance()->primary_clock.mode(); + } else { + m = ARDOUR_UI::instance()->secondary_clock.mode(); + } + + switch (m) { case AudioClock::BBT: session->bbt_time (frame, bbt); snprintf (buf, sizeof (buf), "%02" PRIu32 "|%02" PRIu32 "|%02" PRIu32, bbt.bars, bbt.beats, bbt.ticks); @@ -3537,7 +4341,7 @@ Editor::show_verbose_time_cursor (nframes_t frame, double offset, double xpos, d break; default: - snprintf (buf, sizeof(buf), "%u", frame); + snprintf (buf, sizeof(buf), "%" PRIi64, frame); break; } @@ -3545,20 +4349,20 @@ Editor::show_verbose_time_cursor (nframes_t frame, double offset, double xpos, d set_verbose_canvas_cursor (buf, xpos + offset, ypos + offset); } else { - set_verbose_canvas_cursor (buf, drag_info.current_pointer_x + offset, drag_info.current_pointer_y + offset); + set_verbose_canvas_cursor (buf, drag_info.current_pointer_x + offset - horizontal_adjustment.get_value(), drag_info.current_pointer_y + offset - vertical_adjustment.get_value() + canvas_timebars_vsize); } show_verbose_canvas_cursor (); } void -Editor::show_verbose_duration_cursor (nframes_t start, nframes_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; BBT_Time sbbt; BBT_Time ebbt; int hours, mins; - nframes_t distance, frame_rate; + nframes64_t distance, frame_rate; float secs; Meter meter_at_start(session->tempo_map().meter_at(start)); @@ -3566,7 +4370,15 @@ Editor::show_verbose_duration_cursor (nframes_t start, nframes_t end, double off return; } - switch (ARDOUR_UI::instance()->secondary_clock.mode ()) { + AudioClock::Mode m; + + if (Profile->get_sae() || Profile->get_small_screen()) { + m = ARDOUR_UI::instance()->primary_clock.mode (); + } else { + m = ARDOUR_UI::instance()->secondary_clock.mode (); + } + + switch (m) { case AudioClock::BBT: session->bbt_time (start, sbbt); session->bbt_time (end, ebbt); @@ -3611,7 +4423,7 @@ Editor::show_verbose_duration_cursor (nframes_t start, nframes_t end, double off break; default: - snprintf (buf, sizeof(buf), "%u", end - start); + snprintf (buf, sizeof(buf), "%" PRIi64, end - start); break; } @@ -3621,13 +4433,21 @@ Editor::show_verbose_duration_cursor (nframes_t start, nframes_t end, double off else { set_verbose_canvas_cursor (buf, drag_info.current_pointer_x + offset, drag_info.current_pointer_y + offset); } + show_verbose_canvas_cursor (); } void Editor::collect_new_region_view (RegionView* rv) { - latest_regionview = rv; + latest_regionviews.push_back (rv); +} + +void +Editor::collect_and_select_new_region_view (RegionView* rv) +{ + selection->add(rv); + latest_regionviews.push_back (rv); } void @@ -3639,7 +4459,7 @@ Editor::start_selection_grab (ArdourCanvas::Item* item, GdkEvent* event) /* lets try to create new Region for the selection */ - vector > new_regions; + vector > new_regions; create_region_from_selection (new_regions); if (new_regions.empty()) { @@ -3657,7 +4477,7 @@ Editor::start_selection_grab (ArdourCanvas::Item* item, GdkEvent* event) set the regionview we want to then drag. */ - latest_regionview = 0; + 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 @@ -3677,24 +4497,26 @@ Editor::start_selection_grab (ArdourCanvas::Item* item, GdkEvent* event) c.disconnect (); - if (latest_regionview == 0) { + 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 */ - selection->set (latest_regionview); + i'm ignoring undo stuff, because the region creation will take care of it + */ + selection->set (latest_regionviews); - drag_info.item = latest_regionview->get_canvas_group(); - drag_info.data = latest_regionview; + drag_info.item = latest_regionviews.front()->get_canvas_group(); + drag_info.data = latest_regionviews.front(); drag_info.motion_callback = &Editor::region_drag_motion_callback; drag_info.finished_callback = &Editor::region_drag_finished_callback; start_grab (event); - drag_info.last_trackview = clicked_axisview; - drag_info.last_frame_position = latest_regionview->region()->position(); + drag_info.source_trackview = clicked_routeview; + drag_info.dest_trackview = drag_info.source_trackview; + drag_info.last_frame_position = latest_regionviews.front()->region()->position(); drag_info.pointer_frame_offset = drag_info.grab_frame - drag_info.last_frame_position; show_verbose_time_cursor (drag_info.last_frame_position, 10); @@ -3703,20 +4525,18 @@ Editor::start_selection_grab (ArdourCanvas::Item* item, GdkEvent* event) void Editor::cancel_selection () { - for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) { + for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) { (*i)->hide_selection (); } - begin_reversible_command (_("cancel selection")); selection->clear (); clicked_selection = 0; - commit_reversible_command (); } void Editor::start_selection_op (ArdourCanvas::Item* item, GdkEvent* event, SelectionOp op) { - nframes_t start = 0; - nframes_t end = 0; + nframes64_t start = 0; + nframes64_t end = 0; if (session == 0) { return; @@ -3730,7 +4550,7 @@ Editor::start_selection_op (ArdourCanvas::Item* item, GdkEvent* event, Selection switch (op) { case CreateSelection: - if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Shift)) { + if (Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) { drag_info.copy = true; } else { drag_info.copy = false; @@ -3773,10 +4593,10 @@ Editor::start_selection_op (ArdourCanvas::Item* item, GdkEvent* event, Selection void Editor::drag_selection (ArdourCanvas::Item* item, GdkEvent* event) { - nframes_t start = 0; - nframes_t end = 0; - nframes_t length; - nframes_t pending_position; + nframes64_t start = 0; + nframes64_t end = 0; + nframes64_t length; + nframes64_t pending_position; if (drag_info.current_pointer_frame > drag_info.pointer_frame_offset) { pending_position = drag_info.current_pointer_frame - drag_info.pointer_frame_offset; @@ -3881,7 +4701,7 @@ Editor::drag_selection (ArdourCanvas::Item* item, GdkEvent* event) } if (event->button.x >= horizontal_adjustment.get_value() + canvas_width) { - start_canvas_autoscroll (1); + start_canvas_autoscroll (1, 0); } if (start != end) { @@ -3934,9 +4754,9 @@ Editor::start_trim (ArdourCanvas::Item* item, GdkEvent* event) speed = tv->get_diskstream()->speed(); } - nframes_t region_start = (nframes_t) (clicked_regionview->region()->position() / speed); - nframes_t region_end = (nframes_t) (clicked_regionview->region()->last_frame() / speed); - nframes_t region_length = (nframes_t) (clicked_regionview->region()->length() / speed); + nframes64_t region_start = (nframes64_t) (clicked_regionview->region()->position() / speed); + nframes64_t region_end = (nframes64_t) (clicked_regionview->region()->last_frame() / speed); + nframes64_t region_length = (nframes64_t) (clicked_regionview->region()->length() / speed); //drag_info.item = clicked_regionview->get_name_highlight(); drag_info.item = item; @@ -3945,7 +4765,7 @@ Editor::start_trim (ArdourCanvas::Item* item, GdkEvent* event) start_grab (event, trimmer_cursor); - if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Control)) { + if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) { trim_op = ContentsTrim; } else { /* These will get overridden for a point trim.*/ @@ -3975,7 +4795,7 @@ void Editor::trim_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) { RegionView* rv = clicked_regionview; - nframes_t frame_delta = 0; + nframes64_t frame_delta = 0; bool left_direction; bool obey_snap = !Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier()); @@ -4036,7 +4856,8 @@ Editor::trim_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) boost::shared_ptr pl = (*i)->region()->playlist(); insert_result = motion_frozen_playlists.insert (pl); if (insert_result.second) { - session->add_command(new MementoCommand(*pl, &pl->get_state(), 0)); + session->add_command(new MementoCommand(*pl, &pl->get_state(), 0)); + pl->freeze(); } } } @@ -4051,7 +4872,7 @@ Editor::trim_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) case StartTrim: if ((left_direction == false) && (drag_info.current_pointer_frame <= rv->region()->first_frame()/speed)) { break; - } else { + } else { for (list::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ++i) { single_start_trim (**i, frame_delta, left_direction, obey_snap); } @@ -4059,7 +4880,7 @@ Editor::trim_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) } case EndTrim: - if ((left_direction == true) && (drag_info.current_pointer_frame > (nframes_t) (rv->region()->last_frame()/speed))) { + if ((left_direction == true) && (drag_info.current_pointer_frame > (nframes64_t) (rv->region()->last_frame()/speed))) { break; } else { for (list::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ++i) { @@ -4072,7 +4893,7 @@ Editor::trim_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) { bool swap_direction = false; - if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Control)) { + if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) { swap_direction = true; } @@ -4087,10 +4908,10 @@ Editor::trim_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) switch (trim_op) { case StartTrim: - show_verbose_time_cursor((nframes_t) (rv->region()->position()/speed), 10); + show_verbose_time_cursor((nframes64_t) (rv->region()->position()/speed), 10); break; case EndTrim: - show_verbose_time_cursor((nframes_t) (rv->region()->last_frame()/speed), 10); + show_verbose_time_cursor((nframes64_t) (rv->region()->last_frame()/speed), 10); break; case ContentsTrim: show_verbose_time_cursor(drag_info.current_pointer_frame, 10); @@ -4102,7 +4923,7 @@ Editor::trim_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) } void -Editor::single_contents_trim (RegionView& rv, nframes_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, bool obey_snap) { boost::shared_ptr region (rv.region()); @@ -4110,7 +4931,7 @@ Editor::single_contents_trim (RegionView& rv, nframes_t frame_delta, bool left_d return; } - nframes_t new_bound; + nframes64_t new_bound; double speed = 1.0; TimeAxisView* tvp = clicked_axisview; @@ -4122,27 +4943,27 @@ Editor::single_contents_trim (RegionView& rv, nframes_t frame_delta, bool left_d if (left_direction) { if (swap_direction) { - new_bound = (nframes_t) (region->position()/speed) + frame_delta; + new_bound = (nframes64_t) (region->position()/speed) + frame_delta; } else { - new_bound = (nframes_t) (region->position()/speed) - frame_delta; + new_bound = (nframes64_t) (region->position()/speed) - frame_delta; } } else { if (swap_direction) { - new_bound = (nframes_t) (region->position()/speed) - frame_delta; + new_bound = (nframes64_t) (region->position()/speed) - frame_delta; } else { - new_bound = (nframes_t) (region->position()/speed) + frame_delta; + new_bound = (nframes64_t) (region->position()/speed) + frame_delta; } } if (obey_snap) { snap_to (new_bound); } - region->trim_start ((nframes_t) (new_bound * speed), this); + region->trim_start ((nframes64_t) (new_bound * speed), this); rv.region_changed (StartChanged); } void -Editor::single_start_trim (RegionView& rv, nframes_t frame_delta, bool left_direction, bool obey_snap) +Editor::single_start_trim (RegionView& rv, nframes64_t frame_delta, bool left_direction, bool obey_snap) { boost::shared_ptr region (rv.region()); @@ -4150,7 +4971,7 @@ Editor::single_start_trim (RegionView& rv, nframes_t frame_delta, bool left_dire return; } - nframes_t new_bound; + nframes64_t new_bound; double speed = 1.0; TimeAxisView* tvp = clicked_axisview; @@ -4161,22 +4982,22 @@ Editor::single_start_trim (RegionView& rv, nframes_t frame_delta, bool left_dire } if (left_direction) { - new_bound = (nframes_t) (region->position()/speed) - frame_delta; + new_bound = (nframes64_t) (region->position()/speed) - frame_delta; } else { - new_bound = (nframes_t) (region->position()/speed) + frame_delta; + new_bound = (nframes64_t) (region->position()/speed) + frame_delta; } if (obey_snap) { snap_to (new_bound, (left_direction ? 0 : 1)); } - region->trim_front ((nframes_t) (new_bound * speed), this); + region->trim_front ((nframes64_t) (new_bound * speed), this); rv.region_changed (Change (LengthChanged|PositionChanged|StartChanged)); } void -Editor::single_end_trim (RegionView& rv, nframes_t frame_delta, bool left_direction, bool obey_snap) +Editor::single_end_trim (RegionView& rv, nframes64_t frame_delta, bool left_direction, bool obey_snap) { boost::shared_ptr region (rv.region()); @@ -4184,7 +5005,7 @@ Editor::single_end_trim (RegionView& rv, nframes_t frame_delta, bool left_direct return; } - nframes_t new_bound; + nframes64_t new_bound; double speed = 1.0; TimeAxisView* tvp = clicked_axisview; @@ -4195,15 +5016,15 @@ Editor::single_end_trim (RegionView& rv, nframes_t frame_delta, bool left_direct } if (left_direction) { - new_bound = (nframes_t) ((region->last_frame() + 1)/speed) - frame_delta; + new_bound = (nframes64_t) ((region->last_frame() + 1)/speed) - frame_delta; } else { - new_bound = (nframes_t) ((region->last_frame() + 1)/speed) + frame_delta; + new_bound = (nframes64_t) ((region->last_frame() + 1)/speed) + frame_delta; } if (obey_snap) { snap_to (new_bound); } - region->trim_end ((nframes_t) (new_bound * speed), this); + region->trim_end ((nframes64_t) (new_bound * speed), this); rv.region_changed (LengthChanged); } @@ -4213,7 +5034,7 @@ Editor::trim_finished_callback (ArdourCanvas::Item* item, GdkEvent* event) if (!drag_info.first_move) { trim_motion_callback (item, event); - if (!clicked_regionview->get_selected()) { + if (!selection->selected (clicked_regionview)) { thaw_region_after_trim (*clicked_regionview); } else { @@ -4226,9 +5047,9 @@ Editor::trim_finished_callback (ArdourCanvas::Item* item, GdkEvent* event) } for (set >::iterator p = motion_frozen_playlists.begin(); p != motion_frozen_playlists.end(); ++p) { - //(*p)->thaw (); - session->add_command (new MementoCommand(*(*p).get(), 0, &(*p)->get_state())); - } + (*p)->thaw (); + session->add_command (new MementoCommand(*(*p).get(), 0, &(*p)->get_state())); + } motion_frozen_playlists.clear (); @@ -4243,7 +5064,7 @@ void Editor::point_trim (GdkEvent* event) { RegionView* rv = clicked_regionview; - nframes_t new_bound = drag_info.current_pointer_frame; + nframes64_t new_bound = drag_info.current_pointer_frame; if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) { snap_to (new_bound); @@ -4255,17 +5076,17 @@ Editor::point_trim (GdkEvent* event) trim_op = StartTrim; begin_reversible_command (_("Start point trim")); - if (rv->get_selected()) { + 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(); + XMLNode &before = pl->get_state(); (*i)->region()->trim_front (new_bound, this); - XMLNode &after = pl->get_state(); - session->add_command(new MementoCommand(*pl.get(), &before, &after)); + XMLNode &after = pl->get_state(); + session->add_command(new MementoCommand(*pl.get(), &before, &after)); } } @@ -4275,7 +5096,7 @@ Editor::point_trim (GdkEvent* event) boost::shared_ptr pl = rv->region()->playlist(); XMLNode &before = pl->get_state(); rv->region()->trim_front (new_bound, this); - XMLNode &after = pl->get_state(); + XMLNode &after = pl->get_state(); session->add_command(new MementoCommand(*pl.get(), &before, &after)); } } @@ -4287,7 +5108,7 @@ Editor::point_trim (GdkEvent* event) trim_op = EndTrim; begin_reversible_command (_("End point trim")); - if (rv->get_selected()) { + if (selection->selected (rv)) { for (list::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ++i) { @@ -4306,7 +5127,7 @@ Editor::point_trim (GdkEvent* event) boost::shared_ptr pl = rv->region()->playlist(); XMLNode &before = pl->get_state(); rv->region()->trim_end (new_bound, this); - XMLNode &after = pl->get_state(); + XMLNode &after = pl->get_state(); session->add_command (new MementoCommand(*pl.get(), &before, &after)); } } @@ -4329,7 +5150,7 @@ Editor::thaw_region_after_trim (RegionView& rv) } region->thaw (_("trimmed region")); - XMLNode &after = region->playlist()->get_state(); + XMLNode &after = region->playlist()->get_state(); session->add_command (new MementoCommand(*(region->playlist()), 0, &after)); AudioRegionView* arv = dynamic_cast(&rv); @@ -4373,8 +5194,9 @@ Editor::start_range_markerbar_op (ArdourCanvas::Item* item, GdkEvent* event, Ran switch (op) { case CreateRangeMarker: case CreateTransportMarker: - - if (Keyboard::modifier_state_equals (event->button.state, Keyboard::Shift)) { + case CreateCDMarker: + + if (Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) { drag_info.copy = true; } else { drag_info.copy = false; @@ -4390,9 +5212,25 @@ Editor::start_range_markerbar_op (ArdourCanvas::Item* item, GdkEvent* event, Ran void Editor::drag_range_markerbar_op (ArdourCanvas::Item* item, GdkEvent* event) { - nframes_t start = 0; - nframes_t end = 0; - ArdourCanvas::SimpleRect *crect = (range_marker_op == CreateRangeMarker) ? range_bar_drag_rect: transport_bar_drag_rect; + nframes64_t start = 0; + nframes64_t end = 0; + ArdourCanvas::SimpleRect *crect; + + switch (range_marker_op) { + case CreateRangeMarker: + crect = range_bar_drag_rect; + break; + case CreateTransportMarker: + crect = transport_bar_drag_rect; + break; + case CreateCDMarker: + crect = cd_marker_bar_drag_rect; + break; + default: + cerr << "Error: unknown range marker op passed to Editor::drag_range_markerbar_op ()" << endl; + return; + break; + } if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) { snap_to (drag_info.current_pointer_frame); @@ -4407,6 +5245,7 @@ Editor::drag_range_markerbar_op (ArdourCanvas::Item* item, GdkEvent* event) switch (range_marker_op) { case CreateRangeMarker: case CreateTransportMarker: + case CreateCDMarker: if (drag_info.first_move) { snap_to (drag_info.grab_frame); } @@ -4431,14 +5270,14 @@ Editor::drag_range_markerbar_op (ArdourCanvas::Item* item, GdkEvent* event) update_marker_drag_item (temp_location); range_marker_drag_rect->show(); - range_marker_drag_rect->raise_to_top(); + //range_marker_drag_rect->raise_to_top(); } break; } if (event->button.x >= horizontal_adjustment.get_value() + canvas_width) { - start_canvas_autoscroll (1); + start_canvas_autoscroll (1, 0); } if (start != end) { @@ -4464,23 +5303,32 @@ Editor::end_range_markerbar_op (ArdourCanvas::Item* item, GdkEvent* event) { Location * newloc = 0; string rangename; + int flags; if (!drag_info.first_move) { drag_range_markerbar_op (item, event); switch (range_marker_op) { case CreateRangeMarker: + case CreateCDMarker: { begin_reversible_command (_("new range marker")); - XMLNode &before = session->locations()->get_state(); + XMLNode &before = session->locations()->get_state(); session->locations()->next_available_name(rangename,"unnamed"); - newloc = new Location(temp_location->start(), temp_location->end(), rangename, Location::IsRangeMarker); + if (range_marker_op == CreateCDMarker) { + flags = Location::IsRangeMarker|Location::IsCDMarker; + cd_marker_bar_drag_rect->hide(); + } + else { + flags = Location::IsRangeMarker; + range_bar_drag_rect->hide(); + } + newloc = new Location(temp_location->start(), temp_location->end(), rangename, (Location::Flags) flags); session->locations()->add (newloc, true); - XMLNode &after = session->locations()->get_state(); + XMLNode &after = session->locations()->get_state(); session->add_command(new MementoCommand(*(session->locations()), &before, &after)); commit_reversible_command (); - range_bar_drag_rect->hide(); range_marker_drag_rect->hide(); break; } @@ -4494,10 +5342,10 @@ Editor::end_range_markerbar_op (ArdourCanvas::Item* item, GdkEvent* event) } else { /* just a click, no pointer movement. remember that context menu stuff was handled elsewhere */ - if (Keyboard::no_modifier_keys_pressed (&event->button)) { + if (Keyboard::no_modifier_keys_pressed (&event->button) && range_marker_op != CreateCDMarker) { - nframes_t start; - nframes_t end; + nframes64_t start; + nframes64_t end; start = session->locations()->first_mark_before (drag_info.grab_frame); end = session->locations()->first_mark_after (drag_info.grab_frame); @@ -4547,8 +5395,8 @@ Editor::start_mouse_zoom (ArdourCanvas::Item* item, GdkEvent* event) void Editor::drag_mouse_zoom (ArdourCanvas::Item* item, GdkEvent* event) { - nframes_t start; - nframes_t end; + nframes64_t start; + nframes64_t end; if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) { snap_to (drag_info.current_pointer_frame); @@ -4608,7 +5456,7 @@ Editor::end_mouse_zoom (ArdourCanvas::Item* item, GdkEvent* event) } void -Editor::reposition_zoom_rect (nframes_t start, nframes_t end) +Editor::reposition_zoom_rect (nframes64_t start, nframes64_t end) { double x1 = frame_to_pixel (start); double x2 = frame_to_pixel (end); @@ -4635,8 +5483,8 @@ Editor::start_rubberband_select (ArdourCanvas::Item* item, GdkEvent* event) void Editor::drag_rubberband_select (ArdourCanvas::Item* item, GdkEvent* event) { - nframes_t start; - nframes_t end; + nframes64_t start; + nframes64_t end; double y1; double y2; @@ -4646,7 +5494,7 @@ Editor::drag_rubberband_select (ArdourCanvas::Item* item, GdkEvent* event) return; } - if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier())) { + if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::snap_modifier()) && Config->get_rubberbanding_snaps_to_grid()) { if (drag_info.first_move) { snap_to (drag_info.grab_frame); } @@ -4703,8 +5551,7 @@ Editor::end_rubberband_select (ArdourCanvas::Item* item, GdkEvent* event) if (drag_info.current_pointer_y < drag_info.grab_y) { y1 = drag_info.current_pointer_y; y2 = drag_info.grab_y; - } - else { + } else { y2 = drag_info.current_pointer_y; y1 = drag_info.grab_y; } @@ -4750,7 +5597,7 @@ Editor::mouse_rename_region (ArdourCanvas::Item* item, GdkEvent* event) prompter.show_all (); switch (prompter.run ()) { case Gtk::RESPONSE_ACCEPT: - string str; + string str; prompter.get_result(str); if (str.length()) { clicked_regionview->region()->set_name (str); @@ -4803,26 +5650,40 @@ Editor::end_time_fx (ArdourCanvas::Item* item, GdkEvent* event) if (drag_info.first_move) { return; } + + if (drag_info.last_pointer_frame < clicked_regionview->region()->position()) { + /* backwards drag of the left edge - not usable */ + return; + } + + nframes64_t newlen = drag_info.last_pointer_frame - clicked_regionview->region()->position(); + + float percentage = (double) newlen / (double) clicked_regionview->region()->length(); - nframes_t newlen = drag_info.last_pointer_frame - clicked_regionview->region()->position(); - float percentage = (float) ((double) newlen - (double) clicked_regionview->region()->length()) / ((double) newlen) * 100.0f; +#ifndef USE_RUBBERBAND + // Soundtouch uses percentage / 100 instead of normal (/ 1) + if (clicked_regionview->region()->data_type() == DataType::AUDIO) { + percentage = (float) ((double) newlen - (double) clicked_regionview->region()->length()) / ((double) newlen) * 100.0f; + } +#endif begin_reversible_command (_("timestretch")); + + // XXX how do timeFX on multiple regions ? + + RegionSelection rs; + rs.add (clicked_regionview); - if (run_timestretch (selection->regions, percentage) == 0) { + if (time_stretch (rs, percentage) == 0) { session->commit_reversible_command (); } } void -Editor::mouse_brush_insert_region (RegionView* rv, nframes_t pos) +Editor::mouse_brush_insert_region (RegionView* rv, nframes64_t pos) { /* no brushing without a useful snap setting */ - // FIXME - AudioRegionView* arv = dynamic_cast(rv); - assert(arv); - switch (snap_mode) { case SnapMagnetic: return; /* can't work because it allows region to be placed anywhere */ @@ -4831,9 +5692,7 @@ Editor::mouse_brush_insert_region (RegionView* rv, nframes_t pos) } switch (snap_type) { - case SnapToFrame: case SnapToMark: - case SnapToEditCursor: return; default: @@ -4846,7 +5705,7 @@ Editor::mouse_brush_insert_region (RegionView* rv, nframes_t pos) return; } - RouteTimeAxisView* rtv = dynamic_cast(&arv->get_time_axis_view()); + RouteTimeAxisView* rtv = dynamic_cast(&rv->get_time_axis_view()); if (rtv == 0 || !rtv->is_track()) { return; @@ -4855,9 +5714,9 @@ Editor::mouse_brush_insert_region (RegionView* rv, nframes_t pos) boost::shared_ptr playlist = rtv->playlist(); double speed = rtv->get_diskstream()->speed(); - XMLNode &before = playlist->get_state(); - playlist->add_region (boost::dynamic_pointer_cast (RegionFactory::create (arv->audio_region())), (nframes_t) (pos * speed)); - XMLNode &after = playlist->get_state(); + 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 @@ -4868,15 +5727,10 @@ Editor::mouse_brush_insert_region (RegionView* rv, nframes_t pos) gint Editor::track_height_step_timeout () { - struct timeval now; - struct timeval delta; - - gettimeofday (&now, 0); - timersub (&now, &last_track_height_step_timestamp, &delta); - - if (delta.tv_sec * 1000000 + delta.tv_usec > 250000) { /* milliseconds */ + if (get_microseconds() - last_track_height_step_timestamp < 250000) { current_stepping_trackview = 0; return false; } return true; } +