Merge branch 'master' 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 #ifdef WITH_VIDEOTIMELINE
503 /** Container for details about audio regions being dragged along with video */
504 class AVDraggingView
505 {
506 public:
507         AVDraggingView (RegionView *);
508
509         RegionView* view; ///< the view
510         framepos_t initial_position; ///< initial position of the region
511 };
512
513 /** Drag of video offset */
514 class VideoTimeLineDrag : public Drag
515         //TODO , public sigc::trackable
516 {
517 public:
518         VideoTimeLineDrag (Editor *e, ArdourCanvas::Item *i);
519
520         void motion (GdkEvent *, bool);
521         void finished (GdkEvent *, bool);
522         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
523
524         bool y_movement_matters () const {
525                 return false;
526         }
527
528         bool allow_vertical_autoscroll () const {
529                 return false;
530         }
531
532         void aborted (bool);
533
534 protected:
535         std::list<AVDraggingView> _views; ///< information about all audio that are being dragged along
536
537 private:
538         ARDOUR::frameoffset_t _startdrag_video_offset;
539         ARDOUR::frameoffset_t _max_backwards_drag;
540 };
541 #endif
542
543 /** Drag to trim region(s) */
544 class TrimDrag : public RegionDrag
545 {
546 public:
547         enum Operation {
548                 StartTrim,
549                 EndTrim,
550                 ContentsTrim,
551         };
552
553         TrimDrag (Editor *, ArdourCanvas::Item *, RegionView*, std::list<RegionView*> const &, bool preserve_fade_anchor = false);
554
555         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
556         void motion (GdkEvent *, bool);
557         void finished (GdkEvent *, bool);
558         void aborted (bool);
559
560         bool y_movement_matters () const {
561                 return false;
562         }
563
564         void setup_pointer_frame_offset ();
565
566 private:
567
568         Operation _operation;
569         
570         bool _preserve_fade_anchor;
571 };
572
573 /** Meter marker drag */
574 class MeterMarkerDrag : public Drag
575 {
576 public:
577         MeterMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
578
579         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
580         void motion (GdkEvent *, bool);
581         void finished (GdkEvent *, bool);
582         void aborted (bool);
583
584         bool allow_vertical_autoscroll () const {
585                 return false;
586         }
587
588         bool y_movement_matters () const {
589                 return false;
590         }
591
592         void setup_pointer_frame_offset ();
593
594 private:
595         MeterMarker* _marker;
596         bool _copy;
597         XMLNode* before_state;
598 };
599
600 /** Tempo marker drag */
601 class TempoMarkerDrag : public Drag
602 {
603 public:
604         TempoMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
605
606         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
607         void motion (GdkEvent *, bool);
608         void finished (GdkEvent *, bool);
609         void aborted (bool);
610
611         bool allow_vertical_autoscroll () const {
612                 return false;
613         }
614
615         bool y_movement_matters () const {
616                 return false;
617         }
618
619         void setup_pointer_frame_offset ();
620
621 private:
622         TempoMarker* _marker;
623         bool _copy;
624         XMLNode* before_state;
625 };
626
627
628 /** Drag of the playhead cursor */
629 class CursorDrag : public Drag
630 {
631 public:
632         CursorDrag (Editor *, ArdourCanvas::Item *, bool);
633
634         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
635         void motion (GdkEvent *, bool);
636         void finished (GdkEvent *, bool);
637         void aborted (bool);
638
639         bool active (Editing::MouseMode) {
640                 return true;
641         }
642
643         bool allow_vertical_autoscroll () const {
644                 return false;
645         }
646
647         bool y_movement_matters () const {
648                 return true;
649         }
650
651 private:
652         void fake_locate (framepos_t);
653
654         bool _stop; ///< true to stop the transport on starting the drag, otherwise false
655         double _grab_zoom; ///< editor frames per unit when our grab started
656 };
657
658 /** Region fade-in drag */
659 class FadeInDrag : public RegionDrag
660 {
661 public:
662         FadeInDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
663
664         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
665         void motion (GdkEvent *, bool);
666         void finished (GdkEvent *, bool);
667         void aborted (bool);
668
669         bool y_movement_matters () const {
670                 return false;
671         }
672
673         void setup_pointer_frame_offset ();
674 };
675
676 /** Region fade-out drag */
677 class FadeOutDrag : public RegionDrag
678 {
679 public:
680         FadeOutDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
681
682         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
683         void motion (GdkEvent *, bool);
684         void finished (GdkEvent *, bool);
685         void aborted (bool);
686
687         bool y_movement_matters () const {
688                 return false;
689         }
690
691         void setup_pointer_frame_offset ();
692 };
693
694 /** Marker drag */
695 class MarkerDrag : public Drag
696 {
697 public:
698         MarkerDrag (Editor *, ArdourCanvas::Item *);
699         ~MarkerDrag ();
700
701         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
702         void motion (GdkEvent *, bool);
703         void finished (GdkEvent *, bool);
704         void aborted (bool);
705
706         bool allow_vertical_autoscroll () const {
707                 return false;
708         }
709
710         bool y_movement_matters () const {
711                 return false;
712         }
713
714         void setup_pointer_frame_offset ();
715
716 private:
717         void update_item (ARDOUR::Location *);
718
719         Marker* _marker; ///< marker being dragged
720
721         struct CopiedLocationMarkerInfo {
722             ARDOUR::Location* location;
723             std::vector<Marker*> markers;
724             bool    move_both;
725             CopiedLocationMarkerInfo (ARDOUR::Location* l, Marker* m);
726         };
727
728         typedef std::list<CopiedLocationMarkerInfo> CopiedLocationInfo;
729         CopiedLocationInfo _copied_locations;
730         ArdourCanvas::Points _points;
731 };
732
733 /** Control point drag */
734 class ControlPointDrag : public Drag
735 {
736 public:
737         ControlPointDrag (Editor *, ArdourCanvas::Item *);
738
739         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
740         void motion (GdkEvent *, bool);
741         void finished (GdkEvent *, bool);
742         void aborted (bool);
743
744         bool active (Editing::MouseMode m);
745
746 private:
747
748         ControlPoint* _point;
749         double _fixed_grab_x;
750         double _fixed_grab_y;
751         double _cumulative_x_drag;
752         double _cumulative_y_drag;
753         bool     _pushing;
754         uint32_t _final_index;
755         static double _zero_gain_fraction;
756 };
757
758 /** Gain or automation line drag */
759 class LineDrag : public Drag
760 {
761 public:
762         LineDrag (Editor *e, ArdourCanvas::Item *i);
763
764         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
765         void motion (GdkEvent *, bool);
766         void finished (GdkEvent *, bool);
767         void aborted (bool);
768
769         bool active (Editing::MouseMode) {
770                 return true;
771         }
772
773 private:
774
775         AutomationLine* _line;
776         double _fixed_grab_x;
777         double _fixed_grab_y;
778         uint32_t _before;
779         uint32_t _after;
780         double _cumulative_y_drag;
781 };
782
783 /** Transient feature line drags*/
784 class FeatureLineDrag : public Drag
785 {
786 public:
787         FeatureLineDrag (Editor *e, ArdourCanvas::Item *i);
788
789         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
790         void motion (GdkEvent *, bool);
791         void finished (GdkEvent *, bool);
792         void aborted (bool);
793
794         bool active (Editing::MouseMode) {
795                 return true;
796         }
797
798 private:
799
800         ArdourCanvas::Line* _line;
801         AudioRegionView* _arv;
802
803         double _region_view_grab_x;
804         double _cumulative_x_drag;
805
806         float _before;
807         uint32_t _max_x;
808 };
809
810 /** Dragging of a rubberband rectangle for selecting things */
811 class RubberbandSelectDrag : public Drag
812 {
813 public:
814         RubberbandSelectDrag (Editor *, ArdourCanvas::Item *);
815
816         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
817         void motion (GdkEvent *, bool);
818         void finished (GdkEvent *, bool);
819         void aborted (bool);
820
821         std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
822                 return std::make_pair (8, 1);
823         }
824
825         void do_select_things (GdkEvent *, bool);
826
827         /** Select some things within a rectangle.
828          *  @param button_state The button state from the GdkEvent.
829          *  @param x1 The left-hand side of the rectangle in session frames.
830          *  @param x2 The right-hand side of the rectangle in session frames.
831          *  @param y1 The top of the rectangle in trackview coordinates.
832          *  @param y2 The bottom of the rectangle in trackview coordinates.
833          *  @param drag_in_progress true if the drag is currently happening.
834          */
835         virtual void select_things (int button_state, framepos_t x1, framepos_t x2, double y1, double y2, bool drag_in_progress) = 0;
836         
837         virtual void deselect_things () = 0;
838
839   protected:
840         bool _vertical_only;
841 };
842
843 /** A general editor RubberbandSelectDrag (for regions, automation points etc.) */
844 class EditorRubberbandSelectDrag : public RubberbandSelectDrag
845 {
846 public:
847         EditorRubberbandSelectDrag (Editor *, ArdourCanvas::Item *);
848
849         void select_things (int, framepos_t, framepos_t, double, double, bool);
850         void deselect_things ();
851 };
852
853 /** A RubberbandSelectDrag for selecting MIDI notes */
854 class MidiRubberbandSelectDrag : public RubberbandSelectDrag
855 {
856 public:
857         MidiRubberbandSelectDrag (Editor *, MidiRegionView *);
858
859         void select_things (int, framepos_t, framepos_t, double, double, bool);
860         void deselect_things ();
861
862 private:
863         MidiRegionView* _region_view;
864 };
865
866 /** A RubberbandSelectDrag for selecting MIDI notes but with no horizonal component */
867 class MidiVerticalSelectDrag : public RubberbandSelectDrag
868 {
869 public:
870         MidiVerticalSelectDrag (Editor *, MidiRegionView *);
871
872         void select_things (int, framepos_t, framepos_t, double, double, bool);
873         void deselect_things ();
874
875 private:
876         MidiRegionView* _region_view;
877 };
878
879 /** Region drag in time-FX mode */
880 class TimeFXDrag : public RegionDrag
881 {
882 public:
883         TimeFXDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
884
885         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
886         void motion (GdkEvent *, bool);
887         void finished (GdkEvent *, bool);
888         void aborted (bool);
889 };
890
891 /** Scrub drag in audition mode */
892 class ScrubDrag : public Drag
893 {
894 public:
895         ScrubDrag (Editor *, ArdourCanvas::Item *);
896
897         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
898         void motion (GdkEvent *, bool);
899         void finished (GdkEvent *, bool);
900         void aborted (bool);
901 };
902
903 /** Drag in range select mode */
904 class SelectionDrag : public Drag
905 {
906 public:
907         enum Operation {
908                 CreateSelection,
909                 SelectionStartTrim,
910                 SelectionEndTrim,
911                 SelectionMove,
912                 SelectionExtend
913         };
914
915         SelectionDrag (Editor *, ArdourCanvas::Item *, Operation);
916
917         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
918         void motion (GdkEvent *, bool);
919         void finished (GdkEvent *, bool);
920         void aborted (bool);
921
922         void setup_pointer_frame_offset ();
923
924 private:
925         Operation _operation;
926         bool _add;
927         bool _extend;
928         int _original_pointer_time_axis;
929         int _last_pointer_time_axis;
930         std::list<TimeAxisView*> _added_time_axes;
931         bool _time_selection_at_start;
932         framepos_t start_at_start;
933         framepos_t end_at_start;
934 };
935
936 /** Range marker drag */
937 class RangeMarkerBarDrag : public Drag
938 {
939 public:
940         enum Operation {
941                 CreateRangeMarker,
942                 CreateTransportMarker,
943                 CreateCDMarker
944         };
945
946         RangeMarkerBarDrag (Editor *, ArdourCanvas::Item *, Operation);
947
948         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
949         void motion (GdkEvent *, bool);
950         void finished (GdkEvent *, bool);
951         void aborted (bool);
952
953         bool allow_vertical_autoscroll () const {
954                 return false;
955         }
956
957         bool y_movement_matters () const {
958                 return false;
959         }
960
961 private:
962         void update_item (ARDOUR::Location *);
963
964         Operation _operation;
965         ArdourCanvas::Rectangle* _drag_rect;
966         bool _copy;
967 };
968
969 /** Drag of rectangle to set zoom */
970 class MouseZoomDrag : public Drag
971 {
972 public:
973         MouseZoomDrag (Editor *, ArdourCanvas::Item *);
974
975         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
976         void motion (GdkEvent *, bool);
977         void finished (GdkEvent *, bool);
978         void aborted (bool);
979
980         std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
981                 return std::make_pair (4, 4);
982         }
983
984 private:
985         bool _zoom_out;
986 };
987
988 /** Drag of a range of automation data (either on an automation track or region gain),
989  *  changing value but not position.
990  */
991 class AutomationRangeDrag : public Drag
992 {
993 public:
994         AutomationRangeDrag (Editor *, AutomationTimeAxisView *, std::list<ARDOUR::AudioRange> const &);
995         AutomationRangeDrag (Editor *, AudioRegionView *, std::list<ARDOUR::AudioRange> const &);
996
997         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
998         void motion (GdkEvent *, bool);
999         void finished (GdkEvent *, bool);
1000         void aborted (bool);
1001
1002         bool x_movement_matters () const {
1003                 return false;
1004         }
1005
1006         bool active (Editing::MouseMode) {
1007                 return true;
1008         }
1009
1010 private:
1011         void setup (std::list<boost::shared_ptr<AutomationLine> > const &);
1012         double y_fraction (boost::shared_ptr<AutomationLine>, double global_y_position) const;
1013
1014         std::list<ARDOUR::AudioRange> _ranges;
1015
1016         /** A line that is part of the drag */
1017         struct Line {
1018                 boost::shared_ptr<AutomationLine> line; ///< the line
1019                 std::list<ControlPoint*> points; ///< points to drag on the line
1020                 std::pair<ARDOUR::framepos_t, ARDOUR::framepos_t> range; ///< the range of all points on the line, in session frames
1021                 XMLNode* state; ///< the XML state node before the drag
1022                 double original_fraction; ///< initial y-fraction before the drag
1023         };
1024
1025         std::list<Line> _lines;
1026         double y_origin;
1027         bool _nothing_to_drag;
1028 };
1029
1030 /** Drag of one edge of an xfade
1031  */
1032 class CrossfadeEdgeDrag : public Drag
1033 {
1034   public:
1035         CrossfadeEdgeDrag (Editor*, AudioRegionView*, ArdourCanvas::Item*, bool start);
1036
1037         void start_grab (GdkEvent*, Gdk::Cursor* c = 0);
1038         void motion (GdkEvent*, bool);
1039         void finished (GdkEvent*, bool);
1040         void aborted (bool);
1041         
1042         bool y_movement_matters () const {
1043                 return false;
1044         }
1045
1046         virtual std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
1047                 return std::make_pair (4, 4);
1048         }
1049
1050   private:
1051         AudioRegionView* arv;
1052         bool start;
1053 };
1054
1055 #endif /* __gtk2_ardour_editor_drag_h_ */
1056