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_
28 #include "ardour/types.h"
31 #include "editor_items.h"
38 class StatefulDiffCommand;
43 class CanvasNoteEvent;
44 class CanvasPatchChange;
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
102 bool _old_follow_playhead; ///< state of Editor::follow_playhead() before the drags started
105 /** Abstract base class for dragging of things within the editor */
109 Drag (Editor *, ArdourCanvas::Item *);
112 void set_manager (DragManager* m) {
116 /** @return the canvas item being dragged */
117 ArdourCanvas::Item* item () const {
121 void swap_grab (ArdourCanvas::Item *, Gdk::Cursor *, uint32_t);
122 bool motion_handler (GdkEvent*, bool);
125 ARDOUR::framepos_t adjusted_frame (ARDOUR::framepos_t, GdkEvent const *, bool snap = true) const;
126 ARDOUR::framepos_t adjusted_current_frame (GdkEvent const *, bool snap = true) const;
128 /** Called to start a grab of an item.
129 * @param e Event that caused the grab to start.
130 * @param c Cursor to use, or 0.
132 virtual void start_grab (GdkEvent* e, Gdk::Cursor* c = 0);
134 virtual bool end_grab (GdkEvent *);
136 /** Called when a drag motion has occurred.
137 * @param e Event describing the motion.
138 * @param f true if this is the first movement, otherwise false.
140 virtual void motion (GdkEvent* e, bool f) = 0;
142 /** Called when a drag has finished.
143 * @param e Event describing the finish.
144 * @param m true if some movement occurred, otherwise false.
146 virtual void finished (GdkEvent* e, bool m) = 0;
148 /** Called to abort a drag and return things to how
149 * they were before it started.
150 * @param m true if some movement occurred, otherwise false.
152 virtual void aborted (bool m) = 0;
154 /** @param m Mouse mode.
155 * @return true if this drag should happen in this mouse mode.
157 virtual bool active (Editing::MouseMode m) {
158 return (m != Editing::MouseGain);
161 /** @return minimum number of frames (in x) and pixels (in y) that should be considered a movement */
162 virtual std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
163 return std::make_pair (1, 1);
166 virtual bool allow_vertical_autoscroll () const {
170 /** @return true if x movement matters to this drag */
171 virtual bool x_movement_matters () const {
175 /** @return true if y movement matters to this drag */
176 virtual bool y_movement_matters () const {
180 /** Set up the _pointer_frame_offset */
181 virtual void setup_pointer_frame_offset () {
182 _pointer_frame_offset = 0;
187 double grab_x () const {
191 double grab_y () const {
195 ARDOUR::framepos_t raw_grab_frame () const {
196 return _raw_grab_frame;
199 ARDOUR::framepos_t grab_frame () const {
203 double last_pointer_x () const {
204 return _last_pointer_x;
207 double last_pointer_y () const {
208 return _last_pointer_y;
211 double last_pointer_frame () const {
212 return _last_pointer_frame;
215 void show_verbose_cursor_time (framepos_t);
216 void show_verbose_cursor_duration (framepos_t, framepos_t, double xoffset = 0);
217 void show_verbose_cursor_text (std::string const &);
219 Editor* _editor; ///< our editor
221 ArdourCanvas::Item* _item; ///< our item
222 /** Offset from the mouse's position for the drag to the start of the thing that is being dragged */
223 ARDOUR::framecnt_t _pointer_frame_offset;
224 bool _x_constrained; ///< true if x motion is constrained, otherwise false
225 bool _y_constrained; ///< true if y motion is constrained, otherwise false
226 bool _was_rolling; ///< true if the session was rolling before the drag started, otherwise false
230 bool _move_threshold_passed; ///< true if the move threshold has been passed, otherwise false
231 double _grab_x; ///< trackview x of the grab start position
232 double _grab_y; ///< trackview y of the grab start position
233 double _last_pointer_x; ///< trackview x of the pointer last time a motion occurred
234 double _last_pointer_y; ///< trackview y of the pointer last time a motion occurred
235 ARDOUR::framepos_t _raw_grab_frame; ///< unsnapped frame that the mouse was at when start_grab was called, or 0
236 ARDOUR::framepos_t _grab_frame; ///< adjusted_frame that the mouse was at when start_grab was called, or 0
237 ARDOUR::framepos_t _last_pointer_frame; ///< adjusted_frame the last time a motion occurred
242 /** Container for details about a region being dragged */
245 DraggingView (RegionView *, RegionDrag *);
247 RegionView* view; ///< the view
248 /** index into RegionDrag::_time_axis_views of the view that this region is currently being displayed on,
249 * or -1 if it is not visible.
252 /** layer that this region is currently being displayed on. This is a double
253 rather than a layer_t as we use fractional layers during drags to allow the user
254 to indicate a new layer to put a region on.
257 double initial_y; ///< the initial y position of the view before any reparenting
258 framepos_t initial_position; ///< initial position of the region
259 framepos_t initial_end; ///< initial end position of the region
260 boost::shared_ptr<ARDOUR::Playlist> initial_playlist;
263 /** Abstract base class for drags that involve region(s) */
264 class RegionDrag : public Drag, public sigc::trackable
267 RegionDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
268 virtual ~RegionDrag () {}
272 RegionView* _primary; ///< the view that was clicked on (or whatever) to start the drag
273 std::list<DraggingView> _views; ///< information about all views that are being dragged
275 /** a list of the non-hidden TimeAxisViews sorted by editor order key */
276 std::vector<TimeAxisView*> _time_axis_views;
277 int find_time_axis_view (TimeAxisView *) const;
282 friend class DraggingView;
286 void region_going_away (RegionView *);
287 PBD::ScopedConnection death_connection;
291 /** Drags involving region motion from somewhere */
292 class RegionMotionDrag : public RegionDrag
296 RegionMotionDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &, bool);
297 virtual ~RegionMotionDrag () {}
299 virtual void start_grab (GdkEvent *, Gdk::Cursor *);
300 virtual void motion (GdkEvent *, bool);
301 virtual void finished (GdkEvent *, bool);
302 virtual void aborted (bool);
304 /** @return true if the regions being `moved' came from somewhere on the canvas;
305 * false if they came from outside (e.g. from the region list).
307 virtual bool regions_came_from_canvas () const = 0;
311 double compute_x_delta (GdkEvent const *, ARDOUR::framecnt_t *);
312 bool y_movement_allowed (int, double) const;
315 ARDOUR::framepos_t _last_frame_position; ///< last position of the thing being dragged
316 double _total_x_delta;
317 int _last_pointer_time_axis_view;
318 double _last_pointer_layer;
322 /** Drags to move (or copy) regions that are already shown in the GUI to
323 * somewhere different.
325 class RegionMoveDrag : public RegionMotionDrag
328 RegionMoveDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &, bool, bool);
329 virtual ~RegionMoveDrag () {}
331 void motion (GdkEvent *, bool);
332 void finished (GdkEvent *, bool);
335 bool regions_came_from_canvas () const {
339 std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
340 return std::make_pair (4, 4);
343 void setup_pointer_frame_offset ();
346 typedef std::set<boost::shared_ptr<ARDOUR::Playlist> > PlaylistSet;
348 void finished_no_copy (
351 ARDOUR::framecnt_t const
357 ARDOUR::framecnt_t const
360 RegionView* insert_region_into_playlist (
361 boost::shared_ptr<ARDOUR::Region>,
368 void remove_region_from_playlist (
369 boost::shared_ptr<ARDOUR::Region>,
370 boost::shared_ptr<ARDOUR::Playlist>,
371 PlaylistSet& modified_playlists
374 void add_stateful_diff_commands_for_playlists (PlaylistSet const &);
376 void collect_new_region_view (RegionView *);
379 RegionView* _new_region_view;
382 /** Drag to insert a region from somewhere */
383 class RegionInsertDrag : public RegionMotionDrag
386 RegionInsertDrag (Editor *, boost::shared_ptr<ARDOUR::Region>, RouteTimeAxisView*, ARDOUR::framepos_t);
388 void finished (GdkEvent *, bool);
391 bool regions_came_from_canvas () const {
396 /** Region drag in splice mode */
397 class RegionSpliceDrag : public RegionMoveDrag
400 RegionSpliceDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
402 void motion (GdkEvent *, bool);
403 void finished (GdkEvent *, bool);
407 /** Drags to create regions */
408 class RegionCreateDrag : public Drag
411 RegionCreateDrag (Editor *, ArdourCanvas::Item *, TimeAxisView *);
413 void motion (GdkEvent *, bool);
414 void finished (GdkEvent *, bool);
418 MidiTimeAxisView* _view;
419 boost::shared_ptr<ARDOUR::Region> _region;
423 /** Drags to resize MIDI notes */
424 class NoteResizeDrag : public Drag
427 NoteResizeDrag (Editor *, ArdourCanvas::Item *);
429 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
430 void motion (GdkEvent *, bool);
431 void finished (GdkEvent *, bool);
435 MidiRegionView* region;
440 /** Drags to move MIDI notes */
441 class NoteDrag : public Drag
444 NoteDrag (Editor*, ArdourCanvas::Item*);
446 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
447 void motion (GdkEvent *, bool);
448 void finished (GdkEvent *, bool);
453 ARDOUR::frameoffset_t total_dx () const;
454 int8_t total_dy () const;
456 MidiRegionView* _region;
457 Gnome::Canvas::CanvasNoteEvent* _primary;
458 double _cumulative_dx;
459 double _cumulative_dy;
464 class NoteCreateDrag : public Drag
467 NoteCreateDrag (Editor *, ArdourCanvas::Item *, MidiRegionView *);
470 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
471 void motion (GdkEvent *, bool);
472 void finished (GdkEvent *, bool);
476 double y_to_region (double) const;
477 framecnt_t grid_frames (framepos_t) const;
479 MidiRegionView* _region_view;
480 ArdourCanvas::SimpleRect* _drag_rect;
484 /** Drag to move MIDI patch changes */
485 class PatchChangeDrag : public Drag
488 PatchChangeDrag (Editor *, ArdourCanvas::CanvasPatchChange *, MidiRegionView *);
490 void motion (GdkEvent *, bool);
491 void finished (GdkEvent *, bool);
494 bool y_movement_matters () const {
498 void setup_pointer_frame_offset ();
501 MidiRegionView* _region_view;
502 ArdourCanvas::CanvasPatchChange* _patch_change;
503 double _cumulative_dx;
506 /** Drag of region gain */
507 class RegionGainDrag : public Drag
510 RegionGainDrag (Editor *, ArdourCanvas::Item *);
512 void motion (GdkEvent *, bool);
513 void finished (GdkEvent *, bool);
514 bool active (Editing::MouseMode m) {
515 return (m == Editing::MouseGain);
521 /** Drag to trim region(s) */
522 class TrimDrag : public RegionDrag
531 TrimDrag (Editor *, ArdourCanvas::Item *, RegionView*, std::list<RegionView*> const &);
533 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
534 void motion (GdkEvent *, bool);
535 void finished (GdkEvent *, bool);
538 bool y_movement_matters () const {
542 void setup_pointer_frame_offset ();
546 Operation _operation;
549 /** Meter marker drag */
550 class MeterMarkerDrag : public Drag
553 MeterMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
555 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
556 void motion (GdkEvent *, bool);
557 void finished (GdkEvent *, bool);
560 bool allow_vertical_autoscroll () const {
564 bool y_movement_matters () const {
568 void setup_pointer_frame_offset ();
571 MeterMarker* _marker;
575 /** Tempo marker drag */
576 class TempoMarkerDrag : public Drag
579 TempoMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
581 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
582 void motion (GdkEvent *, bool);
583 void finished (GdkEvent *, bool);
586 bool allow_vertical_autoscroll () const {
590 bool y_movement_matters () const {
594 void setup_pointer_frame_offset ();
597 TempoMarker* _marker;
602 /** Drag of the playhead cursor */
603 class CursorDrag : public Drag
606 CursorDrag (Editor *, ArdourCanvas::Item *, bool);
608 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
609 void motion (GdkEvent *, bool);
610 void finished (GdkEvent *, bool);
613 bool active (Editing::MouseMode) {
617 bool allow_vertical_autoscroll () const {
621 bool y_movement_matters () const {
626 void fake_locate (framepos_t);
628 bool _stop; ///< true to stop the transport on starting the drag, otherwise false
629 double _grab_zoom; ///< editor frames per unit when our grab started
632 /** Region fade-in drag */
633 class FadeInDrag : public RegionDrag
636 FadeInDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
638 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
639 void motion (GdkEvent *, bool);
640 void finished (GdkEvent *, bool);
643 bool y_movement_matters () const {
647 void setup_pointer_frame_offset ();
650 /** Region fade-out drag */
651 class FadeOutDrag : public RegionDrag
654 FadeOutDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
656 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
657 void motion (GdkEvent *, bool);
658 void finished (GdkEvent *, bool);
661 bool y_movement_matters () const {
665 void setup_pointer_frame_offset ();
669 class MarkerDrag : public Drag
672 MarkerDrag (Editor *, ArdourCanvas::Item *);
675 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
676 void motion (GdkEvent *, bool);
677 void finished (GdkEvent *, bool);
680 bool allow_vertical_autoscroll () const {
684 bool y_movement_matters () const {
688 void setup_pointer_frame_offset ();
691 void update_item (ARDOUR::Location *);
693 Marker* _marker; ///< marker being dragged
694 std::list<ARDOUR::Location*> _copied_locations;
695 ArdourCanvas::Points _points;
698 /** Control point drag */
699 class ControlPointDrag : public Drag
702 ControlPointDrag (Editor *, ArdourCanvas::Item *);
704 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
705 void motion (GdkEvent *, bool);
706 void finished (GdkEvent *, bool);
709 bool active (Editing::MouseMode m);
713 ControlPoint* _point;
714 double _fixed_grab_x;
715 double _fixed_grab_y;
716 double _cumulative_x_drag;
717 double _cumulative_y_drag;
718 static double _zero_gain_fraction;
721 /** Gain or automation line drag */
722 class LineDrag : public Drag
725 LineDrag (Editor *e, ArdourCanvas::Item *i);
727 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
728 void motion (GdkEvent *, bool);
729 void finished (GdkEvent *, bool);
732 bool active (Editing::MouseMode) {
738 AutomationLine* _line;
739 double _fixed_grab_x;
740 double _fixed_grab_y;
743 double _cumulative_y_drag;
746 /** Transient feature line drags*/
747 class FeatureLineDrag : public Drag
750 FeatureLineDrag (Editor *e, ArdourCanvas::Item *i);
752 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
753 void motion (GdkEvent *, bool);
754 void finished (GdkEvent *, bool);
757 bool active (Editing::MouseMode) {
763 ArdourCanvas::Line* _line;
764 AudioRegionView* _arv;
766 double _region_view_grab_x;
767 double _cumulative_x_drag;
773 /** Dragging of a rubberband rectangle for selecting things */
774 class RubberbandSelectDrag : public Drag
777 RubberbandSelectDrag (Editor *, ArdourCanvas::Item *);
779 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
780 void motion (GdkEvent *, bool);
781 void finished (GdkEvent *, bool);
784 std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
785 return std::make_pair (8, 1);
788 void do_select_things (GdkEvent *, bool);
790 /** Select some things within a rectangle.
791 * @param button_state The button state from the GdkEvent.
792 * @param x1 The left-hand side of the rectangle in session frames.
793 * @param x2 The right-hand side of the rectangle in session frames.
794 * @param y1 The top of the rectangle in trackview coordinates.
795 * @param y2 The bottom of the rectangle in trackview coordinates.
796 * @param drag_in_progress true if the drag is currently happening.
798 virtual void select_things (int button_state, framepos_t x1, framepos_t x2, double y1, double y2, bool drag_in_progress) = 0;
800 virtual void deselect_things () = 0;
803 /** A general editor RubberbandSelectDrag (for regions, automation points etc.) */
804 class EditorRubberbandSelectDrag : public RubberbandSelectDrag
807 EditorRubberbandSelectDrag (Editor *, ArdourCanvas::Item *);
809 void select_things (int, framepos_t, framepos_t, double, double, bool);
810 void deselect_things ();
813 /** A RubberbandSelectDrag for selecting MIDI notes */
814 class MidiRubberbandSelectDrag : public RubberbandSelectDrag
817 MidiRubberbandSelectDrag (Editor *, MidiRegionView *);
819 void select_things (int, framepos_t, framepos_t, double, double, bool);
820 void deselect_things ();
823 MidiRegionView* _region_view;
826 /** Region drag in time-FX mode */
827 class TimeFXDrag : public RegionDrag
830 TimeFXDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
832 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
833 void motion (GdkEvent *, bool);
834 void finished (GdkEvent *, bool);
838 /** Scrub drag in audition mode */
839 class ScrubDrag : public Drag
842 ScrubDrag (Editor *, ArdourCanvas::Item *);
844 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
845 void motion (GdkEvent *, bool);
846 void finished (GdkEvent *, bool);
850 /** Drag in range select mode */
851 class SelectionDrag : public Drag
861 SelectionDrag (Editor *, ArdourCanvas::Item *, Operation);
863 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
864 void motion (GdkEvent *, bool);
865 void finished (GdkEvent *, bool);
868 void setup_pointer_frame_offset ();
871 Operation _operation;
873 int _original_pointer_time_axis;
874 int _last_pointer_time_axis;
875 std::list<TimeAxisView*> _added_time_axes;
878 /** Range marker drag */
879 class RangeMarkerBarDrag : public Drag
884 CreateTransportMarker,
888 RangeMarkerBarDrag (Editor *, ArdourCanvas::Item *, Operation);
890 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
891 void motion (GdkEvent *, bool);
892 void finished (GdkEvent *, bool);
895 bool allow_vertical_autoscroll () const {
899 bool y_movement_matters () const {
904 void update_item (ARDOUR::Location *);
906 Operation _operation;
907 ArdourCanvas::SimpleRect* _drag_rect;
911 /** Drag of rectangle to set zoom */
912 class MouseZoomDrag : public Drag
915 MouseZoomDrag (Editor *, ArdourCanvas::Item *);
917 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
918 void motion (GdkEvent *, bool);
919 void finished (GdkEvent *, bool);
922 std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
923 return std::make_pair (4, 4);
930 /** Drag of a range of automation data, changing value but not position */
931 class AutomationRangeDrag : public Drag
934 AutomationRangeDrag (Editor *, ArdourCanvas::Item *, std::list<ARDOUR::AudioRange> const &);
936 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
937 void motion (GdkEvent *, bool);
938 void finished (GdkEvent *, bool);
941 bool x_movement_matters () const {
946 std::list<ARDOUR::AudioRange> _ranges;
947 AutomationTimeAxisView* _atav;
949 /** A line that is part of the drag */
951 boost::shared_ptr<AutomationLine> line; ///< the line
952 std::list<ControlPoint*> points; ///< points to drag on the line
953 std::pair<ARDOUR::framepos_t, ARDOUR::framepos_t> range; ///< the range of all points on the line, in session frames
954 XMLNode* state; ///< the XML state node before the drag
957 std::list<Line> _lines;
959 bool _nothing_to_drag;
962 #endif /* __gtk2_ardour_editor_drag_h_ */