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