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