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