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"
42 /** Class to manage current drags */
47 DragManager (Editor* e);
50 bool motion_handler (GdkEvent *, bool);
54 void set (Drag *, GdkEvent *, Gdk::Cursor* c = 0);
55 void start_grab (GdkEvent *);
56 bool end_grab (GdkEvent *);
57 bool have_item (ArdourCanvas::Item *) const;
59 /** @return true if an end drag or abort is in progress */
60 bool ending () const {
64 bool active () const {
65 return !_drags.empty ();
68 /** @return current pointer x position in trackview coordinates */
69 double current_pointer_x () const {
70 return _current_pointer_x;
73 /** @return current pointer y position in trackview coordinates */
74 double current_pointer_y () const {
75 return _current_pointer_y;
78 /** @return current pointer frame */
79 nframes64_t current_pointer_frame () const {
80 return _current_pointer_frame;
85 std::list<Drag*> _drags;
86 bool _ending; ///< true if end_grab or abort is in progress, otherwise false
87 double _current_pointer_x; ///< trackview x of the current pointer
88 double _current_pointer_y; ///< trackview y of the current pointer
89 nframes64_t _current_pointer_frame; ///< frame that the pointer is now at
92 /** Abstract base class for dragging of things within the editor */
96 Drag (Editor *, ArdourCanvas::Item *);
99 void set_manager (DragManager* m) {
103 /** @return the canvas item being dragged */
104 ArdourCanvas::Item* item () const {
108 void swap_grab (ArdourCanvas::Item *, Gdk::Cursor *, uint32_t);
109 bool motion_handler (GdkEvent*, bool);
112 nframes64_t adjusted_frame (nframes64_t, GdkEvent const *, bool snap = true) const;
113 nframes64_t adjusted_current_frame (GdkEvent const *, bool snap = true) const;
115 /** Called to start a grab of an item.
116 * @param e Event that caused the grab to start.
117 * @param c Cursor to use, or 0.
119 virtual void start_grab (GdkEvent* e, Gdk::Cursor* c = 0);
121 virtual bool end_grab (GdkEvent *);
123 /** Called when a drag motion has occurred.
124 * @param e Event describing the motion.
125 * @param f true if this is the first movement, otherwise false.
127 virtual void motion (GdkEvent* e, bool f) = 0;
129 /** Called when a drag has finished.
130 * @param e Event describing the finish.
131 * @param m true if some movement occurred, otherwise false.
133 virtual void finished (GdkEvent* e, bool m) = 0;
135 /** Called to abort a drag and return things to how
136 * they were before it started.
138 virtual void aborted () = 0;
140 /** @param m Mouse mode.
141 * @return true if this drag should happen in this mouse mode.
143 virtual bool active (Editing::MouseMode m) {
144 return (m != Editing::MouseGain);
147 /** @return minimum number of frames (in x) and pixels (in y) that should be considered a movement */
148 virtual std::pair<nframes64_t, int> move_threshold () const {
149 return std::make_pair (1, 1);
152 virtual bool allow_vertical_autoscroll () const {
156 /** @return true if x movement matters to this drag */
157 virtual bool x_movement_matters () const {
161 /** @return true if y movement matters to this drag */
162 virtual bool y_movement_matters () const {
168 double grab_x () const {
172 double grab_y () const {
176 double grab_frame () const {
180 double last_pointer_x () const {
181 return _last_pointer_x;
184 double last_pointer_y () const {
185 return _last_pointer_y;
188 double last_pointer_frame () const {
189 return _last_pointer_frame;
192 Editor* _editor; ///< our editor
194 ArdourCanvas::Item* _item; ///< our item
195 /** Offset from the mouse's position for the drag to the start of the thing that is being dragged */
196 nframes64_t _pointer_frame_offset;
197 bool _x_constrained; ///< true if x motion is constrained, otherwise false
198 bool _y_constrained; ///< true if y motion is constrained, otherwise false
199 bool _was_rolling; ///< true if the session was rolling before the drag started, otherwise false
203 bool _move_threshold_passed; ///< true if the move threshold has been passed, otherwise false
204 double _grab_x; ///< trackview x of the grab start position
205 double _grab_y; ///< trackview y of the grab start position
206 double _last_pointer_x; ///< trackview x of the pointer last time a motion occurred
207 double _last_pointer_y; ///< trackview y of the pointer last time a motion occurred
208 nframes64_t _grab_frame; ///< adjusted_frame that the mouse was at when start_grab was called, or 0
209 nframes64_t _last_pointer_frame; ///< adjusted_frame the last time a motion occurred
214 DraggingView (RegionView* v);
216 RegionView* view; ///< the view
217 double initial_y; ///< the initial y position of the view before any reparenting
220 /** Abstract base class for drags that involve region(s) */
221 class RegionDrag : public Drag, public sigc::trackable
224 RegionDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
225 virtual ~RegionDrag () {}
229 RegionView* _primary; ///< the view that was clicked on (or whatever) to start the drag
230 std::list<DraggingView> _views; ///< information about all views that are being dragged
233 void region_going_away (RegionView *);
234 PBD::ScopedConnection death_connection;
238 /** Drags involving region motion from somewhere */
239 class RegionMotionDrag : public RegionDrag
243 RegionMotionDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &, bool);
244 virtual ~RegionMotionDrag () {}
246 virtual void start_grab (GdkEvent *, Gdk::Cursor *);
247 virtual void motion (GdkEvent *, bool);
248 virtual void finished (GdkEvent *, bool) = 0;
249 virtual void aborted ();
252 struct TimeAxisViewSummary {
253 TimeAxisViewSummary () : height_list(512) {}
255 std::bitset<512> tracks;
256 std::vector<int32_t> height_list;
261 void copy_regions (GdkEvent *);
262 bool y_movement_disallowed (int, int, int, TimeAxisViewSummary const &) const;
263 std::map<RegionView*, std::pair<RouteTimeAxisView*, int> > find_time_axis_views_and_layers ();
264 double compute_x_delta (GdkEvent const *, nframes64_t *);
265 bool compute_y_delta (
266 TimeAxisView const *, TimeAxisView*, int32_t, int32_t, TimeAxisViewSummary const &,
267 int32_t *, int32_t *, int32_t *
270 TimeAxisViewSummary get_time_axis_view_summary ();
271 bool x_move_allowed () const;
273 TimeAxisView* _dest_trackview;
274 ARDOUR::layer_t _dest_layer;
275 bool check_possible (RouteTimeAxisView **, ARDOUR::layer_t *);
277 nframes64_t _last_frame_position; ///< last position of the thing being dragged
278 double _total_x_delta;
282 /** Drags to move (or copy) regions that are already shown in the GUI to
283 * somewhere different.
285 class RegionMoveDrag : public RegionMotionDrag
288 RegionMoveDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &, bool, bool);
289 virtual ~RegionMoveDrag () {}
291 virtual void start_grab (GdkEvent *, Gdk::Cursor *);
292 void motion (GdkEvent *, bool);
293 void finished (GdkEvent *, bool);
296 std::pair<nframes64_t, int> move_threshold () const {
297 return std::make_pair (4, 4);
304 /** Drag to insert a region from somewhere */
305 class RegionInsertDrag : public RegionMotionDrag
308 RegionInsertDrag (Editor *, boost::shared_ptr<ARDOUR::Region>, RouteTimeAxisView*, nframes64_t);
310 void finished (GdkEvent *, bool);
314 /** Region drag in splice mode */
315 class RegionSpliceDrag : public RegionMoveDrag
318 RegionSpliceDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
320 void motion (GdkEvent *, bool);
321 void finished (GdkEvent *, bool);
325 /** Drags to create regions */
326 class RegionCreateDrag : public Drag
329 RegionCreateDrag (Editor *, ArdourCanvas::Item *, TimeAxisView *);
331 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
332 void motion (GdkEvent *, bool);
333 void finished (GdkEvent *, bool);
338 TimeAxisView* _dest_trackview;
341 /** Drags to resize MIDI notes */
342 class NoteResizeDrag : public Drag
345 NoteResizeDrag (Editor *, ArdourCanvas::Item *);
347 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
348 void motion (GdkEvent *, bool);
349 void finished (GdkEvent *, bool);
353 MidiRegionView* region;
358 class NoteDrag : public Drag
361 NoteDrag (Editor*, ArdourCanvas::Item*);
363 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
364 void motion (GdkEvent *, bool);
365 void finished (GdkEvent *, bool);
369 MidiRegionView* region;
373 double drag_delta_note;
377 /** Drag of region gain */
378 class RegionGainDrag : public Drag
381 RegionGainDrag (Editor *e, ArdourCanvas::Item *i) : Drag (e, i) {}
383 void motion (GdkEvent *, bool);
384 void finished (GdkEvent *, bool);
385 bool active (Editing::MouseMode m) {
386 return (m == Editing::MouseGain);
392 /** Drag to trim region(s) */
393 class TrimDrag : public RegionDrag
402 TrimDrag (Editor *, ArdourCanvas::Item *, RegionView*, std::list<RegionView*> const &);
404 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
405 void motion (GdkEvent *, bool);
406 void finished (GdkEvent *, bool);
409 bool y_movement_matters () const {
415 Operation _operation;
416 bool _have_transaction; ///< true if a transaction has been started, false otherwise. Must be set true by derived class.
419 /** Meter marker drag */
420 class MeterMarkerDrag : public Drag
423 MeterMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
425 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
426 void motion (GdkEvent *, bool);
427 void finished (GdkEvent *, bool);
430 bool allow_vertical_autoscroll () const {
434 bool y_movement_matters () const {
439 MeterMarker* _marker;
443 /** Tempo marker drag */
444 class TempoMarkerDrag : public Drag
447 TempoMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
449 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
450 void motion (GdkEvent *, bool);
451 void finished (GdkEvent *, bool);
454 bool allow_vertical_autoscroll () const {
458 bool y_movement_matters () const {
463 TempoMarker* _marker;
468 /** Drag of a cursor */
469 class CursorDrag : public Drag
472 CursorDrag (Editor *, ArdourCanvas::Item *, bool);
474 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
475 void motion (GdkEvent *, bool);
476 void finished (GdkEvent *, bool);
479 bool active (Editing::MouseMode) {
483 bool allow_vertical_autoscroll () const {
487 bool y_movement_matters () const {
492 EditorCursor* _cursor; ///< cursor being dragged
493 bool _stop; ///< true to stop the transport on starting the drag, otherwise false
497 /** Region fade-in drag */
498 class FadeInDrag : public RegionDrag
501 FadeInDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
503 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
504 void motion (GdkEvent *, bool);
505 void finished (GdkEvent *, bool);
508 bool y_movement_matters () const {
513 /** Region fade-out drag */
514 class FadeOutDrag : public RegionDrag
517 FadeOutDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
519 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
520 void motion (GdkEvent *, bool);
521 void finished (GdkEvent *, bool);
524 bool y_movement_matters () const {
530 class MarkerDrag : public Drag
533 MarkerDrag (Editor *, ArdourCanvas::Item *);
536 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
537 void motion (GdkEvent *, bool);
538 void finished (GdkEvent *, bool);
541 bool allow_vertical_autoscroll () const {
545 bool y_movement_matters () const {
550 void update_item (ARDOUR::Location *);
552 Marker* _marker; ///< marker being dragged
553 std::list<ARDOUR::Location*> _copied_locations;
554 ArdourCanvas::Line* _line;
555 ArdourCanvas::Points _points;
558 /** Control point drag */
559 class ControlPointDrag : public Drag
562 ControlPointDrag (Editor *, ArdourCanvas::Item *);
564 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
565 void motion (GdkEvent *, bool);
566 void finished (GdkEvent *, bool);
569 bool active (Editing::MouseMode m);
573 ControlPoint* _point;
574 double _time_axis_view_grab_x;
575 double _time_axis_view_grab_y;
576 double _cumulative_x_drag;
577 double _cumulative_y_drag;
578 static double const _zero_gain_fraction;
581 /** Gain or automation line drag */
582 class LineDrag : public Drag
585 LineDrag (Editor *e, ArdourCanvas::Item *i);
587 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
588 void motion (GdkEvent *, bool);
589 void finished (GdkEvent *, bool);
592 bool active (Editing::MouseMode) {
598 AutomationLine* _line;
599 double _time_axis_view_grab_x;
600 double _time_axis_view_grab_y;
603 double _cumulative_y_drag;
606 /** Dragging of a rubberband rectangle for selecting things */
607 class RubberbandSelectDrag : public Drag
610 RubberbandSelectDrag (Editor *e, ArdourCanvas::Item *i) : Drag (e, i) {}
612 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
613 void motion (GdkEvent *, bool);
614 void finished (GdkEvent *, bool);
617 std::pair<nframes64_t, int> move_threshold () const {
618 return std::make_pair (8, 1);
622 /** Region drag in time-FX mode */
623 class TimeFXDrag : public RegionDrag
626 TimeFXDrag (Editor *e, ArdourCanvas::Item *i, RegionView* p, std::list<RegionView*> const & v) : RegionDrag (e, i, p, v) {}
628 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
629 void motion (GdkEvent *, bool);
630 void finished (GdkEvent *, bool);
634 /** Scrub drag in audition mode */
635 class ScrubDrag : public Drag
638 ScrubDrag (Editor *e, ArdourCanvas::Item *i) : Drag (e, i) {}
640 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
641 void motion (GdkEvent *, bool);
642 void finished (GdkEvent *, bool);
646 /** Drag in range select mode */
647 class SelectionDrag : public Drag
657 SelectionDrag (Editor *, ArdourCanvas::Item *, Operation);
659 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
660 void motion (GdkEvent *, bool);
661 void finished (GdkEvent *, bool);
665 Operation _operation;
667 int _original_pointer_time_axis;
668 int _last_pointer_time_axis;
669 std::list<TimeAxisView*> _added_time_axes;
672 /** Range marker drag */
673 class RangeMarkerBarDrag : public Drag
678 CreateTransportMarker,
682 RangeMarkerBarDrag (Editor *, ArdourCanvas::Item *, Operation);
684 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
685 void motion (GdkEvent *, bool);
686 void finished (GdkEvent *, bool);
689 bool allow_vertical_autoscroll () const {
693 bool y_movement_matters () const {
698 void update_item (ARDOUR::Location *);
700 Operation _operation;
701 ArdourCanvas::SimpleRect* _drag_rect;
705 /** Drag of rectangle to set zoom */
706 class MouseZoomDrag : public Drag
709 MouseZoomDrag (Editor* e, ArdourCanvas::Item *i) : Drag (e, i) {}
711 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
712 void motion (GdkEvent *, bool);
713 void finished (GdkEvent *, bool);
717 /** Drag of a range of automation data, changing value but not position */
718 class AutomationRangeDrag : public Drag
721 AutomationRangeDrag (Editor *, ArdourCanvas::Item *, std::list<ARDOUR::AudioRange> const &);
723 void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
724 void motion (GdkEvent *, bool);
725 void finished (GdkEvent *, bool);
728 bool x_movement_matters () const {
733 std::list<ARDOUR::AudioRange> _ranges;
734 AutomationTimeAxisView* _atav;
735 boost::shared_ptr<AutomationLine> _line;
736 bool _nothing_to_drag;
739 #endif /* __gtk2_ardour_editor_drag_h_ */