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