Don't add history by clicking a control point, fix control point selection.
[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         ARDOUR::frameoffset_t snap_delta (guint const) const;
221
222         double current_pointer_x () const;
223         double current_pointer_y () const;
224
225         /* sets snap delta from unsnapped pos */
226         void setup_snap_delta (framepos_t pos);
227
228         boost::shared_ptr<ARDOUR::Region> add_midi_region (MidiTimeAxisView*);
229
230         void show_verbose_cursor_time (framepos_t);
231         void show_verbose_cursor_duration (framepos_t, framepos_t, double xoffset = 0);
232         void show_verbose_cursor_text (std::string const &);
233
234         Editor* _editor; ///< our editor
235         DragManager* _drags;
236         ArdourCanvas::Item* _item; ///< our item
237         /** Offset from the mouse's position for the drag to the start of the thing that is being dragged */
238         ARDOUR::framecnt_t _pointer_frame_offset;
239         bool _x_constrained; ///< true if x motion is constrained, otherwise false
240         bool _y_constrained; ///< true if y motion is constrained, otherwise false
241         bool _was_rolling; ///< true if the session was rolling before the drag started, otherwise false
242
243 private:
244         bool _trackview_only; ///< true if pointer y value should always be relative to the top of the trackview group
245         bool _move_threshold_passed; ///< true if the move threshold has been passed, otherwise false
246         bool _starting_point_passed; ///< true if we called move () with first_move flag, otherwise false
247         bool _initially_vertical; ///< true if after move threshold is passed we appear to be moving vertically; undefined before that
248         bool _was_double_click; ///< true if drag initiated by a double click event
249         double _grab_x; ///< trackview x of the grab start position
250         double _grab_y; ///< y of the grab start position, possibly adjusted if _trackview_only is true
251         double _last_pointer_x; ///< trackview x of the pointer last time a motion occurred
252         double _last_pointer_y; ///< trackview y of the pointer last time a motion occurred
253         ARDOUR::framepos_t _raw_grab_frame; ///< unsnapped frame that the mouse was at when start_grab was called, or 0
254         ARDOUR::framepos_t _grab_frame; ///< adjusted_frame that the mouse was at when start_grab was called, or 0
255         ARDOUR::framepos_t _last_pointer_frame; ///< adjusted_frame the last time a motion occurred
256
257         /* difference between some key position's snapped and unsnapped
258          *  framepos. used for relative snap.
259          */
260         ARDOUR::frameoffset_t _snap_delta;
261         CursorContext::Handle _cursor_ctx; ///< cursor change context
262 };
263
264 class RegionDrag;
265
266 /** Container for details about a region being dragged */
267 class DraggingView
268 {
269 public:
270         DraggingView (RegionView *, RegionDrag *, TimeAxisView* original_tav);
271
272         RegionView* view; ///< the view
273         /** index into RegionDrag::_time_axis_views of the view that this region is currently being displayed on,
274          *  or -1 if it is not visible.
275          */
276         int time_axis_view;
277         /** layer that this region is currently being displayed on.  This is a double
278             rather than a layer_t as we use fractional layers during drags to allow the user
279             to indicate a new layer to put a region on.
280         */
281         double layer;
282         double initial_y; ///< the initial y position of the view before any reparenting
283         framepos_t initial_position; ///< initial position of the region
284         framepos_t initial_end; ///< initial end position of the region
285         framepos_t anchored_fade_length; ///< fade_length when anchored during drag
286         boost::shared_ptr<ARDOUR::Playlist> initial_playlist;
287         TimeAxisView* initial_time_axis_view;
288 };
289
290 /** Abstract base class for drags that involve region(s) */
291 class RegionDrag : public Drag, public sigc::trackable
292 {
293 public:
294         RegionDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
295         virtual ~RegionDrag () {}
296
297 protected:
298
299         RegionView* _primary; ///< the view that was clicked on (or whatever) to start the drag
300         std::list<DraggingView> _views; ///< information about all views that are being dragged
301
302         /** a list of the non-hidden TimeAxisViews sorted by editor order key */
303         std::vector<TimeAxisView*> _time_axis_views;
304         int find_time_axis_view (TimeAxisView *) const;
305         int apply_track_delta (const int start, const int delta, const int skip, const bool distance_only = false) const;
306
307         int _visible_y_low;
308         int _visible_y_high;
309         uint32_t _ntracks;
310
311         friend class DraggingView;
312
313 private:
314
315         void region_going_away (RegionView *);
316         PBD::ScopedConnection death_connection;
317 };
318
319
320 /** Drags involving region motion from somewhere */
321 class RegionMotionDrag : public RegionDrag
322 {
323 public:
324
325         RegionMotionDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &, bool);
326         virtual ~RegionMotionDrag () {}
327
328         virtual void start_grab (GdkEvent *, Gdk::Cursor *);
329         virtual void motion (GdkEvent *, bool);
330         virtual void finished (GdkEvent *, bool);
331         virtual void aborted (bool);
332
333         /** @return true if the regions being `moved' came from somewhere on the canvas;
334          *  false if they came from outside (e.g. from the region list).
335          */
336         virtual bool regions_came_from_canvas () const = 0;
337
338 protected:
339
340         double compute_x_delta (GdkEvent const *, ARDOUR::framepos_t *);
341         virtual bool y_movement_allowed (int, double, int skip_invisible = 0) const;
342
343         bool _brushing;
344         ARDOUR::framepos_t _last_frame_position; ///< last position of the thing being dragged
345         double _total_x_delta;
346         int _last_pointer_time_axis_view;
347         double _last_pointer_layer;
348 private:
349         uint32_t _ndropzone;
350         uint32_t _pdropzone;
351         uint32_t _ddropzone;
352 };
353
354
355 /** Drags to move (or copy) regions that are already shown in the GUI to
356  *  somewhere different.
357  */
358 class RegionMoveDrag : public RegionMotionDrag
359 {
360 public:
361         RegionMoveDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &, bool, bool);
362         virtual ~RegionMoveDrag () {}
363
364         void motion (GdkEvent *, bool);
365         void finished (GdkEvent *, bool);
366         void aborted (bool);
367
368         bool regions_came_from_canvas () const {
369                 return true;
370         }
371
372         std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
373                 return std::make_pair (4, 4);
374         }
375
376         void setup_pointer_frame_offset ();
377
378 protected:
379         typedef std::set<boost::shared_ptr<ARDOUR::Playlist> > PlaylistSet;
380         void add_stateful_diff_commands_for_playlists (PlaylistSet const &);
381
382 private:
383         void finished_no_copy (
384                 bool const,
385                 bool const,
386                 ARDOUR::framecnt_t const
387                 );
388
389         void finished_copy (
390                 bool const,
391                 bool const,
392                 ARDOUR::framecnt_t const
393                 );
394
395         RegionView* insert_region_into_playlist (
396                 boost::shared_ptr<ARDOUR::Region>,
397                 RouteTimeAxisView*,
398                 ARDOUR::layer_t,
399                 ARDOUR::framecnt_t,
400                 PlaylistSet&
401                 );
402
403         void remove_region_from_playlist (
404                 boost::shared_ptr<ARDOUR::Region>,
405                 boost::shared_ptr<ARDOUR::Playlist>,
406                 PlaylistSet& modified_playlists
407                 );
408
409
410         void collect_new_region_view (RegionView *);
411         RouteTimeAxisView* create_destination_time_axis (boost::shared_ptr<ARDOUR::Region>, TimeAxisView* original);
412
413         bool _copy;
414         RegionView* _new_region_view;
415 };
416
417 /** Drag to insert a region from somewhere */
418 class RegionInsertDrag : public RegionMotionDrag
419 {
420 public:
421         RegionInsertDrag (Editor *, boost::shared_ptr<ARDOUR::Region>, RouteTimeAxisView*, ARDOUR::framepos_t);
422
423         void finished (GdkEvent *, bool);
424         void aborted (bool);
425
426         bool regions_came_from_canvas () const {
427                 return false;
428         }
429 };
430
431 /** Region drag in splice mode */
432 class RegionSpliceDrag : public RegionMoveDrag
433 {
434 public:
435         RegionSpliceDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
436
437         void motion (GdkEvent *, bool);
438         void finished (GdkEvent *, bool);
439         void aborted (bool);
440 };
441
442 /** Region drag in ripple mode */
443
444 class RegionRippleDrag : public RegionMoveDrag
445 {
446 public:
447         RegionRippleDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
448         ~RegionRippleDrag () { delete exclude; }
449
450         void motion (GdkEvent *, bool);
451         void finished (GdkEvent *, bool);
452         void aborted (bool);
453 protected:
454         bool y_movement_allowed (int delta_track, double delta_layer, int skip_invisible = 0) const;
455
456 private:
457         TimeAxisView *prev_tav;         // where regions were most recently dragged from
458         TimeAxisView *orig_tav;         // where drag started
459         framecnt_t prev_amount;
460         framepos_t prev_position;
461         framecnt_t selection_length;
462         bool allow_moves_across_tracks; // only if all selected regions are on one track
463         ARDOUR::RegionList *exclude;
464         void add_all_after_to_views (TimeAxisView *tav, framepos_t where, const RegionSelection &exclude, bool drag_in_progress);
465         void remove_unselected_from_views (framecnt_t amount, bool move_regions);
466
467 };
468
469 /** "Drag" to cut a region (action only on button release) */
470 class RegionCutDrag : public Drag
471 {
472     public:
473         RegionCutDrag (Editor*, ArdourCanvas::Item*, framepos_t);
474         ~RegionCutDrag ();
475
476         void motion (GdkEvent*, bool);
477         void finished (GdkEvent*, bool);
478         void aborted (bool);
479
480     private:
481         EditorCursor* line;
482 };
483
484 /** Drags to create regions */
485 class RegionCreateDrag : public Drag
486 {
487 public:
488         RegionCreateDrag (Editor *, ArdourCanvas::Item *, TimeAxisView *);
489
490         void motion (GdkEvent *, bool);
491         void finished (GdkEvent *, bool);
492         void aborted (bool);
493
494 private:
495         MidiTimeAxisView* _view;
496         boost::shared_ptr<ARDOUR::Region> _region;
497 };
498
499 /** Drags to resize MIDI notes */
500 class NoteResizeDrag : public Drag
501 {
502 public:
503         NoteResizeDrag (Editor *, ArdourCanvas::Item *);
504
505         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
506         void motion (GdkEvent *, bool);
507         void finished (GdkEvent *, bool);
508         void aborted (bool);
509
510 private:
511         MidiRegionView*     region;
512         bool                relative;
513         bool                at_front;
514         double              _snap_delta;
515 };
516
517 /** Drags to move MIDI notes */
518 class NoteDrag : public Drag
519 {
520   public:
521         NoteDrag (Editor*, ArdourCanvas::Item*);
522
523         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
524         void motion (GdkEvent *, bool);
525         void finished (GdkEvent *, bool);
526         void aborted (bool);
527
528   private:
529
530         ARDOUR::frameoffset_t total_dx (const guint) const;
531         int8_t total_dy () const;
532
533         MidiRegionView* _region;
534         NoteBase* _primary;
535         double _cumulative_dx;
536         double _cumulative_dy;
537         bool _was_selected;
538         double _note_height;
539 };
540
541 class NoteCreateDrag : public Drag
542 {
543 public:
544         NoteCreateDrag (Editor *, ArdourCanvas::Item *, MidiRegionView *);
545         ~NoteCreateDrag ();
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         bool active (Editing::MouseMode mode) {
553                 return mode == Editing::MouseDraw || mode == Editing::MouseContent;
554         }
555
556         bool y_movement_matters () const {
557                 return false;
558         }
559
560 private:
561         double y_to_region (double) const;
562         framecnt_t grid_frames (framepos_t) const;
563         
564         MidiRegionView* _region_view;
565         ArdourCanvas::Rectangle* _drag_rect;
566         framepos_t _note[2];
567 };
568
569 /** Drag to move MIDI patch changes */
570 class PatchChangeDrag : public Drag
571 {
572 public:
573         PatchChangeDrag (Editor *, PatchChange *, MidiRegionView *);
574
575         void motion (GdkEvent *, bool);
576         void finished (GdkEvent *, bool);
577         void aborted (bool);
578
579         bool y_movement_matters () const {
580                 return false;
581         }
582
583         void setup_pointer_frame_offset ();
584
585 private:
586         MidiRegionView* _region_view;
587         PatchChange* _patch_change;
588         double _cumulative_dx;
589 };
590
591 /** Container for details about audio regions being dragged along with video */
592 class AVDraggingView
593 {
594 public:
595         AVDraggingView (RegionView *);
596
597         RegionView* view; ///< the view
598         framepos_t initial_position; ///< initial position of the region
599 };
600
601 /** Drag of video offset */
602 class VideoTimeLineDrag : public Drag
603 {
604 public:
605         VideoTimeLineDrag (Editor *e, ArdourCanvas::Item *i);
606
607         void motion (GdkEvent *, bool);
608         void finished (GdkEvent *, bool);
609         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
610
611         bool y_movement_matters () const {
612                 return false;
613         }
614
615         bool allow_vertical_autoscroll () const {
616                 return false;
617         }
618
619         void aborted (bool);
620
621 protected:
622         std::list<AVDraggingView> _views; ///< information about all audio that are being dragged along
623
624 private:
625         ARDOUR::frameoffset_t _startdrag_video_offset;
626         ARDOUR::frameoffset_t _max_backwards_drag;
627 };
628
629 /** Drag to trim region(s) */
630 class TrimDrag : public RegionDrag
631 {
632 public:
633         enum Operation {
634                 StartTrim,
635                 EndTrim,
636                 ContentsTrim,
637         };
638
639         TrimDrag (Editor *, ArdourCanvas::Item *, RegionView*, std::list<RegionView*> const &, bool preserve_fade_anchor = false);
640
641         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
642         void motion (GdkEvent *, bool);
643         void finished (GdkEvent *, bool);
644         void aborted (bool);
645
646         bool y_movement_matters () const {
647                 return false;
648         }
649
650         void setup_pointer_frame_offset ();
651
652 private:
653
654         Operation _operation;
655         
656         bool _preserve_fade_anchor;
657         bool _jump_position_when_done;
658 };
659
660 /** Meter marker drag */
661 class MeterMarkerDrag : public Drag
662 {
663 public:
664         MeterMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
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 allow_vertical_autoscroll () const {
672                 return false;
673         }
674
675         bool y_movement_matters () const {
676                 return false;
677         }
678
679         void setup_pointer_frame_offset ();
680
681 private:
682         MeterMarker* _marker;
683         bool _copy;
684         XMLNode* before_state;
685 };
686
687 /** Tempo marker drag */
688 class TempoMarkerDrag : public Drag
689 {
690 public:
691         TempoMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
692
693         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
694         void motion (GdkEvent *, bool);
695         void finished (GdkEvent *, bool);
696         void aborted (bool);
697
698         bool allow_vertical_autoscroll () const {
699                 return false;
700         }
701
702         bool y_movement_matters () const {
703                 return false;
704         }
705
706         void setup_pointer_frame_offset ();
707
708 private:
709         TempoMarker* _marker;
710         bool _copy;
711         XMLNode* before_state;
712 };
713
714
715 /** Drag of the playhead cursor */
716 class CursorDrag : public Drag
717 {
718 public:
719         CursorDrag (Editor *, EditorCursor&, bool);
720
721         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
722         void motion (GdkEvent *, bool);
723         void finished (GdkEvent *, bool);
724         void aborted (bool);
725
726         bool allow_vertical_autoscroll () const {
727                 return false;
728         }
729
730         bool y_movement_matters () const {
731                 return true;
732         }
733
734 private:
735         void fake_locate (framepos_t);
736
737         EditorCursor& _cursor;
738         bool _stop; ///< true to stop the transport on starting the drag, otherwise false
739         double _grab_zoom; ///< editor frames per unit when our grab started
740 };
741
742 /** Region fade-in drag */
743 class FadeInDrag : public RegionDrag
744 {
745 public:
746         FadeInDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
747
748         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
749         void motion (GdkEvent *, bool);
750         void finished (GdkEvent *, bool);
751         void aborted (bool);
752
753         bool y_movement_matters () const {
754                 return false;
755         }
756
757         void setup_pointer_frame_offset ();
758 };
759
760 /** Region fade-out drag */
761 class FadeOutDrag : public RegionDrag
762 {
763 public:
764         FadeOutDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
765
766         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
767         void motion (GdkEvent *, bool);
768         void finished (GdkEvent *, bool);
769         void aborted (bool);
770
771         bool y_movement_matters () const {
772                 return false;
773         }
774
775         void setup_pointer_frame_offset ();
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   _first_move;
838         bool     _pushing;
839         uint32_t _final_index;
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 };
965
966 /** Scrub drag in audition mode */
967 class ScrubDrag : public Drag
968 {
969 public:
970         ScrubDrag (Editor *, ArdourCanvas::Item *);
971
972         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
973         void motion (GdkEvent *, bool);
974         void finished (GdkEvent *, bool);
975         void aborted (bool);
976 };
977
978 /** Drag in range select mode */
979 class SelectionDrag : public Drag
980 {
981 public:
982         enum Operation {
983                 CreateSelection,
984                 SelectionStartTrim,
985                 SelectionEndTrim,
986                 SelectionMove,
987                 SelectionExtend
988         };
989
990         SelectionDrag (Editor *, ArdourCanvas::Item *, Operation);
991
992         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
993         void motion (GdkEvent *, bool);
994         void finished (GdkEvent *, bool);
995         void aborted (bool);
996
997         void setup_pointer_frame_offset ();
998
999 private:
1000         Operation _operation;
1001         bool _add;
1002         std::list<TimeAxisView*> _added_time_axes;
1003         bool _time_selection_at_start;
1004         framepos_t start_at_start;
1005         framepos_t end_at_start;
1006 };
1007
1008 /** Range marker drag */
1009 class RangeMarkerBarDrag : public Drag
1010 {
1011 public:
1012         enum Operation {
1013                 CreateSkipMarker,
1014                 CreateRangeMarker,
1015                 CreateTransportMarker,
1016                 CreateCDMarker
1017         };
1018
1019         RangeMarkerBarDrag (Editor *, ArdourCanvas::Item *, Operation);
1020         ~RangeMarkerBarDrag ();
1021         
1022         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
1023         void motion (GdkEvent *, bool);
1024         void finished (GdkEvent *, bool);
1025         void aborted (bool);
1026
1027         bool allow_vertical_autoscroll () const {
1028                 return false;
1029         }
1030
1031         bool y_movement_matters () const {
1032                 return false;
1033         }
1034
1035 private:
1036         void update_item (ARDOUR::Location *);
1037
1038         Operation _operation;
1039         ArdourCanvas::Rectangle* _drag_rect;
1040         bool _copy;
1041 };
1042
1043 /** Drag of rectangle to set zoom */
1044 class MouseZoomDrag : public Drag
1045 {
1046 public:
1047         MouseZoomDrag (Editor *, ArdourCanvas::Item *);
1048
1049         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
1050         void motion (GdkEvent *, bool);
1051         void finished (GdkEvent *, bool);
1052         void aborted (bool);
1053
1054         std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
1055                 return std::make_pair (4, 4);
1056         }
1057
1058 private:
1059         bool _zoom_out;
1060 };
1061
1062 /** Drag of a range of automation data (either on an automation track or region gain),
1063  *  changing value but not position.
1064  */
1065 class AutomationRangeDrag : public Drag
1066 {
1067 public:
1068         AutomationRangeDrag (Editor *, AutomationTimeAxisView *, std::list<ARDOUR::AudioRange> const &);
1069         AutomationRangeDrag (Editor *, RegionView *, std::list<ARDOUR::AudioRange> const &);
1070
1071         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
1072         void motion (GdkEvent *, bool);
1073         void finished (GdkEvent *, bool);
1074         void aborted (bool);
1075
1076         bool x_movement_matters () const {
1077                 return false;
1078         }
1079
1080 private:
1081         void setup (std::list<boost::shared_ptr<AutomationLine> > const &);
1082         double y_fraction (boost::shared_ptr<AutomationLine>, double global_y_position) const;
1083         double value (boost::shared_ptr<ARDOUR::AutomationList> list, double x) const;
1084
1085         std::list<ARDOUR::AudioRange> _ranges;
1086
1087         /** A line that is part of the drag */
1088         struct Line {
1089                 boost::shared_ptr<AutomationLine> line; ///< the line
1090                 std::list<ControlPoint*> points; ///< points to drag on the line
1091                 std::pair<ARDOUR::framepos_t, ARDOUR::framepos_t> range; ///< the range of all points on the line, in session frames
1092                 XMLNode* state; ///< the XML state node before the drag
1093                 double original_fraction; ///< initial y-fraction before the drag
1094         };
1095
1096         std::list<Line> _lines;
1097         double          _y_origin;
1098         bool            _nothing_to_drag;
1099         bool            _integral;
1100 };
1101
1102 /** Drag of one edge of an xfade
1103  */
1104 class CrossfadeEdgeDrag : public Drag
1105 {
1106   public:
1107         CrossfadeEdgeDrag (Editor*, AudioRegionView*, ArdourCanvas::Item*, bool start);
1108
1109         void start_grab (GdkEvent*, Gdk::Cursor* c = 0);
1110         void motion (GdkEvent*, bool);
1111         void finished (GdkEvent*, bool);
1112         void aborted (bool);
1113         
1114         bool y_movement_matters () const {
1115                 return false;
1116         }
1117
1118         virtual std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
1119                 return std::make_pair (4, 4);
1120         }
1121
1122   private:
1123         AudioRegionView* arv;
1124         bool start;
1125 };
1126
1127 #endif /* __gtk2_ardour_editor_drag_h_ */
1128