X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Feditor_drag.cc;h=02f827b5792874ffada6eb70dc335899c2aa514e;hb=f90a70e774726a5d67fa462cab06637d4baeabc8;hp=4fed4f072d1f24ef80501597ab17b12da198f85f;hpb=fd36355e2cd95550a0f7d9b7a6f5e3bc2fcc7fa2;p=ardour.git diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index 4fed4f072d..02f827b579 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -3308,10 +3308,9 @@ MeterMarkerDrag::motion (GdkEvent* event, bool first_move) } else { --bbt.bars; } - const double beat = map.beat_at_bbt (bbt); - const framepos_t frame = map.frame_at_beat (beat); + const framepos_t frame = map.frame_at_bbt (bbt); _real_section = map.add_meter (Meter (_marker->meter().divisions_per_bar(), _marker->meter().note_divisor()) - , beat, bbt, frame, _real_section->position_lock_style()); + , bbt, frame, _real_section->position_lock_style()); if (!_real_section) { aborted (true); return; @@ -3548,6 +3547,7 @@ BBTRulerDrag::BBTRulerDrag (Editor* e, ArdourCanvas::Item* i) , _grab_qn (0.0) , _tempo (0) , _before_state (0) + , _drag_valid (true) { DEBUG_TRACE (DEBUG::Drags, "New BBTRulerDrag\n"); @@ -3559,13 +3559,18 @@ BBTRulerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) Drag::start_grab (event, cursor); TempoMap& map (_editor->session()->tempo_map()); _tempo = const_cast (&map.tempo_section_at_frame (raw_grab_frame())); + + if (adjusted_current_frame (event, false) <= _tempo->frame()) { + _drag_valid = false; + return; + } + _editor->tempo_curve_selected (_tempo, true); ostringstream sstr; if (_tempo->clamped()) { TempoSection* prev = map.previous_tempo_section (_tempo); if (prev) { - _editor->tempo_curve_selected (prev, true); sstr << "end: " << fixed << setprecision(3) << prev->end_note_types_per_minute() << "\n"; } } @@ -3604,12 +3609,15 @@ BBTRulerDrag::setup_pointer_frame_offset () void BBTRulerDrag::motion (GdkEvent* event, bool first_move) { - TempoMap& map (_editor->session()->tempo_map()); + if (!_drag_valid) { + return; + } if (first_move) { _editor->begin_reversible_command (_("stretch tempo")); } + TempoMap& map (_editor->session()->tempo_map()); framepos_t pf; if (_editor->snap_musical()) { @@ -3620,7 +3628,7 @@ BBTRulerDrag::motion (GdkEvent* event, bool first_move) if (ArdourKeyboard::indicates_constraint (event->button.state)) { /* adjust previous tempo to match pointer frame */ - _editor->session()->tempo_map().gui_stretch_tempo (_tempo, map.frame_at_quarter_note (_grab_qn), pf); + _editor->session()->tempo_map().gui_stretch_tempo (_tempo, map.frame_at_quarter_note (_grab_qn), pf, _grab_qn, map.quarter_note_at_frame (pf)); } ostringstream sstr; @@ -3644,17 +3652,22 @@ BBTRulerDrag::finished (GdkEvent* event, bool movement_occurred) TempoMap& map (_editor->session()->tempo_map()); - XMLNode &after = map.get_state(); - _editor->session()->add_command(new MementoCommand(map, _before_state, &after)); - _editor->commit_reversible_command (); _editor->tempo_curve_selected (_tempo, false); - if (_tempo->clamped()) { TempoSection* prev_tempo = map.previous_tempo_section (_tempo); if (prev_tempo) { _editor->tempo_curve_selected (prev_tempo, false); } } + + if (!movement_occurred || !_drag_valid) { + return; + } + + XMLNode &after = map.get_state(); + _editor->session()->add_command(new MementoCommand(map, _before_state, &after)); + _editor->commit_reversible_command (); + } void @@ -3687,6 +3700,11 @@ TempoTwistDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) _before_state = &map.get_state(); _tempo = const_cast (&map.tempo_section_at_frame (raw_grab_frame())); + if (_tempo->locked_to_meter()) { + _drag_valid = false; + return; + } + _next_tempo = map.next_tempo_section (_tempo); if (_next_tempo) { if (!map.next_tempo_section (_next_tempo)) { @@ -3770,8 +3788,6 @@ TempoTwistDrag::motion (GdkEvent* event, bool first_move) void TempoTwistDrag::finished (GdkEvent* event, bool movement_occurred) { - TempoMap& map (_editor->session()->tempo_map()); - if (!movement_occurred || !_drag_valid) { return; } @@ -3779,6 +3795,7 @@ TempoTwistDrag::finished (GdkEvent* event, bool movement_occurred) _editor->tempo_curve_selected (_tempo, false); _editor->tempo_curve_selected (_next_tempo, false); + TempoMap& map (_editor->session()->tempo_map()); XMLNode &after = map.get_state(); _editor->session()->add_command(new MementoCommand(map, _before_state, &after)); _editor->commit_reversible_command (); @@ -3797,6 +3814,7 @@ TempoEndDrag::TempoEndDrag (Editor* e, ArdourCanvas::Item* i) , _grab_qn (0.0) , _tempo (0) , _before_state (0) + , _drag_valid (true) { DEBUG_TRACE (DEBUG::Drags, "New TempoEndDrag\n"); TempoMarker* marker = reinterpret_cast (_item->get_data ("marker")); @@ -3813,6 +3831,10 @@ TempoEndDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) /* get current state */ _before_state = &tmap.get_state(); + if (_tempo->locked_to_meter()) { + _drag_valid = false; + return; + } ostringstream sstr; @@ -3842,14 +3864,16 @@ TempoEndDrag::setup_pointer_frame_offset () void TempoEndDrag::motion (GdkEvent* event, bool first_move) { + if (!_drag_valid) { + return; + } + TempoMap& map (_editor->session()->tempo_map()); if (first_move) { _editor->begin_reversible_command (_("stretch end tempo")); } - - framepos_t const pf = adjusted_current_frame (event, false); map.gui_stretch_tempo_end (&map.tempo_section_at_frame (_tempo->frame() - 1), map.frame_at_quarter_note (_grab_qn), pf); @@ -3866,7 +3890,7 @@ TempoEndDrag::motion (GdkEvent* event, bool first_move) void TempoEndDrag::finished (GdkEvent* event, bool movement_occurred) { - if (!movement_occurred) { + if (!movement_occurred || !_drag_valid) { return; } @@ -3981,6 +4005,8 @@ CursorDrag::start_grab (GdkEvent* event, Gdk::Cursor* c) } fake_locate (where.frame - snap_delta (event->button.state)); + + _last_y_delta = 0; } void @@ -3993,6 +4019,39 @@ CursorDrag::motion (GdkEvent* event, bool) if (where.frame != last_pointer_frame()) { fake_locate (where.frame - snap_delta (event->button.state)); } + + //maybe do zooming, too, if the option is enabled + if (UIConfiguration::instance ().get_use_time_rulers_to_zoom_with_vertical_drag () ) { + + //To avoid accidental zooming, the mouse must move exactly vertical, not diagonal, to trigger a zoom step + //we use screen coordinates for this, not canvas-based grab_x + double mx = event->button.x; + double dx = fabs(mx - _last_mx); + double my = event->button.y; + double dy = fabs(my - _last_my); + + { + //do zooming in windowed "steps" so it feels more reversible ? + const int stepsize = 2; //stepsize ==1 means "trigger on every pixel of movement" + int y_delta = grab_y() - current_pointer_y(); + y_delta = y_delta / stepsize; + + //if all requirements are met, do the actual zoom + const double scale = 1.2; + if ( (dy>dx) && (_last_dx ==0) && (y_delta != _last_y_delta) ) { + if ( _last_y_delta > y_delta ) { + _editor->temporal_zoom_step_mouse_focus_scale (true, scale); + } else { + _editor->temporal_zoom_step_mouse_focus_scale (false, scale); + } + _last_y_delta = y_delta; + } + } + + _last_my = my; + _last_mx = mx; + _last_dx = dx; + } } void @@ -4683,7 +4742,7 @@ MarkerDrag::aborted (bool movement_occurred) void MarkerDrag::update_item (Location*) { - /* noop */ + /* noop */ } ControlPointDrag::ControlPointDrag (Editor* e, ArdourCanvas::Item* i) @@ -5846,7 +5905,7 @@ RangeMarkerBarDrag::finished (GdkEvent* event, bool movement_occurred) case CreateSkipMarker: case CreateRangeMarker: case CreateCDMarker: - { + { XMLNode &before = _editor->session()->locations()->get_state(); if (_operation == CreateSkipMarker) { _editor->begin_reversible_command (_("new skip marker")); @@ -5873,7 +5932,7 @@ RangeMarkerBarDrag::finished (GdkEvent* event, bool movement_occurred) _editor->session()->add_command(new MementoCommand(*(_editor->session()->locations()), &before, &after)); _editor->commit_reversible_command (); break; - } + } case CreateTransportMarker: // popup menu to pick loop or punch @@ -6965,56 +7024,3 @@ void RegionCutDrag::aborted (bool) { } - -RulerZoomDrag::RulerZoomDrag (Editor* e, ArdourCanvas::Item* item) - : Drag (e, item, true) -{ -} - -void -RulerZoomDrag::start_grab (GdkEvent* event, Gdk::Cursor* c) -{ - Drag::start_grab (event, c); - - framepos_t where = _editor->canvas_event_sample(event); - - _editor->_dragging_playhead = true; - - _editor->playhead_cursor->set_position (where); -} - -void -RulerZoomDrag::motion (GdkEvent* event, bool) -{ - framepos_t where = _editor->canvas_event_sample(event); - - _editor->playhead_cursor->set_position (where); - - const double movement_limit = 20.0; - const double scale = 1.08; - const double y_delta = last_pointer_y() - current_pointer_y(); - - if (y_delta > 0 && y_delta < movement_limit) { - _editor->temporal_zoom_step_mouse_focus_scale (true, scale); - } else if (y_delta < 0 && y_delta > -movement_limit) { - _editor->temporal_zoom_step_mouse_focus_scale (false, scale); - } -} - -void -RulerZoomDrag::finished (GdkEvent*, bool) -{ - _editor->_dragging_playhead = false; - - Session* s = _editor->session (); - if (s) { - s->request_locate (_editor->playhead_cursor->current_frame (), _was_rolling); - _editor->_pending_locate_request = true; - } - -} - -void -RulerZoomDrag::aborted (bool) -{ -}