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