Set cursor to hint that you can drag automation up and down in object/range link...
[ardour.git] / gtk2_ardour / editor.h
1 /*
2     Copyright (C) 2000-2003 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 __ardour_editor_h__
21 #define __ardour_editor_h__
22
23 #include <list>
24 #include <map>
25 #include <set>
26 #include <string>
27 #include <sys/time.h>
28 #include <bitset>
29
30 #include <glibmm/ustring.h>
31
32 #include <boost/optional.hpp>
33
34 #include <libgnomecanvasmm/canvas.h>
35 #include <libgnomecanvasmm/group.h>
36 #include <libgnomecanvasmm/line.h>
37 #include <libgnomecanvasmm/pixbuf.h>
38
39 #include <cmath>
40
41 #include <gtkmm/comboboxtext.h>
42 #include <gtkmm/layout.h>
43
44 #include <gtkmm2ext/selector.h>
45 #include <gtkmm2ext/click_box.h>
46 #include <gtkmm2ext/dndtreeview.h>
47
48 #include "pbd/stateful.h"
49 #include "pbd/signals.h"
50
51 #include "ardour/import_status.h"
52 #include "ardour/tempo.h"
53 #include "ardour/location.h"
54 #include "ardour/audioregion.h"
55 #include "ardour/track.h"
56 #include "ardour/types.h"
57 #include "ardour/route_group.h"
58
59 #include "audio_clock.h"
60 #include "gtk-custom-ruler.h"
61 #include "ardour_dialog.h"
62 #include "public_editor.h"
63 #include "editing.h"
64 #include "enums.h"
65 #include "editor_items.h"
66 #include "region_selection.h"
67 #include "canvas.h"
68 #include "window_proxy.h"
69
70 namespace Gnome { namespace Canvas {
71         class NoEventText;
72 } }
73
74 namespace Gtkmm2ext {
75         class TearOff;
76 }
77
78 namespace ARDOUR {
79         class RouteGroup;
80         class Playlist;
81         class AudioPlaylist;
82         class Region;
83         class Location;
84         class TempoSection;
85         class NamedSelection;
86         class Session;
87         class Filter;
88         class Crossfade;
89         class ChanCount;
90         class MidiOperator;
91         class MidiTrack;
92         class AudioTrack;
93 }
94
95 namespace LADSPA {
96         class Plugin;
97 }
98
99 class AnalysisWindow;
100 class AudioRegionView;
101 class AudioStreamView;
102 class AudioTimeAxisView;
103 class AutomationLine;
104 class AutomationSelection;
105 class AutomationTimeAxisView;
106 class BundleManager;
107 class ControlPoint;
108 class CrossfadeView;
109 class DragManager;
110 class GroupedButtons;
111 class Marker;
112 class MidiRegionView;
113 class MixerStrip;
114 class PlaylistSelector;
115 class PluginSelector;
116 class RhythmFerret;
117 class Selection;
118 class SoundFileOmega;
119 class StreamView;
120 class TempoLines;
121 class TimeAxisView;
122 class TimeFXDialog;
123 class TimeSelection;
124 class EditorGroupTabs;
125 class EditorRoutes;
126 class EditorRouteGroups;
127 class EditorRegions;
128 class EditorLocations;
129 class EditorSnapshots;
130 class EditorSummary;
131
132 /* <CMT Additions> */
133 class ImageFrameView;
134 class ImageFrameTimeAxisView;
135 class ImageFrameTimeAxis;
136 class MarkerTimeAxis ;
137 class MarkerView ;
138 class ImageFrameSocketHandler ;
139 class TimeAxisViewItem ;
140 /* </CMT Additions> */
141
142 struct EditorCursor {
143         Editor&               editor;
144         ArdourCanvas::Points  points;
145         ArdourCanvas::Line    canvas_item;
146         nframes64_t           current_frame;
147         double            length;
148
149         EditorCursor (Editor&, bool (Editor::*)(GdkEvent*,ArdourCanvas::Item*));
150         ~EditorCursor ();
151
152         void set_position (nframes64_t);
153         void set_length (double units);
154         void set_y_axis (double position);
155
156         PBD::Signal1<void, nframes64_t> PositionChanged;
157 };
158
159 class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARDOUR::SessionHandlePtr
160 {
161   public:
162         Editor ();
163         ~Editor ();
164
165         void             set_session (ARDOUR::Session *);
166         ARDOUR::Session* session() const { return _session; }
167
168         void             first_idle ();
169         virtual bool     have_idled () const { return _have_idled; }
170
171         nframes64_t leftmost_position() const { return leftmost_frame; }
172
173         nframes64_t current_page_frames() const {
174                 return (nframes64_t) floor (_canvas_width * frames_per_unit);
175         }
176
177         double canvas_height () const {
178                 return _canvas_height;
179         }
180
181         void cycle_snap_mode ();
182         void cycle_snap_choice ();
183         void set_snap_to (Editing::SnapType);
184         void set_snap_mode (Editing::SnapMode);
185         void set_snap_threshold (double pixel_distance) {snap_threshold = pixel_distance;}
186
187         Editing::SnapMode  snap_mode () const;
188         Editing::SnapType  snap_type () const;
189
190         void undo (uint32_t n = 1);
191         void redo (uint32_t n = 1);
192
193         XMLNode& get_state ();
194         int set_state (const XMLNode&, int version);
195
196         void set_mouse_mode (Editing::MouseMode, bool force=true);
197         void step_mouse_mode (bool next);
198         Editing::MouseMode current_mouse_mode () const { return mouse_mode; }
199         Editing::MidiEditMode current_midi_edit_mode () const;
200         void remove_midi_note (ArdourCanvas::Item *, GdkEvent *);
201
202         bool internal_editing() const { return _internal_editing ; }
203         void set_internal_edit (bool yn);
204
205 #ifdef WITH_CMT
206         void add_imageframe_time_axis(const std::string & track_name, void*) ;
207         void add_imageframe_marker_time_axis(const std::string & track_name, TimeAxisView* marked_track, void*) ;
208         void connect_to_image_compositor() ;
209         void scroll_timeaxis_to_imageframe_item(const TimeAxisViewItem* item) ;
210         TimeAxisView* get_named_time_axis(const std::string & name) ;
211 #endif /* WITH_CMT */
212
213         void foreach_time_axis_view (sigc::slot<void,TimeAxisView&>);
214         void add_to_idle_resize (TimeAxisView*, int32_t);
215
216         RouteTimeAxisView* get_route_view_by_route_id (PBD::ID& id) const;
217
218         void consider_auditioning (boost::shared_ptr<ARDOUR::Region>);
219         void hide_a_region (boost::shared_ptr<ARDOUR::Region>);
220         void show_a_region (boost::shared_ptr<ARDOUR::Region>);
221
222 #ifdef USE_RUBBERBAND
223         std::vector<std::string> rb_opt_strings;
224         int rb_current_opt;
225 #endif
226
227         /* things that need to be public to be used in the main menubar */
228
229         void new_region_from_selection ();
230         void separate_regions_between (const TimeSelection&);
231         void separate_region_from_selection ();
232         void separate_under_selected_regions ();
233         void separate_region_from_punch ();
234         void separate_region_from_loop ();
235         void separate_regions_using_location (ARDOUR::Location&);
236         void transition_to_rolling (bool forward);
237
238         /* undo related */
239
240         nframes64_t unit_to_frame (double unit) const {
241                 return (nframes64_t) rint (unit * frames_per_unit);
242         }
243
244         double frame_to_unit (nframes64_t frame) const {
245                 return rint ((double) frame / (double) frames_per_unit);
246         }
247
248         double frame_to_unit (double frame) const {
249                 return rint (frame / frames_per_unit);
250         }
251
252         /* NOTE: these functions assume that the "pixel" coordinate is
253            the result of using the world->canvas affine transform on a
254            world coordinate. These coordinates already take into
255            account any scrolling carried out by adjusting the
256            xscroll_adjustment.
257         */
258
259         nframes64_t pixel_to_frame (double pixel) const {
260
261                 /* pixel can be less than zero when motion events
262                    are processed. since we've already run the world->canvas
263                    affine, that means that the location *really* is "off
264                    to the right" and thus really is "before the start".
265                 */
266
267                 if (pixel >= 0) {
268                         return (nframes64_t) rint (pixel * frames_per_unit * GNOME_CANVAS(track_canvas->gobj())->pixels_per_unit);
269                 } else {
270                         return 0;
271                 }
272         }
273
274         gulong frame_to_pixel (nframes64_t frame) const {
275                 return (gulong) rint ((frame / (frames_per_unit * GNOME_CANVAS(track_canvas->gobj())->pixels_per_unit)));
276         }
277
278         void flush_canvas ();
279
280         /* selection */
281
282         Selection& get_selection() const { return *selection; }
283         Selection& get_cut_buffer() const { return *cut_buffer; }
284
285         bool extend_selection_to_track (TimeAxisView&);
286
287         void play_selection ();
288         void select_all_in_track (Selection::Operation op);
289         void select_all (Selection::Operation op);
290         void invert_selection_in_track ();
291         void invert_selection ();
292         void deselect_all ();
293
294         void set_selected_regionview_from_region_list (boost::shared_ptr<ARDOUR::Region> region, Selection::Operation op = Selection::Set);
295
296         /* tempo */
297
298         void set_show_measures (bool yn);
299         bool show_measures () const { return _show_measures; }
300
301         /* analysis window */
302
303         void analyze_region_selection();
304         void analyze_range_selection();
305
306         /* export */
307
308         void export_audio ();
309         void export_selection ();
310         void export_range ();
311         void export_region ();
312
313         void add_toplevel_controls (Gtk::Container&);
314         Gtk::HBox& get_status_bar_packer()  { return status_bar_hpacker; }
315
316         void               set_zoom_focus (Editing::ZoomFocus);
317         Editing::ZoomFocus get_zoom_focus () const { return zoom_focus; }
318         double             get_current_zoom () const { return frames_per_unit; }
319
320         void temporal_zoom_step (bool coarser);
321         void tav_zoom_step (bool coarser);
322
323         /* stuff that AudioTimeAxisView and related classes use */
324
325         PlaylistSelector& playlist_selector() const;
326         void clear_playlist (boost::shared_ptr<ARDOUR::Playlist>);
327
328         void new_playlists (TimeAxisView* v);
329         void copy_playlists (TimeAxisView* v);
330         void clear_playlists (TimeAxisView* v);
331
332         void get_onscreen_tracks (TrackViewList&);
333
334         Width editor_mixer_strip_width;
335         void maybe_add_mixer_strip_width (XMLNode&);
336         void show_editor_mixer (bool yn);
337         void create_editor_mixer ();
338         void show_editor_list (bool yn);
339         void set_selected_mixer_strip (TimeAxisView&);
340         void hide_track_in_display (TimeAxisView* tv, bool temporary = false);
341
342         /* nudge is initiated by transport controls owned by ARDOUR_UI */
343
344         nframes64_t get_nudge_distance (nframes64_t pos, nframes64_t& next);
345         Evoral::MusicalTime get_grid_type_as_beats (bool& success, nframes64_t position);
346
347         void nudge_forward (bool next, bool force_playhead);
348         void nudge_backward (bool next, bool force_playhead);
349
350         /* nudge initiated from context menu */
351
352         void nudge_forward_capture_offset ();
353         void nudge_backward_capture_offset ();
354
355         /* playhead/screen stuff */
356
357         void set_stationary_playhead (bool yn);
358         void toggle_stationary_playhead ();
359         bool stationary_playhead() const { return _stationary_playhead; }
360         
361         void set_follow_playhead (bool yn);
362         void toggle_follow_playhead ();
363         bool follow_playhead() const { return _follow_playhead; }
364         bool dragging_playhead () const { return _dragging_playhead; }
365
366         void toggle_zero_line_visibility ();
367         void set_summary ();
368         void set_group_tabs ();
369         void toggle_measure_visibility ();
370         void toggle_logo_visibility ();
371
372         double get_physical_screen_width () const { return physical_screen_width; };
373         double physical_screen_width;
374         double physical_screen_height;
375
376         /* fades/xfades */
377
378         void toggle_selected_region_fades (int dir);
379         void update_region_fade_visibility ();
380         bool xfade_visibility() const { return _xfade_visibility; }
381         void update_xfade_visibility ();
382
383         /* redirect shared ops menu. caller must free returned menu */
384
385         Gtk::Menu* redirect_menu ();
386
387         /* floating windows/transient */
388
389         void ensure_float (Gtk::Window&);
390
391         void show_window ();
392
393         void scroll_tracks_down_line ();
394         void scroll_tracks_up_line ();
395
396         void prepare_for_cleanup ();
397         void finish_cleanup ();
398
399         void maximise_editing_space();
400         void restore_editing_space();
401
402         void reset_x_origin (nframes64_t);
403         void reset_x_origin_to_follow_playhead ();
404         void reset_y_origin (double);
405         void reset_zoom (double);
406         void reposition_and_zoom (nframes64_t, double);
407
408         nframes64_t get_preferred_edit_position (bool ignore_playhead = false);
409
410         bool update_mouse_speed ();
411         bool decelerate_mouse_speed ();
412
413         void toggle_meter_updating();
414
415         void show_rhythm_ferret();
416
417         void goto_visual_state (uint32_t);
418         void save_visual_state (uint32_t);
419
420         void queue_draw_resize_line (int at);
421         void start_resize_line_ops ();
422         void end_resize_line_ops ();
423
424         TrackViewList const & get_track_views () {
425                 return track_views;
426         }
427
428         int get_regionview_count_from_region_list (boost::shared_ptr<ARDOUR::Region>);
429
430         void do_import (std::vector<Glib::ustring> paths, Editing::ImportDisposition, Editing::ImportMode mode, ARDOUR::SrcQuality, nframes64_t&);
431         void do_embed (std::vector<Glib::ustring> paths, Editing::ImportDisposition, Editing::ImportMode mode,  nframes64_t&);
432
433         void get_regions_corresponding_to (boost::shared_ptr<ARDOUR::Region> region, std::vector<RegionView*>& regions);
434
435         void show_verbose_canvas_cursor_with (const std::string& txt);
436         void hide_verbose_canvas_cursor();
437
438         void center_screen (nframes64_t);
439
440         TrackViewList axis_views_from_routes (boost::shared_ptr<ARDOUR::RouteList>) const;
441         Gtkmm2ext::TearOff* mouse_mode_tearoff () const { return _mouse_mode_tearoff; }
442         Gtkmm2ext::TearOff* tools_tearoff () const { return _tools_tearoff; }
443
444         void snap_to (nframes64_t& first, int32_t direction = 0, bool for_mark = false);
445         void snap_to_with_modifier (nframes64_t& first, GdkEvent const *, int32_t direction = 0, bool for_mark = false);
446         void snap_to (nframes64_t& first, nframes64_t& last, int32_t direction = 0, bool for_mark = false);
447
448         void begin_reversible_command (std::string cmd_name);
449         void commit_reversible_command ();
450
451         DragManager* drags () const {
452                 return _drags;
453         }
454
455         void maybe_autoscroll (bool, bool);
456         
457         /* handy cursors for everyone to use */
458
459         static Gdk::Cursor* cross_hair_cursor;
460         static Gdk::Cursor* trimmer_cursor;
461         static Gdk::Cursor* right_side_trim_cursor;
462         static Gdk::Cursor* left_side_trim_cursor;
463         static Gdk::Cursor* fade_in_cursor;
464         static Gdk::Cursor* fade_out_cursor;
465         static Gdk::Cursor* selector_cursor;
466         static Gdk::Cursor* grabber_cursor;
467         static Gdk::Cursor* grabber_note_cursor;
468         static Gdk::Cursor* grabber_edit_point_cursor;
469         static Gdk::Cursor* zoom_cursor;
470         static Gdk::Cursor* time_fx_cursor;
471         static Gdk::Cursor* fader_cursor;
472         static Gdk::Cursor* speaker_cursor;
473         static Gdk::Cursor* midi_pencil_cursor;
474         static Gdk::Cursor* midi_select_cursor;
475         static Gdk::Cursor* midi_resize_cursor;
476         static Gdk::Cursor* midi_erase_cursor;
477         static Gdk::Cursor* up_down_cursor;
478         static Gdk::Cursor* wait_cursor;
479         static Gdk::Cursor* timebar_cursor;
480         static Gdk::Cursor* transparent_cursor;
481
482   protected:
483         void map_transport_state ();
484         void map_position_change (nframes64_t);
485
486         void on_realize();
487
488   private:
489
490         void color_handler ();
491
492         bool                 constructed;
493
494         // to keep track of the playhead position for control_scroll
495         boost::optional<nframes64_t> _control_scroll_target;
496
497         PlaylistSelector* _playlist_selector;
498
499         typedef std::pair<TimeAxisView*,XMLNode*> TAVState;
500
501         struct VisualState {
502             double              y_position;
503             double              frames_per_unit;
504             nframes64_t         leftmost_frame;
505             Editing::ZoomFocus  zoom_focus;
506             std::list<TAVState> track_states;
507         };
508
509         std::list<VisualState*> undo_visual_stack;
510         std::list<VisualState*> redo_visual_stack;
511         VisualState* current_visual_state (bool with_tracks = true);
512         void undo_visual_state ();
513         void redo_visual_state ();
514         void use_visual_state (VisualState&);
515         bool no_save_visual;
516         void swap_visual_state ();
517
518         std::vector<VisualState*> visual_states;
519         sigc::connection visual_state_op_connection;
520         void start_visual_state_op (uint32_t n);
521         void cancel_visual_state_op (uint32_t n);
522         bool end_visual_state_op (uint32_t n);
523
524         nframes64_t leftmost_frame;
525         double      frames_per_unit;
526         Editing::ZoomFocus zoom_focus;
527
528         void set_frames_per_unit (double);
529         void post_zoom ();
530
531         Editing::MouseMode mouse_mode;
532         bool _internal_editing;
533         Editing::MouseMode effective_mouse_mode () const;
534
535         enum JoinObjectRangeState {
536                 JOIN_OBJECT_RANGE_NONE,
537                 /** `join object/range' mode is active and the mouse is over a place where object mode should happen */
538                 JOIN_OBJECT_RANGE_OBJECT,
539                 /** `join object/range' mode is active and the mouse is over a place where range mode should happen */
540                 JOIN_OBJECT_RANGE_RANGE
541         };
542
543         JoinObjectRangeState _join_object_range_state;
544
545         void update_join_object_range_location (double, double);
546
547         int  post_maximal_editor_width;
548         int  post_maximal_editor_height;
549         int  post_maximal_horizontal_pane_position;
550         int  post_maximal_vertical_pane_position;
551         int  pre_maximal_horizontal_pane_position;
552         int  pre_maximal_vertical_pane_position;
553         int  pre_maximal_editor_width;
554         int  pre_maximal_editor_height;
555         void pane_allocation_handler (Gtk::Allocation&, Gtk::Paned*);
556
557         Gtk::Notebook the_notebook;
558         Gtk::HPaned   edit_pane;
559         Gtk::VPaned   editor_summary_pane;
560
561         Gtk::EventBox meter_base;
562         Gtk::HBox     meter_box;
563         Gtk::EventBox marker_base;
564         Gtk::HBox     marker_box;
565         Gtk::VBox     scrollers_rulers_markers_box;
566
567         void location_changed (ARDOUR::Location *);
568         void location_flags_changed (ARDOUR::Location *, void *);
569         void refresh_location_display ();
570         void refresh_location_display_s (const PBD::PropertyChange&);
571         void refresh_location_display_internal (ARDOUR::Locations::LocationList&);
572         void add_new_location (ARDOUR::Location *);
573         void location_gone (ARDOUR::Location *);
574         void remove_marker (ArdourCanvas::Item&, GdkEvent*);
575         gint really_remove_marker (ARDOUR::Location* loc);
576         void goto_nth_marker (int nth);
577
578         uint32_t location_marker_color;
579         uint32_t location_range_color;
580         uint32_t location_loop_color;
581         uint32_t location_punch_color;
582         uint32_t location_cd_marker_color;
583
584         struct LocationMarkers {
585             Marker* start;
586             Marker* end;
587             bool    valid;
588
589             LocationMarkers () : start(0), end(0), valid (true) {}
590
591             ~LocationMarkers ();
592
593             void hide();
594             void show ();
595             void set_name (const std::string&);
596             void set_position (nframes64_t start, nframes64_t end = 0);
597             void set_color_rgba (uint32_t);
598         };
599
600         LocationMarkers  *find_location_markers (ARDOUR::Location *) const;
601         ARDOUR::Location* find_location_from_marker (Marker *, bool& is_start) const;
602         Marker* entered_marker;
603
604         typedef std::map<ARDOUR::Location*,LocationMarkers *> LocationMarkerMap;
605         LocationMarkerMap location_markers;
606
607         void hide_marker (ArdourCanvas::Item*, GdkEvent*);
608         void clear_marker_display ();
609         void mouse_add_new_marker (nframes64_t where, bool is_cd=false, bool is_xrun=false);
610         bool choose_new_marker_name(std::string &name);
611         void update_cd_marker_display ();
612         void ensure_cd_marker_updated (LocationMarkers * lam, ARDOUR::Location * location);
613
614         TimeAxisView*      clicked_axisview;
615         RouteTimeAxisView* clicked_routeview;
616         /** The last RegionView that was clicked on, or 0 if the last click was not
617          * on a RegionView.  This is set up by the canvas event handlers in
618          * editor_canvas_events.cc
619          */
620         RegionView*        clicked_regionview;
621         RegionSelection    latest_regionviews;
622         uint32_t           clicked_selection;
623         CrossfadeView*     clicked_crossfadeview;
624         ControlPoint*      clicked_control_point;
625
626         void sort_track_selection (TrackViewList* sel = 0);
627
628         void get_equivalent_regions (RegionView* rv, std::vector<RegionView*> &, PBD::PropertyID) const;
629         RegionSelection get_equivalent_regions (RegionSelection &, PBD::PropertyID) const;
630         void mapover_tracks (sigc::slot<void,RouteTimeAxisView&,uint32_t> sl, TimeAxisView*, PBD::PropertyID) const;
631
632         /* functions to be passed to mapover_tracks(), possibly with sigc::bind()-supplied arguments */
633
634         void mapped_get_equivalent_regions (RouteTimeAxisView&, uint32_t, RegionView *, std::vector<RegionView*>*) const;
635         void mapped_use_new_playlist (RouteTimeAxisView&, uint32_t, std::vector<boost::shared_ptr<ARDOUR::Playlist> > const &);
636         void mapped_use_copy_playlist (RouteTimeAxisView&, uint32_t, std::vector<boost::shared_ptr<ARDOUR::Playlist> > const &);
637         void mapped_clear_playlist (RouteTimeAxisView&, uint32_t);
638
639         /* end */
640
641         void button_selection (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type);
642         bool button_release_can_deselect;
643
644         void catch_vanishing_regionview (RegionView *);
645
646         void set_selected_track (TimeAxisView&, Selection::Operation op = Selection::Set, bool no_remove=false);
647         void select_all_tracks ();
648
649         bool set_selected_control_point_from_click (Selection::Operation op = Selection::Set, bool no_remove=false);
650         void set_selected_track_from_click (bool press, Selection::Operation op = Selection::Set, bool no_remove=false);
651         void set_selected_track_as_side_effect (bool force = false);
652         bool set_selected_regionview_from_click (bool press, Selection::Operation op = Selection::Set, bool no_track_remove=false);
653
654         bool set_selected_regionview_from_map_event (GdkEventAny*, StreamView*, boost::weak_ptr<ARDOUR::Region>);
655         void collect_new_region_view (RegionView *);
656         void collect_and_select_new_region_view (RegionView *);
657
658         long select_range_around_region (RegionView *);
659
660         Gtk::Menu track_context_menu;
661         Gtk::Menu track_region_context_menu;
662         Gtk::Menu track_selection_context_menu;
663         Gtk::Menu track_crossfade_context_menu;
664
665         Gtk::MenuItem* region_edit_menu_split_item;
666         Gtk::MenuItem* region_edit_menu_split_multichannel_item;
667         Gtk::Menu * track_region_edit_playlist_menu;
668         Gtk::Menu * track_edit_playlist_submenu;
669         Gtk::Menu * track_selection_edit_playlist_submenu;
670
671         void popup_track_context_menu (int, int, ItemType, bool, nframes64_t);
672         Gtk::Menu* build_track_context_menu (nframes64_t);
673         Gtk::Menu* build_track_bus_context_menu (nframes64_t);
674         Gtk::Menu* build_track_region_context_menu (nframes64_t frame);
675         Gtk::Menu* build_track_crossfade_context_menu (nframes64_t);
676         Gtk::Menu* build_track_selection_context_menu (nframes64_t);
677         void add_dstream_context_items (Gtk::Menu_Helpers::MenuList&);
678         void add_bus_context_items (Gtk::Menu_Helpers::MenuList&);
679         void add_region_context_items (StreamView*, std::list<boost::shared_ptr<ARDOUR::Region> >, Gtk::Menu_Helpers::MenuList&);
680         void add_crossfade_context_items (AudioStreamView*, boost::shared_ptr<ARDOUR::Crossfade>, Gtk::Menu_Helpers::MenuList&, bool many);
681         void add_selection_context_items (Gtk::Menu_Helpers::MenuList&);
682
683         void handle_new_route (ARDOUR::RouteList&);
684         void timeaxisview_deleted (TimeAxisView *);
685
686         Gtk::HBox           global_hpacker;
687         Gtk::VBox           global_vpacker;
688         Gtk::VBox           vpacker;
689
690         Gdk::Cursor*          current_canvas_cursor;
691         void set_canvas_cursor ();
692         Gdk::Cursor* which_grabber_cursor ();
693
694         ArdourCanvas::Canvas* track_canvas;
695
696         ArdourCanvas::NoEventText* verbose_canvas_cursor;
697         bool                 verbose_cursor_visible;
698
699         void parameter_changed (std::string);
700
701         bool track_canvas_motion (GdkEvent*);
702
703         void set_verbose_canvas_cursor (const std::string &, double x, double y);
704         void set_verbose_canvas_cursor_text (const std::string &);
705         void show_verbose_canvas_cursor();
706
707         bool verbose_cursor_on; // so far unused
708
709         Gtk::EventBox             time_canvas_event_box;
710         Gtk::EventBox             track_canvas_event_box;
711         Gtk::EventBox             time_button_event_box;
712         Gtk::EventBox             ruler_label_event_box;
713
714         ArdourCanvas::Group      *minsec_group;
715         ArdourCanvas::Pixbuf     *logo_item;
716         ArdourCanvas::Group      *bbt_group;
717         ArdourCanvas::Group      *timecode_group;
718         ArdourCanvas::Group      *frame_group;
719         ArdourCanvas::Group      *tempo_group;
720         ArdourCanvas::Group      *meter_group;
721         ArdourCanvas::Group      *marker_group;
722         ArdourCanvas::Group      *range_marker_group;
723         ArdourCanvas::Group      *transport_marker_group;
724         ArdourCanvas::Group*      cd_marker_group;
725
726         ArdourCanvas::Group*      timebar_group;
727
728         /* These bars never need to be scrolled */
729         ArdourCanvas::Group*      meter_bar_group;
730         ArdourCanvas::Group*      tempo_bar_group;
731         ArdourCanvas::Group*      marker_bar_group;
732         ArdourCanvas::Group*      range_marker_bar_group;
733         ArdourCanvas::Group*      transport_marker_bar_group;
734         ArdourCanvas::Group*      cd_marker_bar_group;
735
736         /** The group containing all items that require horizontal scrolling. */
737         ArdourCanvas::Group* _background_group;
738         /*
739            The _master_group is the group containing all items
740            that require horizontal scrolling..
741            It is primarily used to separate canvas items
742            that require horizontal scrolling from those that do not.
743         */
744         ArdourCanvas::Group* _master_group;
745
746         /* The group containing all trackviews.  Only scrolled vertically. */
747         ArdourCanvas::Group* _trackview_group;
748
749         /* The group used for region motion.  Sits on top of _trackview_group */
750         ArdourCanvas::Group* _region_motion_group;
751
752         enum RulerType {
753                 ruler_metric_timecode = 0,
754                 ruler_metric_bbt = 1,
755                 ruler_metric_frames = 2,
756                 ruler_metric_minsec = 3,
757
758                 ruler_time_tempo = 4,
759                 ruler_time_meter = 5,
760                 ruler_time_marker = 6,
761                 ruler_time_range_marker = 7,
762                 ruler_time_transport_marker = 8,
763                 ruler_time_cd_marker = 9,
764         };
765
766         static GtkCustomMetric ruler_metrics[4];
767         Glib::RefPtr<Gtk::ToggleAction> ruler_timecode_action;
768         Glib::RefPtr<Gtk::ToggleAction> ruler_bbt_action;
769         Glib::RefPtr<Gtk::ToggleAction> ruler_samples_action;
770         Glib::RefPtr<Gtk::ToggleAction> ruler_minsec_action;
771         Glib::RefPtr<Gtk::ToggleAction> ruler_tempo_action;
772         Glib::RefPtr<Gtk::ToggleAction> ruler_meter_action;
773         Glib::RefPtr<Gtk::ToggleAction> ruler_marker_action;
774         Glib::RefPtr<Gtk::ToggleAction> ruler_range_action;
775         Glib::RefPtr<Gtk::ToggleAction> ruler_loop_punch_action;
776         Glib::RefPtr<Gtk::ToggleAction> ruler_cd_marker_action;
777         bool                            no_ruler_shown_update;
778
779         gint ruler_button_press (GdkEventButton*);
780         gint ruler_button_release (GdkEventButton*);
781         gint ruler_mouse_motion (GdkEventMotion*);
782         bool ruler_scroll (GdkEventScroll* event);
783
784         Gtk::Widget * ruler_grabbed_widget;
785
786         void initialize_rulers ();
787         void update_just_timecode ();
788         void compute_fixed_ruler_scale (); //calculates the RulerScale of the fixed rulers
789         void update_fixed_rulers ();
790         void update_tempo_based_rulers ();
791         void popup_ruler_menu (nframes64_t where = 0, ItemType type = RegionItem);
792         void update_ruler_visibility ();
793         void set_ruler_visible (RulerType, bool);
794         void toggle_ruler_visibility (RulerType rt);
795         void ruler_toggled (int);
796         gint ruler_label_button_release (GdkEventButton*);
797         void store_ruler_visibility ();
798         void restore_ruler_visibility ();
799
800         static gint _metric_get_timecode (GtkCustomRulerMark **, gdouble, gdouble, gint);
801         static gint _metric_get_bbt (GtkCustomRulerMark **, gdouble, gdouble, gint);
802         static gint _metric_get_frames (GtkCustomRulerMark **, gdouble, gdouble, gint);
803         static gint _metric_get_minsec (GtkCustomRulerMark **, gdouble, gdouble, gint);
804
805         enum MinsecRulerScale {
806                 minsec_show_seconds,
807                 minsec_show_minutes,
808                 minsec_show_hours,
809                 minsec_show_frames
810         };
811
812         MinsecRulerScale minsec_ruler_scale;
813
814         nframes_t minsec_mark_interval;
815         gint minsec_mark_modulo;
816         gint minsec_nmarks;
817         void set_minsec_ruler_scale (gdouble lower, gdouble upper);
818
819         enum TimecodeRulerScale {
820                 timecode_show_bits,
821                 timecode_show_frames,
822                 timecode_show_seconds,
823                 timecode_show_minutes,
824                 timecode_show_hours
825         };
826
827         TimecodeRulerScale timecode_ruler_scale;
828
829         nframes_t timecode_mark_interval;
830         gint timecode_mark_modulo;
831         gint timecode_nmarks;
832         void set_timecode_ruler_scale (gdouble lower, gdouble upper);
833
834         enum BBTRulerScale {
835                 bbt_over,
836                 bbt_show_64,
837                 bbt_show_16,
838                 bbt_show_4,
839                 bbt_show_1,
840                 bbt_show_beats,
841                 bbt_show_ticks,
842                 bbt_show_ticks_detail,
843                 bbt_show_ticks_super_detail
844         };
845
846         BBTRulerScale bbt_ruler_scale;
847
848         uint32_t bbt_bars;
849         gint bbt_nmarks;
850         uint32_t bbt_bar_helper_on;
851         uint32_t bbt_accent_modulo;
852         void compute_bbt_ruler_scale (nframes64_t lower, nframes64_t upper);
853
854         gint metric_get_timecode (GtkCustomRulerMark **, gdouble, gdouble, gint);
855         gint metric_get_bbt (GtkCustomRulerMark **, gdouble, gdouble, gint);
856         gint metric_get_frames (GtkCustomRulerMark **, gdouble, gdouble, gint);
857         gint metric_get_minsec (GtkCustomRulerMark **, gdouble, gdouble, gint);
858
859         Gtk::Widget        *_ruler_separator;
860         GtkWidget          *_timecode_ruler;
861         GtkWidget          *_bbt_ruler;
862         GtkWidget          *_frames_ruler;
863         GtkWidget          *_minsec_ruler;
864         Gtk::Widget        *timecode_ruler;
865         Gtk::Widget        *bbt_ruler;
866         Gtk::Widget        *frames_ruler;
867         Gtk::Widget        *minsec_ruler;
868         static Editor      *ruler_editor;
869
870         static const double timebar_height;
871         guint32 visible_timebars;
872         gdouble canvas_timebars_vsize;
873         gdouble get_canvas_timebars_vsize () const { return canvas_timebars_vsize; }
874         Gtk::Menu          *editor_ruler_menu;
875
876         ArdourCanvas::SimpleRect* tempo_bar;
877         ArdourCanvas::SimpleRect* meter_bar;
878         ArdourCanvas::SimpleRect* marker_bar;
879         ArdourCanvas::SimpleRect* range_marker_bar;
880         ArdourCanvas::SimpleRect* transport_marker_bar;
881         ArdourCanvas::SimpleRect* cd_marker_bar;
882
883         Gtk::Label  minsec_label;
884         Gtk::Label  bbt_label;
885         Gtk::Label  timecode_label;
886         Gtk::Label  frame_label;
887         Gtk::Label  tempo_label;
888         Gtk::Label  meter_label;
889         Gtk::Label  mark_label;
890         Gtk::Label  range_mark_label;
891         Gtk::Label  transport_mark_label;
892         Gtk::Label  cd_mark_label;
893
894         Gtk::VBox          time_button_vbox;
895         Gtk::HBox          time_button_hbox;
896
897         friend class EditorCursor;
898
899         EditorCursor*        playhead_cursor;
900         ArdourCanvas::Group* cursor_group;
901
902         nframes64_t get_region_boundary (nframes64_t pos, int32_t dir, bool with_selection, bool only_onscreen);
903
904         void    cursor_to_region_boundary (bool with_selection, int32_t dir);
905         void    cursor_to_next_region_boundary (bool with_selection);
906         void    cursor_to_previous_region_boundary (bool with_selection);
907         void    cursor_to_next_region_point (EditorCursor*, ARDOUR::RegionPoint);
908         void    cursor_to_previous_region_point (EditorCursor*, ARDOUR::RegionPoint);
909         void    cursor_to_region_point (EditorCursor*, ARDOUR::RegionPoint, int32_t dir);
910         void    cursor_to_selection_start (EditorCursor *);
911         void    cursor_to_selection_end   (EditorCursor *);
912
913         void    selected_marker_to_region_boundary (bool with_selection, int32_t dir);
914         void    selected_marker_to_next_region_boundary (bool with_selection);
915         void    selected_marker_to_previous_region_boundary (bool with_selection);
916         void    selected_marker_to_next_region_point (ARDOUR::RegionPoint);
917         void    selected_marker_to_previous_region_point (ARDOUR::RegionPoint);
918         void    selected_marker_to_region_point (ARDOUR::RegionPoint, int32_t dir);
919         void    selected_marker_to_selection_start ();
920         void    selected_marker_to_selection_end   ();
921
922         void    select_all_selectables_using_cursor (EditorCursor *, bool);
923         void    select_all_selectables_using_edit (bool);
924         void    select_all_selectables_between (bool within);
925         void    select_range_between ();
926
927         boost::shared_ptr<ARDOUR::Region> find_next_region (ARDOUR::framepos_t, ARDOUR::RegionPoint, int32_t dir, TrackViewList&, TimeAxisView ** = 0);
928         ARDOUR::framepos_t find_next_region_boundary (ARDOUR::framepos_t, int32_t dir, const TrackViewList&);
929
930         std::vector<ARDOUR::framepos_t> region_boundary_cache;
931         void build_region_boundary_cache ();
932
933         Gtk::HBox           top_hbox;
934         Gtk::HBox           bottom_hbox;
935
936         Gtk::Table          edit_packer;
937
938         Gtk::Adjustment     vertical_adjustment;
939
940         Gtk::Layout         controls_layout;
941         bool control_layout_scroll (GdkEventScroll* ev);
942         void controls_layout_size_request (Gtk::Requisition*);
943         sigc::connection controls_layout_size_request_connection;
944
945         bool horizontal_scroll_left_press ();
946         void horizontal_scroll_left_release ();
947         bool horizontal_scroll_right_press ();
948         void horizontal_scroll_right_release ();
949         sigc::connection _scroll_connection;
950         int _scroll_callbacks;
951
952         double _canvas_width;
953         double _canvas_height; ///< height of the visible area of the track canvas
954         double full_canvas_height; ///< full height of the canvas
955
956         bool track_canvas_map_handler (GdkEventAny*);
957
958         gint edit_controls_button_release (GdkEventButton*);
959         Gtk::Menu *edit_controls_left_menu;
960         Gtk::Menu *edit_controls_right_menu;
961
962         Gtk::VBox           ruler_label_vbox;
963         Gtk::VBox           track_canvas_vbox;
964         Gtk::VBox           time_canvas_vbox;
965         Gtk::VBox           edit_controls_vbox;
966         Gtk::HBox           edit_controls_hbox;
967
968         void control_scroll (float);
969         void access_action (std::string,std::string);
970         bool deferred_control_scroll (nframes64_t);
971         sigc::connection control_scroll_connection;
972
973         gdouble get_trackview_group_vertical_offset () const { return vertical_adjustment.get_value () - canvas_timebars_vsize;}
974
975         ArdourCanvas::Group* get_background_group () const { return _background_group; }
976         ArdourCanvas::Group* get_trackview_group () const { return _trackview_group; }
977         double last_trackview_group_vertical_offset;
978         void tie_vertical_scrolling ();
979         void set_horizontal_position (double);
980         double horizontal_position () const;
981         void scroll_canvas_vertically ();
982
983         struct VisualChange {
984                 enum Type {
985                         TimeOrigin = 0x1,
986                         ZoomLevel = 0x2,
987                         YOrigin = 0x4
988                 };
989
990                 Type pending;
991                 nframes64_t time_origin;
992                 double frames_per_unit;
993                 double y_origin;
994
995                 int idle_handler_id;
996
997                 VisualChange() : pending ((VisualChange::Type) 0), time_origin (0), frames_per_unit (0), idle_handler_id (-1) {}
998                 void add (Type t) {
999                         pending = Type (pending | t);
1000                 }
1001         };
1002
1003
1004         VisualChange pending_visual_change;
1005
1006         static int _idle_visual_changer (void *arg);
1007         int idle_visual_changer ();
1008
1009         void queue_visual_change (nframes64_t);
1010         void queue_visual_change (double);
1011         void queue_visual_change_y (double);
1012         void ensure_visual_change_idle_handler ();
1013
1014         /* track views */
1015         TrackViewList track_views;
1016         std::pair<TimeAxisView*, ARDOUR::layer_t> trackview_by_y_position (double);
1017         TimeAxisView* axis_view_from_route (boost::shared_ptr<ARDOUR::Route>) const;
1018
1019         TrackViewList get_tracks_for_range_action () const;
1020
1021         static void build_cursors ();
1022
1023         sigc::connection super_rapid_screen_update_connection;
1024         nframes64_t last_update_frame;
1025         void center_screen_internal (nframes64_t, float);
1026
1027         void super_rapid_screen_update ();
1028
1029         void session_going_away ();
1030
1031         nframes64_t cut_buffer_start;
1032         nframes64_t cut_buffer_length;
1033
1034         bool typed_event (ArdourCanvas::Item*, GdkEvent*, ItemType);
1035         bool button_press_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1036         bool button_press_handler_1 (ArdourCanvas::Item *, GdkEvent *, ItemType);
1037         bool button_press_handler_2 (ArdourCanvas::Item *, GdkEvent *, ItemType);
1038         bool button_release_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1039         bool motion_handler (ArdourCanvas::Item*, GdkEvent*, bool from_autoscroll = false);
1040         bool enter_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1041         bool leave_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1042
1043         /* KEYMAP HANDLING */
1044
1045         void register_actions ();
1046
1047         int ensure_cursor (nframes64_t* pos);
1048
1049         void cut_copy (Editing::CutCopyOp);
1050         bool can_cut_copy () const;
1051         void cut_copy_points (Editing::CutCopyOp);
1052         void cut_copy_regions (Editing::CutCopyOp, RegionSelection&);
1053         void cut_copy_ranges (Editing::CutCopyOp);
1054         void cut_copy_midi (Editing::CutCopyOp);
1055
1056         void mouse_paste ();
1057         void paste_internal (nframes64_t position, float times);
1058
1059         /* EDITING OPERATIONS */
1060
1061         void reset_point_selection ();
1062         void toggle_region_mute ();
1063         void toggle_region_lock ();
1064         void toggle_region_opaque ();
1065         void toggle_record_enable ();
1066         void toggle_region_lock_style ();
1067         void raise_region ();
1068         void raise_region_to_top ();
1069         void lower_region ();
1070         void lower_region_to_bottom ();
1071         void split_regions_at (nframes64_t, RegionSelection&);
1072         void split_region_at_transients ();
1073         void split_region_at_points (boost::shared_ptr<ARDOUR::Region>, ARDOUR::AnalysisFeatureList&, bool can_ferret);
1074         void crop_region_to_selection ();
1075         void crop_region_to (nframes64_t start, nframes64_t end);
1076         void set_sync_point (nframes64_t, const RegionSelection&);
1077         void set_region_sync_from_edit_point ();
1078         void remove_region_sync();
1079         void align_selection (ARDOUR::RegionPoint, nframes64_t position, const RegionSelection&);
1080         void align_selection_relative (ARDOUR::RegionPoint point, nframes64_t position, const RegionSelection&);
1081         void align_region (boost::shared_ptr<ARDOUR::Region>, ARDOUR::RegionPoint point, nframes64_t position);
1082         void align_region_internal (boost::shared_ptr<ARDOUR::Region>, ARDOUR::RegionPoint point, nframes64_t position);
1083         void remove_selected_regions ();
1084         void remove_clicked_region ();
1085         void edit_region ();
1086         void show_midi_list_editor ();
1087         void rename_region ();
1088         void duplicate_some_regions (RegionSelection&, float times);
1089         void duplicate_selection (float times);
1090         void region_fill_selection ();
1091
1092         void region_fill_track ();
1093         void audition_playlist_region_standalone (boost::shared_ptr<ARDOUR::Region>);
1094         void audition_playlist_region_via_route (boost::shared_ptr<ARDOUR::Region>, ARDOUR::Route&);
1095         void split_multichannel_region();
1096         void reverse_region ();
1097         void strip_region_silence ();
1098         void normalize_region ();
1099         double _last_normalization_value;
1100         void reset_region_scale_amplitude ();
1101         void adjust_region_scale_amplitude (bool up);
1102         void quantize_region ();
1103         void fork_region ();
1104
1105         void do_insert_time ();
1106         void insert_time (nframes64_t, nframes64_t, Editing::InsertTimeOption, bool, bool, bool, bool, bool);
1107
1108         void tab_to_transient (bool forward);
1109
1110         void use_region_as_bar ();
1111         void use_range_as_bar ();
1112
1113         void define_one_bar (nframes64_t start, nframes64_t end);
1114
1115         void audition_region_from_region_list ();
1116         void hide_region_from_region_list ();
1117         void show_region_in_region_list ();
1118
1119         void align (ARDOUR::RegionPoint);
1120         void align_relative (ARDOUR::RegionPoint);
1121         void naturalize ();
1122
1123         void reset_focus ();
1124
1125         void split ();
1126
1127         void cut ();
1128         void copy ();
1129         void paste (float times);
1130         
1131         void place_transient ();
1132         void remove_transient (ArdourCanvas::Item* item);
1133         void snap_regions_to_grid ();
1134         void close_region_gaps ();
1135
1136         int  get_prefix (float&, bool&);
1137
1138         void keyboard_paste ();
1139         void keyboard_insert_region_list_selection ();
1140
1141         void region_from_selection ();
1142         void create_region_from_selection (std::vector<boost::shared_ptr<ARDOUR::Region> >&);
1143
1144         void play_from_start ();
1145         void play_from_edit_point ();
1146         void play_from_edit_point_and_return ();
1147         void play_selected_region ();
1148         void play_edit_range ();
1149         void loop_selected_region ();
1150         void play_location (ARDOUR::Location&);
1151         void loop_location (ARDOUR::Location&);
1152
1153         void temporal_zoom_selection ();
1154         void temporal_zoom_region (bool both_axes);
1155         void zoom_to_region (bool both_axes);
1156         void temporal_zoom_session ();
1157         void temporal_zoom (gdouble scale);
1158         void temporal_zoom_by_frame (nframes64_t start, nframes64_t end, const std::string & op);
1159         void temporal_zoom_to_frame (bool coarser, nframes64_t frame);
1160
1161         void amplitude_zoom (gdouble scale);
1162         void amplitude_zoom_step (bool in);
1163
1164         void insert_region_list_drag (boost::shared_ptr<ARDOUR::Region>, int x, int y);
1165         void insert_region_list_selection (float times);
1166
1167         void insert_route_list_drag (boost::shared_ptr<ARDOUR::Route>, int x, int y);
1168
1169         /* import & embed */
1170
1171         void add_external_audio_action (Editing::ImportMode);
1172         void external_audio_dialog ();
1173         void session_import_dialog ();
1174
1175         int  check_whether_and_how_to_import(std::string, bool all_or_nothing = true);
1176         bool check_multichannel_status (const std::vector<Glib::ustring>& paths);
1177
1178         SoundFileOmega* sfbrowser;
1179
1180         void bring_in_external_audio (Editing::ImportMode mode,  nframes64_t& pos);
1181
1182         bool  idle_drop_paths  (std::vector<Glib::ustring> paths, nframes64_t frame, double ypos);
1183         void  drop_paths_part_two  (const std::vector<Glib::ustring>& paths, nframes64_t frame, double ypos);
1184
1185         int  import_sndfiles (std::vector<Glib::ustring> paths, Editing::ImportMode mode,  ARDOUR::SrcQuality, nframes64_t& pos,
1186                               int target_regions, int target_tracks, boost::shared_ptr<ARDOUR::Track>&, bool);
1187         int  embed_sndfiles (std::vector<Glib::ustring> paths, bool multiple_files, bool& check_sample_rate, Editing::ImportMode mode,
1188                              nframes64_t& pos, int target_regions, int target_tracks, boost::shared_ptr<ARDOUR::Track>&);
1189
1190         int add_sources (std::vector<Glib::ustring> paths, ARDOUR::SourceList& sources, nframes64_t& pos, Editing::ImportMode,
1191                          int target_regions, int target_tracks, boost::shared_ptr<ARDOUR::Track>&, bool add_channel_suffix);
1192         int finish_bringing_in_material (boost::shared_ptr<ARDOUR::Region> region, uint32_t, uint32_t,  nframes64_t& pos, Editing::ImportMode mode,
1193                                       boost::shared_ptr<ARDOUR::Track>& existing_track);
1194
1195         boost::shared_ptr<ARDOUR::AudioTrack> get_nth_selected_audio_track (int nth) const;
1196         boost::shared_ptr<ARDOUR::MidiTrack> get_nth_selected_midi_track (int nth) const;
1197
1198         ARDOUR::InterThreadInfo* current_interthread_info;
1199
1200         AnalysisWindow* analysis_window;
1201
1202         /* import specific info */
1203
1204         struct EditorImportStatus : public ARDOUR::ImportStatus {
1205             Editing::ImportMode mode;
1206             nframes64_t pos;
1207             int target_tracks;
1208             int target_regions;
1209             boost::shared_ptr<ARDOUR::Track> track;
1210             bool replace;
1211         };
1212
1213         EditorImportStatus import_status;
1214         static void *_import_thread (void *);
1215         void* import_thread ();
1216         void finish_import ();
1217
1218         /* to support this ... */
1219
1220         void import_audio (bool as_tracks);
1221         void do_import (std::vector<Glib::ustring> paths, bool split, bool as_tracks);
1222
1223         void move_to_start ();
1224         void move_to_end ();
1225         void goto_frame ();
1226         void center_playhead ();
1227         void center_edit_point ();
1228         void edit_cursor_backward ();
1229         void edit_cursor_forward ();
1230         void playhead_forward_to_grid ();
1231         void playhead_backward_to_grid ();
1232         void playhead_backward ();
1233         void playhead_forward ();
1234         void scroll_playhead (bool forward);
1235         void scroll_backward (float pages=0.8f);
1236         void scroll_forward (float pages=0.8f);
1237         void scroll_tracks_down ();
1238         void scroll_tracks_up ();
1239         void delete_sample_forward ();
1240         void delete_sample_backward ();
1241         void delete_screen ();
1242         void search_backwards ();
1243         void search_forwards ();
1244         void set_mark ();
1245         void clear_markers ();
1246         void clear_ranges ();
1247         void clear_locations ();
1248         void unhide_markers ();
1249         void unhide_ranges ();
1250         void jump_forward_to_mark ();
1251         void jump_backward_to_mark ();
1252         void cursor_align (bool playhead_to_edit);
1253
1254         void remove_last_capture ();
1255         void select_all_selectables_using_time_selection ();
1256         void select_all_selectables_using_loop();
1257         void select_all_selectables_using_punch();
1258         void set_selection_from_range (ARDOUR::Location&);
1259         void set_selection_from_punch ();
1260         void set_selection_from_loop ();
1261         void set_selection_from_region ();
1262
1263         void add_location_mark (nframes64_t where);
1264         void add_location_from_audio_region ();
1265         void add_locations_from_audio_region ();
1266         void add_location_from_selection ();
1267         void set_loop_from_selection (bool play);
1268         void set_punch_from_selection ();
1269         void set_punch_from_region ();
1270
1271         void set_loop_from_edit_range (bool play);
1272         void set_loop_from_region (bool play);
1273         void set_punch_from_edit_range ();
1274
1275         void set_loop_range (nframes64_t start, nframes64_t end, std::string cmd);
1276         void set_punch_range (nframes64_t start, nframes64_t end, std::string cmd);
1277
1278         void add_location_from_playhead_cursor ();
1279         bool select_new_marker;
1280
1281         void reverse_selection ();
1282         void edit_envelope ();
1283
1284         double last_scrub_x;
1285         int scrubbing_direction;
1286         int scrub_reversals;
1287         int scrub_reverse_distance;
1288         void scrub (nframes64_t, double);
1289
1290         void keyboard_selection_begin ();
1291         void keyboard_selection_finish (bool add);
1292         bool have_pending_keyboard_selection;
1293         nframes64_t pending_keyboard_selection_start;
1294
1295         boost::shared_ptr<ARDOUR::Region> select_region_for_operation (int dir, TimeAxisView **tv);
1296         void extend_selection_to_end_of_region (bool next);
1297         void extend_selection_to_start_of_region (bool previous);
1298
1299         Editing::SnapType _snap_type;
1300         Editing::SnapMode _snap_mode;
1301
1302         /// Snap threshold in pixels
1303         double snap_threshold;
1304
1305         bool ignore_gui_changes;
1306
1307         DragManager* _drags;
1308
1309         void escape ();
1310
1311         Gtk::Menu fade_context_menu;
1312         void popup_fade_context_menu (int, int, ArdourCanvas::Item*, ItemType);
1313
1314         void set_fade_in_shape (ARDOUR::AudioRegion::FadeShape);
1315         void set_fade_out_shape (ARDOUR::AudioRegion::FadeShape);
1316
1317         void set_fade_length (bool in);
1318         void toggle_fade_active (bool in);
1319         void set_fade_in_active (bool);
1320         void set_fade_out_active (bool);
1321
1322         std::set<boost::shared_ptr<ARDOUR::Playlist> > motion_frozen_playlists;
1323
1324         bool _dragging_playhead;
1325         bool _dragging_edit_point;
1326
1327         void marker_drag_motion_callback (GdkEvent*);
1328         void marker_drag_finished_callback (GdkEvent*);
1329
1330         gint mouse_rename_region (ArdourCanvas::Item*, GdkEvent*);
1331
1332         void add_region_drag (ArdourCanvas::Item*, GdkEvent*, RegionView*);
1333         void start_create_region_grab (ArdourCanvas::Item*, GdkEvent*);
1334         void add_region_copy_drag (ArdourCanvas::Item*, GdkEvent*, RegionView*);
1335         void add_region_brush_drag (ArdourCanvas::Item*, GdkEvent*, RegionView*);
1336         void start_selection_grab (ArdourCanvas::Item*, GdkEvent*);
1337
1338         void region_view_item_click (AudioRegionView&, GdkEventButton*);
1339
1340         void remove_gain_control_point (ArdourCanvas::Item*, GdkEvent*);
1341         void remove_control_point (ArdourCanvas::Item*, GdkEvent*);
1342
1343         void mouse_brush_insert_region (RegionView*, nframes64_t pos);
1344         void brush (nframes64_t);
1345
1346         void show_verbose_time_cursor (nframes64_t frame, double offset = 0, double xpos=-1, double ypos=-1);
1347         void show_verbose_duration_cursor (nframes64_t start, nframes64_t end, double offset = 0, double xpos=-1, double ypos=-1);
1348         double clamp_verbose_cursor_x (double);
1349         double clamp_verbose_cursor_y (double);
1350
1351         /* Canvas event handlers */
1352
1353         bool canvas_control_point_event (GdkEvent* event,ArdourCanvas::Item*, ControlPoint*);
1354         bool canvas_line_event (GdkEvent* event,ArdourCanvas::Item*, AutomationLine*);
1355         bool canvas_selection_rect_event (GdkEvent* event,ArdourCanvas::Item*, SelectionRect*);
1356         bool canvas_selection_start_trim_event (GdkEvent* event,ArdourCanvas::Item*, SelectionRect*);
1357         bool canvas_selection_end_trim_event (GdkEvent* event,ArdourCanvas::Item*, SelectionRect*);
1358         bool canvas_crossfade_view_event (GdkEvent* event,ArdourCanvas::Item*, CrossfadeView*);
1359         bool canvas_fade_in_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1360         bool canvas_fade_in_handle_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1361         bool canvas_fade_out_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1362         bool canvas_fade_out_handle_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1363
1364
1365         // These variables are used to detect a feedback loop and break it to avoid a gui hang
1366 private:
1367         ArdourCanvas::Item *last_item_entered;
1368         int last_item_entered_n;
1369
1370 public:
1371         bool canvas_region_view_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1372         bool canvas_frame_handle_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1373         bool canvas_region_view_name_highlight_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1374         bool canvas_region_view_name_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1375         bool canvas_feature_line_event (GdkEvent* event, ArdourCanvas::Item*, RegionView*);
1376         bool canvas_stream_view_event (GdkEvent* event,ArdourCanvas::Item*, RouteTimeAxisView*);
1377         bool canvas_marker_event (GdkEvent* event,ArdourCanvas::Item*, Marker*);
1378         bool canvas_zoom_rect_event (GdkEvent* event,ArdourCanvas::Item*);
1379         bool canvas_tempo_marker_event (GdkEvent* event,ArdourCanvas::Item*, TempoMarker*);
1380         bool canvas_meter_marker_event (GdkEvent* event,ArdourCanvas::Item*, MeterMarker*);
1381         bool canvas_automation_track_event(GdkEvent* event, ArdourCanvas::Item*, AutomationTimeAxisView*) ;
1382         bool canvas_note_event (GdkEvent* event, ArdourCanvas::Item*);
1383
1384         bool canvas_tempo_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1385         bool canvas_meter_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1386         bool canvas_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1387         bool canvas_range_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1388         bool canvas_transport_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1389         bool canvas_cd_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1390
1391         bool canvas_imageframe_item_view_event(GdkEvent* event, ArdourCanvas::Item*,ImageFrameView*);
1392         bool canvas_imageframe_view_event(GdkEvent* event, ArdourCanvas::Item*,ImageFrameTimeAxis*);
1393         bool canvas_imageframe_start_handle_event(GdkEvent* event, ArdourCanvas::Item*,ImageFrameView*);
1394         bool canvas_imageframe_end_handle_event(GdkEvent* event, ArdourCanvas::Item*,ImageFrameView*);
1395         bool canvas_marker_time_axis_view_event(GdkEvent* event, ArdourCanvas::Item*,MarkerTimeAxis*);
1396         bool canvas_markerview_item_view_event(GdkEvent* event, ArdourCanvas::Item*,MarkerView*);
1397         bool canvas_markerview_start_handle_event(GdkEvent* event, ArdourCanvas::Item*,MarkerView*);
1398         bool canvas_markerview_end_handle_event(GdkEvent* event, ArdourCanvas::Item*,MarkerView*);
1399
1400   private:
1401         friend class DragManager;
1402         friend class EditorRouteGroups;
1403         friend class EditorRegions;
1404
1405         /* non-public event handlers */
1406
1407         bool canvas_playhead_cursor_event (GdkEvent* event, ArdourCanvas::Item*);
1408         bool track_canvas_scroll (GdkEventScroll* event);
1409
1410         bool track_canvas_scroll_event (GdkEventScroll* event);
1411         bool track_canvas_button_press_event (GdkEventButton* event);
1412         bool track_canvas_button_release_event (GdkEventButton* event);
1413         bool track_canvas_motion_notify_event (GdkEventMotion* event);
1414
1415         Gtk::Allocation canvas_allocation;
1416         void track_canvas_allocate (Gtk::Allocation alloc);
1417         bool track_canvas_size_allocated ();
1418         bool track_canvas_drag_motion (Glib::RefPtr<Gdk::DragContext> const &, int, int, guint);
1419
1420         void set_playhead_cursor ();
1421
1422         void kbd_driver (sigc::slot<void,GdkEvent*>, bool use_track_canvas = true, bool use_time_canvas = true, bool can_select = true);
1423         void kbd_mute_unmute_region ();
1424         void kbd_brush ();
1425
1426         void kbd_do_brush (GdkEvent*);
1427         void kbd_do_audition (GdkEvent*);
1428
1429         void initialize_canvas ();
1430
1431         /* display control */
1432
1433         bool _show_measures;
1434         /// true if the editor should follow the playhead, otherwise false
1435         bool _follow_playhead;
1436         /// true if we scroll the tracks rather than the playhead
1437         bool _stationary_playhead;
1438
1439         ARDOUR::TempoMap::BBTPointList *current_bbt_points;
1440
1441         TempoLines* tempo_lines;
1442
1443         ArdourCanvas::Group* time_line_group;
1444
1445         void hide_measures ();
1446         void draw_measures ();
1447         bool redraw_measures ();
1448
1449         void new_tempo_section ();
1450
1451         void mouse_add_new_tempo_event (nframes64_t where);
1452         void mouse_add_new_meter_event (nframes64_t where);
1453
1454         void remove_tempo_marker (ArdourCanvas::Item*);
1455         void remove_meter_marker (ArdourCanvas::Item*);
1456         gint real_remove_tempo_marker (ARDOUR::TempoSection*);
1457         gint real_remove_meter_marker (ARDOUR::MeterSection*);
1458
1459         void edit_tempo_section (ARDOUR::TempoSection*);
1460         void edit_meter_section (ARDOUR::MeterSection*);
1461         void edit_tempo_marker (ArdourCanvas::Item*);
1462         void edit_meter_marker (ArdourCanvas::Item*);
1463         void edit_control_point (ArdourCanvas::Item*);
1464         void edit_note (ArdourCanvas::Item *);
1465
1466         void marker_menu_edit ();
1467         void marker_menu_remove ();
1468         void marker_menu_rename ();
1469         void toggle_marker_menu_lock ();
1470         void toggle_marker_menu_glue ();
1471         void marker_menu_hide ();
1472         void marker_menu_loop_range ();
1473         void marker_menu_select_all_selectables_using_range ();
1474         void marker_menu_select_using_range ();
1475         void marker_menu_separate_regions_using_location ();
1476         void marker_menu_play_from ();
1477         void marker_menu_play_range ();
1478         void marker_menu_set_playhead ();
1479         void marker_menu_set_from_playhead ();
1480         void marker_menu_set_from_selection ();
1481         void marker_menu_range_to_next ();
1482         void new_transport_marker_menu_set_loop ();
1483         void new_transport_marker_menu_set_punch ();
1484         void update_loop_range_view (bool visibility=false);
1485         void update_punch_range_view (bool visibility=false);
1486         void new_transport_marker_menu_popdown ();
1487         void marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
1488         void tempo_or_meter_marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
1489         void transport_marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
1490         void new_transport_marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
1491         void build_range_marker_menu (bool loop_or_punch);
1492         void build_marker_menu (bool, ARDOUR::Location *);
1493         void build_tempo_or_meter_marker_menu (bool);
1494         void build_new_transport_marker_menu ();
1495         void dynamic_cast_marker_object (void*, MeterMarker**, TempoMarker**) const;
1496
1497         Gtk::Menu* tempo_or_meter_marker_menu;
1498         Gtk::Menu* marker_menu;
1499         Gtk::Menu* session_range_marker_menu;
1500         Gtk::Menu* range_marker_menu;
1501         Gtk::Menu* transport_marker_menu;
1502         Gtk::Menu* new_transport_marker_menu;
1503         Gtk::Menu* cd_marker_menu;
1504         ArdourCanvas::Item* marker_menu_item;
1505
1506         typedef std::list<Marker*> Marks;
1507         Marks metric_marks;
1508
1509         void remove_metric_marks ();
1510         void draw_metric_marks (const ARDOUR::Metrics& metrics);
1511
1512         void compute_current_bbt_points (nframes_t left, nframes_t right);
1513         void tempo_map_changed (const PBD::PropertyChange&);
1514         void redisplay_tempo (bool immediate_redraw);
1515
1516         uint32_t bbt_beat_subdivision;
1517
1518         /* toolbar */
1519
1520         Gtk::ToggleButton editor_mixer_button;
1521         Gtk::ToggleButton editor_list_button;
1522         void editor_mixer_button_toggled ();
1523         void editor_list_button_toggled ();
1524
1525         AudioClock               zoom_range_clock;
1526         Gtk::Button              zoom_in_button;
1527         Gtk::Button              zoom_out_button;
1528         Gtk::Button              zoom_out_full_button;
1529         Gtk::Button              zoom_onetoone_button;
1530
1531         Gtk::Button              tav_expand_button;
1532         Gtk::Button              tav_shrink_button;
1533
1534         Gtk::VBox                toolbar_clock_vbox;
1535         Gtk::VBox                toolbar_selection_clock_vbox;
1536         Gtk::Table               toolbar_selection_clock_table;
1537         Gtk::Label               toolbar_selection_cursor_label;
1538
1539         Gtkmm2ext::TearOff*      _mouse_mode_tearoff;
1540         Gtk::ToggleButton         mouse_select_button;
1541         Gtk::ToggleButton         mouse_move_button;
1542         Gtk::ToggleButton         mouse_gain_button;
1543         Gtk::ToggleButton         mouse_zoom_button;
1544         Gtk::ToggleButton         mouse_timefx_button;
1545         Gtk::ToggleButton         mouse_audition_button;
1546         Gtk::ToggleButton         join_object_range_button;
1547
1548         void                     mouse_mode_toggled (Editing::MouseMode m);
1549         void                     mouse_mode_object_range_toggled () {}
1550         bool                     ignore_mouse_mode_toggle;
1551
1552         Gtk::ToggleButton        internal_edit_button;
1553         void                     toggle_internal_editing ();
1554
1555         gint                     mouse_select_button_release (GdkEventButton*);
1556
1557         Gtk::VBox                automation_box;
1558         Gtk::Button              automation_mode_button;
1559         Gtk::ToggleButton        global_automation_button;
1560
1561         Gtk::ComboBoxText edit_mode_selector;
1562         Gtk::VBox         edit_mode_box;
1563
1564         void set_edit_mode (ARDOUR::EditMode);
1565         void cycle_edit_mode ();
1566         void edit_mode_selection_done ();
1567
1568         Gtk::ComboBoxText snap_type_selector;
1569         Gtk::ComboBoxText snap_mode_selector;
1570         Gtk::HBox         snap_box;
1571
1572         std::vector<std::string> snap_type_strings;
1573         std::vector<std::string> snap_mode_strings;
1574
1575         void snap_type_selection_done ();
1576         void snap_mode_selection_done ();
1577         void snap_mode_chosen (Editing::SnapMode);
1578         void snap_type_chosen (Editing::SnapType);
1579
1580         Glib::RefPtr<Gtk::RadioAction> snap_type_action (Editing::SnapType);
1581         Glib::RefPtr<Gtk::RadioAction> snap_mode_action (Editing::SnapMode);
1582
1583         Gtk::ComboBoxText zoom_focus_selector;
1584         Gtk::VBox         zoom_focus_box;
1585
1586         std::vector<std::string> zoom_focus_strings;
1587
1588         void zoom_focus_selection_done ();
1589         void zoom_focus_chosen (Editing::ZoomFocus);
1590
1591         Glib::RefPtr<Gtk::RadioAction> zoom_focus_action (Editing::ZoomFocus);
1592
1593         Gtk::HBox           _zoom_box;
1594         Gtkmm2ext::TearOff* _zoom_tearoff;
1595         void                zoom_adjustment_changed();
1596
1597         void setup_toolbar ();
1598
1599         void setup_tooltips ();
1600
1601         Gtkmm2ext::TearOff*     _tools_tearoff;
1602         Gtk::HBox                toolbar_hbox;
1603         Gtk::EventBox            toolbar_base;
1604         Gtk::Frame               toolbar_frame;
1605
1606         /* midi toolbar */
1607
1608         Gtk::HBox                panic_box;
1609         Gtk::Button              midi_panic_button;
1610         Gtk::ToggleButton        midi_sound_notes;
1611         void                     midi_panic ();
1612         bool                     sound_notes () const { return midi_sound_notes.get_active(); }
1613
1614         void setup_midi_toolbar ();
1615
1616         /* selection process */
1617
1618         Selection* selection;
1619         Selection* cut_buffer;
1620
1621         void time_selection_changed ();
1622         void track_selection_changed ();
1623         void region_selection_changed ();
1624         sigc::connection editor_regions_selection_changed_connection;
1625         void sensitize_the_right_region_actions (bool have_selected_regions);
1626         void point_selection_changed ();
1627         void marker_selection_changed ();
1628
1629         void cancel_selection ();
1630
1631         void region_selection_op (void (ARDOUR::Region::*pmf)(void));
1632         void region_selection_op (void (ARDOUR::Region::*pmf)(void*), void*);
1633         void region_selection_op (void (ARDOUR::Region::*pmf)(bool), bool);
1634
1635         bool audio_region_selection_covers (nframes64_t where);
1636
1637         /* transport range select process */
1638
1639         ArdourCanvas::SimpleRect*  cd_marker_bar_drag_rect;
1640         ArdourCanvas::SimpleRect*  range_bar_drag_rect;
1641         ArdourCanvas::SimpleRect*  transport_bar_drag_rect;
1642
1643 #ifdef GTKOSX
1644         ArdourCanvas::SimpleRect     *bogus_background_rect;
1645 #endif
1646         ArdourCanvas::SimpleRect     *transport_bar_range_rect;
1647         ArdourCanvas::SimpleRect     *transport_bar_preroll_rect;
1648         ArdourCanvas::SimpleRect     *transport_bar_postroll_rect;
1649         ArdourCanvas::SimpleRect     *transport_loop_range_rect;
1650         ArdourCanvas::SimpleRect     *transport_punch_range_rect;
1651         ArdourCanvas::SimpleLine     *transport_punchin_line;
1652         ArdourCanvas::SimpleLine     *transport_punchout_line;
1653         ArdourCanvas::SimpleRect     *transport_preroll_rect;
1654         ArdourCanvas::SimpleRect     *transport_postroll_rect;
1655
1656         ARDOUR::Location*  transport_loop_location();
1657         ARDOUR::Location*  transport_punch_location();
1658
1659         ARDOUR::Location   *temp_location;
1660
1661         /* object rubberband select process */
1662
1663         bool select_all_within (nframes64_t, nframes64_t, double, double, TrackViewList const &, Selection::Operation, bool);
1664
1665         ArdourCanvas::SimpleRect   *rubberband_rect;
1666
1667         /* mouse zoom process */
1668
1669         ArdourCanvas::SimpleRect   *zoom_rect;
1670         void reposition_zoom_rect (nframes64_t start, nframes64_t end);
1671
1672         EditorRouteGroups* _route_groups;
1673         EditorRoutes* _routes;
1674         EditorRegions* _regions;
1675         EditorSnapshots* _snapshots;
1676         EditorLocations* _locations;
1677
1678         /* diskstream/route display management */
1679         Glib::RefPtr<Gdk::Pixbuf> rec_enabled_icon;
1680         Glib::RefPtr<Gdk::Pixbuf> rec_disabled_icon;
1681
1682         Glib::RefPtr<Gtk::TreeSelection> route_display_selection;
1683
1684         bool sync_track_view_list_and_routes ();
1685
1686         Gtk::VBox           list_vpacker;
1687
1688         /* autoscrolling */
1689
1690         bool autoscroll_active;
1691         int autoscroll_timeout_tag;
1692         int autoscroll_x;
1693         int autoscroll_y;
1694         int last_autoscroll_x;
1695         int last_autoscroll_y;
1696         uint32_t autoscroll_cnt;
1697         nframes64_t autoscroll_x_distance;
1698         double autoscroll_y_distance;
1699
1700         static gint _autoscroll_canvas (void *);
1701         bool autoscroll_canvas ();
1702         void start_canvas_autoscroll (int x, int y);
1703         void stop_canvas_autoscroll ();
1704
1705         /* trimming */
1706         void point_trim (GdkEvent *, nframes64_t);
1707         void single_contents_trim (RegionView&, nframes64_t, bool, bool);
1708         void single_start_trim (RegionView&, nframes64_t, bool);
1709         void single_end_trim (RegionView&, nframes64_t, bool);
1710
1711         void thaw_region_after_trim (RegionView& rv);
1712
1713         void trim_region_front();
1714         void trim_region_back();
1715         void trim_region (bool front);
1716
1717         void trim_region_to_edit_point ();
1718         void trim_region_from_edit_point ();
1719         void trim_region_to_loop ();
1720         void trim_region_to_punch ();
1721         void trim_region_to_location (const ARDOUR::Location&, const char* cmd);
1722
1723         void trim_to_region(bool forward);
1724         void trim_region_to_previous_region_end();
1725         void trim_region_to_next_region_start();
1726
1727         bool show_gain_after_trim;
1728
1729         /* Drag-n-Drop */
1730
1731         int convert_drop_to_paths (
1732                         std::vector<Glib::ustring>&           paths,
1733                         const Glib::RefPtr<Gdk::DragContext>& context,
1734                         gint                                  x,
1735                         gint                                  y,
1736                         const Gtk::SelectionData&             data,
1737                         guint                                 info,
1738                         guint                                 time);
1739
1740         void track_canvas_drag_data_received (
1741                         const Glib::RefPtr<Gdk::DragContext>& context,
1742                         gint                                  x,
1743                         gint                                  y,
1744                         const Gtk::SelectionData&             data,
1745                         guint                                 info,
1746                         guint                                 time);
1747
1748         void drop_paths (
1749                         const Glib::RefPtr<Gdk::DragContext>& context,
1750                         gint                                  x,
1751                         gint                                  y,
1752                         const Gtk::SelectionData&             data,
1753                         guint                                 info,
1754                         guint                                 time);
1755
1756         void drop_regions (
1757                         const Glib::RefPtr<Gdk::DragContext>& context,
1758                         gint                                  x,
1759                         gint                                  y,
1760                         const Gtk::SelectionData&             data,
1761                         guint                                 info,
1762                         guint                                 time);
1763
1764         void drop_routes (
1765                         const Glib::RefPtr<Gdk::DragContext>& context,
1766                         gint                x,
1767                         gint                y,
1768                         const Gtk::SelectionData& data,
1769                         guint               info,
1770                         guint               time);
1771
1772         /* audio export */
1773
1774         int  write_region_selection(RegionSelection&);
1775         bool write_region (std::string path, boost::shared_ptr<ARDOUR::AudioRegion>);
1776         void bounce_region_selection ();
1777         void bounce_range_selection (bool replace, bool enable_processing);
1778         void external_edit_region ();
1779
1780         int write_audio_selection (TimeSelection&);
1781         bool write_audio_range (ARDOUR::AudioPlaylist&, const ARDOUR::ChanCount& channels, std::list<ARDOUR::AudioRange>&);
1782
1783         void write_selection ();
1784
1785         XMLNode *before; /* used in *_reversible_command */
1786
1787         void update_title ();
1788         void update_title_s (const std::string & snapshot_name);
1789
1790         struct State {
1791             Selection* selection;
1792             double frames_per_unit;
1793
1794             State (PublicEditor const * e);
1795             ~State ();
1796         };
1797
1798         void instant_save ();
1799
1800         boost::shared_ptr<ARDOUR::AudioRegion> last_audition_region;
1801
1802         /* freeze operations */
1803
1804         ARDOUR::InterThreadInfo freeze_status;
1805         static void* _freeze_thread (void*);
1806         void* freeze_thread ();
1807
1808         void freeze_route ();
1809         void unfreeze_route ();
1810
1811         /* route-group solo + mute */
1812
1813         void set_route_group_solo (ARDOUR::Route&, bool);
1814         void set_route_group_mute (ARDOUR::Route&, bool);
1815
1816         /* duplication */
1817
1818         void duplicate_dialog (bool with_dialog);
1819
1820         nframes64_t event_frame (GdkEvent const *, double* px = 0, double* py = 0) const;
1821
1822         /* returns false if mouse pointer is not in track or marker canvas
1823          */
1824         bool mouse_frame (nframes64_t&, bool& in_track_canvas) const;
1825
1826         /* "whats mine is yours" */
1827
1828         TimeFXDialog* current_timefx;
1829
1830         static void* timefx_thread (void *arg);
1831         void do_timefx (TimeFXDialog&);
1832
1833         int time_stretch (RegionSelection&, float fraction);
1834         int pitch_shift (RegionSelection&, float cents);
1835         void pitch_shift_regions ();
1836         int time_fx (RegionSelection&, float val, bool pitching);
1837
1838         /* editor-mixer strip */
1839
1840         MixerStrip *current_mixer_strip;
1841         bool show_editor_mixer_when_tracks_arrive;
1842         Gtk::VBox current_mixer_strip_vbox;
1843         void cms_new (boost::shared_ptr<ARDOUR::Route>);
1844         void current_mixer_strip_hidden ();
1845
1846         void detach_tearoff (Gtk::Box* b, Gtk::Window* w);
1847         void reattach_tearoff (Gtk::Box* b, Gtk::Window* w, int32_t n);
1848 #ifdef GTKOSX
1849         void ensure_all_elements_drawn ();
1850 #endif
1851         /* nudging tracks */
1852
1853         void nudge_track (bool use_edit_point, bool forwards);
1854
1855         /* xfades */
1856
1857         bool _xfade_visibility;
1858
1859 #ifdef WITH_CMT
1860         void handle_new_imageframe_time_axis_view(const std::string & track_name, void* src) ;
1861         void handle_new_imageframe_marker_time_axis_view(const std::string & track_name, TimeAxisView* marked_track) ;
1862
1863         void start_imageframe_grab(ArdourCanvas::Item*, GdkEvent*) ;
1864         void start_markerview_grab(ArdourCanvas::Item*, GdkEvent*) ;
1865
1866         void imageframe_drag_motion_callback(ArdourCanvas::Item*, GdkEvent*) ;
1867         void markerview_drag_motion_callback(ArdourCanvas::Item*, GdkEvent*) ;
1868         void timeaxis_item_drag_finished_callback(ArdourCanvas::Item*, GdkEvent*) ;
1869
1870         gint canvas_imageframe_item_view_event(ArdourCanvas::Item* item, GdkEvent* event, ImageFrameView* ifv);
1871         gint canvas_imageframe_view_event(ArdourCanvas::Item* item, GdkEvent* event, ImageFrameTimeAxis* ifta);
1872         gint canvas_imageframe_start_handle_event(ArdourCanvas::Item* item, GdkEvent* event, ImageFrameView* ifv);
1873         gint canvas_imageframe_end_handle_event(ArdourCanvas::Item* item, GdkEvent* event, ImageFrameView* ifv);
1874
1875         gint canvas_marker_time_axis_view_event(ArdourCanvas::Item* item, GdkEvent* event, MarkerTimeAxis* mta);
1876         gint canvas_markerview_item_view_event(ArdourCanvas::Item* item, GdkEvent* event, MarkerView* mv);
1877         gint canvas_markerview_start_handle_event(ArdourCanvas::Item* item, GdkEvent* event, MarkerView* mv);
1878         gint canvas_markerview_end_handle_event(ArdourCanvas::Item* item, GdkEvent* event, MarkerView* mv);
1879
1880         void imageframe_start_handle_op(ArdourCanvas::Item* item, GdkEvent* event) ;
1881         void imageframe_end_handle_op(ArdourCanvas::Item* item, GdkEvent* event) ;
1882         void imageframe_start_handle_trim_motion(ArdourCanvas::Item* item, GdkEvent* event) ;
1883         void imageframe_start_handle_end_trim(ArdourCanvas::Item* item, GdkEvent* event) ;
1884         void imageframe_end_handle_trim_motion(ArdourCanvas::Item* item, GdkEvent* event) ;
1885         void imageframe_end_handle_end_trim(ArdourCanvas::Item* item, GdkEvent* event) ;
1886
1887         void markerview_item_start_handle_op(ArdourCanvas::Item* item, GdkEvent* event) ;
1888         void markerview_item_end_handle_op(ArdourCanvas::Item* item, GdkEvent* event) ;
1889         void markerview_start_handle_trim_motion(ArdourCanvas::Item* item, GdkEvent* event) ;
1890         void markerview_start_handle_end_trim(ArdourCanvas::Item* item, GdkEvent* event) ;
1891         void markerview_end_handle_trim_motion(ArdourCanvas::Item* item, GdkEvent* event) ;
1892         void markerview_end_handle_end_trim(ArdourCanvas::Item* item, GdkEvent* event) ;
1893
1894         void popup_imageframe_edit_menu(int button, int32_t time, ArdourCanvas::Item* ifv, bool with_frame) ;
1895         void popup_marker_time_axis_edit_menu(int button, int32_t time, ArdourCanvas::Item* ifv, bool with_frame) ;
1896
1897         ImageFrameSocketHandler* image_socket_listener ;
1898 #endif
1899
1900         void toggle_xfade_active (boost::weak_ptr<ARDOUR::Crossfade>);
1901         void toggle_xfade_length (boost::weak_ptr<ARDOUR::Crossfade>);
1902         void edit_xfade (boost::weak_ptr<ARDOUR::Crossfade>);
1903         void xfade_edit_left_region ();
1904         void xfade_edit_right_region ();
1905
1906         static const int32_t default_width = 995;
1907         static const int32_t default_height = 765;
1908
1909         /* nudge */
1910
1911         Gtk::Button      nudge_forward_button;
1912         Gtk::Button      nudge_backward_button;
1913         Gtk::HBox        nudge_hbox;
1914         Gtk::VBox        nudge_vbox;
1915         AudioClock       nudge_clock;
1916
1917         bool nudge_forward_release (GdkEventButton*);
1918         bool nudge_backward_release (GdkEventButton*);
1919
1920         /* audio filters */
1921
1922         void apply_filter (ARDOUR::Filter&, std::string cmd);
1923
1924         Command* apply_midi_note_edit_op_to_region (ARDOUR::MidiOperator& op, MidiRegionView& mrv);
1925         void apply_midi_note_edit_op (ARDOUR::MidiOperator& op);
1926
1927         /* handling cleanup */
1928
1929         int playlist_deletion_dialog (boost::shared_ptr<ARDOUR::Playlist>);
1930
1931         PBD::ScopedConnectionList session_connections;
1932
1933         /* tracking step changes of track height */
1934
1935         TimeAxisView* current_stepping_trackview;
1936         ARDOUR::microseconds_t last_track_height_step_timestamp;
1937         gint track_height_step_timeout();
1938         sigc::connection step_timeout;
1939
1940         TimeAxisView* entered_track;
1941         /** If the mouse is over a RegionView or one of its child canvas items, this is set up
1942             to point to the RegionView.  Otherwise it is 0.
1943         */
1944         RegionView*   entered_regionview;
1945
1946
1947         void ensure_entered_track_selected (bool op_acts_on_objects = false);
1948         bool clear_entered_track;
1949         bool left_track_canvas (GdkEventCrossing*);
1950         bool entered_track_canvas (GdkEventCrossing*);
1951         void set_entered_track (TimeAxisView*);
1952         void set_entered_regionview (RegionView*);
1953         void ensure_track_visible (TimeAxisView*);
1954         gint left_automation_track ();
1955
1956         void reset_canvas_action_sensitivity (bool);
1957         void toggle_gain_envelope_visibility ();
1958         void toggle_gain_envelope_active ();
1959         void reset_region_gain_envelopes ();
1960
1961         bool on_key_press_event (GdkEventKey*);
1962         bool on_key_release_event (GdkEventKey*);
1963
1964         void session_state_saved (std::string);
1965
1966         Glib::RefPtr<Gtk::Action>              undo_action;
1967         Glib::RefPtr<Gtk::Action>              redo_action;
1968
1969         void history_changed ();
1970
1971         Gtk::HBox      status_bar_hpacker;
1972
1973         Editing::EditPoint _edit_point;
1974
1975         Gtk::ComboBoxText edit_point_selector;
1976
1977         void set_edit_point_preference (Editing::EditPoint ep, bool force = false);
1978         void cycle_edit_point (bool with_marker);
1979         void set_edit_point ();
1980         void edit_point_selection_done ();
1981         void edit_point_chosen (Editing::EditPoint);
1982         Glib::RefPtr<Gtk::RadioAction> edit_point_action (Editing::EditPoint);
1983         std::vector<std::string> edit_point_strings;
1984
1985         void selected_marker_moved (ARDOUR::Location*);
1986
1987         bool get_edit_op_range (nframes64_t& start, nframes64_t& end) const;
1988
1989         void get_regions_at (RegionSelection&, nframes64_t where, const TrackViewList& ts) const;
1990         void get_regions_after (RegionSelection&, nframes64_t where, const TrackViewList& ts) const;
1991
1992         void get_regions_for_action (RegionSelection&, bool allow_entered = false, bool allow_edit_position = true);
1993
1994         void start_updating_meters ();
1995         void stop_updating_meters ();
1996         bool meters_running;
1997
1998         void select_next_route ();
1999         void select_prev_route ();
2000
2001         void snap_to_internal (nframes64_t& first, int32_t direction = 0, bool for_mark = false);
2002         void timecode_snap_to_internal (nframes64_t& first, int32_t direction = 0, bool for_mark = false);
2003
2004         RhythmFerret* rhythm_ferret;
2005         BundleManager* _bundle_manager;
2006
2007         void fit_tracks (TrackViewList &);
2008         void fit_selected_tracks ();
2009         void set_track_height (Height);
2010
2011         void remove_tracks ();
2012         void toggle_tracks_active ();
2013
2014         bool _have_idled;
2015         int resize_idle_id;
2016         static gboolean _idle_resize (gpointer);
2017         bool idle_resize();
2018         int32_t _pending_resize_amount;
2019         TimeAxisView* _pending_resize_view;
2020
2021         void visible_order_range (int*, int*) const;
2022
2023         void located ();
2024         
2025         /** true if we've made a locate request that hasn't yet been processed */
2026         bool _pending_locate_request;
2027         
2028         /** if true, there is a pending Session locate which is the initial one when loading a session;
2029             we need to know this so that we don't (necessarily) set the viewport to show the playhead
2030             initially.
2031         */
2032         bool _pending_initial_locate;
2033
2034         Gtk::HBox _summary_hbox;
2035         EditorSummary* _summary;
2036         void region_view_added (RegionView *);
2037
2038         void update_canvas_now ();
2039
2040         EditorGroupTabs* _group_tabs;
2041         void fit_route_group (ARDOUR::RouteGroup *);
2042
2043         void step_edit_status_change (bool);
2044         void start_step_editing ();
2045         void stop_step_editing ();
2046         bool check_step_edit ();
2047         sigc::connection step_edit_connection;
2048
2049         double _last_motion_y;
2050
2051         friend class Drag;
2052         friend class RegionDrag;
2053         friend class RegionMoveDrag;
2054         friend class RegionSpliceDrag;
2055         friend class TrimDrag;
2056         friend class MeterMarkerDrag;
2057         friend class TempoMarkerDrag;
2058         friend class CursorDrag;
2059         friend class FadeInDrag;
2060         friend class FadeOutDrag;
2061         friend class MarkerDrag;
2062         friend class RegionGainDrag;
2063         friend class ControlPointDrag;
2064         friend class LineDrag;
2065         friend class RubberbandSelectDrag;
2066         friend class TimeFXDrag;
2067         friend class ScrubDrag;
2068         friend class SelectionDrag;
2069         friend class RangeMarkerBarDrag;
2070         friend class MouseZoomDrag;
2071         friend class RegionCreateDrag;
2072         friend class RegionMotionDrag;
2073         friend class RegionInsertDrag;
2074
2075         friend class EditorSummary;
2076         friend class EditorGroupTabs;
2077
2078         friend class EditorRoutes;
2079         friend class RhythmFerret;
2080 };
2081
2082 #endif /* __ardour_editor_h__ */