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 virtual bool allow_vertical_autoscroll () const {
118 nframes64_t adjusted_current_frame (GdkEvent *) const;
120 Editor* _editor; ///< our editor
121 ArdourCanvas::Item* _item; ///< our item
122 nframes64_t _pointer_frame_offset; ///< offset from the mouse's position for the drag
123 ///< to the start of the thing that is being dragged
124 nframes64_t _last_frame_position; ///< last position of the thing being dragged
125 nframes64_t _grab_frame; ///< frame that the mouse was at when start_grab was called, or 0
126 nframes64_t _last_pointer_frame; ///< frame that the pointer was at last time a motion occurred
127 nframes64_t _current_pointer_frame; ///< frame that the pointer is now at
128 double _original_x; ///< original world x of the thing being dragged
129 double _original_y; ///< original world y of the thing being dragged
130 double _grab_x; ///< item x of the grab start position
131 double _grab_y; ///< item y of the grab start position
132 double _current_pointer_x; ///< item x of the current pointer
133 double _current_pointer_y; ///< item y of the current pointer
134 double _last_pointer_x; ///< item x of the pointer last time a motion occurred
135 double _last_pointer_y; ///< item y of the pointer last time a motion occurred
136 bool _x_constrained; ///< true if x motion is constrained, otherwise false
137 bool _y_constrained; ///< true if y motion is constrained, otherwise false
138 bool _was_rolling; ///< true if the session was rolling before the drag started, otherwise false
142 bool _ending; ///< true if end_grab is in progress, otherwise false
143 bool _had_movement; ///< true if movement has occurred, otherwise false
144 bool _move_threshold_passed; ///< true if the move threshold has been passed, otherwise false
148 /** Abstract base class for drags that involve region(s) */
149 class RegionDrag : public Drag, public sigc::trackable
152 RegionDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
153 virtual ~RegionDrag () {}
157 RegionView* _primary; ///< the view that was clicked on (or whatever) to start the drag
158 std::list<RegionView*> _views; ///< all views that are being dragged
161 void region_going_away (RegionView *);
165 /** Drags involving region motion from somewhere */
166 class RegionMotionDrag : public RegionDrag
170 RegionMotionDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &, bool);
171 virtual ~RegionMotionDrag () {}
173 virtual void start_grab (GdkEvent *, Gdk::Cursor *);
174 virtual void motion (GdkEvent *, bool);
175 virtual void finished (GdkEvent *, bool) = 0;
178 struct TimeAxisViewSummary {
179 TimeAxisViewSummary () : height_list(512) {}
181 std::bitset<512> tracks;
182 std::vector<int32_t> height_list;
187 void copy_regions (GdkEvent *);
188 bool y_movement_disallowed (int, int, int, TimeAxisViewSummary const &) const;
189 std::map<RegionView*, std::pair<RouteTimeAxisView*, int> > find_time_axis_views_and_layers ();
190 double compute_x_delta (GdkEvent const *, nframes64_t *);
191 bool compute_y_delta (
192 TimeAxisView const *, TimeAxisView*, int32_t, int32_t, TimeAxisViewSummary const &,
193 int32_t *, int32_t *, int32_t *
196 TimeAxisViewSummary get_time_axis_view_summary ();
197 virtual bool x_move_allowed () const = 0;
199 TimeAxisView* _dest_trackview;
200 ARDOUR::layer_t _dest_layer;
201 bool check_possible (RouteTimeAxisView **, ARDOUR::layer_t *);
206 /** Drags to move (or copy) regions that are already shown in the GUI to
207 * somewhere different.
209 class RegionMoveDrag : public RegionMotionDrag
212 RegionMoveDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &, bool, bool);
213 virtual ~RegionMoveDrag () {}
215 virtual void start_grab (GdkEvent *, Gdk::Cursor *);
216 void motion (GdkEvent *, bool);
217 void finished (GdkEvent *, bool);
219 bool apply_move_threshold () const {
224 bool x_move_allowed () const;
229 /** Drag to insert a region from somewhere */
230 class RegionInsertDrag : public RegionMotionDrag
233 RegionInsertDrag (Editor *, boost::shared_ptr<ARDOUR::Region>, RouteTimeAxisView*, nframes64_t);
235 void finished (GdkEvent *, bool);
238 bool x_move_allowed () const;
241 /** Region drag in splice mode */
242 class RegionSpliceDrag : public RegionMoveDrag
245 RegionSpliceDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
247 void motion (GdkEvent *, bool);
248 void finished (GdkEvent *, bool);
251 /** Drags to create regions */
252 class RegionCreateDrag : public Drag
255 RegionCreateDrag (Editor *, ArdourCanvas::Item *, TimeAxisView *);
257 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
258 void motion (GdkEvent *, bool);
259 void finished (GdkEvent *, bool);
263 TimeAxisView* _dest_trackview;
266 /** Drags to resize MIDI notes */
267 class NoteResizeDrag : public Drag
270 NoteResizeDrag (Editor *, ArdourCanvas::Item *);
272 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
273 void motion (GdkEvent *, bool);
274 void finished (GdkEvent *, bool);
277 MidiRegionView* region;
282 class NoteDrag : public Drag
285 NoteDrag (Editor*, ArdourCanvas::Item*);
287 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
288 void motion (GdkEvent *, bool);
289 void finished (GdkEvent *, bool);
292 MidiRegionView* region;
296 double drag_delta_note;
300 /** Drag of region gain */
301 class RegionGainDrag : public Drag
304 RegionGainDrag (Editor *e, ArdourCanvas::Item *i) : Drag (e, i) {}
306 void motion (GdkEvent *, bool);
307 void finished (GdkEvent *, bool);
308 bool active (Editing::MouseMode m) {
309 return (m == Editing::MouseGain);
313 /** Drag to trim region(s) */
314 class TrimDrag : public RegionDrag
323 TrimDrag (Editor *, ArdourCanvas::Item *, RegionView*, std::list<RegionView*> const &);
325 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
326 void motion (GdkEvent *, bool);
327 void finished (GdkEvent *, bool);
331 Operation _operation;
334 /** Meter marker drag */
335 class MeterMarkerDrag : public Drag
338 MeterMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
340 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
341 void motion (GdkEvent *, bool);
342 void finished (GdkEvent *, bool);
345 MeterMarker* _marker;
349 /** Tempo marker drag */
350 class TempoMarkerDrag : public Drag
353 TempoMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
355 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
356 void motion (GdkEvent *, bool);
357 void finished (GdkEvent *, bool);
360 TempoMarker* _marker;
365 /** Drag of a cursor */
366 class CursorDrag : public Drag
369 CursorDrag (Editor *, ArdourCanvas::Item *, bool);
371 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
372 void motion (GdkEvent *, bool);
373 void finished (GdkEvent *, bool);
375 bool active (Editing::MouseMode) {
379 bool allow_vertical_autoscroll () const {
384 EditorCursor* _cursor; ///< cursor being dragged
385 bool _stop; ///< true to stop the transport on starting the drag, otherwise false
389 /** Region fade-in drag */
390 class FadeInDrag : public RegionDrag
393 FadeInDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
395 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
396 void motion (GdkEvent *, bool);
397 void finished (GdkEvent *, bool);
400 /** Region fade-out drag */
401 class FadeOutDrag : public RegionDrag
404 FadeOutDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
406 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
407 void motion (GdkEvent *, bool);
408 void finished (GdkEvent *, bool);
412 class MarkerDrag : public Drag
415 MarkerDrag (Editor *, ArdourCanvas::Item *);
418 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
419 void motion (GdkEvent *, bool);
420 void finished (GdkEvent *, bool);
423 void update_item (ARDOUR::Location *);
425 Marker* _marker; ///< marker being dragged
426 std::list<ARDOUR::Location*> _copied_locations;
427 ArdourCanvas::Line* _line;
428 ArdourCanvas::Points _points;
431 /** Control point drag */
432 class ControlPointDrag : public Drag
435 ControlPointDrag (Editor *, ArdourCanvas::Item *);
437 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
438 void motion (GdkEvent *, bool);
439 void finished (GdkEvent *, bool);
441 bool active (Editing::MouseMode m);
445 ControlPoint* _point;
446 double _cumulative_x_drag;
447 double _cumulative_y_drag;
448 static double const _zero_gain_fraction;
451 /** Gain or automation line drag */
452 class LineDrag : public Drag
455 LineDrag (Editor *e, ArdourCanvas::Item *i);
457 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
458 void motion (GdkEvent *, bool);
459 void finished (GdkEvent *, bool);
461 bool active (Editing::MouseMode) {
467 AutomationLine* _line;
470 double _cumulative_y_drag;
473 /** Dragging of a rubberband rectangle for selecting things */
474 class RubberbandSelectDrag : public Drag
477 RubberbandSelectDrag (Editor *e, ArdourCanvas::Item *i) : Drag (e, i) {}
479 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
480 void motion (GdkEvent *, bool);
481 void finished (GdkEvent *, bool);
484 /** Region drag in time-FX mode */
485 class TimeFXDrag : public RegionDrag
488 TimeFXDrag (Editor *e, ArdourCanvas::Item *i, RegionView* p, std::list<RegionView*> const & v) : RegionDrag (e, i, p, v) {}
490 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
491 void motion (GdkEvent *, bool);
492 void finished (GdkEvent *, bool);
495 /** Scrub drag in audition mode */
496 class ScrubDrag : public Drag
499 ScrubDrag (Editor *e, ArdourCanvas::Item *i) : Drag (e, i) {}
501 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
502 void motion (GdkEvent *, bool);
503 void finished (GdkEvent *, bool);
506 /** Drag in range select(gc_owner.get()) moAutomatable */
507 class SelectionDrag : public Drag
517 SelectionDrag (Editor *, ArdourCanvas::Item *, Operation);
519 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
520 void motion (GdkEvent *, bool);
521 void finished (GdkEvent *, bool);
524 Operation _operation;
528 /** Range marker drag */
529 class RangeMarkerBarDrag : public Drag
534 CreateTransportMarker,
538 RangeMarkerBarDrag (Editor *, ArdourCanvas::Item *, Operation);
540 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
541 void motion (GdkEvent *, bool);
542 void finished (GdkEvent *, bool);
545 void update_item (ARDOUR::Location *);
547 Operation _operation;
548 ArdourCanvas::SimpleRect* _drag_rect;
552 /* Drag of rectangle to set zoom */
553 class MouseZoomDrag : public Drag
556 MouseZoomDrag (Editor *e, ArdourCanvas::Item *i) : Drag (e, i) {}
558 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
559 void motion (GdkEvent *, bool);
560 void finished (GdkEvent *, bool);
563 #endif /* __gtk2_ardour_editor_drag_h_ */