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