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"
41 /** Abstract base class for dragging of things within the editor */
46 Drag (Editor *, ArdourCanvas::Item *);
49 /** @return the canvas item being dragged */
50 ArdourCanvas::Item* item () const {
54 void swap_grab (ArdourCanvas::Item *, Gdk::Cursor *, uint32_t);
57 bool motion_handler (GdkEvent*, bool);
59 /** @return true if an end drag is in progress */
60 bool ending () const {
64 /** @return true if the first move (past any move threshold) has occurred */
65 bool first_move () const {
69 /** @return current pointer x position in item coordinates */
70 double current_pointer_x () const {
71 return _current_pointer_x;
74 /** @return current pointer y position in item coordinates */
75 double current_pointer_y () const {
76 return _current_pointer_y;
79 /** @return current pointer frame */
80 nframes64_t current_pointer_frame () const {
81 return _current_pointer_frame;
84 /** Called to start a grab of an item.
85 * @param e Event that caused the grab to start.
86 * @param c Cursor to use, or 0.
88 virtual void start_grab (GdkEvent* e, Gdk::Cursor* c = 0);
90 virtual bool end_grab (GdkEvent *);
92 /** Called when a drag motion has occurred.
93 * @param e Event describing the motion.
95 virtual void motion (GdkEvent* e) = 0;
97 /** Called when a drag has finished.
98 * @param e Event describing the finish.
100 virtual void finished (GdkEvent *) = 0;
102 /** @param m Mouse mode.
103 * @return true if this drag should happen in this mouse mode.
105 virtual bool active (Editing::MouseMode m) {
106 return (m != Editing::MouseGain);
109 /** Called when a subclass should update the editor's selection following a drag */
110 virtual void update_selection () {}
113 nframes64_t adjusted_current_frame () const;
115 Editor* _editor; ///< our editor
116 ArdourCanvas::Item* _item; ///< our item
117 nframes64_t _pointer_frame_offset; ///< offset from the mouse's position for the drag
118 ///< to the start of the thing that is being dragged
119 nframes64_t _last_frame_position; ///< last position of the thing being dragged
120 nframes64_t _grab_frame; ///< frame that the mouse was at when start_grab was called, or 0
121 nframes64_t _last_pointer_frame; ///< frame that the pointer was at last time a motion occurred
122 nframes64_t _current_pointer_frame; ///< frame that the pointer is now at
123 double _original_x; ///< original world x of the thing being dragged
124 double _original_y; ///< original world y of the thing being dragged
125 double _grab_x; ///< item x of the grab start position
126 double _grab_y; ///< item y of the grab start position
127 double _current_pointer_x; ///< item x of the current pointer
128 double _current_pointer_y; ///< item y of the current pointer
129 double _last_pointer_x; ///< item x of the pointer last time a motion occurred
130 double _last_pointer_y; ///< item y of the pointer last time a motion occurred
131 bool _x_constrained; ///< true if x motion is constrained, otherwise false
132 bool _y_constrained; ///< true if y motion is constrained, otherwise false
133 bool _copy; ///< true if we're copying the things that we're dragging
134 bool _was_rolling; ///< true if the session was rolling before the drag started, otherwise false
135 bool _first_move; ///< true if some movement has occurred, otherwise false
136 bool _move_threshold_passed; ///< true if the move threshold has been passed, otherwise false
137 bool _want_move_threshold; ///< true if a move threshold should be applied, otherwise false
141 bool _ending; ///< true if end_grab is in progress, otherwise false
145 /** Abstract base class for drags that involve region(s) */
146 class RegionDrag : public Drag, public sigc::trackable
149 RegionDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
150 virtual ~RegionDrag () {}
152 void update_selection ();
156 RegionView* _primary; ///< the view that was clicked on (or whatever) to start the drag
157 std::list<RegionView*> _views; ///< all views that are being dragged
160 void region_going_away (RegionView *);
164 /** Drags to move regions */
165 class RegionMoveDrag : public RegionDrag
168 RegionMoveDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &, bool, bool);
169 virtual ~RegionMoveDrag () {}
171 virtual void start_grab (GdkEvent *, Gdk::Cursor *);
172 virtual void motion (GdkEvent *);
173 virtual void finished (GdkEvent *);
177 bool check_possible (RouteTimeAxisView **, ARDOUR::layer_t *);
179 TimeAxisView* _source_trackview;
180 ARDOUR::layer_t _source_layer;
181 TimeAxisView* _dest_trackview;
182 ARDOUR::layer_t _dest_layer;
186 void copy_regions (GdkEvent *);
187 bool y_movement_disallowed (int, int, int, int, int, std::bitset<512> const &, std::vector<int32_t> const &) const;
192 /** Region drag in splice mode */
193 class RegionSpliceDrag : public RegionMoveDrag
196 RegionSpliceDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
198 void motion (GdkEvent *);
199 void finished (GdkEvent *);
202 /** Drags to create regions */
203 class RegionCreateDrag : public Drag
206 RegionCreateDrag (Editor *, ArdourCanvas::Item *, TimeAxisView *);
208 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
209 void motion (GdkEvent *);
210 void finished (GdkEvent *);
215 TimeAxisView* _source_trackview;
216 ARDOUR::layer_t _source_layer;
217 TimeAxisView* _dest_trackview;
218 ARDOUR::layer_t _dest_layer;
221 /** Drag of region gain */
222 class RegionGainDrag : public Drag
225 RegionGainDrag (Editor *e, ArdourCanvas::Item *i) : Drag (e, i) {}
227 void motion (GdkEvent *);
228 void finished (GdkEvent *);
229 bool active (Editing::MouseMode m) {
230 return (m == Editing::MouseGain);
234 /** Drag to trim region(s) */
235 class TrimDrag : public RegionDrag
244 TrimDrag (Editor *, ArdourCanvas::Item *, RegionView*, std::list<RegionView*> const &);
246 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
247 void motion (GdkEvent *);
248 void finished (GdkEvent *);
252 Operation _operation;
255 /** Meter marker drag */
256 class MeterMarkerDrag : public Drag
259 MeterMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
261 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
262 void motion (GdkEvent *);
263 void finished (GdkEvent *);
266 MeterMarker* _marker;
269 /** Tempo marker drag */
270 class TempoMarkerDrag : public Drag
273 TempoMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
275 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
276 void motion (GdkEvent *);
277 void finished (GdkEvent *);
280 TempoMarker* _marker;
284 /** Drag of a cursor */
285 class CursorDrag : public Drag
288 CursorDrag (Editor *, ArdourCanvas::Item *, bool);
290 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
291 void motion (GdkEvent *);
292 void finished (GdkEvent *);
295 EditorCursor* _cursor; ///< cursor being dragged
296 bool _stop; ///< true to stop the transport on starting the drag, otherwise false
300 /** Region fade-in drag */
301 class FadeInDrag : public RegionDrag
304 FadeInDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
306 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
307 void motion (GdkEvent *);
308 void finished (GdkEvent *);
311 /** Region fade-out drag */
312 class FadeOutDrag : public RegionDrag
315 FadeOutDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
317 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
318 void motion (GdkEvent *);
319 void finished (GdkEvent *);
323 class MarkerDrag : public Drag
326 MarkerDrag (Editor *, ArdourCanvas::Item *);
329 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
330 void motion (GdkEvent *);
331 void finished (GdkEvent *);
334 void update_item (ARDOUR::Location *);
336 Marker* _marker; ///< marker being dragged
337 std::list<ARDOUR::Location*> _copied_locations;
338 ArdourCanvas::Line* _line;
339 ArdourCanvas::Points _points;
342 /** Control point drag */
343 class ControlPointDrag : public Drag
346 ControlPointDrag (Editor *, ArdourCanvas::Item *);
348 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
349 void motion (GdkEvent *);
350 void finished (GdkEvent *);
354 ControlPoint* _point;
355 double _cumulative_x_drag;
356 double _cumulative_y_drag;
357 static double const _zero_gain_fraction;
360 /** Gain or automation line drag */
361 class LineDrag : public Drag
364 LineDrag (Editor *e, ArdourCanvas::Item *i);
366 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
367 void motion (GdkEvent *);
368 void finished (GdkEvent *);
372 AutomationLine* _line;
375 double _cumulative_y_drag;
378 /** Dragging of a rubberband rectangle for selecting things */
379 class RubberbandSelectDrag : public Drag
382 RubberbandSelectDrag (Editor *e, ArdourCanvas::Item *i) : Drag (e, i) {}
384 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
385 void motion (GdkEvent *);
386 void finished (GdkEvent *);
389 /** Region drag in time-FX mode */
390 class TimeFXDrag : public RegionDrag
393 TimeFXDrag (Editor *e, ArdourCanvas::Item *i, RegionView* p, std::list<RegionView*> const & v) : RegionDrag (e, i, p, v) {}
395 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
396 void motion (GdkEvent *);
397 void finished (GdkEvent *);
400 /** Drag in range selection mode */
401 class SelectionDrag : public Drag
411 SelectionDrag (Editor *, ArdourCanvas::Item *, Operation);
413 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
414 void motion (GdkEvent *);
415 void finished (GdkEvent *);
418 Operation _operation;
421 /** Range marker drag */
422 class RangeMarkerBarDrag : public Drag
427 CreateTransportMarker,
431 RangeMarkerBarDrag (Editor *, ArdourCanvas::Item *, Operation);
433 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
434 void motion (GdkEvent *);
435 void finished (GdkEvent *);
438 void update_item (ARDOUR::Location *);
440 Operation _operation;
441 ArdourCanvas::SimpleRect* _drag_rect;
444 /* Drag of rectangle to set zoom */
445 class MouseZoomDrag : public Drag
448 MouseZoomDrag (Editor *e, ArdourCanvas::Item *i) : Drag (e, i) {}
450 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
451 void motion (GdkEvent *);
452 void finished (GdkEvent *);
455 #endif /* __gtk2_ardour_editor_drag_h_ */