Tempo ramps - tempos now musically snap to their future.
[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
745 /** Drag of the playhead cursor */
746 class CursorDrag : public Drag
747 {
748 public:
749         CursorDrag (Editor *, EditorCursor&, bool);
750
751         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
752         void motion (GdkEvent *, bool);
753         void finished (GdkEvent *, bool);
754         void aborted (bool);
755
756         bool allow_vertical_autoscroll () const {
757                 return false;
758         }
759
760         bool y_movement_matters () const {
761                 return true;
762         }
763
764 private:
765         void fake_locate (framepos_t);
766
767         EditorCursor& _cursor;
768         bool _stop; ///< true to stop the transport on starting the drag, otherwise false
769         double _grab_zoom; ///< editor frames per unit when our grab started
770 };
771
772 /** Region fade-in drag */
773 class FadeInDrag : public RegionDrag
774 {
775 public:
776         FadeInDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
777
778         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
779         void motion (GdkEvent *, bool);
780         void finished (GdkEvent *, bool);
781         void aborted (bool);
782
783         bool y_movement_matters () const {
784                 return false;
785         }
786
787         void setup_pointer_frame_offset ();
788 };
789
790 /** Region fade-out drag */
791 class FadeOutDrag : public RegionDrag
792 {
793 public:
794         FadeOutDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
795
796         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
797         void motion (GdkEvent *, bool);
798         void finished (GdkEvent *, bool);
799         void aborted (bool);
800
801         bool y_movement_matters () const {
802                 return false;
803         }
804
805         void setup_pointer_frame_offset ();
806 };
807
808 /** Marker drag */
809 class MarkerDrag : public Drag
810 {
811 public:
812         MarkerDrag (Editor *, ArdourCanvas::Item *);
813         ~MarkerDrag ();
814
815         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
816         void motion (GdkEvent *, bool);
817         void finished (GdkEvent *, bool);
818         void aborted (bool);
819
820         bool allow_vertical_autoscroll () const {
821                 return false;
822         }
823
824         bool y_movement_matters () const {
825                 return false;
826         }
827
828         void setup_pointer_frame_offset ();
829
830 private:
831         void update_item (ARDOUR::Location *);
832
833         ArdourMarker* _marker; ///< marker being dragged
834         bool _selection_changed;
835         struct CopiedLocationMarkerInfo {
836             ARDOUR::Location* location;
837             std::vector<ArdourMarker*> markers;
838             bool    move_both;
839             CopiedLocationMarkerInfo (ARDOUR::Location* l, ArdourMarker* m);
840         };
841
842         typedef std::list<CopiedLocationMarkerInfo> CopiedLocationInfo;
843         CopiedLocationInfo _copied_locations;
844         ArdourCanvas::Points _points;
845 };
846
847 /** Control point drag */
848 class ControlPointDrag : public Drag
849 {
850 public:
851         ControlPointDrag (Editor *, ArdourCanvas::Item *);
852
853         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
854         void motion (GdkEvent *, bool);
855         void finished (GdkEvent *, bool);
856         void aborted (bool);
857
858         bool active (Editing::MouseMode m);
859
860 private:
861
862         ControlPoint* _point;
863         double _fixed_grab_x;
864         double _fixed_grab_y;
865         double _cumulative_x_drag;
866         double _cumulative_y_drag;
867         bool     _pushing;
868         uint32_t _final_index;
869         static double _zero_gain_fraction;
870 };
871
872 /** Gain or automation line drag */
873 class LineDrag : public Drag
874 {
875 public:
876         LineDrag (Editor *e, ArdourCanvas::Item *i);
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 private:
884
885         AutomationLine* _line;
886         double _fixed_grab_x;
887         double _fixed_grab_y;
888         double _cumulative_y_drag;
889         uint32_t _before;
890         uint32_t _after;
891 };
892
893 /** Transient feature line drags*/
894 class FeatureLineDrag : public Drag
895 {
896 public:
897         FeatureLineDrag (Editor *e, ArdourCanvas::Item *i);
898
899         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
900         void motion (GdkEvent *, bool);
901         void finished (GdkEvent *, bool);
902         void aborted (bool);
903
904 private:
905
906         ArdourCanvas::Line* _line;
907         AudioRegionView* _arv;
908
909         double _region_view_grab_x;
910         double _cumulative_x_drag;
911
912         float _before;
913         uint32_t _max_x;
914 };
915
916 /** Dragging of a rubberband rectangle for selecting things */
917 class RubberbandSelectDrag : public Drag
918 {
919 public:
920         RubberbandSelectDrag (Editor *, ArdourCanvas::Item *);
921
922         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
923         void motion (GdkEvent *, bool);
924         void finished (GdkEvent *, bool);
925         void aborted (bool);
926
927         std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
928                 return std::make_pair (8, 1);
929         }
930
931         void do_select_things (GdkEvent *, bool);
932
933         /** Select some things within a rectangle.
934          *  @param button_state The button state from the GdkEvent.
935          *  @param x1 The left-hand side of the rectangle in session frames.
936          *  @param x2 The right-hand side of the rectangle in session frames.
937          *  @param y1 The top of the rectangle in trackview coordinates.
938          *  @param y2 The bottom of the rectangle in trackview coordinates.
939          *  @param drag_in_progress true if the drag is currently happening.
940          */
941         virtual void select_things (int button_state, framepos_t x1, framepos_t x2, double y1, double y2, bool drag_in_progress) = 0;
942
943         virtual void deselect_things () = 0;
944
945   protected:
946         bool _vertical_only;
947 };
948
949 /** A general editor RubberbandSelectDrag (for regions, automation points etc.) */
950 class EditorRubberbandSelectDrag : public RubberbandSelectDrag
951 {
952 public:
953         EditorRubberbandSelectDrag (Editor *, ArdourCanvas::Item *);
954
955         void select_things (int, framepos_t, framepos_t, double, double, bool);
956         void deselect_things ();
957 };
958
959 /** A RubberbandSelectDrag for selecting MIDI notes */
960 class MidiRubberbandSelectDrag : public RubberbandSelectDrag
961 {
962 public:
963         MidiRubberbandSelectDrag (Editor *, MidiRegionView *);
964
965         void select_things (int, framepos_t, framepos_t, double, double, bool);
966         void deselect_things ();
967
968 private:
969         MidiRegionView* _region_view;
970 };
971
972 /** A RubberbandSelectDrag for selecting MIDI notes but with no horizonal component */
973 class MidiVerticalSelectDrag : public RubberbandSelectDrag
974 {
975 public:
976         MidiVerticalSelectDrag (Editor *, MidiRegionView *);
977
978         void select_things (int, framepos_t, framepos_t, double, double, bool);
979         void deselect_things ();
980
981 private:
982         MidiRegionView* _region_view;
983 };
984
985 /** Region drag in time-FX mode */
986 class TimeFXDrag : public RegionDrag
987 {
988 public:
989         TimeFXDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
990
991         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
992         void motion (GdkEvent *, bool);
993         void finished (GdkEvent *, bool);
994         void aborted (bool);
995 };
996
997 /** Scrub drag in audition mode */
998 class ScrubDrag : public Drag
999 {
1000 public:
1001         ScrubDrag (Editor *, ArdourCanvas::Item *);
1002
1003         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
1004         void motion (GdkEvent *, bool);
1005         void finished (GdkEvent *, bool);
1006         void aborted (bool);
1007 };
1008
1009 /** Drag in range select mode */
1010 class SelectionDrag : public Drag
1011 {
1012 public:
1013         enum Operation {
1014                 CreateSelection,
1015                 SelectionStartTrim,
1016                 SelectionEndTrim,
1017                 SelectionMove,
1018                 SelectionExtend
1019         };
1020
1021         SelectionDrag (Editor *, ArdourCanvas::Item *, Operation);
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         void setup_pointer_frame_offset ();
1029
1030 private:
1031         Operation _operation;
1032         bool _add;
1033         std::list<TimeAxisView*> _added_time_axes;
1034         bool _time_selection_at_start;
1035         framepos_t start_at_start;
1036         framepos_t end_at_start;
1037 };
1038
1039 /** Range marker drag */
1040 class RangeMarkerBarDrag : public Drag
1041 {
1042 public:
1043         enum Operation {
1044                 CreateSkipMarker,
1045                 CreateRangeMarker,
1046                 CreateTransportMarker,
1047                 CreateCDMarker
1048         };
1049
1050         RangeMarkerBarDrag (Editor *, ArdourCanvas::Item *, Operation);
1051         ~RangeMarkerBarDrag ();
1052
1053         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
1054         void motion (GdkEvent *, bool);
1055         void finished (GdkEvent *, bool);
1056         void aborted (bool);
1057
1058         bool allow_vertical_autoscroll () const {
1059                 return false;
1060         }
1061
1062         bool y_movement_matters () const {
1063                 return false;
1064         }
1065
1066 private:
1067         void update_item (ARDOUR::Location *);
1068
1069         Operation _operation;
1070         ArdourCanvas::Rectangle* _drag_rect;
1071         bool _copy;
1072 };
1073
1074 /** Drag of rectangle to set zoom */
1075 class MouseZoomDrag : public Drag
1076 {
1077 public:
1078         MouseZoomDrag (Editor *, ArdourCanvas::Item *);
1079
1080         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
1081         void motion (GdkEvent *, bool);
1082         void finished (GdkEvent *, bool);
1083         void aborted (bool);
1084
1085         std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
1086                 return std::make_pair (4, 4);
1087         }
1088
1089 private:
1090         bool _zoom_out;
1091 };
1092
1093 /** Drag of a range of automation data (either on an automation track or region gain),
1094  *  changing value but not position.
1095  */
1096 class AutomationRangeDrag : public Drag
1097 {
1098 public:
1099         AutomationRangeDrag (Editor *, AutomationTimeAxisView *, std::list<ARDOUR::AudioRange> const &);
1100         AutomationRangeDrag (Editor *, RegionView *, std::list<ARDOUR::AudioRange> const &);
1101
1102         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
1103         void motion (GdkEvent *, bool);
1104         void finished (GdkEvent *, bool);
1105         void aborted (bool);
1106
1107         bool x_movement_matters () const {
1108                 return false;
1109         }
1110
1111 private:
1112         void setup (std::list<boost::shared_ptr<AutomationLine> > const &);
1113         double y_fraction (boost::shared_ptr<AutomationLine>, double global_y_position) const;
1114         double value (boost::shared_ptr<ARDOUR::AutomationList> list, double x) const;
1115
1116         std::list<ARDOUR::AudioRange> _ranges;
1117
1118         /** A line that is part of the drag */
1119         struct Line {
1120                 boost::shared_ptr<AutomationLine> line; ///< the line
1121                 std::list<ControlPoint*> points; ///< points to drag on the line
1122                 std::pair<ARDOUR::framepos_t, ARDOUR::framepos_t> range; ///< the range of all points on the line, in session frames
1123                 XMLNode* state; ///< the XML state node before the drag
1124                 double original_fraction; ///< initial y-fraction before the drag
1125         };
1126
1127         std::list<Line> _lines;
1128         double          _y_origin;
1129         bool            _nothing_to_drag;
1130         bool            _integral;
1131 };
1132
1133 /** Drag of one edge of an xfade
1134  */
1135 class CrossfadeEdgeDrag : public Drag
1136 {
1137   public:
1138         CrossfadeEdgeDrag (Editor*, AudioRegionView*, ArdourCanvas::Item*, bool start);
1139
1140         void start_grab (GdkEvent*, Gdk::Cursor* c = 0);
1141         void motion (GdkEvent*, bool);
1142         void finished (GdkEvent*, bool);
1143         void aborted (bool);
1144
1145         bool y_movement_matters () const {
1146                 return false;
1147         }
1148
1149         virtual std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
1150                 return std::make_pair (4, 4);
1151         }
1152
1153   private:
1154         AudioRegionView* arv;
1155         bool start;
1156 };
1157
1158 #endif /* __gtk2_ardour_editor_drag_h_ */
1159