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