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