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