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"
39 class StatefulDiffCommand;
44 class CanvasNoteEvent;
51 class MidiTimeAxisView;
54 /** Class to manage current drags */
59 DragManager (Editor* e);
62 bool motion_handler (GdkEvent *, bool);
66 void set (Drag *, GdkEvent *, Gdk::Cursor* c = 0);
67 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
68 bool end_grab (GdkEvent *);
69 bool have_item (ArdourCanvas::Item *) const;
71 /** @return true if an end drag or abort is in progress */
72 bool ending () const {
76 bool active () const {
77 return !_drags.empty ();
80 /** @return current pointer x position in trackview coordinates */
81 double current_pointer_x () const {
82 return _current_pointer_x;
85 /** @return current pointer y position in trackview coordinates */
86 double current_pointer_y () const {
87 return _current_pointer_y;
90 /** @return current pointer frame */
91 ARDOUR::framepos_t current_pointer_frame () const {
92 return _current_pointer_frame;
97 std::list<Drag*> _drags;
98 bool _ending; ///< true if end_grab or abort is in progress, otherwise false
99 double _current_pointer_x; ///< trackview x of the current pointer
100 double _current_pointer_y; ///< trackview y of the current pointer
101 ARDOUR::framepos_t _current_pointer_frame; ///< frame that the pointer is now at
104 /** Abstract base class for dragging of things within the editor */
108 Drag (Editor *, ArdourCanvas::Item *);
111 void set_manager (DragManager* m) {
115 /** @return the canvas item being dragged */
116 ArdourCanvas::Item* item () const {
120 void swap_grab (ArdourCanvas::Item *, Gdk::Cursor *, uint32_t);
121 bool motion_handler (GdkEvent*, bool);
124 ARDOUR::framepos_t adjusted_frame (ARDOUR::framepos_t, GdkEvent const *, bool snap = true) const;
125 ARDOUR::framepos_t adjusted_current_frame (GdkEvent const *, bool snap = true) const;
127 /** Called to start a grab of an item.
128 * @param e Event that caused the grab to start.
129 * @param c Cursor to use, or 0.
131 virtual void start_grab (GdkEvent* e, Gdk::Cursor* c = 0);
133 virtual bool end_grab (GdkEvent *);
135 /** Called when a drag motion has occurred.
136 * @param e Event describing the motion.
137 * @param f true if this is the first movement, otherwise false.
139 virtual void motion (GdkEvent* e, bool f) = 0;
141 /** Called when a drag has finished.
142 * @param e Event describing the finish.
143 * @param m true if some movement occurred, otherwise false.
145 virtual void finished (GdkEvent* e, bool m) = 0;
147 /** Called to abort a drag and return things to how
148 * they were before it started.
150 virtual void aborted () = 0;
152 /** @param m Mouse mode.
153 * @return true if this drag should happen in this mouse mode.
155 virtual bool active (Editing::MouseMode m) {
156 return (m != Editing::MouseGain);
159 /** @return minimum number of frames (in x) and pixels (in y) that should be considered a movement */
160 virtual std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
161 return std::make_pair (1, 1);
164 virtual bool allow_vertical_autoscroll () const {
168 /** @return true if x movement matters to this drag */
169 virtual bool x_movement_matters () const {
173 /** @return true if y movement matters to this drag */
174 virtual bool y_movement_matters () const {
180 double grab_x () const {
184 double grab_y () const {
188 ARDOUR::framepos_t raw_grab_frame () const {
189 return _raw_grab_frame;
192 ARDOUR::framepos_t grab_frame () const {
196 double last_pointer_x () const {
197 return _last_pointer_x;
200 double last_pointer_y () const {
201 return _last_pointer_y;
204 double last_pointer_frame () const {
205 return _last_pointer_frame;
208 Editor* _editor; ///< our editor
210 ArdourCanvas::Item* _item; ///< our item
211 /** Offset from the mouse's position for the drag to the start of the thing that is being dragged */
212 ARDOUR::framecnt_t _pointer_frame_offset;
213 bool _x_constrained; ///< true if x motion is constrained, otherwise false
214 bool _y_constrained; ///< true if y motion is constrained, otherwise false
215 bool _was_rolling; ///< true if the session was rolling before the drag started, otherwise false
219 bool _move_threshold_passed; ///< true if the move threshold has been passed, otherwise false
220 double _grab_x; ///< trackview x of the grab start position
221 double _grab_y; ///< trackview y of the grab start position
222 double _last_pointer_x; ///< trackview x of the pointer last time a motion occurred
223 double _last_pointer_y; ///< trackview y of the pointer last time a motion occurred
224 ARDOUR::framepos_t _raw_grab_frame; ///< unsnapped frame that the mouse was at when start_grab was called, or 0
225 ARDOUR::framepos_t _grab_frame; ///< adjusted_frame that the mouse was at when start_grab was called, or 0
226 ARDOUR::framepos_t _last_pointer_frame; ///< adjusted_frame the last time a motion occurred
231 /** Container for details about a region being dragged */
234 DraggingView (RegionView *, RegionDrag *);
236 RegionView* view; ///< the view
237 /** index into RegionDrag::_time_axis_views of the view that this region is currently beind displayed on */
239 /** layer that this region is currently being displayed on */
240 ARDOUR::layer_t layer;
241 double initial_y; ///< the initial y position of the view before any reparenting
242 boost::shared_ptr<ARDOUR::Playlist> initial_playlist;
245 /** Abstract base class for drags that involve region(s) */
246 class RegionDrag : public Drag, public sigc::trackable
249 RegionDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
250 virtual ~RegionDrag () {}
254 RegionView* _primary; ///< the view that was clicked on (or whatever) to start the drag
255 std::list<DraggingView> _views; ///< information about all views that are being dragged
257 /** a list of the non-hidden TimeAxisViews sorted by editor order key */
258 std::vector<TimeAxisView*> _time_axis_views;
259 int find_time_axis_view (TimeAxisView *) const;
264 friend class DraggingView;
268 void region_going_away (RegionView *);
269 PBD::ScopedConnection death_connection;
273 /** Drags involving region motion from somewhere */
274 class RegionMotionDrag : public RegionDrag
278 RegionMotionDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &, bool);
279 virtual ~RegionMotionDrag () {}
281 virtual void start_grab (GdkEvent *, Gdk::Cursor *);
282 virtual void motion (GdkEvent *, bool);
283 virtual void finished (GdkEvent *, bool) = 0;
284 virtual void aborted ();
286 /** @return true if the regions being `moved' came from somewhere on the canvas;
287 * false if they came from outside (e.g. from the region list).
289 virtual bool regions_came_from_canvas () const = 0;
293 double compute_x_delta (GdkEvent const *, ARDOUR::framecnt_t *);
294 bool y_movement_allowed (int, ARDOUR::layer_t) const;
297 ARDOUR::framepos_t _last_frame_position; ///< last position of the thing being dragged
298 double _total_x_delta;
299 int _last_pointer_time_axis_view;
300 ARDOUR::layer_t _last_pointer_layer;
304 /** Drags to move (or copy) regions that are already shown in the GUI to
305 * somewhere different.
307 class RegionMoveDrag : public RegionMotionDrag
310 RegionMoveDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &, bool, bool);
311 virtual ~RegionMoveDrag () {}
313 virtual void start_grab (GdkEvent *, Gdk::Cursor *);
314 void motion (GdkEvent *, bool);
315 void finished (GdkEvent *, bool);
318 bool regions_came_from_canvas () const {
322 std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
323 return std::make_pair (4, 4);
327 typedef std::set<boost::shared_ptr<ARDOUR::Playlist> > PlaylistSet;
329 void finished_no_copy (
332 ARDOUR::framecnt_t const
338 ARDOUR::framecnt_t const
341 RegionView* insert_region_into_playlist (
342 boost::shared_ptr<ARDOUR::Region>,
349 void remove_region_from_playlist (
350 boost::shared_ptr<ARDOUR::Region>,
351 boost::shared_ptr<ARDOUR::Playlist>,
352 PlaylistSet& modified_playlists
355 void add_stateful_diff_commands_for_playlists (PlaylistSet const &);
357 void collect_new_region_view (RegionView *);
360 RegionView* _new_region_view;
363 /** Drag to insert a region from somewhere */
364 class RegionInsertDrag : public RegionMotionDrag
367 RegionInsertDrag (Editor *, boost::shared_ptr<ARDOUR::Region>, RouteTimeAxisView*, ARDOUR::framepos_t);
369 void finished (GdkEvent *, bool);
372 bool regions_came_from_canvas () const {
377 /** Region drag in splice mode */
378 class RegionSpliceDrag : public RegionMoveDrag
381 RegionSpliceDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
383 void motion (GdkEvent *, bool);
384 void finished (GdkEvent *, bool);
388 /** Drags to create regions */
389 class RegionCreateDrag : public Drag
392 RegionCreateDrag (Editor *, ArdourCanvas::Item *, TimeAxisView *);
394 void motion (GdkEvent *, bool);
395 void finished (GdkEvent *, bool);
399 MidiTimeAxisView* _view;
400 boost::shared_ptr<ARDOUR::Region> _region;
403 /** Drags to resize MIDI notes */
404 class NoteResizeDrag : public Drag
407 NoteResizeDrag (Editor *, ArdourCanvas::Item *);
409 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
410 void motion (GdkEvent *, bool);
411 void finished (GdkEvent *, bool);
415 MidiRegionView* region;
420 /** Drags to move MIDI notes */
421 class NoteDrag : public Drag
424 NoteDrag (Editor*, ArdourCanvas::Item*);
426 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
427 void motion (GdkEvent *, bool);
428 void finished (GdkEvent *, bool);
433 ARDOUR::frameoffset_t total_dx () const;
434 int8_t total_dy () const;
436 MidiRegionView* _region;
437 Gnome::Canvas::CanvasNoteEvent* _primary;
438 double _cumulative_dx;
439 double _cumulative_dy;
444 /** Drag of region gain */
445 class RegionGainDrag : public Drag
448 RegionGainDrag (Editor *, ArdourCanvas::Item *);
450 void motion (GdkEvent *, bool);
451 void finished (GdkEvent *, bool);
452 bool active (Editing::MouseMode m) {
453 return (m == Editing::MouseGain);
459 /** Drag to trim region(s) */
460 class TrimDrag : public RegionDrag
469 TrimDrag (Editor *, ArdourCanvas::Item *, RegionView*, std::list<RegionView*> const &);
471 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
472 void motion (GdkEvent *, bool);
473 void finished (GdkEvent *, bool);
476 bool y_movement_matters () const {
482 Operation _operation;
483 bool _have_transaction; ///< true if a transaction has been started, false otherwise. Must be set true by derived class.
486 /** Meter marker drag */
487 class MeterMarkerDrag : public Drag
490 MeterMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
492 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
493 void motion (GdkEvent *, bool);
494 void finished (GdkEvent *, bool);
497 bool allow_vertical_autoscroll () const {
501 bool y_movement_matters () const {
506 MeterMarker* _marker;
510 /** Tempo marker drag */
511 class TempoMarkerDrag : public Drag
514 TempoMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
516 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
517 void motion (GdkEvent *, bool);
518 void finished (GdkEvent *, bool);
521 bool allow_vertical_autoscroll () const {
525 bool y_movement_matters () const {
530 TempoMarker* _marker;
535 /** Drag of a cursor */
536 class CursorDrag : public Drag
539 CursorDrag (Editor *, ArdourCanvas::Item *, bool);
541 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
542 void motion (GdkEvent *, bool);
543 void finished (GdkEvent *, bool);
546 bool active (Editing::MouseMode) {
550 bool allow_vertical_autoscroll () const {
554 bool y_movement_matters () const {
559 EditorCursor* _cursor; ///< cursor being dragged
560 bool _stop; ///< true to stop the transport on starting the drag, otherwise false
564 /** Region fade-in drag */
565 class FadeInDrag : public RegionDrag
568 FadeInDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
570 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
571 void motion (GdkEvent *, bool);
572 void finished (GdkEvent *, bool);
575 bool y_movement_matters () const {
580 /** Region fade-out drag */
581 class FadeOutDrag : public RegionDrag
584 FadeOutDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
586 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
587 void motion (GdkEvent *, bool);
588 void finished (GdkEvent *, bool);
591 bool y_movement_matters () const {
597 class MarkerDrag : public Drag
600 MarkerDrag (Editor *, ArdourCanvas::Item *);
603 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
604 void motion (GdkEvent *, bool);
605 void finished (GdkEvent *, bool);
608 bool allow_vertical_autoscroll () const {
612 bool y_movement_matters () const {
617 void update_item (ARDOUR::Location *);
619 Marker* _marker; ///< marker being dragged
620 std::list<ARDOUR::Location*> _copied_locations;
621 ArdourCanvas::Line* _line;
622 ArdourCanvas::Points _points;
625 /** Control point drag */
626 class ControlPointDrag : public Drag
629 ControlPointDrag (Editor *, ArdourCanvas::Item *);
631 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
632 void motion (GdkEvent *, bool);
633 void finished (GdkEvent *, bool);
636 bool active (Editing::MouseMode m);
640 ControlPoint* _point;
641 double _fixed_grab_x;
642 double _fixed_grab_y;
643 double _cumulative_x_drag;
644 double _cumulative_y_drag;
645 static double const _zero_gain_fraction;
648 /** Gain or automation line drag */
649 class LineDrag : public Drag
652 LineDrag (Editor *e, ArdourCanvas::Item *i);
654 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
655 void motion (GdkEvent *, bool);
656 void finished (GdkEvent *, bool);
659 bool active (Editing::MouseMode) {
665 AutomationLine* _line;
666 double _fixed_grab_x;
667 double _fixed_grab_y;
670 double _cumulative_y_drag;
673 /** Transient feature line drags*/
674 class FeatureLineDrag : public Drag
677 FeatureLineDrag (Editor *e, ArdourCanvas::Item *i);
679 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
680 void motion (GdkEvent *, bool);
681 void finished (GdkEvent *, bool);
684 bool active (Editing::MouseMode) {
690 ArdourCanvas::SimpleLine* _line;
691 AudioRegionView* _arv;
693 double _region_view_grab_x;
694 double _cumulative_x_drag;
700 /** Dragging of a rubberband rectangle for selecting things */
701 class RubberbandSelectDrag : public Drag
704 RubberbandSelectDrag (Editor *, ArdourCanvas::Item *);
706 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
707 void motion (GdkEvent *, bool);
708 void finished (GdkEvent *, bool);
711 std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
712 return std::make_pair (8, 1);
716 /** Region drag in time-FX mode */
717 class TimeFXDrag : public RegionDrag
720 TimeFXDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
722 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
723 void motion (GdkEvent *, bool);
724 void finished (GdkEvent *, bool);
728 /** Scrub drag in audition mode */
729 class ScrubDrag : public Drag
732 ScrubDrag (Editor *, ArdourCanvas::Item *);
734 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
735 void motion (GdkEvent *, bool);
736 void finished (GdkEvent *, bool);
740 /** Drag in range select mode */
741 class SelectionDrag : public Drag
751 SelectionDrag (Editor *, ArdourCanvas::Item *, Operation);
753 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
754 void motion (GdkEvent *, bool);
755 void finished (GdkEvent *, bool);
759 Operation _operation;
761 int _original_pointer_time_axis;
762 int _last_pointer_time_axis;
763 std::list<TimeAxisView*> _added_time_axes;
766 /** Range marker drag */
767 class RangeMarkerBarDrag : public Drag
772 CreateTransportMarker,
776 RangeMarkerBarDrag (Editor *, ArdourCanvas::Item *, Operation);
778 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
779 void motion (GdkEvent *, bool);
780 void finished (GdkEvent *, bool);
783 bool allow_vertical_autoscroll () const {
787 bool y_movement_matters () const {
792 void update_item (ARDOUR::Location *);
794 Operation _operation;
795 ArdourCanvas::SimpleRect* _drag_rect;
799 /** Drag of rectangle to set zoom */
800 class MouseZoomDrag : public Drag
803 MouseZoomDrag (Editor *, ArdourCanvas::Item *);
805 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
806 void motion (GdkEvent *, bool);
807 void finished (GdkEvent *, bool);
811 /** Drag of a range of automation data, changing value but not position */
812 class AutomationRangeDrag : public Drag
815 AutomationRangeDrag (Editor *, ArdourCanvas::Item *, std::list<ARDOUR::AudioRange> const &);
817 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
818 void motion (GdkEvent *, bool);
819 void finished (GdkEvent *, bool);
822 bool x_movement_matters () const {
827 std::list<ARDOUR::AudioRange> _ranges;
828 AutomationTimeAxisView* _atav;
829 boost::shared_ptr<AutomationLine> _line;
830 bool _nothing_to_drag;
833 #endif /* __gtk2_ardour_editor_drag_h_ */