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