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 current pointer x position in item coordinates */
65 double current_pointer_x () const {
66 return _current_pointer_x;
69 /** @return current pointer y position in item coordinates */
70 double current_pointer_y () const {
71 return _current_pointer_y;
74 /** @return current pointer frame */
75 nframes64_t current_pointer_frame () const {
76 return _current_pointer_frame;
79 /** Called to start a grab of an item.
80 * @param e Event that caused the grab to start.
81 * @param c Cursor to use, or 0.
83 virtual void start_grab (GdkEvent* e, Gdk::Cursor* c = 0);
85 virtual bool end_grab (GdkEvent *);
87 /** Called when a drag motion has occurred.
88 * @param e Event describing the motion.
89 * @param f true if this is the first movement, otherwise false.
91 virtual void motion (GdkEvent* e, bool f) = 0;
93 /** Called when a drag has finished.
94 * @param e Event describing the finish.
95 * @param m true if some movement occurred, otherwise false.
97 virtual void finished (GdkEvent* e, bool m) = 0;
99 /** @param m Mouse mode.
100 * @return true if this drag should happen in this mouse mode.
102 virtual bool active (Editing::MouseMode m) {
103 return (m != Editing::MouseGain);
106 /** @return true if a small threshold should be applied before a mouse movement
107 * is considered a drag, otherwise false.
109 virtual bool apply_move_threshold () const {
113 /** Called when a subclass should update the editor's selection following a drag */
114 virtual void update_selection () {}
117 nframes64_t adjusted_current_frame () const;
119 Editor* _editor; ///< our editor
120 ArdourCanvas::Item* _item; ///< our item
121 nframes64_t _pointer_frame_offset; ///< offset from the mouse's position for the drag
122 ///< to the start of the thing that is being dragged
123 nframes64_t _last_frame_position; ///< last position of the thing being dragged
124 nframes64_t _grab_frame; ///< frame that the mouse was at when start_grab was called, or 0
125 nframes64_t _last_pointer_frame; ///< frame that the pointer was at last time a motion occurred
126 nframes64_t _current_pointer_frame; ///< frame that the pointer is now at
127 double _original_x; ///< original world x of the thing being dragged
128 double _original_y; ///< original world y of the thing being dragged
129 double _grab_x; ///< item x of the grab start position
130 double _grab_y; ///< item y of the grab start position
131 double _current_pointer_x; ///< item x of the current pointer
132 double _current_pointer_y; ///< item y of the current pointer
133 double _last_pointer_x; ///< item x of the pointer last time a motion occurred
134 double _last_pointer_y; ///< item y of the pointer last time a motion occurred
135 bool _x_constrained; ///< true if x motion is constrained, otherwise false
136 bool _y_constrained; ///< true if y motion is constrained, otherwise false
137 bool _was_rolling; ///< true if the session was rolling before the drag started, otherwise false
141 bool _ending; ///< true if end_grab is in progress, otherwise false
142 bool _had_movement; ///< true if movement has occurred, otherwise false
143 bool _move_threshold_passed; ///< true if the move threshold has been passed, otherwise false
147 /** Abstract base class for drags that involve region(s) */
148 class RegionDrag : public Drag, public sigc::trackable
151 RegionDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
152 virtual ~RegionDrag () {}
154 void update_selection ();
158 RegionView* _primary; ///< the view that was clicked on (or whatever) to start the drag
159 std::list<RegionView*> _views; ///< all views that are being dragged
162 void region_going_away (RegionView *);
166 /** Drags involving region motion from somewhere */
167 class RegionMotionDrag : public RegionDrag
171 RegionMotionDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &, bool);
172 virtual ~RegionMotionDrag () {}
174 virtual void start_grab (GdkEvent *, Gdk::Cursor *);
175 virtual void motion (GdkEvent *, bool);
176 virtual void finished (GdkEvent *, bool) = 0;
179 struct TimeAxisViewSummary {
180 TimeAxisViewSummary () : height_list(512) {}
182 std::bitset<512> tracks;
183 std::vector<int32_t> height_list;
188 void copy_regions (GdkEvent *);
189 bool y_movement_disallowed (int, int, int, TimeAxisViewSummary const &) const;
190 std::map<RegionView*, RouteTimeAxisView*> find_time_axis_views ();
191 double compute_x_delta (GdkEvent const *, nframes64_t *);
192 bool compute_y_delta (
193 TimeAxisView const *, TimeAxisView*, int32_t, int32_t, TimeAxisViewSummary const &,
194 int32_t *, int32_t *, int32_t *
197 TimeAxisViewSummary get_time_axis_view_summary ();
198 virtual bool x_move_allowed () const = 0;
200 TimeAxisView* _dest_trackview;
201 ARDOUR::layer_t _dest_layer;
202 bool check_possible (RouteTimeAxisView **, ARDOUR::layer_t *);
207 /** Drags to move (or copy) regions that are already shown in the GUI to
208 * somewhere different.
210 class RegionMoveDrag : public RegionMotionDrag
213 RegionMoveDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &, bool, bool);
214 virtual ~RegionMoveDrag () {}
216 virtual void start_grab (GdkEvent *, Gdk::Cursor *);
217 void motion (GdkEvent *, bool);
218 void finished (GdkEvent *, bool);
220 bool apply_move_threshold () const {
225 bool x_move_allowed () const;
230 /** Drag to insert a region from somewhere */
231 class RegionInsertDrag : public RegionMotionDrag
234 RegionInsertDrag (Editor *, boost::shared_ptr<ARDOUR::Region>, RouteTimeAxisView*, nframes64_t);
236 void finished (GdkEvent *, bool);
239 bool x_move_allowed () const;
242 /** Region drag in splice mode */
243 class RegionSpliceDrag : public RegionMoveDrag
246 RegionSpliceDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
248 void motion (GdkEvent *, bool);
249 void finished (GdkEvent *, bool);
252 /** Drags to create regions */
253 class RegionCreateDrag : public Drag
256 RegionCreateDrag (Editor *, ArdourCanvas::Item *, TimeAxisView *);
258 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
259 void motion (GdkEvent *, bool);
260 void finished (GdkEvent *, bool);
264 TimeAxisView* _dest_trackview;
267 /** Drag of region gain */
268 class RegionGainDrag : public Drag
271 RegionGainDrag (Editor *e, ArdourCanvas::Item *i) : Drag (e, i) {}
273 void motion (GdkEvent *, bool);
274 void finished (GdkEvent *, bool);
275 bool active (Editing::MouseMode m) {
276 return (m == Editing::MouseGain);
280 /** Drag to trim region(s) */
281 class TrimDrag : public RegionDrag
290 TrimDrag (Editor *, ArdourCanvas::Item *, RegionView*, std::list<RegionView*> const &);
292 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
293 void motion (GdkEvent *, bool);
294 void finished (GdkEvent *, bool);
298 Operation _operation;
301 /** Meter marker drag */
302 class MeterMarkerDrag : public Drag
305 MeterMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
307 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
308 void motion (GdkEvent *, bool);
309 void finished (GdkEvent *, bool);
312 MeterMarker* _marker;
316 /** Tempo marker drag */
317 class TempoMarkerDrag : public Drag
320 TempoMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
322 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
323 void motion (GdkEvent *, bool);
324 void finished (GdkEvent *, bool);
327 TempoMarker* _marker;
332 /** Drag of a cursor */
333 class CursorDrag : public Drag
336 CursorDrag (Editor *, ArdourCanvas::Item *, bool);
338 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
339 void motion (GdkEvent *, bool);
340 void finished (GdkEvent *, bool);
343 EditorCursor* _cursor; ///< cursor being dragged
344 bool _stop; ///< true to stop the transport on starting the drag, otherwise false
348 /** Region fade-in drag */
349 class FadeInDrag : public RegionDrag
352 FadeInDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
354 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
355 void motion (GdkEvent *, bool);
356 void finished (GdkEvent *, bool);
359 /** Region fade-out drag */
360 class FadeOutDrag : public RegionDrag
363 FadeOutDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
365 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
366 void motion (GdkEvent *, bool);
367 void finished (GdkEvent *, bool);
371 class MarkerDrag : public Drag
374 MarkerDrag (Editor *, ArdourCanvas::Item *);
377 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
378 void motion (GdkEvent *, bool);
379 void finished (GdkEvent *, bool);
382 void update_item (ARDOUR::Location *);
384 Marker* _marker; ///< marker being dragged
385 std::list<ARDOUR::Location*> _copied_locations;
386 ArdourCanvas::Line* _line;
387 ArdourCanvas::Points _points;
390 /** Control point drag */
391 class ControlPointDrag : public Drag
394 ControlPointDrag (Editor *, ArdourCanvas::Item *);
396 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
397 void motion (GdkEvent *, bool);
398 void finished (GdkEvent *, bool);
400 bool active (Editing::MouseMode m) {
401 return (m == Editing::MouseGain);
406 ControlPoint* _point;
407 double _cumulative_x_drag;
408 double _cumulative_y_drag;
409 static double const _zero_gain_fraction;
412 /** Gain or automation line drag */
413 class LineDrag : public Drag
416 LineDrag (Editor *e, ArdourCanvas::Item *i);
418 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
419 void motion (GdkEvent *, bool);
420 void finished (GdkEvent *, bool);
422 bool active (Editing::MouseMode) {
428 AutomationLine* _line;
431 double _cumulative_y_drag;
434 /** Dragging of a rubberband rectangle for selecting things */
435 class RubberbandSelectDrag : public Drag
438 RubberbandSelectDrag (Editor *e, ArdourCanvas::Item *i) : Drag (e, i) {}
440 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
441 void motion (GdkEvent *, bool);
442 void finished (GdkEvent *, bool);
445 /** Region drag in time-FX mode */
446 class TimeFXDrag : public RegionDrag
449 TimeFXDrag (Editor *e, ArdourCanvas::Item *i, RegionView* p, std::list<RegionView*> const & v) : RegionDrag (e, i, p, v) {}
451 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
452 void motion (GdkEvent *, bool);
453 void finished (GdkEvent *, bool);
456 /** Drag in range selection mode */
457 class SelectionDrag : public Drag
467 SelectionDrag (Editor *, ArdourCanvas::Item *, Operation);
469 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
470 void motion (GdkEvent *, bool);
471 void finished (GdkEvent *, bool);
474 Operation _operation;
478 /** Range marker drag */
479 class RangeMarkerBarDrag : public Drag
484 CreateTransportMarker,
488 RangeMarkerBarDrag (Editor *, ArdourCanvas::Item *, Operation);
490 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
491 void motion (GdkEvent *, bool);
492 void finished (GdkEvent *, bool);
495 void update_item (ARDOUR::Location *);
497 Operation _operation;
498 ArdourCanvas::SimpleRect* _drag_rect;
502 /* Drag of rectangle to set zoom */
503 class MouseZoomDrag : public Drag
506 MouseZoomDrag (Editor *e, ArdourCanvas::Item *i) : Drag (e, i) {}
508 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
509 void motion (GdkEvent *, bool);
510 void finished (GdkEvent *, bool);
513 #endif /* __gtk2_ardour_editor_drag_h_ */