add editor to Theme Manager for modifiers
[ardour.git] / gtk2_ardour / editor_drag.cc
index aa37467f2c18d4e048c3953d6fbdc9eb51ecffad..370a6936b16864beb94858bf89e82a7b7a90c0c4 100644 (file)
@@ -338,6 +338,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 +359,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;
        }
@@ -1924,25 +1930,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) {
@@ -1967,7 +1964,10 @@ NoteResizeDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*ignored*/)
                MidiRegionSelection::iterator next;
                next = r;
                ++next;
-               (*r)->begin_resizing (at_front);
+               MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(*r);
+               if (mrv) {
+                       mrv->begin_resizing (at_front);
+               }
                r = next;
        }
 }
@@ -1979,7 +1979,10 @@ NoteResizeDrag::motion (GdkEvent* /*event*/, bool /*first_move*/)
        for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ++r) {
                NoteBase* nb = reinterpret_cast<NoteBase*> (_item->get_data ("notebase"));
                assert (nb);
-               (*r)->update_resizing (nb, at_front, _drags->current_pointer_x() - grab_x(), relative);
+               MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(*r);
+               if (mrv) {
+                       mrv->update_resizing (nb, at_front, _drags->current_pointer_x() - grab_x(), relative);
+               }
        }
 }
 
@@ -1990,7 +1993,10 @@ NoteResizeDrag::finished (GdkEvent*, bool /*movement_occurred*/)
        for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ++r) {
                NoteBase* nb = reinterpret_cast<NoteBase*> (_item->get_data ("notebase"));
                assert (nb);
-               (*r)->commit_resizing (nb, at_front, _drags->current_pointer_x() - grab_x(), relative);
+               MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(*r);
+               if (mrv) {
+                       mrv->commit_resizing (nb, at_front, _drags->current_pointer_x() - grab_x(), relative);
+               }
        }
 }
 
@@ -1999,7 +2005,10 @@ NoteResizeDrag::aborted (bool)
 {
        MidiRegionSelection& ms (_editor->get_selection().midi_regions);
        for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ++r) {
-               (*r)->abort_resizing ();
+               MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(*r);
+               if (mrv) {
+                       mrv->abort_resizing ();
+               }
        }
 }
 
@@ -2583,7 +2592,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())
                );
@@ -2601,6 +2610,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);
 }
@@ -2713,7 +2723,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())
                        );
@@ -2752,7 +2762,7 @@ TempoMarkerDrag::finished (GdkEvent* event, bool movement_occurred)
        motion (event, false);
 
        TempoMap& map (_editor->session()->tempo_map());
-       framepos_t beat_time = map.round_to_beat (last_pointer_frame(), 0);
+       framepos_t beat_time = map.round_to_beat (last_pointer_frame(), RoundNearest);
        Timecode::BBT_Time when;
 
        map.bbt_time (beat_time, when);
@@ -3389,7 +3399,7 @@ MarkerDrag::motion (GdkEvent* event, bool)
                                } else  if (new_start < copy_location->end()) {
                                        copy_location->set_start (new_start);
                                } else if (newframe > 0) {
-                                       _editor->snap_to (next, 1, true);
+                                       _editor->snap_to (next, RoundUpAlways, true);
                                        copy_location->set_end (next);
                                        copy_location->set_start (newframe);
                                }
@@ -3402,7 +3412,7 @@ MarkerDrag::motion (GdkEvent* event, bool)
                                } else if (new_end > copy_location->start()) {
                                        copy_location->set_end (new_end);
                                } else if (newframe > 0) {
-                                       _editor->snap_to (next, -1, true);
+                                       _editor->snap_to (next, RoundDownAlways, true);
                                        copy_location->set_start (next);
                                        copy_location->set_end (newframe);
                                }
@@ -3634,8 +3644,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;
        }
 
@@ -3958,7 +3968,7 @@ RubberbandSelectDrag::finished (GdkEvent* event, bool movement_occurred)
 
                if ((mtv = dynamic_cast<MidiTimeAxisView*>(_editor->clicked_axisview)) != 0) {
                        /* MIDI track */
-                       if (_editor->selection->empty()) {
+                       if (_editor->selection->empty() && _editor->mouse_mode == MouseDraw) {
                                /* nothing selected */
                                add_midi_region (mtv);
                                do_deselect = false;
@@ -4100,9 +4110,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");
@@ -4209,9 +4217,9 @@ SelectionDrag::motion (GdkEvent* event, bool first_move)
                if (first_move) {
                        grab = adjusted_current_frame (event, false);
                        if (grab < pending_position) {
-                               _editor->snap_to (grab, -1);
+                               _editor->snap_to (grab, RoundDownMaybe);
                        }  else {
-                               _editor->snap_to (grab, 1);
+                               _editor->snap_to (grab, RoundUpMaybe);
                        }
                }
 
@@ -4445,8 +4453,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
@@ -5127,21 +5135,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
@@ -5215,7 +5211,7 @@ NoteCreateDrag::NoteCreateDrag (Editor* e, ArdourCanvas::Item* i, MidiRegionView
        , _region_view (rv)
        , _drag_rect (0)
 {
-       
+       _note[0] = _note[1] = 0;
 }
 
 NoteCreateDrag::~NoteCreateDrag ()
@@ -5229,7 +5225,7 @@ NoteCreateDrag::grid_frames (framepos_t t) const
        bool success;
        Evoral::MusicalTime grid_beats = _editor->get_grid_type_as_beats (success, t);
        if (!success) {
-               grid_beats = 1;
+               grid_beats = Evoral::MusicalTime(1);
        }
 
        return _region_view->region_beats_to_region_frames (grid_beats);
@@ -5253,6 +5249,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]);
@@ -5268,12 +5265,10 @@ void
 NoteCreateDrag::motion (GdkEvent* event, bool)
 {
        _note[1] = max ((framepos_t)0, adjusted_current_frame (event) - _region_view->region()->position ());
-       double const x = _editor->sample_to_pixel (_note[1]);
-       if (_note[1] > _note[0]) {
-               _drag_rect->set_x1 (x);
-       } else {
-               _drag_rect->set_x0 (x);
-       }
+       double const x0 = _editor->sample_to_pixel (_note[0]);
+       double const x1 = _editor->sample_to_pixel (_note[1]);
+       _drag_rect->set_x0 (std::min(x0, x1));
+       _drag_rect->set_x1 (std::max(x0, x1));
 }
 
 void
@@ -5287,13 +5282,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::MusicalTime const one_tick = Evoral::MusicalTime::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::MusicalTime 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);
 }