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