f39f5cfcb3e006148bb521c613aefc3d5cdad1dd
[ardour.git] / gtk2_ardour / editor_drag.h
1 /*
2     Copyright (C) 2009 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #ifndef __gtk2_ardour_editor_drag_h_
21 #define __gtk2_ardour_editor_drag_h_
22
23 #include <list>
24
25 #include <gdk/gdk.h>
26 #include <stdint.h>
27
28 #include "ardour/types.h"
29
30 #include "canvas.h"
31 #include "editor_items.h"
32
33 namespace ARDOUR {
34         class Location;
35 }
36
37 namespace PBD {
38         class StatefulDiffCommand;
39 }
40
41 namespace Gnome {
42         namespace Canvas {
43                 class CanvasNoteEvent;
44                 class CanvasPatchChange;
45         }
46 }
47
48 class Editor;
49 class EditorCursor;
50 class TimeAxisView;
51 class MidiTimeAxisView;
52 class Drag;
53
54 /** Class to manage current drags */
55 class DragManager
56 {
57 public:
58
59         DragManager (Editor* e);
60         ~DragManager ();
61
62         bool motion_handler (GdkEvent *, bool);
63
64         void abort ();
65         void add (Drag *);
66         void set (Drag *, GdkEvent *, Gdk::Cursor* c = 0);
67         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
68         bool end_grab (GdkEvent *);
69         bool have_item (ArdourCanvas::Item *) const;
70
71         /** @return true if an end drag or abort is in progress */
72         bool ending () const {
73                 return _ending;
74         }
75
76         bool active () const {
77                 return !_drags.empty ();
78         }
79
80         /** @return current pointer x position in trackview coordinates */
81         double current_pointer_x () const {
82                 return _current_pointer_x;
83         }
84
85         /** @return current pointer y position in trackview coordinates */
86         double current_pointer_y () const {
87                 return _current_pointer_y;
88         }
89
90         /** @return current pointer frame */
91         ARDOUR::framepos_t current_pointer_frame () const {
92                 return _current_pointer_frame;
93         }
94
95 private:
96         Editor* _editor;
97         std::list<Drag*> _drags;
98         bool _ending; ///< true if end_grab or abort is in progress, otherwise false
99         double _current_pointer_x; ///< trackview x of the current pointer
100         double _current_pointer_y; ///< trackview y of the current pointer
101         ARDOUR::framepos_t _current_pointer_frame; ///< frame that the pointer is now at
102         bool _old_follow_playhead; ///< state of Editor::follow_playhead() before the drags started
103 };
104
105 /** Abstract base class for dragging of things within the editor */
106 class Drag
107 {
108 public:
109         Drag (Editor *, ArdourCanvas::Item *);
110         virtual ~Drag () {}
111
112         void set_manager (DragManager* m) {
113                 _drags = m;
114         }
115
116         /** @return the canvas item being dragged */
117         ArdourCanvas::Item* item () const {
118                 return _item;
119         }
120
121         void swap_grab (ArdourCanvas::Item *, Gdk::Cursor *, uint32_t);
122         bool motion_handler (GdkEvent*, bool);
123         void abort ();
124
125         ARDOUR::framepos_t adjusted_frame (ARDOUR::framepos_t, GdkEvent const *, bool snap = true) const;
126         ARDOUR::framepos_t adjusted_current_frame (GdkEvent const *, bool snap = true) const;
127
128         /** Called to start a grab of an item.
129          *  @param e Event that caused the grab to start.
130          *  @param c Cursor to use, or 0.
131          */
132         virtual void start_grab (GdkEvent* e, Gdk::Cursor* c = 0);
133
134         virtual bool end_grab (GdkEvent *);
135
136         /** Called when a drag motion has occurred.
137          *  @param e Event describing the motion.
138          *  @param f true if this is the first movement, otherwise false.
139          */
140         virtual void motion (GdkEvent* e, bool f) = 0;
141
142         /** Called when a drag has finished.
143          *  @param e Event describing the finish.
144          *  @param m true if some movement occurred, otherwise false.
145          */
146         virtual void finished (GdkEvent* e, bool m) = 0;
147
148         /** Called to abort a drag and return things to how
149          *  they were before it started.
150          *  @param m true if some movement occurred, otherwise false.
151          */
152         virtual void aborted (bool m) = 0;
153
154         /** @param m Mouse mode.
155          *  @return true if this drag should happen in this mouse mode.
156          */
157         virtual bool active (Editing::MouseMode m) {
158                 return (m != Editing::MouseGain);
159         }
160
161         /** @return minimum number of frames (in x) and pixels (in y) that should be considered a movement */
162         virtual std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
163                 return std::make_pair (1, 1);
164         }
165
166         virtual bool allow_vertical_autoscroll () const {
167                 return true;
168         }
169
170         /** @return true if x movement matters to this drag */
171         virtual bool x_movement_matters () const {
172                 return true;
173         }
174
175         /** @return true if y movement matters to this drag */
176         virtual bool y_movement_matters () const {
177                 return true;
178         }
179
180         /** Set up the _pointer_frame_offset */
181         virtual void setup_pointer_frame_offset () {
182                 _pointer_frame_offset = 0;
183         }
184
185 protected:
186
187         double grab_x () const {
188                 return _grab_x;
189         }
190
191         double grab_y () const {
192                 return _grab_y;
193         }
194
195         ARDOUR::framepos_t raw_grab_frame () const {
196                 return _raw_grab_frame;
197         }
198
199         ARDOUR::framepos_t grab_frame () const {
200                 return _grab_frame;
201         }
202
203         double last_pointer_x () const {
204                 return _last_pointer_x;
205         }
206
207         double last_pointer_y () const {
208                 return _last_pointer_y;
209         }
210
211         double last_pointer_frame () const {
212                 return _last_pointer_frame;
213         }
214
215         boost::shared_ptr<ARDOUR::Region> add_midi_region (MidiTimeAxisView*);
216
217         void show_verbose_cursor_time (framepos_t);
218         void show_verbose_cursor_duration (framepos_t, framepos_t, double xoffset = 0);
219         void show_verbose_cursor_text (std::string const &);
220
221         Editor* _editor; ///< our editor
222         DragManager* _drags;
223         ArdourCanvas::Item* _item; ///< our item
224         /** Offset from the mouse's position for the drag to the start of the thing that is being dragged */
225         ARDOUR::framecnt_t _pointer_frame_offset;
226         bool _x_constrained; ///< true if x motion is constrained, otherwise false
227         bool _y_constrained; ///< true if y motion is constrained, otherwise false
228         bool _was_rolling; ///< true if the session was rolling before the drag started, otherwise false
229
230 private:
231
232         bool _move_threshold_passed; ///< true if the move threshold has been passed, otherwise false
233         double _grab_x; ///< trackview x of the grab start position
234         double _grab_y; ///< trackview y of the grab start position
235         double _last_pointer_x; ///< trackview x of the pointer last time a motion occurred
236         double _last_pointer_y; ///< trackview y of the pointer last time a motion occurred
237         ARDOUR::framepos_t _raw_grab_frame; ///< unsnapped frame that the mouse was at when start_grab was called, or 0
238         ARDOUR::framepos_t _grab_frame; ///< adjusted_frame that the mouse was at when start_grab was called, or 0
239         ARDOUR::framepos_t _last_pointer_frame; ///< adjusted_frame the last time a motion occurred
240 };
241
242 class RegionDrag;
243
244 /** Container for details about a region being dragged */
245 struct DraggingView
246 {
247         DraggingView (RegionView *, RegionDrag *);
248
249         RegionView* view; ///< the view
250         /** index into RegionDrag::_time_axis_views of the view that this region is currently being displayed on,
251          *  or -1 if it is not visible.
252          */
253         int time_axis_view;
254         /** layer that this region is currently being displayed on.  This is a double
255             rather than a layer_t as we use fractional layers during drags to allow the user
256             to indicate a new layer to put a region on.
257         */
258         double layer;
259         double initial_y; ///< the initial y position of the view before any reparenting
260         framepos_t initial_position; ///< initial position of the region
261         framepos_t initial_end; ///< initial end position of the region
262         boost::shared_ptr<ARDOUR::Playlist> initial_playlist;
263 };
264
265 /** Abstract base class for drags that involve region(s) */
266 class RegionDrag : public Drag, public sigc::trackable
267 {
268 public:
269         RegionDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
270         virtual ~RegionDrag () {}
271
272 protected:
273
274         RegionView* _primary; ///< the view that was clicked on (or whatever) to start the drag
275         std::list<DraggingView> _views; ///< information about all views that are being dragged
276
277         /** a list of the non-hidden TimeAxisViews sorted by editor order key */
278         std::vector<TimeAxisView*> _time_axis_views;
279         int find_time_axis_view (TimeAxisView *) const;
280
281         int _visible_y_low;
282         int _visible_y_high;
283
284         friend class DraggingView;
285
286 private:
287
288         void region_going_away (RegionView *);
289         PBD::ScopedConnection death_connection;
290 };
291
292
293 /** Drags involving region motion from somewhere */
294 class RegionMotionDrag : public RegionDrag
295 {
296 public:
297
298         RegionMotionDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &, bool);
299         virtual ~RegionMotionDrag () {}
300
301         virtual void start_grab (GdkEvent *, Gdk::Cursor *);
302         virtual void motion (GdkEvent *, bool);
303         virtual void finished (GdkEvent *, bool);
304         virtual void aborted (bool);
305
306         /** @return true if the regions being `moved' came from somewhere on the canvas;
307          *  false if they came from outside (e.g. from the region list).
308          */
309         virtual bool regions_came_from_canvas () const = 0;
310
311 protected:
312
313         double compute_x_delta (GdkEvent const *, ARDOUR::framecnt_t *);
314         bool y_movement_allowed (int, double) const;
315
316         bool _brushing;
317         ARDOUR::framepos_t _last_frame_position; ///< last position of the thing being dragged
318         double _total_x_delta;
319         int _last_pointer_time_axis_view;
320         double _last_pointer_layer;
321 };
322
323
324 /** Drags to move (or copy) regions that are already shown in the GUI to
325  *  somewhere different.
326  */
327 class RegionMoveDrag : public RegionMotionDrag
328 {
329 public:
330         RegionMoveDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &, bool, bool);
331         virtual ~RegionMoveDrag () {}
332
333         void motion (GdkEvent *, bool);
334         void finished (GdkEvent *, bool);
335         void aborted (bool);
336
337         bool regions_came_from_canvas () const {
338                 return true;
339         }
340
341         std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
342                 return std::make_pair (4, 4);
343         }
344
345         void setup_pointer_frame_offset ();
346
347 private:
348         typedef std::set<boost::shared_ptr<ARDOUR::Playlist> > PlaylistSet;
349
350         void finished_no_copy (
351                 bool const,
352                 bool const,
353                 ARDOUR::framecnt_t const
354                 );
355
356         void finished_copy (
357                 bool const,
358                 bool const,
359                 ARDOUR::framecnt_t const
360                 );
361
362         RegionView* insert_region_into_playlist (
363                 boost::shared_ptr<ARDOUR::Region>,
364                 RouteTimeAxisView*,
365                 ARDOUR::layer_t,
366                 ARDOUR::framecnt_t,
367                 PlaylistSet&
368                 );
369
370         void remove_region_from_playlist (
371                 boost::shared_ptr<ARDOUR::Region>,
372                 boost::shared_ptr<ARDOUR::Playlist>,
373                 PlaylistSet& modified_playlists
374                 );
375
376         void add_stateful_diff_commands_for_playlists (PlaylistSet const &);
377
378         void collect_new_region_view (RegionView *);
379
380         bool _copy;
381         RegionView* _new_region_view;
382 };
383
384 /** Drag to insert a region from somewhere */
385 class RegionInsertDrag : public RegionMotionDrag
386 {
387 public:
388         RegionInsertDrag (Editor *, boost::shared_ptr<ARDOUR::Region>, RouteTimeAxisView*, ARDOUR::framepos_t);
389
390         void finished (GdkEvent *, bool);
391         void aborted (bool);
392
393         bool regions_came_from_canvas () const {
394                 return false;
395         }
396 };
397
398 /** Region drag in splice mode */
399 class RegionSpliceDrag : public RegionMoveDrag
400 {
401 public:
402         RegionSpliceDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
403
404         void motion (GdkEvent *, bool);
405         void finished (GdkEvent *, bool);
406         void aborted (bool);
407 };
408
409 /** Drags to create regions */
410 class RegionCreateDrag : public Drag
411 {
412 public:
413         RegionCreateDrag (Editor *, ArdourCanvas::Item *, TimeAxisView *);
414
415         void motion (GdkEvent *, bool);
416         void finished (GdkEvent *, bool);
417         void aborted (bool);
418
419 private:
420         MidiTimeAxisView* _view;
421         boost::shared_ptr<ARDOUR::Region> _region;
422 };
423
424 /** Drags to resize MIDI notes */
425 class NoteResizeDrag : public Drag
426 {
427 public:
428         NoteResizeDrag (Editor *, ArdourCanvas::Item *);
429
430         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
431         void motion (GdkEvent *, bool);
432         void finished (GdkEvent *, bool);
433         void aborted (bool);
434
435 private:
436         MidiRegionView*     region;
437         bool                relative;
438         bool                at_front;
439 };
440
441 /** Drags to move MIDI notes */
442 class NoteDrag : public Drag
443 {
444   public:
445         NoteDrag (Editor*, ArdourCanvas::Item*);
446
447         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
448         void motion (GdkEvent *, bool);
449         void finished (GdkEvent *, bool);
450         void aborted (bool);
451
452   private:
453
454         ARDOUR::frameoffset_t total_dx () const;
455         int8_t total_dy () const;
456
457         MidiRegionView* _region;
458         Gnome::Canvas::CanvasNoteEvent* _primary;
459         double _cumulative_dx;
460         double _cumulative_dy;
461         bool _was_selected;
462         double _note_height;
463 };
464
465 class NoteCreateDrag : public Drag
466 {
467 public:
468         NoteCreateDrag (Editor *, ArdourCanvas::Item *, MidiRegionView *);
469         ~NoteCreateDrag ();
470
471         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
472         void motion (GdkEvent *, bool);
473         void finished (GdkEvent *, bool);
474         void aborted (bool);
475
476 private:
477         double y_to_region (double) const;
478         framecnt_t grid_frames (framepos_t) const;
479         
480         MidiRegionView* _region_view;
481         ArdourCanvas::SimpleRect* _drag_rect;
482         framepos_t _note[2];
483 };
484
485 /** Drag to move MIDI patch changes */
486 class PatchChangeDrag : public Drag
487 {
488 public:
489         PatchChangeDrag (Editor *, ArdourCanvas::CanvasPatchChange *, MidiRegionView *);
490
491         void motion (GdkEvent *, bool);
492         void finished (GdkEvent *, bool);
493         void aborted (bool);
494
495         bool y_movement_matters () const {
496                 return false;
497         }
498
499         void setup_pointer_frame_offset ();
500
501 private:
502         MidiRegionView* _region_view;
503         ArdourCanvas::CanvasPatchChange* _patch_change;
504         double _cumulative_dx;
505 };
506
507 /** Drag to trim region(s) */
508 class TrimDrag : public RegionDrag
509 {
510 public:
511         enum Operation {
512                 StartTrim,
513                 EndTrim,
514                 ContentsTrim,
515         };
516
517         TrimDrag (Editor *, ArdourCanvas::Item *, RegionView*, std::list<RegionView*> const &);
518
519         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
520         void motion (GdkEvent *, bool);
521         void finished (GdkEvent *, bool);
522         void aborted (bool);
523
524         bool y_movement_matters () const {
525                 return false;
526         }
527
528         void setup_pointer_frame_offset ();
529
530 private:
531
532         Operation _operation;
533 };
534
535 /** Meter marker drag */
536 class MeterMarkerDrag : public Drag
537 {
538 public:
539         MeterMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
540
541         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
542         void motion (GdkEvent *, bool);
543         void finished (GdkEvent *, bool);
544         void aborted (bool);
545
546         bool allow_vertical_autoscroll () const {
547                 return false;
548         }
549
550         bool y_movement_matters () const {
551                 return false;
552         }
553
554         void setup_pointer_frame_offset ();
555
556 private:
557         MeterMarker* _marker;
558         bool _copy;
559         XMLNode* before_state;
560 };
561
562 /** Tempo marker drag */
563 class TempoMarkerDrag : public Drag
564 {
565 public:
566         TempoMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
567
568         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
569         void motion (GdkEvent *, bool);
570         void finished (GdkEvent *, bool);
571         void aborted (bool);
572
573         bool allow_vertical_autoscroll () const {
574                 return false;
575         }
576
577         bool y_movement_matters () const {
578                 return false;
579         }
580
581         void setup_pointer_frame_offset ();
582
583 private:
584         TempoMarker* _marker;
585         bool _copy;
586         XMLNode* before_state;
587 };
588
589
590 /** Drag of the playhead cursor */
591 class CursorDrag : public Drag
592 {
593 public:
594         CursorDrag (Editor *, ArdourCanvas::Item *, bool);
595
596         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
597         void motion (GdkEvent *, bool);
598         void finished (GdkEvent *, bool);
599         void aborted (bool);
600
601         bool active (Editing::MouseMode) {
602                 return true;
603         }
604
605         bool allow_vertical_autoscroll () const {
606                 return false;
607         }
608
609         bool y_movement_matters () const {
610                 return true;
611         }
612
613 private:
614         void fake_locate (framepos_t);
615
616         bool _stop; ///< true to stop the transport on starting the drag, otherwise false
617         double _grab_zoom; ///< editor frames per unit when our grab started
618 };
619
620 /** Region fade-in drag */
621 class FadeInDrag : public RegionDrag
622 {
623 public:
624         FadeInDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
625
626         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
627         void motion (GdkEvent *, bool);
628         void finished (GdkEvent *, bool);
629         void aborted (bool);
630
631         bool y_movement_matters () const {
632                 return false;
633         }
634
635         void setup_pointer_frame_offset ();
636 };
637
638 /** Region fade-out drag */
639 class FadeOutDrag : public RegionDrag
640 {
641 public:
642         FadeOutDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
643
644         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
645         void motion (GdkEvent *, bool);
646         void finished (GdkEvent *, bool);
647         void aborted (bool);
648
649         bool y_movement_matters () const {
650                 return false;
651         }
652
653         void setup_pointer_frame_offset ();
654 };
655
656 /** Marker drag */
657 class MarkerDrag : public Drag
658 {
659 public:
660         MarkerDrag (Editor *, ArdourCanvas::Item *);
661         ~MarkerDrag ();
662
663         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
664         void motion (GdkEvent *, bool);
665         void finished (GdkEvent *, bool);
666         void aborted (bool);
667
668         bool allow_vertical_autoscroll () const {
669                 return false;
670         }
671
672         bool y_movement_matters () const {
673                 return false;
674         }
675
676         void setup_pointer_frame_offset ();
677
678 private:
679         void update_item (ARDOUR::Location *);
680
681         Marker* _marker; ///< marker being dragged
682         std::list<ARDOUR::Location*> _copied_locations;
683         ArdourCanvas::Points _points;
684 };
685
686 /** Control point drag */
687 class ControlPointDrag : public Drag
688 {
689 public:
690         ControlPointDrag (Editor *, ArdourCanvas::Item *);
691
692         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
693         void motion (GdkEvent *, bool);
694         void finished (GdkEvent *, bool);
695         void aborted (bool);
696
697         bool active (Editing::MouseMode m);
698
699 private:
700
701         ControlPoint* _point;
702         double _fixed_grab_x;
703         double _fixed_grab_y;
704         double _cumulative_x_drag;
705         double _cumulative_y_drag;
706         static double _zero_gain_fraction;
707 };
708
709 /** Gain or automation line drag */
710 class LineDrag : public Drag
711 {
712 public:
713         LineDrag (Editor *e, ArdourCanvas::Item *i);
714
715         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
716         void motion (GdkEvent *, bool);
717         void finished (GdkEvent *, bool);
718         void aborted (bool);
719
720         bool active (Editing::MouseMode) {
721                 return true;
722         }
723
724 private:
725
726         AutomationLine* _line;
727         double _fixed_grab_x;
728         double _fixed_grab_y;
729         uint32_t _before;
730         uint32_t _after;
731         double _cumulative_y_drag;
732 };
733
734 /** Transient feature line drags*/
735 class FeatureLineDrag : public Drag
736 {
737 public:
738         FeatureLineDrag (Editor *e, ArdourCanvas::Item *i);
739
740         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
741         void motion (GdkEvent *, bool);
742         void finished (GdkEvent *, bool);
743         void aborted (bool);
744
745         bool active (Editing::MouseMode) {
746                 return true;
747         }
748
749 private:
750
751         ArdourCanvas::Line* _line;
752         AudioRegionView* _arv;
753
754         double _region_view_grab_x;
755         double _cumulative_x_drag;
756
757         float _before;
758         uint32_t _max_x;
759 };
760
761 /** Dragging of a rubberband rectangle for selecting things */
762 class RubberbandSelectDrag : public Drag
763 {
764 public:
765         RubberbandSelectDrag (Editor *, ArdourCanvas::Item *);
766
767         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
768         void motion (GdkEvent *, bool);
769         void finished (GdkEvent *, bool);
770         void aborted (bool);
771
772         std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
773                 return std::make_pair (8, 1);
774         }
775
776         void do_select_things (GdkEvent *, bool);
777
778         /** Select some things within a rectangle.
779          *  @param button_state The button state from the GdkEvent.
780          *  @param x1 The left-hand side of the rectangle in session frames.
781          *  @param x2 The right-hand side of the rectangle in session frames.
782          *  @param y1 The top of the rectangle in trackview coordinates.
783          *  @param y2 The bottom of the rectangle in trackview coordinates.
784          *  @param drag_in_progress true if the drag is currently happening.
785          */
786         virtual void select_things (int button_state, framepos_t x1, framepos_t x2, double y1, double y2, bool drag_in_progress) = 0;
787         
788         virtual void deselect_things () = 0;
789
790   protected:
791         bool _vertical_only;
792 };
793
794 /** A general editor RubberbandSelectDrag (for regions, automation points etc.) */
795 class EditorRubberbandSelectDrag : public RubberbandSelectDrag
796 {
797 public:
798         EditorRubberbandSelectDrag (Editor *, ArdourCanvas::Item *);
799
800         void select_things (int, framepos_t, framepos_t, double, double, bool);
801         void deselect_things ();
802 };
803
804 /** A RubberbandSelectDrag for selecting MIDI notes */
805 class MidiRubberbandSelectDrag : public RubberbandSelectDrag
806 {
807 public:
808         MidiRubberbandSelectDrag (Editor *, MidiRegionView *);
809
810         void select_things (int, framepos_t, framepos_t, double, double, bool);
811         void deselect_things ();
812
813 private:
814         MidiRegionView* _region_view;
815 };
816
817 /** A RubberbandSelectDrag for selecting MIDI notes but with no horizonal component */
818 class MidiVerticalSelectDrag : public RubberbandSelectDrag
819 {
820 public:
821         MidiVerticalSelectDrag (Editor *, MidiRegionView *);
822
823         void select_things (int, framepos_t, framepos_t, double, double, bool);
824         void deselect_things ();
825
826 private:
827         MidiRegionView* _region_view;
828 };
829
830 /** Region drag in time-FX mode */
831 class TimeFXDrag : public RegionDrag
832 {
833 public:
834         TimeFXDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
835
836         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
837         void motion (GdkEvent *, bool);
838         void finished (GdkEvent *, bool);
839         void aborted (bool);
840 };
841
842 /** Scrub drag in audition mode */
843 class ScrubDrag : public Drag
844 {
845 public:
846         ScrubDrag (Editor *, ArdourCanvas::Item *);
847
848         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
849         void motion (GdkEvent *, bool);
850         void finished (GdkEvent *, bool);
851         void aborted (bool);
852 };
853
854 /** Drag in range select mode */
855 class SelectionDrag : public Drag
856 {
857 public:
858         enum Operation {
859                 CreateSelection,
860                 SelectionStartTrim,
861                 SelectionEndTrim,
862                 SelectionMove
863         };
864
865         SelectionDrag (Editor *, ArdourCanvas::Item *, Operation);
866
867         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
868         void motion (GdkEvent *, bool);
869         void finished (GdkEvent *, bool);
870         void aborted (bool);
871
872         void setup_pointer_frame_offset ();
873
874 private:
875         Operation _operation;
876         bool _copy;
877         int _original_pointer_time_axis;
878         int _last_pointer_time_axis;
879         std::list<TimeAxisView*> _added_time_axes;
880         bool _time_selection_at_start;
881 };
882
883 /** Range marker drag */
884 class RangeMarkerBarDrag : public Drag
885 {
886 public:
887         enum Operation {
888                 CreateRangeMarker,
889                 CreateTransportMarker,
890                 CreateCDMarker
891         };
892
893         RangeMarkerBarDrag (Editor *, ArdourCanvas::Item *, Operation);
894
895         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
896         void motion (GdkEvent *, bool);
897         void finished (GdkEvent *, bool);
898         void aborted (bool);
899
900         bool allow_vertical_autoscroll () const {
901                 return false;
902         }
903
904         bool y_movement_matters () const {
905                 return false;
906         }
907
908 private:
909         void update_item (ARDOUR::Location *);
910
911         Operation _operation;
912         ArdourCanvas::SimpleRect* _drag_rect;
913         bool _copy;
914 };
915
916 /** Drag of rectangle to set zoom */
917 class MouseZoomDrag : public Drag
918 {
919 public:
920         MouseZoomDrag (Editor *, ArdourCanvas::Item *);
921
922         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
923         void motion (GdkEvent *, bool);
924         void finished (GdkEvent *, bool);
925         void aborted (bool);
926
927         std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
928                 return std::make_pair (4, 4);
929         }
930
931 private:
932         bool _zoom_out;
933 };
934
935 /** Drag of a range of automation data, changing value but not position */
936 class AutomationRangeDrag : public Drag
937 {
938 public:
939         AutomationRangeDrag (Editor *, ArdourCanvas::Item *, std::list<ARDOUR::AudioRange> const &);
940
941         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
942         void motion (GdkEvent *, bool);
943         void finished (GdkEvent *, bool);
944         void aborted (bool);
945
946         bool x_movement_matters () const {
947                 return false;
948         }
949
950 private:
951         std::list<ARDOUR::AudioRange> _ranges;
952         AutomationTimeAxisView* _atav;
953
954         /** A line that is part of the drag */
955         struct Line {
956                 boost::shared_ptr<AutomationLine> line; ///< the line
957                 std::list<ControlPoint*> points; ///< points to drag on the line
958                 std::pair<ARDOUR::framepos_t, ARDOUR::framepos_t> range; ///< the range of all points on the line, in session frames
959                 XMLNode* state; ///< the XML state node before the drag
960         };
961
962         std::list<Line> _lines;
963
964         bool _nothing_to_drag;
965 };
966
967 #endif /* __gtk2_ardour_editor_drag_h_ */
968