adding a new track via copy-region-drag now works (and shares code with the non-copy...
[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 "editor_items.h"
31
32 namespace ARDOUR {
33         class Location;
34 }
35
36 namespace PBD {
37         class StatefulDiffCommand;
38 }
39
40 class PatchChange;
41 class Editor;
42 class EditorCursor;
43 class TimeAxisView;
44 class MidiTimeAxisView;
45 class Drag;
46 class NoteBase;
47
48 /** Class to manage current drags */
49 class DragManager
50 {
51 public:
52
53         DragManager (Editor* e);
54         ~DragManager ();
55
56         bool motion_handler (GdkEvent *, bool);
57         bool window_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 *);
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 (m != Editing::MouseGain);
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         boost::shared_ptr<ARDOUR::Region> add_midi_region (MidiTimeAxisView*);
216
217         void show_verbose_cursor_time (framepos_t);
218         void show_verbose_cursor_duration (framepos_t, framepos_t, double xoffset = 0);
219         void show_verbose_cursor_text (std::string const &);
220
221         Editor* _editor; ///< our editor
222         DragManager* _drags;
223         ArdourCanvas::Item* _item; ///< our item
224         /** Offset from the mouse's position for the drag to the start of the thing that is being dragged */
225         ARDOUR::framecnt_t _pointer_frame_offset;
226         bool _x_constrained; ///< true if x motion is constrained, otherwise false
227         bool _y_constrained; ///< true if y motion is constrained, otherwise false
228         bool _was_rolling; ///< true if the session was rolling before the drag started, otherwise false
229
230 private:
231
232         bool _move_threshold_passed; ///< true if the move threshold has been passed, otherwise false
233         bool _was_double_click; ///< true if drag initiated by a double click event
234         double _grab_x; ///< trackview x of the grab start position
235         double _grab_y; ///< trackview y of the grab start position
236         double _last_pointer_x; ///< trackview x of the pointer last time a motion occurred
237         double _last_pointer_y; ///< trackview y of the pointer last time a motion occurred
238         ARDOUR::framepos_t _raw_grab_frame; ///< unsnapped frame that the mouse was at when start_grab was called, or 0
239         ARDOUR::framepos_t _grab_frame; ///< adjusted_frame that the mouse was at when start_grab was called, or 0
240         ARDOUR::framepos_t _last_pointer_frame; ///< adjusted_frame the last time a motion occurred
241 };
242
243 class RegionDrag;
244
245 /** Container for details about a region being dragged */
246 class DraggingView
247 {
248 public:
249         DraggingView (RegionView *, RegionDrag *);
250
251         RegionView* view; ///< the view
252         /** index into RegionDrag::_time_axis_views of the view that this region is currently being displayed on,
253          *  or -1 if it is not visible.
254          */
255         int time_axis_view;
256         /** layer that this region is currently being displayed on.  This is a double
257             rather than a layer_t as we use fractional layers during drags to allow the user
258             to indicate a new layer to put a region on.
259         */
260         double layer;
261         double initial_y; ///< the initial y position of the view before any reparenting
262         framepos_t initial_position; ///< initial position of the region
263         framepos_t initial_end; ///< initial end position of the region
264         boost::shared_ptr<ARDOUR::Playlist> initial_playlist;
265 };
266
267 /** Abstract base class for drags that involve region(s) */
268 class RegionDrag : public Drag, public sigc::trackable
269 {
270 public:
271         RegionDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
272         virtual ~RegionDrag () {}
273
274 protected:
275
276         RegionView* _primary; ///< the view that was clicked on (or whatever) to start the drag
277         std::list<DraggingView> _views; ///< information about all views that are being dragged
278
279         /** a list of the non-hidden TimeAxisViews sorted by editor order key */
280         std::vector<TimeAxisView*> _time_axis_views;
281         int find_time_axis_view (TimeAxisView *) const;
282
283         int _visible_y_low;
284         int _visible_y_high;
285
286         friend class DraggingView;
287
288 private:
289
290         void region_going_away (RegionView *);
291         PBD::ScopedConnection death_connection;
292 };
293
294
295 /** Drags involving region motion from somewhere */
296 class RegionMotionDrag : public RegionDrag
297 {
298 public:
299
300         RegionMotionDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &, bool);
301         virtual ~RegionMotionDrag () {}
302
303         virtual void start_grab (GdkEvent *, Gdk::Cursor *);
304         virtual void motion (GdkEvent *, bool);
305         virtual void finished (GdkEvent *, bool);
306         virtual void aborted (bool);
307
308         /** @return true if the regions being `moved' came from somewhere on the canvas;
309          *  false if they came from outside (e.g. from the region list).
310          */
311         virtual bool regions_came_from_canvas () const = 0;
312
313 protected:
314
315         double compute_x_delta (GdkEvent const *, ARDOUR::framepos_t *);
316         bool y_movement_allowed (int, double) const;
317
318         bool _brushing;
319         ARDOUR::framepos_t _last_frame_position; ///< last position of the thing being dragged
320         double _total_x_delta;
321         int _last_pointer_time_axis_view;
322         double _last_pointer_layer;
323 };
324
325
326 /** Drags to move (or copy) regions that are already shown in the GUI to
327  *  somewhere different.
328  */
329 class RegionMoveDrag : public RegionMotionDrag
330 {
331 public:
332         RegionMoveDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &, bool, bool);
333         virtual ~RegionMoveDrag () {}
334
335         void motion (GdkEvent *, bool);
336         void finished (GdkEvent *, bool);
337         void aborted (bool);
338
339         bool regions_came_from_canvas () const {
340                 return true;
341         }
342
343         std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
344                 return std::make_pair (4, 4);
345         }
346
347         void setup_pointer_frame_offset ();
348
349 private:
350         typedef std::set<boost::shared_ptr<ARDOUR::Playlist> > PlaylistSet;
351
352         void finished_no_copy (
353                 bool const,
354                 bool const,
355                 ARDOUR::framecnt_t const
356                 );
357
358         void finished_copy (
359                 bool const,
360                 bool const,
361                 ARDOUR::framecnt_t const
362                 );
363
364         RegionView* insert_region_into_playlist (
365                 boost::shared_ptr<ARDOUR::Region>,
366                 RouteTimeAxisView*,
367                 ARDOUR::layer_t,
368                 ARDOUR::framecnt_t,
369                 PlaylistSet&
370                 );
371
372         void remove_region_from_playlist (
373                 boost::shared_ptr<ARDOUR::Region>,
374                 boost::shared_ptr<ARDOUR::Playlist>,
375                 PlaylistSet& modified_playlists
376                 );
377
378         void add_stateful_diff_commands_for_playlists (PlaylistSet const &);
379
380         void collect_new_region_view (RegionView *);
381         RouteTimeAxisView* create_destination_time_axis (boost::shared_ptr<ARDOUR::Region>);
382
383         bool _copy;
384         RegionView* _new_region_view;
385 };
386
387 /** Drag to insert a region from somewhere */
388 class RegionInsertDrag : public RegionMotionDrag
389 {
390 public:
391         RegionInsertDrag (Editor *, boost::shared_ptr<ARDOUR::Region>, RouteTimeAxisView*, ARDOUR::framepos_t);
392
393         void finished (GdkEvent *, bool);
394         void aborted (bool);
395
396         bool regions_came_from_canvas () const {
397                 return false;
398         }
399 };
400
401 /** Region drag in splice mode */
402 class RegionSpliceDrag : public RegionMoveDrag
403 {
404 public:
405         RegionSpliceDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
406
407         void motion (GdkEvent *, bool);
408         void finished (GdkEvent *, bool);
409         void aborted (bool);
410 };
411
412 /** Drags to create regions */
413 class RegionCreateDrag : public Drag
414 {
415 public:
416         RegionCreateDrag (Editor *, ArdourCanvas::Item *, TimeAxisView *);
417
418         void motion (GdkEvent *, bool);
419         void finished (GdkEvent *, bool);
420         void aborted (bool);
421
422 private:
423         MidiTimeAxisView* _view;
424         boost::shared_ptr<ARDOUR::Region> _region;
425 };
426
427 /** Drags to resize MIDI notes */
428 class NoteResizeDrag : public Drag
429 {
430 public:
431         NoteResizeDrag (Editor *, ArdourCanvas::Item *);
432
433         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
434         void motion (GdkEvent *, bool);
435         void finished (GdkEvent *, bool);
436         void aborted (bool);
437
438 private:
439         MidiRegionView*     region;
440         bool                relative;
441         bool                at_front;
442 };
443
444 /** Drags to move MIDI notes */
445 class NoteDrag : public Drag
446 {
447   public:
448         NoteDrag (Editor*, ArdourCanvas::Item*);
449
450         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
451         void motion (GdkEvent *, bool);
452         void finished (GdkEvent *, bool);
453         void aborted (bool);
454
455   private:
456
457         ARDOUR::frameoffset_t total_dx () const;
458         int8_t total_dy () const;
459
460         MidiRegionView* _region;
461         NoteBase* _primary;
462         double _cumulative_dx;
463         double _cumulative_dy;
464         bool _was_selected;
465         double _note_height;
466 };
467
468 class NoteCreateDrag : public Drag
469 {
470 public:
471         NoteCreateDrag (Editor *, ArdourCanvas::Item *, MidiRegionView *);
472         ~NoteCreateDrag ();
473
474         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
475         void motion (GdkEvent *, bool);
476         void finished (GdkEvent *, bool);
477         void aborted (bool);
478
479 private:
480         double y_to_region (double) const;
481         framecnt_t grid_frames (framepos_t) const;
482         
483         MidiRegionView* _region_view;
484         ArdourCanvas::Rectangle* _drag_rect;
485         framepos_t _note[2];
486 };
487
488 /** Drag to move MIDI patch changes */
489 class PatchChangeDrag : public Drag
490 {
491 public:
492         PatchChangeDrag (Editor *, PatchChange *, MidiRegionView *);
493
494         void motion (GdkEvent *, bool);
495         void finished (GdkEvent *, bool);
496         void aborted (bool);
497
498         bool y_movement_matters () const {
499                 return false;
500         }
501
502         void setup_pointer_frame_offset ();
503
504 private:
505         MidiRegionView* _region_view;
506         PatchChange* _patch_change;
507         double _cumulative_dx;
508 };
509
510 /** Container for details about audio regions being dragged along with video */
511 class AVDraggingView
512 {
513 public:
514         AVDraggingView (RegionView *);
515
516         RegionView* view; ///< the view
517         framepos_t initial_position; ///< initial position of the region
518 };
519
520 /** Drag of video offset */
521 class VideoTimeLineDrag : public Drag
522 {
523 public:
524         VideoTimeLineDrag (Editor *e, ArdourCanvas::Item *i);
525
526         void motion (GdkEvent *, bool);
527         void finished (GdkEvent *, bool);
528         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
529
530         bool y_movement_matters () const {
531                 return false;
532         }
533
534         bool allow_vertical_autoscroll () const {
535                 return false;
536         }
537
538         void aborted (bool);
539
540 protected:
541         std::list<AVDraggingView> _views; ///< information about all audio that are being dragged along
542
543 private:
544         ARDOUR::frameoffset_t _startdrag_video_offset;
545         ARDOUR::frameoffset_t _max_backwards_drag;
546 };
547
548 /** Drag to trim region(s) */
549 class TrimDrag : public RegionDrag
550 {
551 public:
552         enum Operation {
553                 StartTrim,
554                 EndTrim,
555                 ContentsTrim,
556         };
557
558         TrimDrag (Editor *, ArdourCanvas::Item *, RegionView*, std::list<RegionView*> const &, bool preserve_fade_anchor = false);
559
560         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
561         void motion (GdkEvent *, bool);
562         void finished (GdkEvent *, bool);
563         void aborted (bool);
564
565         bool y_movement_matters () const {
566                 return false;
567         }
568
569         void setup_pointer_frame_offset ();
570
571 private:
572
573         Operation _operation;
574         
575         bool _preserve_fade_anchor;
576         bool _jump_position_when_done;
577 };
578
579 /** Meter marker drag */
580 class MeterMarkerDrag : public Drag
581 {
582 public:
583         MeterMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
584
585         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
586         void motion (GdkEvent *, bool);
587         void finished (GdkEvent *, bool);
588         void aborted (bool);
589
590         bool allow_vertical_autoscroll () const {
591                 return false;
592         }
593
594         bool y_movement_matters () const {
595                 return false;
596         }
597
598         void setup_pointer_frame_offset ();
599
600 private:
601         MeterMarker* _marker;
602         bool _copy;
603         XMLNode* before_state;
604 };
605
606 /** Tempo marker drag */
607 class TempoMarkerDrag : public Drag
608 {
609 public:
610         TempoMarkerDrag (Editor *, ArdourCanvas::Item *, bool);
611
612         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
613         void motion (GdkEvent *, bool);
614         void finished (GdkEvent *, bool);
615         void aborted (bool);
616
617         bool allow_vertical_autoscroll () const {
618                 return false;
619         }
620
621         bool y_movement_matters () const {
622                 return false;
623         }
624
625         void setup_pointer_frame_offset ();
626
627 private:
628         TempoMarker* _marker;
629         bool _copy;
630         XMLNode* before_state;
631 };
632
633
634 /** Drag of the playhead cursor */
635 class CursorDrag : public Drag
636 {
637 public:
638         CursorDrag (Editor *, EditorCursor&, bool);
639
640         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
641         void motion (GdkEvent *, bool);
642         void finished (GdkEvent *, bool);
643         void aborted (bool);
644
645         bool active (Editing::MouseMode) {
646                 return true;
647         }
648
649         bool allow_vertical_autoscroll () const {
650                 return false;
651         }
652
653         bool y_movement_matters () const {
654                 return true;
655         }
656
657 private:
658         void fake_locate (framepos_t);
659
660         EditorCursor& _cursor;
661         bool _stop; ///< true to stop the transport on starting the drag, otherwise false
662         double _grab_zoom; ///< editor frames per unit when our grab started
663 };
664
665 /** Region fade-in drag */
666 class FadeInDrag : public RegionDrag
667 {
668 public:
669         FadeInDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
670
671         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
672         void motion (GdkEvent *, bool);
673         void finished (GdkEvent *, bool);
674         void aborted (bool);
675
676         bool y_movement_matters () const {
677                 return false;
678         }
679
680         void setup_pointer_frame_offset ();
681 };
682
683 /** Region fade-out drag */
684 class FadeOutDrag : public RegionDrag
685 {
686 public:
687         FadeOutDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
688
689         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
690         void motion (GdkEvent *, bool);
691         void finished (GdkEvent *, bool);
692         void aborted (bool);
693
694         bool y_movement_matters () const {
695                 return false;
696         }
697
698         void setup_pointer_frame_offset ();
699 };
700
701 /** Marker drag */
702 class MarkerDrag : public Drag
703 {
704 public:
705         MarkerDrag (Editor *, ArdourCanvas::Item *);
706         ~MarkerDrag ();
707
708         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
709         void motion (GdkEvent *, bool);
710         void finished (GdkEvent *, bool);
711         void aborted (bool);
712
713         bool allow_vertical_autoscroll () const {
714                 return false;
715         }
716
717         bool y_movement_matters () const {
718                 return false;
719         }
720
721         void setup_pointer_frame_offset ();
722
723 private:
724         void update_item (ARDOUR::Location *);
725
726         Marker* _marker; ///< marker being dragged
727
728         struct CopiedLocationMarkerInfo {
729             ARDOUR::Location* location;
730             std::vector<Marker*> markers;
731             bool    move_both;
732             CopiedLocationMarkerInfo (ARDOUR::Location* l, Marker* m);
733         };
734
735         typedef std::list<CopiedLocationMarkerInfo> CopiedLocationInfo;
736         CopiedLocationInfo _copied_locations;
737         ArdourCanvas::Points _points;
738 };
739
740 /** Control point drag */
741 class ControlPointDrag : public Drag
742 {
743 public:
744         ControlPointDrag (Editor *, ArdourCanvas::Item *);
745
746         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
747         void motion (GdkEvent *, bool);
748         void finished (GdkEvent *, bool);
749         void aborted (bool);
750
751         bool active (Editing::MouseMode m);
752
753 private:
754
755         ControlPoint* _point;
756         double _fixed_grab_x;
757         double _fixed_grab_y;
758         double _cumulative_x_drag;
759         double _cumulative_y_drag;
760         bool     _pushing;
761         uint32_t _final_index;
762         static double _zero_gain_fraction;
763 };
764
765 /** Gain or automation line drag */
766 class LineDrag : public Drag
767 {
768 public:
769         LineDrag (Editor *e, ArdourCanvas::Item *i);
770
771         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
772         void motion (GdkEvent *, bool);
773         void finished (GdkEvent *, bool);
774         void aborted (bool);
775
776         bool active (Editing::MouseMode) {
777                 return true;
778         }
779
780 private:
781
782         AutomationLine* _line;
783         double _fixed_grab_x;
784         double _fixed_grab_y;
785         uint32_t _before;
786         uint32_t _after;
787         double _cumulative_y_drag;
788 };
789
790 /** Transient feature line drags*/
791 class FeatureLineDrag : public Drag
792 {
793 public:
794         FeatureLineDrag (Editor *e, ArdourCanvas::Item *i);
795
796         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
797         void motion (GdkEvent *, bool);
798         void finished (GdkEvent *, bool);
799         void aborted (bool);
800
801         bool active (Editing::MouseMode) {
802                 return true;
803         }
804
805 private:
806
807         ArdourCanvas::Line* _line;
808         AudioRegionView* _arv;
809
810         double _region_view_grab_x;
811         double _cumulative_x_drag;
812
813         float _before;
814         uint32_t _max_x;
815 };
816
817 /** Dragging of a rubberband rectangle for selecting things */
818 class RubberbandSelectDrag : public Drag
819 {
820 public:
821         RubberbandSelectDrag (Editor *, ArdourCanvas::Item *);
822
823         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
824         void motion (GdkEvent *, bool);
825         void finished (GdkEvent *, bool);
826         void aborted (bool);
827
828         std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
829                 return std::make_pair (8, 1);
830         }
831
832         void do_select_things (GdkEvent *, bool);
833
834         /** Select some things within a rectangle.
835          *  @param button_state The button state from the GdkEvent.
836          *  @param x1 The left-hand side of the rectangle in session frames.
837          *  @param x2 The right-hand side of the rectangle in session frames.
838          *  @param y1 The top of the rectangle in trackview coordinates.
839          *  @param y2 The bottom of the rectangle in trackview coordinates.
840          *  @param drag_in_progress true if the drag is currently happening.
841          */
842         virtual void select_things (int button_state, framepos_t x1, framepos_t x2, double y1, double y2, bool drag_in_progress) = 0;
843         
844         virtual void deselect_things () = 0;
845
846   protected:
847         bool _vertical_only;
848 };
849
850 /** A general editor RubberbandSelectDrag (for regions, automation points etc.) */
851 class EditorRubberbandSelectDrag : public RubberbandSelectDrag
852 {
853 public:
854         EditorRubberbandSelectDrag (Editor *, ArdourCanvas::Item *);
855
856         void select_things (int, framepos_t, framepos_t, double, double, bool);
857         void deselect_things ();
858 };
859
860 /** A RubberbandSelectDrag for selecting MIDI notes */
861 class MidiRubberbandSelectDrag : public RubberbandSelectDrag
862 {
863 public:
864         MidiRubberbandSelectDrag (Editor *, MidiRegionView *);
865
866         void select_things (int, framepos_t, framepos_t, double, double, bool);
867         void deselect_things ();
868
869 private:
870         MidiRegionView* _region_view;
871 };
872
873 /** A RubberbandSelectDrag for selecting MIDI notes but with no horizonal component */
874 class MidiVerticalSelectDrag : public RubberbandSelectDrag
875 {
876 public:
877         MidiVerticalSelectDrag (Editor *, MidiRegionView *);
878
879         void select_things (int, framepos_t, framepos_t, double, double, bool);
880         void deselect_things ();
881
882 private:
883         MidiRegionView* _region_view;
884 };
885
886 /** Region drag in time-FX mode */
887 class TimeFXDrag : public RegionDrag
888 {
889 public:
890         TimeFXDrag (Editor *, ArdourCanvas::Item *, RegionView *, std::list<RegionView*> const &);
891
892         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
893         void motion (GdkEvent *, bool);
894         void finished (GdkEvent *, bool);
895         void aborted (bool);
896 };
897
898 /** Scrub drag in audition mode */
899 class ScrubDrag : public Drag
900 {
901 public:
902         ScrubDrag (Editor *, ArdourCanvas::Item *);
903
904         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
905         void motion (GdkEvent *, bool);
906         void finished (GdkEvent *, bool);
907         void aborted (bool);
908 };
909
910 /** Drag in range select mode */
911 class SelectionDrag : public Drag
912 {
913 public:
914         enum Operation {
915                 CreateSelection,
916                 SelectionStartTrim,
917                 SelectionEndTrim,
918                 SelectionMove,
919                 SelectionExtend
920         };
921
922         SelectionDrag (Editor *, ArdourCanvas::Item *, Operation);
923
924         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
925         void motion (GdkEvent *, bool);
926         void finished (GdkEvent *, bool);
927         void aborted (bool);
928
929         void setup_pointer_frame_offset ();
930
931 private:
932         Operation _operation;
933         bool _add;
934         bool _extend;
935         int _original_pointer_time_axis;
936         int _last_pointer_time_axis;
937         std::list<TimeAxisView*> _added_time_axes;
938         bool _time_selection_at_start;
939         framepos_t start_at_start;
940         framepos_t end_at_start;
941 };
942
943 /** Range marker drag */
944 class RangeMarkerBarDrag : public Drag
945 {
946 public:
947         enum Operation {
948                 CreateRangeMarker,
949                 CreateTransportMarker,
950                 CreateCDMarker
951         };
952
953         RangeMarkerBarDrag (Editor *, ArdourCanvas::Item *, Operation);
954
955         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
956         void motion (GdkEvent *, bool);
957         void finished (GdkEvent *, bool);
958         void aborted (bool);
959
960         bool allow_vertical_autoscroll () const {
961                 return false;
962         }
963
964         bool y_movement_matters () const {
965                 return false;
966         }
967
968 private:
969         void update_item (ARDOUR::Location *);
970
971         Operation _operation;
972         ArdourCanvas::Rectangle* _drag_rect;
973         bool _copy;
974 };
975
976 /** Drag of rectangle to set zoom */
977 class MouseZoomDrag : public Drag
978 {
979 public:
980         MouseZoomDrag (Editor *, ArdourCanvas::Item *);
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         std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
988                 return std::make_pair (4, 4);
989         }
990
991 private:
992         bool _zoom_out;
993 };
994
995 /** Drag of a range of automation data (either on an automation track or region gain),
996  *  changing value but not position.
997  */
998 class AutomationRangeDrag : public Drag
999 {
1000 public:
1001         AutomationRangeDrag (Editor *, AutomationTimeAxisView *, std::list<ARDOUR::AudioRange> const &);
1002         AutomationRangeDrag (Editor *, AudioRegionView *, std::list<ARDOUR::AudioRange> const &);
1003
1004         void start_grab (GdkEvent *, Gdk::Cursor* c = 0);
1005         void motion (GdkEvent *, bool);
1006         void finished (GdkEvent *, bool);
1007         void aborted (bool);
1008
1009         bool x_movement_matters () const {
1010                 return false;
1011         }
1012
1013         bool active (Editing::MouseMode) {
1014                 return true;
1015         }
1016
1017 private:
1018         void setup (std::list<boost::shared_ptr<AutomationLine> > const &);
1019         double y_fraction (boost::shared_ptr<AutomationLine>, double global_y_position) const;
1020
1021         std::list<ARDOUR::AudioRange> _ranges;
1022
1023         /** A line that is part of the drag */
1024         struct Line {
1025                 boost::shared_ptr<AutomationLine> line; ///< the line
1026                 std::list<ControlPoint*> points; ///< points to drag on the line
1027                 std::pair<ARDOUR::framepos_t, ARDOUR::framepos_t> range; ///< the range of all points on the line, in session frames
1028                 XMLNode* state; ///< the XML state node before the drag
1029                 double original_fraction; ///< initial y-fraction before the drag
1030         };
1031
1032         std::list<Line> _lines;
1033         double y_origin;
1034         bool _nothing_to_drag;
1035 };
1036
1037 /** Drag of one edge of an xfade
1038  */
1039 class CrossfadeEdgeDrag : public Drag
1040 {
1041   public:
1042         CrossfadeEdgeDrag (Editor*, AudioRegionView*, ArdourCanvas::Item*, bool start);
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 y_movement_matters () const {
1050                 return false;
1051         }
1052
1053         virtual std::pair<ARDOUR::framecnt_t, int> move_threshold () const {
1054                 return std::make_pair (4, 4);
1055         }
1056
1057   private:
1058         AudioRegionView* arv;
1059         bool start;
1060 };
1061
1062 #endif /* __gtk2_ardour_editor_drag_h_ */
1063