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