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