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