2 Copyright (C) 2009 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __gtk2_ardour_editor_drag_h_
21 #define __gtk2_ardour_editor_drag_h_
29 #include "ardour/types.h"
32 #include "editor_items.h"
40 class CanvasNoteEvent;
47 class MidiTimeAxisView;
50 /** Class to manage current drags */
55 DragManager (Editor* e);
58 bool motion_handler (GdkEvent *, bool);
62 void set (Drag *, GdkEvent *, Gdk::Cursor* c = 0);
63 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
64 bool end_grab (GdkEvent *);
65 bool have_item (ArdourCanvas::Item *) const;
67 /** @return true if an end drag or abort is in progress */
68 bool ending () const {
72 bool active () const {
73 return !_drags.empty ();
76 /** @return current pointer x position in trackview coordinates */
77 double current_pointer_x () const {
78 return _current_pointer_x;
81 /** @return current pointer y position in trackview coordinates */
82 double current_pointer_y () const {
83 return _current_pointer_y;
86 /** @return current pointer frame */
87 nframes64_t current_pointer_frame () const {
88 return _current_pointer_frame;
93 std::list<Drag*> _drags;
94 bool _ending; ///< true if end_grab or abort is in progress, otherwise false
95 double _current_pointer_x; ///< trackview x of the current pointer
96 double _current_pointer_y; ///< trackview y of the current pointer
97 nframes64_t _current_pointer_frame; ///< frame that the pointer is now at
100 /** Abstract base class for dragging of things within the editor */
104 Drag (Editor *, ArdourCanvas::Item *);
107 void set_manager (DragManager* m) {
111 /** @return the canvas item being dragged */
112 ArdourCanvas::Item* item () const {
116 void swap_grab (ArdourCanvas::Item *, Gdk::Cursor *, uint32_t);
117 bool motion_handler (GdkEvent*, bool);
120 nframes64_t adjusted_frame (nframes64_t, GdkEvent const *, bool snap = true) const;
121 nframes64_t adjusted_current_frame (GdkEvent const *, bool snap = true) const;
123 /** Called to start a grab of an item.
124 * @param e Event that caused the grab to start.
125 * @param c Cursor to use, or 0.
127 virtual void start_grab (GdkEvent* e, Gdk::Cursor* c = 0);
129 virtual bool end_grab (GdkEvent *);
131 /** Called when a drag motion has occurred.
132 * @param e Event describing the motion.
133 * @param f true if this is the first movement, otherwise false.
135 virtual void motion (GdkEvent* e, bool f) = 0;
137 /** Called when a drag has finished.
138 * @param e Event describing the finish.
139 * @param m true if some movement occurred, otherwise false.
141 virtual void finished (GdkEvent* e, bool m) = 0;
143 /** Called to abort a drag and return things to how
144 * they were before it started.
146 virtual void aborted () = 0;
148 /** @param m Mouse mode.
149 * @return true if this drag should happen in this mouse mode.
151 virtual bool active (Editing::MouseMode m) {
152 return (m != Editing::MouseGain);
155 /** @return minimum number of frames (in x) and pixels (in y) that should be considered a movement */
156 virtual std::pair<nframes64_t, int> move_threshold () const {
157 return std::make_pair (1, 1);
160 virtual bool allow_vertical_autoscroll () const {
164 /** @return true if x movement matters to this drag */
165 virtual bool x_movement_matters () const {
169 /** @return true if y movement matters to this drag */
170 virtual bool y_movement_matters () const {
176 double grab_x () const {
180 double grab_y () const {
184 ARDOUR::framepos_t grab_frame () const {
188 double last_pointer_x () const {
189 return _last_pointer_x;
192 double last_pointer_y () const {
193 return _last_pointer_y;
196 double last_pointer_frame () const {
197 return _last_pointer_frame;
200 Editor* _editor; ///< our editor
202 ArdourCanvas::Item* _item; ///< our item
203 /** Offset from the mouse's position for the drag to the start of the thing that is being dragged */
204 nframes64_t _pointer_frame_offset;
205 bool _x_constrained; ///< true if x motion is constrained, otherwise false
206 bool _y_constrained; ///< true if y motion is constrained, otherwise false
207 bool _was_rolling; ///< true if the session was rolling before the drag started, otherwise false
211 bool _move_threshold_passed; ///< true if the move threshold has been passed, otherwise false
212 double _grab_x; ///< trackview x of the grab start position
213 double _grab_y; ///< trackview y of the grab start position
214 double _last_pointer_x; ///< trackview x of the pointer last time a motion occurred
215 double _last_pointer_y; ///< trackview y of the pointer last time a motion occurred
216 nframes64_t _grab_frame; ///< adjusted_frame that the mouse was at when start_grab was called, or 0
217 nframes64_t _last_pointer_frame; ///< adjusted_frame the last time a motion occurred
222 DraggingView (RegionView* v);
224 RegionView* view; ///< the view
225 double initial_y; ///< the initial y position of the view before any reparenting
228 /** Abstract base class for drags that involve region(s) */
229 class RegionDrag : public Drag, public sigc::trackable
232 RegionDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
233 virtual ~RegionDrag () {}
237 RegionView* _primary; ///< the view that was clicked on (or whatever) to start the drag
238 std::list<DraggingView> _views; ///< information about all views that are being dragged
241 void region_going_away (RegionView *);
242 PBD::ScopedConnection death_connection;
246 /** Drags involving region motion from somewhere */
247 class RegionMotionDrag : public RegionDrag
251 RegionMotionDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &, bool);
252 virtual ~RegionMotionDrag () {}
254 virtual void start_grab (GdkEvent *, Gdk::Cursor *);
255 virtual void motion (GdkEvent *, bool);
256 virtual void finished (GdkEvent *, bool) = 0;
257 virtual void aborted ();
259 /** @return true if the regions being `moved' came from somewhere on the canvas;
260 * false if they came from outside (e.g. from the region list).
262 virtual bool regions_came_from_canvas () const = 0;
265 struct TimeAxisViewSummary {
266 TimeAxisViewSummary () : height_list(512) {}
268 std::bitset<512> tracks;
269 std::vector<int32_t> height_list;
274 void copy_regions (GdkEvent *);
275 bool y_movement_disallowed (int, int, int, TimeAxisViewSummary const &) const;
276 std::map<RegionView*, std::pair<RouteTimeAxisView*, int> > find_time_axis_views_and_layers ();
277 double compute_x_delta (GdkEvent const *, nframes64_t *);
278 bool compute_y_delta (
279 TimeAxisView const *, TimeAxisView*, int32_t, int32_t, TimeAxisViewSummary const &,
280 int32_t *, int32_t *, int32_t *
283 TimeAxisViewSummary get_time_axis_view_summary ();
284 bool x_move_allowed () const;
286 TimeAxisView* _dest_trackview;
287 ARDOUR::layer_t _dest_layer;
288 bool check_possible (RouteTimeAxisView **, ARDOUR::layer_t *);
290 nframes64_t _last_frame_position; ///< last position of the thing being dragged
291 double _total_x_delta;
295 /** Drags to move (or copy) regions that are already shown in the GUI to
296 * somewhere different.
298 class RegionMoveDrag : public RegionMotionDrag
301 RegionMoveDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &, bool, bool);
302 virtual ~RegionMoveDrag () {}
304 virtual void start_grab (GdkEvent *, Gdk::Cursor *);
305 void motion (GdkEvent *, bool);
306 void finished (GdkEvent *, bool);
309 bool regions_came_from_canvas () const {
313 std::pair<nframes64_t, int> move_threshold () const {
314 return std::make_pair (4, 4);
321 /** Drag to insert a region from somewhere */
322 class RegionInsertDrag : public RegionMotionDrag
325 RegionInsertDrag (Editor *, boost::shared_ptr<ARDOUR::Region>, RouteTimeAxisView*, nframes64_t);
327 void finished (GdkEvent *, bool);
330 bool regions_came_from_canvas () const {
335 /** Region drag in splice mode */
336 class RegionSpliceDrag : public RegionMoveDrag
339 RegionSpliceDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
341 void motion (GdkEvent *, bool);
342 void finished (GdkEvent *, bool);
346 /** Drags to create regions */
347 class RegionCreateDrag : public Drag
350 RegionCreateDrag (Editor *, ArdourCanvas::Item *, TimeAxisView *);
352 void motion (GdkEvent *, bool);
353 void finished (GdkEvent *, bool);
357 MidiTimeAxisView* _view;
358 boost::shared_ptr<ARDOUR::Region> _region;
361 /** Drags to resize MIDI notes */
362 class NoteResizeDrag : public Drag
365 NoteResizeDrag (Editor *, ArdourCanvas::Item *);
367 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
368 void motion (GdkEvent *, bool);
369 void finished (GdkEvent *, bool);
373 MidiRegionView* region;
378 /** Drags to move MIDI notes */
379 class NoteDrag : public Drag
382 NoteDrag (Editor*, ArdourCanvas::Item*);
384 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
385 void motion (GdkEvent *, bool);
386 void finished (GdkEvent *, bool);
391 ARDOUR::frameoffset_t total_dx () const;
392 int8_t total_dy () const;
394 MidiRegionView* _region;
395 Gnome::Canvas::CanvasNoteEvent* _primary;
396 double _cumulative_dx;
397 double _cumulative_dy;
402 /** Drag of region gain */
403 class RegionGainDrag : public Drag
406 RegionGainDrag (Editor *e, ArdourCanvas::Item *i) : Drag (e, i) {}
408 void motion (GdkEvent *, bool);
409 void finished (GdkEvent *, bool);
410 bool active (Editing::MouseMode m) {
411 return (m == Editing::MouseGain);
417 /** Drag to trim region(s) */
418 class TrimDrag : public RegionDrag
427 TrimDrag (Editor *, ArdourCanvas::Item *, RegionView*, std::list<RegionView*> const &);
429 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
430 void motion (GdkEvent *, bool);
431 void finished (GdkEvent *, bool);
434 bool y_movement_matters () const {
440 Operation _operation;
441 bool _have_transaction; ///< true if a transaction has been started, false otherwise. Must be set true by derived class.
444 /** Meter marker drag */
445 class MeterMarkerDrag : public Drag
448 MeterMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
450 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
451 void motion (GdkEvent *, bool);
452 void finished (GdkEvent *, bool);
455 bool allow_vertical_autoscroll () const {
459 bool y_movement_matters () const {
464 MeterMarker* _marker;
468 /** Tempo marker drag */
469 class TempoMarkerDrag : public Drag
472 TempoMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
474 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
475 void motion (GdkEvent *, bool);
476 void finished (GdkEvent *, bool);
479 bool allow_vertical_autoscroll () const {
483 bool y_movement_matters () const {
488 TempoMarker* _marker;
493 /** Drag of a cursor */
494 class CursorDrag : public Drag
497 CursorDrag (Editor *, ArdourCanvas::Item *, bool);
499 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
500 void motion (GdkEvent *, bool);
501 void finished (GdkEvent *, bool);
504 bool active (Editing::MouseMode) {
508 bool allow_vertical_autoscroll () const {
512 bool y_movement_matters () const {
517 EditorCursor* _cursor; ///< cursor being dragged
518 bool _stop; ///< true to stop the transport on starting the drag, otherwise false
522 /** Region fade-in drag */
523 class FadeInDrag : public RegionDrag
526 FadeInDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
528 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
529 void motion (GdkEvent *, bool);
530 void finished (GdkEvent *, bool);
533 bool y_movement_matters () const {
538 /** Region fade-out drag */
539 class FadeOutDrag : public RegionDrag
542 FadeOutDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
544 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
545 void motion (GdkEvent *, bool);
546 void finished (GdkEvent *, bool);
549 bool y_movement_matters () const {
555 class MarkerDrag : public Drag
558 MarkerDrag (Editor *, ArdourCanvas::Item *);
561 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
562 void motion (GdkEvent *, bool);
563 void finished (GdkEvent *, bool);
566 bool allow_vertical_autoscroll () const {
570 bool y_movement_matters () const {
575 void update_item (ARDOUR::Location *);
577 Marker* _marker; ///< marker being dragged
578 std::list<ARDOUR::Location*> _copied_locations;
579 ArdourCanvas::Line* _line;
580 ArdourCanvas::Points _points;
583 /** Control point drag */
584 class ControlPointDrag : public Drag
587 ControlPointDrag (Editor *, ArdourCanvas::Item *);
589 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
590 void motion (GdkEvent *, bool);
591 void finished (GdkEvent *, bool);
594 bool active (Editing::MouseMode m);
598 ControlPoint* _point;
599 double _time_axis_view_grab_x;
600 double _time_axis_view_grab_y;
601 double _cumulative_x_drag;
602 double _cumulative_y_drag;
603 static double const _zero_gain_fraction;
606 /** Gain or automation line drag */
607 class LineDrag : public Drag
610 LineDrag (Editor *e, ArdourCanvas::Item *i);
612 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
613 void motion (GdkEvent *, bool);
614 void finished (GdkEvent *, bool);
617 bool active (Editing::MouseMode) {
623 AutomationLine* _line;
624 double _time_axis_view_grab_x;
625 double _time_axis_view_grab_y;
628 double _cumulative_y_drag;
631 /** Transient feature line drags*/
632 class FeatureLineDrag : public Drag
635 FeatureLineDrag (Editor *e, ArdourCanvas::Item *i);
637 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
638 void motion (GdkEvent *, bool);
639 void finished (GdkEvent *, bool);
642 bool active (Editing::MouseMode) {
648 ArdourCanvas::SimpleLine* _line;
649 AudioRegionView* _arv;
651 double _region_view_grab_x;
652 double _cumulative_x_drag;
658 /** Dragging of a rubberband rectangle for selecting things */
659 class RubberbandSelectDrag : public Drag
662 RubberbandSelectDrag (Editor *e, ArdourCanvas::Item *i) : Drag (e, i) {}
664 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
665 void motion (GdkEvent *, bool);
666 void finished (GdkEvent *, bool);
669 std::pair<nframes64_t, int> move_threshold () const {
670 return std::make_pair (8, 1);
674 /** Region drag in time-FX mode */
675 class TimeFXDrag : public RegionDrag
678 TimeFXDrag (Editor *e, ArdourCanvas::Item *i, RegionView* p, std::list<RegionView*> const & v) : RegionDrag (e, i, p, v) {}
680 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
681 void motion (GdkEvent *, bool);
682 void finished (GdkEvent *, bool);
686 /** Scrub drag in audition mode */
687 class ScrubDrag : public Drag
690 ScrubDrag (Editor *e, ArdourCanvas::Item *i) : Drag (e, i) {}
692 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
693 void motion (GdkEvent *, bool);
694 void finished (GdkEvent *, bool);
698 /** Drag in range select mode */
699 class SelectionDrag : public Drag
709 SelectionDrag (Editor *, ArdourCanvas::Item *, Operation);
711 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
712 void motion (GdkEvent *, bool);
713 void finished (GdkEvent *, bool);
717 Operation _operation;
719 int _original_pointer_time_axis;
720 int _last_pointer_time_axis;
721 std::list<TimeAxisView*> _added_time_axes;
724 /** Range marker drag */
725 class RangeMarkerBarDrag : public Drag
730 CreateTransportMarker,
734 RangeMarkerBarDrag (Editor *, ArdourCanvas::Item *, Operation);
736 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
737 void motion (GdkEvent *, bool);
738 void finished (GdkEvent *, bool);
741 bool allow_vertical_autoscroll () const {
745 bool y_movement_matters () const {
750 void update_item (ARDOUR::Location *);
752 Operation _operation;
753 ArdourCanvas::SimpleRect* _drag_rect;
757 /** Drag of rectangle to set zoom */
758 class MouseZoomDrag : public Drag
761 MouseZoomDrag (Editor* e, ArdourCanvas::Item *i) : Drag (e, i) {}
763 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
764 void motion (GdkEvent *, bool);
765 void finished (GdkEvent *, bool);
769 /** Drag of a range of automation data, changing value but not position */
770 class AutomationRangeDrag : public Drag
773 AutomationRangeDrag (Editor *, ArdourCanvas::Item *, std::list<ARDOUR::AudioRange> const &);
775 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
776 void motion (GdkEvent *, bool);
777 void finished (GdkEvent *, bool);
780 bool x_movement_matters () const {
785 std::list<ARDOUR::AudioRange> _ranges;
786 AutomationTimeAxisView* _atav;
787 boost::shared_ptr<AutomationLine> _line;
788 bool _nothing_to_drag;
791 #endif /* __gtk2_ardour_editor_drag_h_ */