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