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