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