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