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