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