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