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);
55 bool motion_handler (GdkEvent*, bool);
58 /** @return true if an end drag is in progress */
59 bool ending () const {
63 /** @return current pointer x position in trackview coordinates */
64 double current_pointer_x () const {
65 return _current_pointer_x;
68 /** @return current pointer y position in trackview coordinates */
69 double current_pointer_y () const {
70 return _current_pointer_y;
73 nframes64_t adjusted_frame (nframes64_t, GdkEvent const *, bool snap = true) const;
74 nframes64_t adjusted_current_frame (GdkEvent const *, bool snap = true) const;
76 /** Called to start a grab of an item.
77 * @param e Event that caused the grab to start.
78 * @param c Cursor to use, or 0.
80 virtual void start_grab (GdkEvent* e, Gdk::Cursor* c = 0);
82 virtual bool end_grab (GdkEvent *);
84 /** Called when a drag motion has occurred.
85 * @param e Event describing the motion.
86 * @param f true if this is the first movement, otherwise false.
88 virtual void motion (GdkEvent* e, bool f) = 0;
90 /** Called when a drag has finished.
91 * @param e Event describing the finish.
92 * @param m true if some movement occurred, otherwise false.
94 virtual void finished (GdkEvent* e, bool m) = 0;
96 /** Called to abort a drag and return things to how
97 * they were before it started.
99 virtual void aborted () = 0;
101 /** @param m Mouse mode.
102 * @return true if this drag should happen in this mouse mode.
104 virtual bool active (Editing::MouseMode m) {
105 return (m != Editing::MouseGain);
108 /** @return minimum number of frames (in x) and pixels (in y) that should be considered a movement */
109 virtual std::pair<nframes64_t, int> move_threshold () const {
110 return std::make_pair (1, 1);
113 virtual bool allow_vertical_autoscroll () const {
117 /** @return true if x movement matters to this drag */
118 virtual bool x_movement_matters () const {
122 /** @return true if y movement matters to this drag */
123 virtual bool y_movement_matters () const {
127 /** @return current x extent of the thing being dragged; ie
128 * a pair of (leftmost_position, rightmost_position)
130 virtual std::pair<nframes64_t, nframes64_t> extent () const;
134 double grab_x () const {
138 double grab_y () const {
142 double grab_frame () const {
146 double last_pointer_x () const {
147 return _last_pointer_x;
150 double last_pointer_y () const {
151 return _last_pointer_y;
154 double last_pointer_frame () const {
155 return _last_pointer_frame;
158 Editor* _editor; ///< our editor
159 ArdourCanvas::Item* _item; ///< our item
160 /** Offset from the mouse's position for the drag to the start of the thing that is being dragged */
161 nframes64_t _pointer_frame_offset;
162 bool _x_constrained; ///< true if x motion is constrained, otherwise false
163 bool _y_constrained; ///< true if y motion is constrained, otherwise false
164 bool _was_rolling; ///< true if the session was rolling before the drag started, otherwise false
165 bool _have_transaction; ///< true if a transaction has been started, false otherwise. Must be set true by derived class.
169 bool _ending; ///< true if end_grab or break_drag is in progress, otherwise false
170 bool _move_threshold_passed; ///< true if the move threshold has been passed, otherwise false
171 double _grab_x; ///< trackview x of the grab start position
172 double _grab_y; ///< trackview y of the grab start position
173 double _current_pointer_x; ///< trackview x of the current pointer
174 double _current_pointer_y; ///< trackview y of the current pointer
175 double _last_pointer_x; ///< trackview x of the pointer last time a motion occurred
176 double _last_pointer_y; ///< trackview y of the pointer last time a motion occurred
177 nframes64_t _grab_frame; ///< adjusted_frame that the mouse was at when start_grab was called, or 0
178 nframes64_t _last_pointer_frame; ///< adjusted_frame the last time a motion occurred
179 nframes64_t _current_pointer_frame; ///< frame that the pointer is now at
183 /** Abstract base class for drags that involve region(s) */
184 class RegionDrag : public Drag, public sigc::trackable
187 RegionDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
188 virtual ~RegionDrag () {}
190 std::pair<nframes64_t, nframes64_t> extent () const;
194 RegionView* _primary; ///< the view that was clicked on (or whatever) to start the drag
195 std::list<RegionView*> _views; ///< all views that are being dragged
198 void region_going_away (RegionView *);
199 PBD::ScopedConnection death_connection;
203 /** Drags involving region motion from somewhere */
204 class RegionMotionDrag : public RegionDrag
208 RegionMotionDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &, bool);
209 virtual ~RegionMotionDrag () {}
211 virtual void start_grab (GdkEvent *, Gdk::Cursor *);
212 virtual void motion (GdkEvent *, bool);
213 virtual void finished (GdkEvent *, bool) = 0;
214 virtual void aborted ();
217 struct TimeAxisViewSummary {
218 TimeAxisViewSummary () : height_list(512) {}
220 std::bitset<512> tracks;
221 std::vector<int32_t> height_list;
226 void copy_regions (GdkEvent *);
227 bool y_movement_disallowed (int, int, int, TimeAxisViewSummary const &) const;
228 std::map<RegionView*, std::pair<RouteTimeAxisView*, int> > find_time_axis_views_and_layers ();
229 double compute_x_delta (GdkEvent const *, nframes64_t *);
230 bool compute_y_delta (
231 TimeAxisView const *, TimeAxisView*, int32_t, int32_t, TimeAxisViewSummary const &,
232 int32_t *, int32_t *, int32_t *
235 TimeAxisViewSummary get_time_axis_view_summary ();
236 bool x_move_allowed () const;
238 TimeAxisView* _dest_trackview;
239 ARDOUR::layer_t _dest_layer;
240 bool check_possible (RouteTimeAxisView **, ARDOUR::layer_t *);
242 nframes64_t _last_frame_position; ///< last position of the thing being dragged
243 double _total_x_delta;
247 /** Drags to move (or copy) regions that are already shown in the GUI to
248 * somewhere different.
250 class RegionMoveDrag : public RegionMotionDrag
253 RegionMoveDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &, bool, bool);
254 virtual ~RegionMoveDrag () {}
256 virtual void start_grab (GdkEvent *, Gdk::Cursor *);
257 void motion (GdkEvent *, bool);
258 void finished (GdkEvent *, bool);
261 std::pair<nframes64_t, int> move_threshold () const {
262 return std::make_pair (4, 4);
269 /** Drag to insert a region from somewhere */
270 class RegionInsertDrag : public RegionMotionDrag
273 RegionInsertDrag (Editor *, boost::shared_ptr<ARDOUR::Region>, RouteTimeAxisView*, nframes64_t);
275 void finished (GdkEvent *, bool);
279 /** Region drag in splice mode */
280 class RegionSpliceDrag : public RegionMoveDrag
283 RegionSpliceDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
285 void motion (GdkEvent *, bool);
286 void finished (GdkEvent *, bool);
290 /** Drags to create regions */
291 class RegionCreateDrag : public Drag
294 RegionCreateDrag (Editor *, ArdourCanvas::Item *, TimeAxisView *);
296 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
297 void motion (GdkEvent *, bool);
298 void finished (GdkEvent *, bool);
303 TimeAxisView* _dest_trackview;
306 /** Drags to resize MIDI notes */
307 class NoteResizeDrag : public Drag
310 NoteResizeDrag (Editor *, ArdourCanvas::Item *);
312 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
313 void motion (GdkEvent *, bool);
314 void finished (GdkEvent *, bool);
318 MidiRegionView* region;
323 class NoteDrag : public Drag
326 NoteDrag (Editor*, ArdourCanvas::Item*);
328 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
329 void motion (GdkEvent *, bool);
330 void finished (GdkEvent *, bool);
334 MidiRegionView* region;
338 double drag_delta_note;
342 /** Drag of region gain */
343 class RegionGainDrag : public Drag
346 RegionGainDrag (Editor *e, ArdourCanvas::Item *i) : Drag (e, i) {}
348 void motion (GdkEvent *, bool);
349 void finished (GdkEvent *, bool);
350 bool active (Editing::MouseMode m) {
351 return (m == Editing::MouseGain);
357 /** Drag to trim region(s) */
358 class TrimDrag : public RegionDrag
367 TrimDrag (Editor *, ArdourCanvas::Item *, RegionView*, std::list<RegionView*> const &);
369 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
370 void motion (GdkEvent *, bool);
371 void finished (GdkEvent *, bool);
374 bool y_movement_matters () const {
380 Operation _operation;
383 /** Meter marker drag */
384 class MeterMarkerDrag : public Drag
387 MeterMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
389 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
390 void motion (GdkEvent *, bool);
391 void finished (GdkEvent *, bool);
394 bool allow_vertical_autoscroll () const {
398 bool y_movement_matters () const {
403 MeterMarker* _marker;
407 /** Tempo marker drag */
408 class TempoMarkerDrag : public Drag
411 TempoMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
413 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
414 void motion (GdkEvent *, bool);
415 void finished (GdkEvent *, bool);
418 bool allow_vertical_autoscroll () const {
422 bool y_movement_matters () const {
427 TempoMarker* _marker;
432 /** Drag of a cursor */
433 class CursorDrag : public Drag
436 CursorDrag (Editor *, ArdourCanvas::Item *, bool);
438 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
439 void motion (GdkEvent *, bool);
440 void finished (GdkEvent *, bool);
443 bool active (Editing::MouseMode) {
447 bool allow_vertical_autoscroll () const {
451 bool y_movement_matters () const {
456 EditorCursor* _cursor; ///< cursor being dragged
457 bool _stop; ///< true to stop the transport on starting the drag, otherwise false
461 /** Region fade-in drag */
462 class FadeInDrag : public RegionDrag
465 FadeInDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
467 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
468 void motion (GdkEvent *, bool);
469 void finished (GdkEvent *, bool);
472 bool y_movement_matters () const {
477 /** Region fade-out drag */
478 class FadeOutDrag : public RegionDrag
481 FadeOutDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
483 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
484 void motion (GdkEvent *, bool);
485 void finished (GdkEvent *, bool);
488 bool y_movement_matters () const {
494 class MarkerDrag : public Drag
497 MarkerDrag (Editor *, ArdourCanvas::Item *);
500 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
501 void motion (GdkEvent *, bool);
502 void finished (GdkEvent *, bool);
505 bool allow_vertical_autoscroll () const {
509 bool y_movement_matters () const {
514 void update_item (ARDOUR::Location *);
516 Marker* _marker; ///< marker being dragged
517 std::list<ARDOUR::Location*> _copied_locations;
518 ArdourCanvas::Line* _line;
519 ArdourCanvas::Points _points;
522 /** Control point drag */
523 class ControlPointDrag : public Drag
526 ControlPointDrag (Editor *, ArdourCanvas::Item *);
528 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
529 void motion (GdkEvent *, bool);
530 void finished (GdkEvent *, bool);
533 bool active (Editing::MouseMode m);
537 ControlPoint* _point;
538 double _time_axis_view_grab_x;
539 double _time_axis_view_grab_y;
540 double _cumulative_x_drag;
541 double _cumulative_y_drag;
542 static double const _zero_gain_fraction;
545 /** Gain or automation line drag */
546 class LineDrag : public Drag
549 LineDrag (Editor *e, ArdourCanvas::Item *i);
551 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
552 void motion (GdkEvent *, bool);
553 void finished (GdkEvent *, bool);
556 bool active (Editing::MouseMode) {
562 AutomationLine* _line;
563 double _time_axis_view_grab_x;
564 double _time_axis_view_grab_y;
567 double _cumulative_y_drag;
570 /** Dragging of a rubberband rectangle for selecting things */
571 class RubberbandSelectDrag : public Drag
574 RubberbandSelectDrag (Editor *e, ArdourCanvas::Item *i) : Drag (e, i) {}
576 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
577 void motion (GdkEvent *, bool);
578 void finished (GdkEvent *, bool);
582 /** Region drag in time-FX mode */
583 class TimeFXDrag : public RegionDrag
586 TimeFXDrag (Editor *e, ArdourCanvas::Item *i, RegionView* p, std::list<RegionView*> const & v) : RegionDrag (e, i, p, v) {}
588 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
589 void motion (GdkEvent *, bool);
590 void finished (GdkEvent *, bool);
594 /** Scrub drag in audition mode */
595 class ScrubDrag : public Drag
598 ScrubDrag (Editor *e, ArdourCanvas::Item *i) : Drag (e, i) {}
600 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
601 void motion (GdkEvent *, bool);
602 void finished (GdkEvent *, bool);
606 /** Drag in range select mode */
607 class SelectionDrag : public Drag
617 SelectionDrag (Editor *, ArdourCanvas::Item *, Operation);
619 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
620 void motion (GdkEvent *, bool);
621 void finished (GdkEvent *, bool);
625 Operation _operation;
627 int _original_pointer_time_axis;
628 int _last_pointer_time_axis;
629 std::list<TimeAxisView*> _added_time_axes;
632 /** Range marker drag */
633 class RangeMarkerBarDrag : public Drag
638 CreateTransportMarker,
642 RangeMarkerBarDrag (Editor *, ArdourCanvas::Item *, Operation);
644 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
645 void motion (GdkEvent *, bool);
646 void finished (GdkEvent *, bool);
649 bool allow_vertical_autoscroll () const {
653 bool y_movement_matters () const {
658 void update_item (ARDOUR::Location *);
660 Operation _operation;
661 ArdourCanvas::SimpleRect* _drag_rect;
665 /** Drag of rectangle to set zoom */
666 class MouseZoomDrag : public Drag
669 MouseZoomDrag (Editor* e, ArdourCanvas::Item *i) : Drag (e, i) {}
671 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
672 void motion (GdkEvent *, bool);
673 void finished (GdkEvent *, bool);
677 /** Drag of a range of automation data, changing value but not position */
678 class AutomationRangeDrag : public Drag
681 AutomationRangeDrag (Editor *, ArdourCanvas::Item *, std::list<ARDOUR::AudioRange> const &);
683 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
684 void motion (GdkEvent *, bool);
685 void finished (GdkEvent *, bool);
688 bool x_movement_matters () const {
693 std::list<ARDOUR::AudioRange> _ranges;
694 AutomationTimeAxisView* _atav;
695 boost::shared_ptr<AutomationLine> _line;
696 bool _nothing_to_drag;
699 #endif /* __gtk2_ardour_editor_drag_h_ */