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 */
253 ARDOUR::layer_t layer;
254 double initial_y; ///< the initial y position of the view before any reparenting
255 framepos_t initial_position; ///< initial position of the region
256 framepos_t initial_end; ///< initial end position of the region
257 boost::shared_ptr<ARDOUR::Playlist> initial_playlist;
260 /** Abstract base class for drags that involve region(s) */
261 class RegionDrag : public Drag, public sigc::trackable
264 RegionDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
265 virtual ~RegionDrag () {}
269 RegionView* _primary; ///< the view that was clicked on (or whatever) to start the drag
270 std::list<DraggingView> _views; ///< information about all views that are being dragged
272 /** a list of the non-hidden TimeAxisViews sorted by editor order key */
273 std::vector<TimeAxisView*> _time_axis_views;
274 int find_time_axis_view (TimeAxisView *) const;
279 friend class DraggingView;
283 void region_going_away (RegionView *);
284 PBD::ScopedConnection death_connection;
288 /** Drags involving region motion from somewhere */
289 class RegionMotionDrag : public RegionDrag
293 RegionMotionDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &, bool);
294 virtual ~RegionMotionDrag () {}
296 virtual void start_grab (GdkEvent *, Gdk::Cursor *);
297 virtual void motion (GdkEvent *, bool);
298 virtual void finished (GdkEvent *, bool) = 0;
299 virtual void aborted (bool);
301 /** @return true if the regions being `moved' came from somewhere on the canvas;
302 * false if they came from outside (e.g. from the region list).
304 virtual bool regions_came_from_canvas () const = 0;
308 double compute_x_delta (GdkEvent const *, ARDOUR::framecnt_t *);
309 bool y_movement_allowed (int, ARDOUR::layer_t) const;
312 ARDOUR::framepos_t _last_frame_position; ///< last position of the thing being dragged
313 double _total_x_delta;
314 int _last_pointer_time_axis_view;
315 ARDOUR::layer_t _last_pointer_layer;
319 /** Drags to move (or copy) regions that are already shown in the GUI to
320 * somewhere different.
322 class RegionMoveDrag : public RegionMotionDrag
325 RegionMoveDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &, bool, bool);
326 virtual ~RegionMoveDrag () {}
328 void motion (GdkEvent *, bool);
329 void finished (GdkEvent *, bool);
332 bool regions_came_from_canvas () const {
336 std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
337 return std::make_pair (4, 4);
340 void setup_pointer_frame_offset ();
343 typedef std::set<boost::shared_ptr<ARDOUR::Playlist> > PlaylistSet;
345 void finished_no_copy (
348 ARDOUR::framecnt_t const
354 ARDOUR::framecnt_t const
357 RegionView* insert_region_into_playlist (
358 boost::shared_ptr<ARDOUR::Region>,
365 void remove_region_from_playlist (
366 boost::shared_ptr<ARDOUR::Region>,
367 boost::shared_ptr<ARDOUR::Playlist>,
368 PlaylistSet& modified_playlists
371 void add_stateful_diff_commands_for_playlists (PlaylistSet const &);
373 void collect_new_region_view (RegionView *);
376 RegionView* _new_region_view;
379 /** Drag to insert a region from somewhere */
380 class RegionInsertDrag : public RegionMotionDrag
383 RegionInsertDrag (Editor *, boost::shared_ptr<ARDOUR::Region>, RouteTimeAxisView*, ARDOUR::framepos_t);
385 void finished (GdkEvent *, bool);
388 bool regions_came_from_canvas () const {
393 /** Region drag in splice mode */
394 class RegionSpliceDrag : public RegionMoveDrag
397 RegionSpliceDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
399 void motion (GdkEvent *, bool);
400 void finished (GdkEvent *, bool);
404 /** Drags to create regions */
405 class RegionCreateDrag : public Drag
408 RegionCreateDrag (Editor *, ArdourCanvas::Item *, TimeAxisView *);
410 void motion (GdkEvent *, bool);
411 void finished (GdkEvent *, bool);
415 MidiTimeAxisView* _view;
416 boost::shared_ptr<ARDOUR::Region> _region;
420 /** Drags to resize MIDI notes */
421 class NoteResizeDrag : public Drag
424 NoteResizeDrag (Editor *, ArdourCanvas::Item *);
426 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
427 void motion (GdkEvent *, bool);
428 void finished (GdkEvent *, bool);
432 MidiRegionView* region;
437 /** Drags to move MIDI notes */
438 class NoteDrag : public Drag
441 NoteDrag (Editor*, ArdourCanvas::Item*);
443 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
444 void motion (GdkEvent *, bool);
445 void finished (GdkEvent *, bool);
450 ARDOUR::frameoffset_t total_dx () const;
451 int8_t total_dy () const;
453 MidiRegionView* _region;
454 Gnome::Canvas::CanvasNoteEvent* _primary;
455 double _cumulative_dx;
456 double _cumulative_dy;
461 /** Drag to move MIDI patch changes */
462 class PatchChangeDrag : public Drag
465 PatchChangeDrag (Editor *, ArdourCanvas::CanvasPatchChange *, MidiRegionView *);
467 void motion (GdkEvent *, bool);
468 void finished (GdkEvent *, bool);
471 bool y_movement_matters () const {
475 void setup_pointer_frame_offset ();
478 MidiRegionView* _region_view;
479 ArdourCanvas::CanvasPatchChange* _patch_change;
480 double _cumulative_dx;
483 /** Drag of region gain */
484 class RegionGainDrag : public Drag
487 RegionGainDrag (Editor *, ArdourCanvas::Item *);
489 void motion (GdkEvent *, bool);
490 void finished (GdkEvent *, bool);
491 bool active (Editing::MouseMode m) {
492 return (m == Editing::MouseGain);
498 /** Drag to trim region(s) */
499 class TrimDrag : public RegionDrag
508 TrimDrag (Editor *, ArdourCanvas::Item *, RegionView*, std::list<RegionView*> const &);
510 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
511 void motion (GdkEvent *, bool);
512 void finished (GdkEvent *, bool);
515 bool y_movement_matters () const {
519 void setup_pointer_frame_offset ();
523 Operation _operation;
526 /** Meter marker drag */
527 class MeterMarkerDrag : public Drag
530 MeterMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
532 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
533 void motion (GdkEvent *, bool);
534 void finished (GdkEvent *, bool);
537 bool allow_vertical_autoscroll () const {
541 bool y_movement_matters () const {
545 void setup_pointer_frame_offset ();
548 MeterMarker* _marker;
552 /** Tempo marker drag */
553 class TempoMarkerDrag : public Drag
556 TempoMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
558 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
559 void motion (GdkEvent *, bool);
560 void finished (GdkEvent *, bool);
563 bool allow_vertical_autoscroll () const {
567 bool y_movement_matters () const {
571 void setup_pointer_frame_offset ();
574 TempoMarker* _marker;
579 /** Drag of the playhead cursor */
580 class CursorDrag : public Drag
583 CursorDrag (Editor *, ArdourCanvas::Item *, bool);
585 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
586 void motion (GdkEvent *, bool);
587 void finished (GdkEvent *, bool);
590 bool active (Editing::MouseMode) {
594 bool allow_vertical_autoscroll () const {
598 bool y_movement_matters () const {
603 void fake_locate (framepos_t);
605 bool _stop; ///< true to stop the transport on starting the drag, otherwise false
606 double _grab_zoom; ///< editor frames per unit when our grab started
609 /** Region fade-in drag */
610 class FadeInDrag : public RegionDrag
613 FadeInDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
615 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
616 void motion (GdkEvent *, bool);
617 void finished (GdkEvent *, bool);
620 bool y_movement_matters () const {
624 void setup_pointer_frame_offset ();
627 /** Region fade-out drag */
628 class FadeOutDrag : public RegionDrag
631 FadeOutDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
633 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
634 void motion (GdkEvent *, bool);
635 void finished (GdkEvent *, bool);
638 bool y_movement_matters () const {
642 void setup_pointer_frame_offset ();
646 class MarkerDrag : public Drag
649 MarkerDrag (Editor *, ArdourCanvas::Item *);
652 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
653 void motion (GdkEvent *, bool);
654 void finished (GdkEvent *, bool);
657 bool allow_vertical_autoscroll () const {
661 bool y_movement_matters () const {
665 void setup_pointer_frame_offset ();
668 void update_item (ARDOUR::Location *);
670 Marker* _marker; ///< marker being dragged
671 std::list<ARDOUR::Location*> _copied_locations;
672 ArdourCanvas::Points _points;
675 /** Control point drag */
676 class ControlPointDrag : public Drag
679 ControlPointDrag (Editor *, ArdourCanvas::Item *);
681 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
682 void motion (GdkEvent *, bool);
683 void finished (GdkEvent *, bool);
686 bool active (Editing::MouseMode m);
690 ControlPoint* _point;
691 double _fixed_grab_x;
692 double _fixed_grab_y;
693 double _cumulative_x_drag;
694 double _cumulative_y_drag;
695 static double _zero_gain_fraction;
698 /** Gain or automation line drag */
699 class LineDrag : public Drag
702 LineDrag (Editor *e, ArdourCanvas::Item *i);
704 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
705 void motion (GdkEvent *, bool);
706 void finished (GdkEvent *, bool);
709 bool active (Editing::MouseMode) {
715 AutomationLine* _line;
716 double _fixed_grab_x;
717 double _fixed_grab_y;
720 double _cumulative_y_drag;
723 /** Transient feature line drags*/
724 class FeatureLineDrag : public Drag
727 FeatureLineDrag (Editor *e, ArdourCanvas::Item *i);
729 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
730 void motion (GdkEvent *, bool);
731 void finished (GdkEvent *, bool);
734 bool active (Editing::MouseMode) {
740 ArdourCanvas::Line* _line;
741 AudioRegionView* _arv;
743 double _region_view_grab_x;
744 double _cumulative_x_drag;
750 /** Dragging of a rubberband rectangle for selecting things */
751 class RubberbandSelectDrag : public Drag
754 RubberbandSelectDrag (Editor *, ArdourCanvas::Item *);
756 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
757 void motion (GdkEvent *, bool);
758 void finished (GdkEvent *, bool);
761 std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
762 return std::make_pair (8, 1);
766 /** Region drag in time-FX mode */
767 class TimeFXDrag : public RegionDrag
770 TimeFXDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
772 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
773 void motion (GdkEvent *, bool);
774 void finished (GdkEvent *, bool);
778 /** Scrub drag in audition mode */
779 class ScrubDrag : public Drag
782 ScrubDrag (Editor *, ArdourCanvas::Item *);
784 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
785 void motion (GdkEvent *, bool);
786 void finished (GdkEvent *, bool);
790 /** Drag in range select mode */
791 class SelectionDrag : public Drag
801 SelectionDrag (Editor *, ArdourCanvas::Item *, Operation);
803 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
804 void motion (GdkEvent *, bool);
805 void finished (GdkEvent *, bool);
808 void setup_pointer_frame_offset ();
811 Operation _operation;
813 int _original_pointer_time_axis;
814 int _last_pointer_time_axis;
815 std::list<TimeAxisView*> _added_time_axes;
818 /** Range marker drag */
819 class RangeMarkerBarDrag : public Drag
824 CreateTransportMarker,
828 RangeMarkerBarDrag (Editor *, ArdourCanvas::Item *, Operation);
830 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
831 void motion (GdkEvent *, bool);
832 void finished (GdkEvent *, bool);
835 bool allow_vertical_autoscroll () const {
839 bool y_movement_matters () const {
844 void update_item (ARDOUR::Location *);
846 Operation _operation;
847 ArdourCanvas::SimpleRect* _drag_rect;
851 /** Drag of rectangle to set zoom */
852 class MouseZoomDrag : public Drag
855 MouseZoomDrag (Editor *, ArdourCanvas::Item *);
857 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
858 void motion (GdkEvent *, bool);
859 void finished (GdkEvent *, bool);
862 std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
863 return std::make_pair (4, 4);
870 /** Drag of a range of automation data, changing value but not position */
871 class AutomationRangeDrag : public Drag
874 AutomationRangeDrag (Editor *, ArdourCanvas::Item *, std::list<ARDOUR::AudioRange> const &);
876 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
877 void motion (GdkEvent *, bool);
878 void finished (GdkEvent *, bool);
881 bool x_movement_matters () const {
886 std::list<ARDOUR::AudioRange> _ranges;
887 AutomationTimeAxisView* _atav;
889 /** A line that is part of the drag */
891 boost::shared_ptr<AutomationLine> line; ///< the line
892 std::list<ControlPoint*> points; ///< points to drag on the line
893 std::pair<ARDOUR::framepos_t, ARDOUR::framepos_t> range; ///< the range of all points on the line, in session frames
894 XMLNode* state; ///< the XML state node before the drag
897 std::list<Line> _lines;
899 bool _nothing_to_drag;
902 #endif /* __gtk2_ardour_editor_drag_h_ */