X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Feditor_drag.cc;h=34e169b133c2de77e7e962609454c5fdbf80661c;hb=ade1c4923ca58a56c5160826253091f67f03fd2f;hp=773ef191dfafdc49db1ef81979ed750fef4f298a;hpb=d63161426f256c293c92b73f1be4b375f962d298;p=ardour.git diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index 773ef191df..34e169b133 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -47,6 +47,7 @@ #include "i18n.h" #include "keyboard.h" #include "audio_region_view.h" +#include "automation_region_view.h" #include "midi_region_view.h" #include "ardour_ui.h" #include "gui_thread.h" @@ -274,7 +275,7 @@ Drag::start_grab (GdkEvent* event, Gdk::Cursor *cursor) } else { /* CAIROCANVAS need a variant here that passes *cursor */ _item->grab (); - _editor->push_canvas_cursor (cursor); + _cursor_ctx = CursorContext::create(*_editor, cursor); } if (_editor->session() && _editor->session()->transport_rolling()) { @@ -311,7 +312,7 @@ Drag::end_grab (GdkEvent* event) finished (event, _move_threshold_passed); _editor->verbose_cursor()->hide (); - _editor->pop_canvas_cursor (); + _cursor_ctx.reset(); return _move_threshold_passed; } @@ -338,6 +339,12 @@ Drag::adjusted_current_frame (GdkEvent const * event, bool snap) const return adjusted_frame (_drags->current_pointer_frame (), event, snap); } +double +Drag::current_pointer_x() const +{ + return _drags->current_pointer_x (); +} + double Drag::current_pointer_y () const { @@ -353,7 +360,7 @@ Drag::motion_handler (GdkEvent* event, bool from_autoscroll) { /* check to see if we have moved in any way that matters since the last motion event */ if (_move_threshold_passed && - (!x_movement_matters() || _last_pointer_frame == adjusted_current_frame (event)) && + (!x_movement_matters() || _last_pointer_x == current_pointer_x ()) && (!y_movement_matters() || _last_pointer_y == current_pointer_y ()) ) { return false; } @@ -834,6 +841,12 @@ RegionMoveDrag::motion (GdkEvent* event, bool first_move) { if (_copy && first_move) { + if (_x_constrained) { + _editor->begin_reversible_command (Operations::fixed_time_region_copy); + } else { + _editor->begin_reversible_command (Operations::region_copy); + } + /* duplicate the regionview(s) and region(s) */ list new_regionviews; @@ -884,6 +897,14 @@ RegionMoveDrag::motion (GdkEvent* event, bool first_move) swap_grab (new_regionviews.front().view->get_canvas_group (), 0, event ? event->motion.time : 0); } + + } else if (!_copy && first_move) { + + if (_x_constrained) { + _editor->begin_reversible_command (_("fixed time region drag")); + } else { + _editor->begin_reversible_command (Operations::region_drag); + } } RegionMotionDrag::motion (event, first_move); @@ -1014,12 +1035,6 @@ RegionMoveDrag::finished_copy (bool const changed_position, bool const /*changed return; } - if (_x_constrained) { - _editor->begin_reversible_command (Operations::fixed_time_region_copy); - } else { - _editor->begin_reversible_command (Operations::region_copy); - } - /* insert the regions into their new playlists */ for (list::const_iterator i = _views.begin(); i != _views.end();) { @@ -1096,12 +1111,6 @@ RegionMoveDrag::finished_no_copy ( return; } - if (_x_constrained) { - _editor->begin_reversible_command (_("fixed time region drag")); - } else { - _editor->begin_reversible_command (Operations::region_drag); - } - for (list::const_iterator i = _views.begin(); i != _views.end(); ) { RegionView* rv = i->view; @@ -1924,25 +1933,16 @@ NoteResizeDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*ignored*/) if (x_fraction > 0.0 && x_fraction < 0.25) { cursor = _editor->cursors()->left_side_trim; + at_front = true; } else { cursor = _editor->cursors()->right_side_trim; + at_front = false; } Drag::start_grab (event, cursor); region = &cnote->region_view(); - double const region_start = region->get_position_pixels(); - double const middle_point = region_start + cnote->x0() + (cnote->x1() - cnote->x0()) / 2.0L; - - if (grab_x() <= middle_point) { - cursor = _editor->cursors()->left_side_trim; - at_front = true; - } else { - cursor = _editor->cursors()->right_side_trim; - at_front = false; - } - _item->grab (); if (event->motion.state & Keyboard::PrimaryModifier) { @@ -1963,6 +1963,8 @@ NoteResizeDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*ignored*/) */ region->note_selected (cnote, cnote->selected ()); + _editor->begin_reversible_command (_("resize notes")); + for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ) { MidiRegionSelection::iterator next; next = r; @@ -2001,6 +2003,8 @@ NoteResizeDrag::finished (GdkEvent*, bool /*movement_occurred*/) mrv->commit_resizing (nb, at_front, _drags->current_pointer_x() - grab_x(), relative); } } + + _editor->commit_reversible_command (); } void @@ -2595,7 +2599,7 @@ MeterMarkerDrag::motion (GdkEvent* event, bool first_move) _marker = new MeterMarker ( *_editor, *_editor->meter_group, - ARDOUR_UI::config()->get_MeterMarker(), + ARDOUR_UI::config()->color ("meter marker"), name, *new MeterSection (_marker->meter()) ); @@ -2613,6 +2617,7 @@ MeterMarkerDrag::motion (GdkEvent* event, bool first_move) } framepos_t const pf = adjusted_current_frame (event); + _marker->set_position (pf); show_verbose_cursor_time (pf); } @@ -2725,7 +2730,7 @@ TempoMarkerDrag::motion (GdkEvent* event, bool first_move) _marker = new TempoMarker ( *_editor, *_editor->tempo_group, - ARDOUR_UI::config()->get_TempoMarker(), + ARDOUR_UI::config()->color ("tempo marker"), name, *new TempoSection (_marker->tempo()) ); @@ -3634,7 +3639,7 @@ ControlPointDrag::finished (GdkEvent* event, bool movement_occurred) } _point->line().end_drag (_pushing, _final_index); - _editor->session()->commit_reversible_command (); + _editor->commit_reversible_command (); } void @@ -3646,8 +3651,8 @@ ControlPointDrag::aborted (bool) bool ControlPointDrag::active (Editing::MouseMode m) { - if (m == Editing::MouseGain) { - /* always active in mouse gain */ + if (m == Editing::MouseDraw) { + /* always active in mouse draw */ return true; } @@ -3748,7 +3753,7 @@ LineDrag::finished (GdkEvent* event, bool movement_occured) } } - _editor->session()->commit_reversible_command (); + _editor->commit_reversible_command (); } void @@ -3855,10 +3860,10 @@ RubberbandSelectDrag::motion (GdkEvent* event, bool) double y1; double y2; - framepos_t const pf = adjusted_current_frame (event, Config->get_rubberbanding_snaps_to_grid ()); + framepos_t const pf = adjusted_current_frame (event, ARDOUR_UI::config()->get_rubberbanding_snaps_to_grid ()); framepos_t grab = grab_frame (); - if (Config->get_rubberbanding_snaps_to_grid ()) { + if (ARDOUR_UI::config()->get_rubberbanding_snaps_to_grid ()) { _editor->snap_to_with_modifier (grab, event); } @@ -4112,9 +4117,7 @@ SelectionDrag::SelectionDrag (Editor* e, ArdourCanvas::Item* i, Operation o) : Drag (e, i) , _operation (o) , _add (false) - , _extend (false) , _original_pointer_time_axis (-1) - , _last_pointer_time_axis (-1) , _time_selection_at_start (!_editor->get_selection().time.empty()) { DEBUG_TRACE (DEBUG::Drags, "New SelectionDrag\n"); @@ -4381,6 +4384,7 @@ SelectionDrag::finished (GdkEvent* event, bool movement_occurred) { Session* s = _editor->session(); + _editor->begin_reversible_selection_op (_("Change Time Selection")); if (movement_occurred) { motion (event, false); /* XXX this is not object-oriented programming at all. ick */ @@ -4393,7 +4397,7 @@ SelectionDrag::finished (GdkEvent* event, bool movement_occurred) if ( s->get_play_range() && s->transport_rolling() ) { s->request_play_range (&_editor->selection->time, true); } else { - if (Config->get_follow_edits() && !s->transport_rolling()) { + if (ARDOUR_UI::config()->get_follow_edits() && !s->transport_rolling()) { if (_operation == SelectionEndTrim) _editor->maybe_locate_with_edit_preroll( _editor->get_selection().time.end_frame()); else @@ -4437,6 +4441,7 @@ SelectionDrag::finished (GdkEvent* event, bool movement_occurred) _editor->stop_canvas_autoscroll (); _editor->clicked_selection = 0; + _editor->commit_reversible_selection_op (); } void @@ -4457,8 +4462,8 @@ RangeMarkerBarDrag::RangeMarkerBarDrag (Editor* e, ArdourCanvas::Item* i, Operat physical_screen_height (_editor->get_window()))); _drag_rect->hide (); - _drag_rect->set_fill_color (ARDOUR_UI::config()->get_RangeDragRect()); - _drag_rect->set_outline_color (ARDOUR_UI::config()->get_RangeDragRect()); + _drag_rect->set_fill_color (ARDOUR_UI::config()->color ("range drag rect")); + _drag_rect->set_outline_color (ARDOUR_UI::config()->color ("range drag rect")); } void @@ -4718,6 +4723,9 @@ NoteDrag::start_grab (GdkEvent* event, Gdk::Cursor *) } else { _region->unique_select (_primary); } + + _editor->begin_reversible_selection_op(_("Select Note Press")); + _editor->commit_reversible_selection_op(); } } } @@ -4799,14 +4807,17 @@ NoteDrag::finished (GdkEvent* ev, bool moved) { if (!moved) { /* no motion - select note */ - + if (_editor->current_mouse_mode() == Editing::MouseObject || _editor->current_mouse_mode() == Editing::MouseDraw) { - + + bool changed = false; + if (_was_selected) { bool add = Keyboard::modifier_state_equals (ev->button.state, Keyboard::PrimaryModifier); if (add) { _region->note_deselected (_primary); + changed = true; } } else { bool extend = Keyboard::modifier_state_equals (ev->button.state, Keyboard::TertiaryModifier); @@ -4814,12 +4825,19 @@ NoteDrag::finished (GdkEvent* ev, bool moved) if (!extend && !add && _region->selection_size() > 1) { _region->unique_select (_primary); + changed = true; } else if (extend) { _region->note_selected (_primary, true, true); + changed = true; } else { /* it was added during button press */ } } + + if (changed) { + _editor->begin_reversible_selection_op(_("Select Note Release")); + _editor->commit_reversible_selection_op(); + } } } else { _region->note_dropped (_primary, total_dx(), total_dy()); @@ -4836,24 +4854,36 @@ NoteDrag::aborted (bool) AutomationRangeDrag::AutomationRangeDrag (Editor* editor, AutomationTimeAxisView* atv, list const & r) : Drag (editor, atv->base_item ()) , _ranges (r) + , _y_origin (atv->y_position()) , _nothing_to_drag (false) { DEBUG_TRACE (DEBUG::Drags, "New AutomationRangeDrag\n"); - y_origin = atv->y_position(); setup (atv->lines ()); } -/** Make an AutomationRangeDrag for region gain lines */ -AutomationRangeDrag::AutomationRangeDrag (Editor* editor, AudioRegionView* rv, list const & r) +/** Make an AutomationRangeDrag for region gain lines or MIDI controller regions */ +AutomationRangeDrag::AutomationRangeDrag (Editor* editor, RegionView* rv, list const & r) : Drag (editor, rv->get_canvas_group ()) , _ranges (r) + , _y_origin (rv->get_time_axis_view().y_position()) , _nothing_to_drag (false) + , _integral (false) { DEBUG_TRACE (DEBUG::Drags, "New AutomationRangeDrag\n"); list > lines; - lines.push_back (rv->get_gain_line ()); - y_origin = rv->get_time_axis_view().y_position(); + + AudioRegionView* audio_view; + AutomationRegionView* automation_view; + if ((audio_view = dynamic_cast(rv))) { + lines.push_back (audio_view->get_gain_line ()); + } else if ((automation_view = dynamic_cast(rv))) { + lines.push_back (automation_view->line ()); + _integral = true; + } else { + error << _("Automation range drag created for invalid region type") << endmsg; + } + setup (lines); } @@ -4898,7 +4928,14 @@ AutomationRangeDrag::setup (list > const & lin double AutomationRangeDrag::y_fraction (boost::shared_ptr line, double global_y) const { - return 1.0 - ((global_y - y_origin) / line->height()); + return 1.0 - ((global_y - _y_origin) / line->height()); +} + +double +AutomationRangeDrag::value (boost::shared_ptr list, double x) const +{ + const double v = list->eval(x); + return _integral ? rint(v) : v; } void @@ -4949,8 +4986,8 @@ AutomationRangeDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) double const p = j->line->time_converter().from (i->start - j->line->time_converter().origin_b ()); double const q = j->line->time_converter().from (a - j->line->time_converter().origin_b ()); - the_list->editor_add (p, the_list->eval (p)); - the_list->editor_add (q, the_list->eval (q)); + the_list->editor_add (p, value (the_list, p)); + the_list->editor_add (q, value (the_list, q)); } /* same thing for the end */ @@ -4975,8 +5012,8 @@ AutomationRangeDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) double const p = j->line->time_converter().from (b - j->line->time_converter().origin_b ()); double const q = j->line->time_converter().from (i->end - j->line->time_converter().origin_b ()); - the_list->editor_add (p, the_list->eval (p)); - the_list->editor_add (q, the_list->eval (q)); + the_list->editor_add (p, value (the_list, p)); + the_list->editor_add (q, value (the_list, q)); } } @@ -5047,7 +5084,7 @@ AutomationRangeDrag::finished (GdkEvent* event, bool) i->line->end_drag (false, 0); } - _editor->session()->commit_reversible_command (); + _editor->commit_reversible_command (); } void @@ -5139,21 +5176,9 @@ MidiRubberbandSelectDrag::MidiRubberbandSelectDrag (Editor* e, MidiRegionView* r void MidiRubberbandSelectDrag::select_things (int button_state, framepos_t x1, framepos_t x2, double y1, double y2, bool /*drag_in_progress*/) { - framepos_t const p = _region_view->region()->position (); - double const y = _region_view->midi_view()->y_position (); - - x1 = max ((framepos_t) 0, x1 - p); - x2 = max ((framepos_t) 0, x2 - p); - y1 = max (0.0, y1 - y); - y2 = max (0.0, y2 - y); - _region_view->update_drag_selection ( - _editor->sample_to_pixel (x1), - _editor->sample_to_pixel (x2), - y1, - y2, - Keyboard::modifier_state_contains (button_state, Keyboard::TertiaryModifier) - ); + x1, x2, y1, y2, + Keyboard::modifier_state_contains (button_state, Keyboard::TertiaryModifier)); } void @@ -5205,21 +5230,26 @@ EditorRubberbandSelectDrag::select_things (int button_state, framepos_t x1, fram } Selection::Operation op = ArdourKeyboard::selection_type (button_state); - - _editor->begin_reversible_command (_("rubberband selection")); + + _editor->begin_reversible_selection_op (_("rubberband selection")); + _editor->select_all_within (x1, x2 - 1, y1, y2, _editor->track_views, op, false); - _editor->commit_reversible_command (); + + _editor->commit_reversible_selection_op (); } void EditorRubberbandSelectDrag::deselect_things () { - if (!getenv("ARDOUR_SAE")) { - _editor->selection->clear_tracks(); - } + _editor->begin_reversible_selection_op (_("Clear Selection (rubberband)")); + + _editor->selection->clear_tracks(); _editor->selection->clear_regions(); _editor->selection->clear_points (); _editor->selection->clear_lines (); + _editor->selection->clear_midi_notes (); + + _editor->commit_reversible_selection_op(); } NoteCreateDrag::NoteCreateDrag (Editor* e, ArdourCanvas::Item* i, MidiRegionView* rv) @@ -5227,7 +5257,7 @@ NoteCreateDrag::NoteCreateDrag (Editor* e, ArdourCanvas::Item* i, MidiRegionView , _region_view (rv) , _drag_rect (0) { - + _note[0] = _note[1] = 0; } NoteCreateDrag::~NoteCreateDrag () @@ -5239,9 +5269,9 @@ framecnt_t NoteCreateDrag::grid_frames (framepos_t t) const { bool success; - Evoral::MusicalTime grid_beats = _editor->get_grid_type_as_beats (success, t); + Evoral::Beats grid_beats = _editor->get_grid_type_as_beats (success, t); if (!success) { - grid_beats = 1; + grid_beats = Evoral::Beats(1); } return _region_view->region_beats_to_region_frames (grid_beats); @@ -5265,6 +5295,7 @@ NoteCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) } _note[0] = adjusted_frame (pf, event) - _region_view->region()->position (); + _note[1] = _note[0]; MidiStreamView* sv = _region_view->midi_stream_view (); double const x = _editor->sample_to_pixel (_note[0]); @@ -5297,13 +5328,14 @@ NoteCreateDrag::finished (GdkEvent*, bool had_movement) framecnt_t length = (framecnt_t) fabs ((double)(_note[0] - _note[1])); framecnt_t const g = grid_frames (start); - double const one_tick = 1 / Timecode::BBT_Time::ticks_per_beat; + Evoral::Beats const one_tick = Evoral::Beats::ticks(1); if (_editor->snap_mode() == SnapNormal && length < g) { - length = g - one_tick; + length = g; } - double const length_beats = max (one_tick, _region_view->region_frames_to_region_beats (length)); + Evoral::Beats length_beats = max ( + one_tick, _region_view->region_frames_to_region_beats (length) - one_tick); _region_view->create_note_at (start, _drag_rect->y0(), length_beats, false); }