pay some attention to the special guest of the night: KDE window stacking
[ardour.git] / gtk2_ardour / editor_drag.cc
index 8ba745d5876188a8c29117ead3a4a386ed4770fe..018c8c1f382f740506a5b3d566f278988dc6bdf7 100644 (file)
@@ -1122,6 +1122,10 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
                                y_delta = yposition - rv->get_canvas_group()->canvas_origin().y;
                        }
 
+                       MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(rv);
+                       if (mrv) {
+                               mrv->apply_note_range (60, 71, true);
+                       }
                } else {
 
                        /* The TimeAxisView that this region is now over */
@@ -1183,6 +1187,14 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
                                y_delta = track_origin.y - rv->get_canvas_group()->canvas_origin().y;
 
                        }
+
+                       MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(rv);
+                       if (mrv) {
+                               MidiStreamView* msv;
+                               if ((msv = dynamic_cast <MidiStreamView*> (current_tv->view())) != 0) {
+                                       mrv->apply_note_range (msv->lowest_note(), msv->highest_note(), true);
+                               }
+                       }
                }
 
                /* Now move the region view */
@@ -5664,15 +5676,15 @@ NoteDrag::total_dy () const
                return 0;
        }
 
-       MidiStreamView* msv = _region->midi_stream_view ();
        double const y = _region->midi_view()->y_position ();
        /* new current note */
-       uint8_t n = msv->y_to_note (current_pointer_y () - y);
+       uint8_t n = _region->y_to_note (current_pointer_y () - y);
        /* clamp */
+       MidiStreamView* msv = _region->midi_stream_view ();
        n = max (msv->lowest_note(), n);
        n = min (msv->highest_note(), n);
        /* and work out delta */
-       return n - msv->y_to_note (grab_y() - y);
+       return n - _region->y_to_note (grab_y() - y);
 }
 
 void
@@ -6203,16 +6215,12 @@ NoteCreateDrag::~NoteCreateDrag ()
 framecnt_t
 NoteCreateDrag::grid_frames (framepos_t t) const
 {
-       bool success;
-       Evoral::Beats grid_beats = _editor->get_grid_type_as_beats (success, t);
-       if (!success) {
-               grid_beats = Evoral::Beats(1);
-       }
+
+       const Evoral::Beats grid_beats = _region_view->get_grid_beats (t);
        const Evoral::Beats t_beats = _region_view->region_frames_to_region_beats (t);
 
        return _region_view->region_beats_to_region_frames (t_beats + grid_beats)
                - _region_view->region_beats_to_region_frames (t_beats);
-
 }
 
 void
@@ -6226,11 +6234,7 @@ NoteCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
        const framepos_t pf = _drags->current_pointer_frame ();
        const int32_t divisions = _editor->get_grid_music_divisions (event->button.state);
 
-       bool success = false;
-       Evoral::Beats grid_beats = _editor->get_grid_type_as_beats (success, pf);
-       if (!success) {
-               grid_beats = Evoral::Beats(1);
-       }
+       const Evoral::Beats grid_beats = _region_view->get_grid_beats (pf);
 
        double eqaf = map.exact_qn_at_frame (pf, divisions);
 
@@ -6247,16 +6251,14 @@ NoteCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
                        eqaf -= grid_beats.to_double();
                }
        }
-       /* minimum initial length is grid beats */
-       const double end_qn = eqaf + grid_beats.to_double();
 
        _note[0] = map.frame_at_quarter_note (eqaf) - _region_view->region()->position();
-       _note[1] = map.frame_at_quarter_note (end_qn) - _region_view->region()->position();
+       /* minimum initial length is grid beats */
+       _note[1] = map.frame_at_quarter_note (eqaf + grid_beats.to_double()) - _region_view->region()->position();
 
-       MidiStreamView* sv = _region_view->midi_stream_view ();
        double const x0 = _editor->sample_to_pixel (_note[0]);
        double const x1 = _editor->sample_to_pixel (_note[1]);
-       double const y = sv->note_to_y (sv->y_to_note (y_to_region (event->button.y)));
+       double const y = _region_view->note_to_y (_region_view->y_to_note (y_to_region (event->button.y)));
 
        _drag_rect->set (ArdourCanvas::Rect (x0, y, x1, y + floor (_region_view->midi_stream_view()->note_height ())));
        _drag_rect->set_outline_all ();
@@ -6273,11 +6275,8 @@ NoteCreateDrag::motion (GdkEvent* event, bool)
        double eqaf = map.exact_qn_at_frame (pf, divisions);
 
        if (divisions != 0) {
-               bool success = false;
-               Evoral::Beats grid_beats = _editor->get_grid_type_as_beats (success, pf);
-               if (!success) {
-                       grid_beats = Evoral::Beats(1);
-               }
+
+               const Evoral::Beats grid_beats = _region_view->get_grid_beats (pf);
 
                const double qaf = map.quarter_note_at_frame (pf);
                /* Hack so that we always snap to the note that we are over, instead of snapping
@@ -6336,6 +6335,8 @@ NoteCreateDrag::aborted (bool)
 HitCreateDrag::HitCreateDrag (Editor* e, ArdourCanvas::Item* i, MidiRegionView* rv)
        : Drag (e, i)
        , _region_view (rv)
+       , _last_pos (0)
+       , _last_y (0.0)
 {
 }
 
@@ -6353,19 +6354,23 @@ HitCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
        const framepos_t pf = _drags->current_pointer_frame ();
        const int32_t divisions = _editor->get_grid_music_divisions (event->button.state);
 
-       bool success = false;
-       Evoral::Beats grid_beats = _editor->get_grid_type_as_beats (success, pf);
-       if (!success) {
-               grid_beats = Evoral::Beats(1);
+       const double eqaf = map.exact_qn_at_frame (pf, divisions);
+
+       boost::shared_ptr<MidiRegion> mr = _region_view->midi_region();
+
+       if (eqaf >= mr->quarter_note() + mr->length_beats()) {
+               return;
        }
 
-       const double eqaf = map.exact_qn_at_frame (pf, divisions);
        const framepos_t start = map.frame_at_quarter_note (eqaf) - _region_view->region()->position();
+       const double y = _region_view->note_to_y (_region_view->y_to_note (y_to_region (event->button.y)));
+
+       Evoral::Beats length = _region_view->get_grid_beats (pf);
 
-       MidiStreamView* sv = _region_view->midi_stream_view ();
-       const double y = sv->note_to_y (sv->y_to_note (y_to_region (event->button.y)));
+       _region_view->create_note_at (start, y, length, event->button.state, false);
 
-       _region_view->create_note_at (start, y,  grid_beats, event->button.state, false);
+       _last_pos = start;
+       _last_y = y;
 }
 
 void
@@ -6382,18 +6387,23 @@ HitCreateDrag::motion (GdkEvent* event, bool)
 
        const double eqaf = map.exact_qn_at_frame (pf, divisions);
        const framepos_t start = map.frame_at_quarter_note (eqaf) - _region_view->region()->position ();
+       const double y = _region_view->note_to_y (_region_view->y_to_note (y_to_region (event->button.y)));
 
-       MidiStreamView* sv = _region_view->midi_stream_view ();
-       const double y = sv->note_to_y (sv->y_to_note (y_to_region (event->button.y)));
+       if (_last_pos == start && y == _last_y) {
+               return;
+       }
+
+       Evoral::Beats length = _region_view->get_grid_beats (pf);
 
-       bool success = false;
-       Evoral::Beats grid_beats = _editor->get_grid_type_as_beats (success, pf);
-       if (!success) {
-               grid_beats = Evoral::Beats(1);
+       boost::shared_ptr<MidiRegion> mr = _region_view->midi_region();
+       if (eqaf >= mr->quarter_note() + mr->length_beats()) {
+               return;
        }
 
-       _region_view->create_note_at (start, y, grid_beats, event->button.state, false);
+       _region_view->create_note_at (start, y, length, event->button.state, false);
 
+       _last_pos = start;
+       _last_y = y;
 }
 
 void
@@ -6527,12 +6537,19 @@ RegionCutDrag::~RegionCutDrag ()
 }
 
 void
-RegionCutDrag::motion (GdkEvent*, bool)
+RegionCutDrag::start_grab (GdkEvent* event, Gdk::Cursor* c)
 {
-       framepos_t where = _drags->current_pointer_frame();
-       _editor->snap_to (where);
+       Drag::start_grab (event, c);
+       motion (event, false);
+}
 
-       line->set_position (where);
+void
+RegionCutDrag::motion (GdkEvent* event, bool)
+{
+       framepos_t pos = _drags->current_pointer_frame();
+       _editor->snap_to_with_modifier (pos, event);
+
+       line->set_position (pos);
 }
 
 void
@@ -6541,6 +6558,7 @@ RegionCutDrag::finished (GdkEvent* event, bool)
        _editor->get_track_canvas()->canvas()->re_enter();
 
        framepos_t pos = _drags->current_pointer_frame();
+       _editor->snap_to_with_modifier (pos, event);
 
        line->hide ();
 
@@ -6550,7 +6568,8 @@ RegionCutDrag::finished (GdkEvent* event, bool)
                return;
        }
 
-       _editor->split_regions_at (pos, rs, _editor->get_grid_music_divisions (event->button.state));
+       _editor->split_regions_at (pos, rs, _editor->get_grid_music_divisions (event->button.state),
+                                  false);
 }
 
 void