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