233816295b81d4fda4dad87b1624444899f7f0ad
[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 (bool range = false);
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_double_click_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1055         bool button_press_dispatch (GdkEventButton*);
1056         bool button_release_dispatch (GdkEventButton*);
1057         bool motion_handler (ArdourCanvas::Item*, GdkEvent*, bool from_autoscroll = false);
1058         bool enter_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1059         bool leave_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1060         bool key_press_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1061         bool key_release_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1062
1063         Gtkmm2ext::Bindings* button_bindings;
1064         XMLNode* button_settings () const;
1065
1066         /* KEYMAP HANDLING */
1067
1068         void register_actions ();
1069         void register_region_actions ();
1070
1071         void load_bindings ();
1072         Gtkmm2ext::ActionMap editor_action_map;
1073         Gtkmm2ext::Bindings  key_bindings;
1074
1075         int ensure_cursor (framepos_t* pos);
1076
1077         void cut_copy (Editing::CutCopyOp);
1078         bool can_cut_copy () const;
1079         void cut_copy_points (Editing::CutCopyOp);
1080         void cut_copy_regions (Editing::CutCopyOp, RegionSelection&);
1081         void cut_copy_ranges (Editing::CutCopyOp);
1082         void cut_copy_midi (Editing::CutCopyOp);
1083
1084         void mouse_paste ();
1085         void paste_internal (framepos_t position, float times);
1086
1087         /* EDITING OPERATIONS */
1088
1089         void reset_point_selection ();
1090         void toggle_region_lock ();
1091         void toggle_opaque_region ();
1092         void toggle_record_enable ();
1093         void toggle_solo ();
1094         void toggle_solo_isolate ();
1095         void toggle_mute ();
1096         void toggle_region_lock_style ();
1097
1098         enum LayerOperation {
1099                 Raise,
1100                 RaiseToTop,
1101                 Lower,
1102                 LowerToBottom
1103         };
1104
1105         void do_layer_operation (LayerOperation);
1106         void raise_region ();
1107         void raise_region_to_top ();
1108         void change_region_layering_order (bool from_context_menu);
1109         void lower_region ();
1110         void lower_region_to_bottom ();
1111         void split_regions_at (framepos_t, RegionSelection&);
1112         void split_region_at_transients ();
1113         void split_region_at_points (boost::shared_ptr<ARDOUR::Region>, ARDOUR::AnalysisFeatureList&, bool can_ferret, bool select_new = false);
1114         void crop_region_to_selection ();
1115         void crop_region_to (framepos_t start, framepos_t end);
1116         void set_sync_point (framepos_t, const RegionSelection&);
1117         void set_region_sync_position ();
1118         void remove_region_sync();
1119         void align_regions (ARDOUR::RegionPoint);
1120         void align_regions_relative (ARDOUR::RegionPoint point);
1121         void align_region (boost::shared_ptr<ARDOUR::Region>, ARDOUR::RegionPoint point, framepos_t position);
1122         void align_region_internal (boost::shared_ptr<ARDOUR::Region>, ARDOUR::RegionPoint point, framepos_t position);
1123         void remove_selected_regions ();
1124         void remove_clicked_region ();
1125         void show_region_properties ();
1126         void show_midi_list_editor ();
1127         void rename_region ();
1128         void duplicate_some_regions (RegionSelection&, float times);
1129         void duplicate_selection (float times);
1130         void region_fill_selection ();
1131         void combine_regions ();
1132         void uncombine_regions ();
1133
1134         void region_fill_track ();
1135         void audition_playlist_region_standalone (boost::shared_ptr<ARDOUR::Region>);
1136         void audition_playlist_region_via_route (boost::shared_ptr<ARDOUR::Region>, ARDOUR::Route&);
1137         void split_multichannel_region();
1138         void reverse_region ();
1139         void strip_region_silence ();
1140         void normalize_region ();
1141         void reset_region_scale_amplitude ();
1142         void adjust_region_gain (bool up);
1143         void quantize_region ();
1144         void insert_patch_change (bool from_context);
1145         void fork_region ();
1146
1147         void do_insert_time ();
1148         void insert_time (framepos_t, framecnt_t, Editing::InsertTimeOption, bool, bool, bool, bool, bool, bool);
1149
1150         void tab_to_transient (bool forward);
1151
1152         void set_tempo_from_region ();
1153         void use_range_as_bar ();
1154
1155         void define_one_bar (framepos_t start, framepos_t end);
1156
1157         void audition_region_from_region_list ();
1158         void hide_region_from_region_list ();
1159         void show_region_in_region_list ();
1160
1161         void naturalize_region ();
1162
1163         void reset_focus ();
1164
1165         void split_region ();
1166
1167         void delete_ ();
1168         void cut ();
1169         void copy ();
1170         void paste (float times, bool from_context_menu = false);
1171
1172         void place_transient ();
1173         void remove_transient (ArdourCanvas::Item* item);
1174         void snap_regions_to_grid ();
1175         void close_region_gaps ();
1176
1177         void keyboard_paste ();
1178
1179         void region_from_selection ();
1180         void create_region_from_selection (std::vector<boost::shared_ptr<ARDOUR::Region> >&);
1181
1182         void play_from_start ();
1183         void play_from_edit_point ();
1184         void play_from_edit_point_and_return ();
1185         void play_selected_region ();
1186         void play_edit_range ();
1187         void play_location (ARDOUR::Location&);
1188         void loop_location (ARDOUR::Location&);
1189
1190         void temporal_zoom_selection ();
1191         void temporal_zoom_region (bool both_axes);
1192         void zoom_to_region (bool both_axes);
1193         void temporal_zoom_session ();
1194         void temporal_zoom (framecnt_t samples_per_pixel);
1195         void temporal_zoom_by_frame (framepos_t start, framepos_t end);
1196         void temporal_zoom_to_frame (bool coarser, framepos_t frame);
1197
1198         void insert_region_list_drag (boost::shared_ptr<ARDOUR::Region>, int x, int y);
1199         void insert_region_list_selection (float times);
1200
1201         void insert_route_list_drag (boost::shared_ptr<ARDOUR::Route>, int x, int y);
1202
1203         /* import & embed */
1204
1205         void add_external_audio_action (Editing::ImportMode);
1206         void external_audio_dialog ();
1207         void session_import_dialog ();
1208
1209         int  check_whether_and_how_to_import(std::string, bool all_or_nothing = true);
1210         bool check_multichannel_status (const std::vector<std::string>& paths);
1211
1212         SoundFileOmega* sfbrowser;
1213
1214         void bring_in_external_audio (Editing::ImportMode mode,  framepos_t& pos);
1215
1216         bool  idle_drop_paths  (std::vector<std::string> paths, framepos_t frame, double ypos, bool copy);
1217         void  drop_paths_part_two  (const std::vector<std::string>& paths, framepos_t frame, double ypos, bool copy);
1218
1219         int  import_sndfiles (std::vector<std::string> paths, Editing::ImportDisposition, Editing::ImportMode mode,  
1220                               ARDOUR::SrcQuality, framepos_t& pos,
1221                               int target_regions, int target_tracks, boost::shared_ptr<ARDOUR::Track>&, bool);
1222         int  embed_sndfiles (std::vector<std::string> paths, bool multiple_files, bool& check_sample_rate, 
1223                              Editing::ImportDisposition disposition, Editing::ImportMode mode,
1224                              framepos_t& pos, int target_regions, int target_tracks, boost::shared_ptr<ARDOUR::Track>&);
1225
1226         int add_sources (std::vector<std::string> paths, ARDOUR::SourceList& sources, framepos_t& pos, 
1227                          Editing::ImportDisposition, Editing::ImportMode,
1228                          int target_regions, int target_tracks, boost::shared_ptr<ARDOUR::Track>&, bool add_channel_suffix);
1229
1230         int finish_bringing_in_material (boost::shared_ptr<ARDOUR::Region> region, uint32_t, uint32_t,  framepos_t& pos, Editing::ImportMode mode,
1231                                       boost::shared_ptr<ARDOUR::Track>& existing_track);
1232
1233         boost::shared_ptr<ARDOUR::AudioTrack> get_nth_selected_audio_track (int nth) const;
1234         boost::shared_ptr<ARDOUR::MidiTrack> get_nth_selected_midi_track (int nth) const;
1235
1236         void toggle_midi_input_active (bool flip_others);
1237
1238         ARDOUR::InterThreadInfo* current_interthread_info;
1239
1240         AnalysisWindow* analysis_window;
1241
1242         /* import specific info */
1243
1244         struct EditorImportStatus : public ARDOUR::ImportStatus {
1245             Editing::ImportMode mode;
1246             framepos_t pos;
1247             int target_tracks;
1248             int target_regions;
1249             boost::shared_ptr<ARDOUR::Track> track;
1250             bool replace;
1251         };
1252
1253         EditorImportStatus import_status;
1254         static void *_import_thread (void *);
1255         void* import_thread ();
1256         void finish_import ();
1257
1258         /* to support this ... */
1259
1260         void import_audio (bool as_tracks);
1261         void do_import (std::vector<std::string> paths, bool split, bool as_tracks);
1262
1263         void move_to_start ();
1264         void move_to_end ();
1265         void center_playhead ();
1266         void center_edit_point ();
1267         void playhead_forward_to_grid ();
1268         void playhead_backward_to_grid ();
1269         void scroll_playhead (bool forward);
1270         void scroll_backward (float pages=0.8f);
1271         void scroll_forward (float pages=0.8f);
1272         void scroll_tracks_down ();
1273         void scroll_tracks_up ();
1274         void set_mark ();
1275         void clear_markers ();
1276         void clear_ranges ();
1277         void clear_locations ();
1278         void unhide_markers ();
1279         void unhide_ranges ();
1280         void jump_forward_to_mark ();
1281         void jump_backward_to_mark ();
1282         void cursor_align (bool playhead_to_edit);
1283
1284         void remove_last_capture ();
1285         void select_all_selectables_using_time_selection ();
1286         void select_all_selectables_using_loop();
1287         void select_all_selectables_using_punch();
1288         void set_selection_from_range (ARDOUR::Location&);
1289         void set_selection_from_punch ();
1290         void set_selection_from_loop ();
1291         void set_selection_from_region ();
1292
1293         void add_location_mark (framepos_t where);
1294         void add_location_from_region ();
1295         void add_locations_from_region ();
1296         void add_location_from_selection ();
1297         void set_loop_from_selection (bool play);
1298         void set_punch_from_selection ();
1299         void set_punch_from_region ();
1300
1301         void set_loop_from_edit_range (bool play);
1302         void set_loop_from_region (bool play);
1303         void set_punch_from_edit_range ();
1304
1305         void set_loop_range (framepos_t start, framepos_t end, std::string cmd);
1306         void set_punch_range (framepos_t start, framepos_t end, std::string cmd);
1307
1308         void add_location_from_playhead_cursor ();
1309         bool select_new_marker;
1310
1311         void reverse_selection ();
1312         void edit_envelope ();
1313
1314         double last_scrub_x;
1315         int scrubbing_direction;
1316         int scrub_reversals;
1317         int scrub_reverse_distance;
1318         void scrub (framepos_t, double);
1319
1320         void keyboard_selection_begin ();
1321         void keyboard_selection_finish (bool add);
1322         bool have_pending_keyboard_selection;
1323         framepos_t pending_keyboard_selection_start;
1324
1325         void move_range_selection_start_or_end_to_region_boundary (bool, bool);
1326
1327         Editing::SnapType _snap_type;
1328         Editing::SnapMode _snap_mode;
1329
1330         /// Snap threshold in pixels
1331         double snap_threshold;
1332
1333         bool ignore_gui_changes;
1334
1335         DragManager* _drags;
1336
1337         void escape ();
1338
1339         Gtk::Menu fade_context_menu;
1340         void popup_fade_context_menu (int, int, ArdourCanvas::Item*, ItemType);
1341
1342         Gtk::Menu xfade_in_context_menu;
1343         Gtk::Menu xfade_out_context_menu;
1344         void popup_xfade_in_context_menu (int, int, ArdourCanvas::Item*, ItemType);
1345         void popup_xfade_out_context_menu (int, int, ArdourCanvas::Item*, ItemType);
1346         void fill_xfade_menu (Gtk::Menu_Helpers::MenuList& items, bool start);
1347
1348         void set_fade_in_shape (ARDOUR::FadeShape);
1349         void set_fade_out_shape (ARDOUR::FadeShape);
1350
1351         void set_fade_length (bool in);
1352         void set_fade_in_active (bool);
1353         void set_fade_out_active (bool);
1354
1355         std::set<boost::shared_ptr<ARDOUR::Playlist> > motion_frozen_playlists;
1356
1357         bool _dragging_playhead;
1358         bool _dragging_edit_point;
1359
1360         void marker_drag_motion_callback (GdkEvent*);
1361         void marker_drag_finished_callback (GdkEvent*);
1362
1363         gint mouse_rename_region (ArdourCanvas::Item*, GdkEvent*);
1364
1365         void add_region_drag (ArdourCanvas::Item*, GdkEvent*, RegionView*);
1366         void start_create_region_grab (ArdourCanvas::Item*, GdkEvent*);
1367         void add_region_copy_drag (ArdourCanvas::Item*, GdkEvent*, RegionView*);
1368         void add_region_brush_drag (ArdourCanvas::Item*, GdkEvent*, RegionView*);
1369         void start_selection_grab (ArdourCanvas::Item*, GdkEvent*);
1370
1371         void region_view_item_click (AudioRegionView&, GdkEventButton*);
1372
1373         bool can_remove_control_point (ArdourCanvas::Item *);
1374         void remove_control_point (ArdourCanvas::Item *);
1375
1376         void mouse_brush_insert_region (RegionView*, framepos_t pos);
1377
1378         /* Canvas event handlers */
1379
1380         bool canvas_control_point_event (GdkEvent* event,ArdourCanvas::Item*, ControlPoint*);
1381         bool canvas_line_event (GdkEvent* event,ArdourCanvas::Item*, AutomationLine*);
1382         bool canvas_selection_rect_event (GdkEvent* event,ArdourCanvas::Item*, SelectionRect*);
1383         bool canvas_selection_start_trim_event (GdkEvent* event,ArdourCanvas::Item*, SelectionRect*);
1384         bool canvas_selection_end_trim_event (GdkEvent* event,ArdourCanvas::Item*, SelectionRect*);
1385         bool canvas_start_xfade_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1386         bool canvas_end_xfade_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1387         bool canvas_fade_in_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1388         bool canvas_fade_in_handle_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1389         bool canvas_fade_out_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1390         bool canvas_fade_out_handle_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1391         bool canvas_region_view_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1392         bool canvas_frame_handle_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1393         bool canvas_region_view_name_highlight_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1394         bool canvas_region_view_name_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1395         bool canvas_feature_line_event (GdkEvent* event, ArdourCanvas::Item*, RegionView*);
1396         bool canvas_stream_view_event (GdkEvent* event,ArdourCanvas::Item*, RouteTimeAxisView*);
1397         bool canvas_marker_event (GdkEvent* event,ArdourCanvas::Item*, Marker*);
1398         bool canvas_zoom_rect_event (GdkEvent* event,ArdourCanvas::Item*);
1399         bool canvas_tempo_marker_event (GdkEvent* event,ArdourCanvas::Item*, TempoMarker*);
1400         bool canvas_meter_marker_event (GdkEvent* event,ArdourCanvas::Item*, MeterMarker*);
1401         bool canvas_automation_track_event(GdkEvent* event, ArdourCanvas::Item*, AutomationTimeAxisView*);
1402         bool canvas_note_event (GdkEvent* event, ArdourCanvas::Item *);
1403
1404         bool canvas_tempo_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1405         bool canvas_meter_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1406         bool canvas_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1407         bool canvas_range_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1408         bool canvas_transport_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1409         bool canvas_cd_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1410
1411         bool canvas_videotl_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1412         void update_video_timeline (bool flush = false);
1413         void set_video_timeline_height (const int);
1414         bool is_video_timeline_locked ();
1415         void toggle_video_timeline_locked ();
1416         void set_video_timeline_locked (const bool);
1417         void queue_visual_videotimeline_update ();
1418         void embed_audio_from_video (std::string, framepos_t n = 0);
1419
1420         PBD::Signal0<void> EditorFreeze;
1421         PBD::Signal0<void> EditorThaw;
1422
1423   private:
1424         friend class DragManager;
1425         friend class EditorRouteGroups;
1426         friend class EditorRegions;
1427
1428         /** true if the mouse is over a place where region trim can happen */
1429         bool _over_region_trim_target;
1430
1431         /* non-public event handlers */
1432
1433         bool canvas_playhead_cursor_event (GdkEvent* event, ArdourCanvas::Item*);
1434         bool track_canvas_scroll (GdkEventScroll* event);
1435
1436         bool track_canvas_scroll_event (GdkEventScroll* event);
1437         bool track_canvas_button_press_event (GdkEventButton* event);
1438         bool track_canvas_button_release_event (GdkEventButton* event);
1439         bool track_canvas_motion_notify_event (GdkEventMotion* event);
1440
1441         Gtk::Allocation _canvas_viewport_allocation;
1442         void track_canvas_viewport_allocate (Gtk::Allocation alloc);
1443         bool track_canvas_viewport_size_allocated ();
1444         bool track_canvas_drag_motion (Glib::RefPtr<Gdk::DragContext> const &, int, int, guint);
1445         bool track_canvas_key_press (GdkEventKey *);
1446         bool track_canvas_key_release (GdkEventKey *);
1447
1448         void set_playhead_cursor ();
1449
1450         void toggle_region_mute ();
1451
1452         void initialize_canvas ();
1453
1454         /* display control */
1455
1456         bool _show_measures;
1457         /// true if the editor should follow the playhead, otherwise false
1458         bool _follow_playhead;
1459         /// true if we scroll the tracks rather than the playhead
1460         bool _stationary_playhead;
1461         /// true if we are in fullscreen mode
1462         bool _maximised;
1463
1464         TempoLines* tempo_lines;
1465
1466         ArdourCanvas::Group* time_line_group;
1467
1468         void hide_measures ();
1469         void draw_measures (ARDOUR::TempoMap::BBTPointList::const_iterator& begin,
1470                             ARDOUR::TempoMap::BBTPointList::const_iterator& end);
1471
1472         void new_tempo_section ();
1473
1474         void mouse_add_new_tempo_event (framepos_t where);
1475         void mouse_add_new_meter_event (framepos_t where);
1476
1477         void remove_tempo_marker (ArdourCanvas::Item*);
1478         void remove_meter_marker (ArdourCanvas::Item*);
1479         gint real_remove_tempo_marker (ARDOUR::TempoSection*);
1480         gint real_remove_meter_marker (ARDOUR::MeterSection*);
1481
1482         void edit_tempo_section (ARDOUR::TempoSection*);
1483         void edit_meter_section (ARDOUR::MeterSection*);
1484         void edit_tempo_marker (ArdourCanvas::Item*);
1485         void edit_meter_marker (ArdourCanvas::Item*);
1486         void edit_control_point (ArdourCanvas::Item*);
1487         void edit_notes (TimeAxisViewItem&);
1488
1489         void marker_menu_edit ();
1490         void marker_menu_remove ();
1491         void marker_menu_rename ();
1492         void rename_marker (Marker *marker);
1493         void toggle_marker_menu_lock ();
1494         void toggle_marker_menu_glue ();
1495         void marker_menu_hide ();
1496         void marker_menu_loop_range ();
1497         void marker_menu_select_all_selectables_using_range ();
1498         void marker_menu_select_using_range ();
1499         void marker_menu_separate_regions_using_location ();
1500         void marker_menu_play_from ();
1501         void marker_menu_play_range ();
1502         void marker_menu_set_playhead ();
1503         void marker_menu_set_from_playhead ();
1504         void marker_menu_set_from_selection (bool force_regions);
1505         void marker_menu_range_to_next ();
1506         void marker_menu_zoom_to_range ();
1507         void new_transport_marker_menu_set_loop ();
1508         void new_transport_marker_menu_set_punch ();
1509         void update_loop_range_view (bool visibility=false);
1510         void update_punch_range_view (bool visibility=false);
1511         void new_transport_marker_menu_popdown ();
1512         void marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
1513         void tempo_or_meter_marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
1514         void new_transport_marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
1515         void build_range_marker_menu (bool, bool);
1516         void build_marker_menu (ARDOUR::Location *);
1517         void build_tempo_or_meter_marker_menu (bool);
1518         void build_new_transport_marker_menu ();
1519         void dynamic_cast_marker_object (void*, MeterMarker**, TempoMarker**) const;
1520
1521         Gtk::Menu* tempo_or_meter_marker_menu;
1522         Gtk::Menu* marker_menu;
1523         Gtk::Menu* range_marker_menu;
1524         Gtk::Menu* transport_marker_menu;
1525         Gtk::Menu* new_transport_marker_menu;
1526         Gtk::Menu* cd_marker_menu;
1527         ArdourCanvas::Item* marker_menu_item;
1528
1529         typedef std::list<Marker*> Marks;
1530         Marks metric_marks;
1531
1532         void remove_metric_marks ();
1533         void draw_metric_marks (const ARDOUR::Metrics& metrics);
1534
1535         void compute_current_bbt_points (framepos_t left, framepos_t right, 
1536                                          ARDOUR::TempoMap::BBTPointList::const_iterator& begin,
1537                                          ARDOUR::TempoMap::BBTPointList::const_iterator& end);
1538
1539         void tempo_map_changed (const PBD::PropertyChange&);
1540         void redisplay_tempo (bool immediate_redraw);
1541
1542         uint32_t bbt_beat_subdivision;
1543
1544         /* toolbar */
1545
1546         Gtk::ToggleButton editor_mixer_button;
1547         Gtk::ToggleButton editor_list_button;
1548         void editor_mixer_button_toggled ();
1549         void editor_list_button_toggled ();
1550
1551         AudioClock*               zoom_range_clock;
1552
1553         ArdourButton              zoom_in_button;
1554         ArdourButton              zoom_out_button;
1555         ArdourButton              zoom_out_full_button;
1556
1557         ArdourButton              tav_expand_button;
1558         ArdourButton              tav_shrink_button;
1559
1560         Gtk::VBox                toolbar_clock_vbox;
1561         Gtk::VBox                toolbar_selection_clock_vbox;
1562         Gtk::Table               toolbar_selection_clock_table;
1563         Gtk::Label               toolbar_selection_cursor_label;
1564
1565         Gtkmm2ext::TearOff*      _mouse_mode_tearoff;
1566         ArdourButton mouse_select_button;
1567         ArdourButton mouse_draw_button;
1568         ArdourButton mouse_move_button;
1569         ArdourButton mouse_gain_button;
1570         ArdourButton mouse_zoom_button;
1571         ArdourButton mouse_timefx_button;
1572         ArdourButton mouse_audition_button;
1573
1574         ArdourButton smart_mode_button;
1575         Glib::RefPtr<Gtk::ToggleAction> smart_mode_action;
1576
1577         void                     mouse_mode_toggled (Editing::MouseMode m);
1578         void                     mouse_mode_object_range_toggled ();
1579         bool                     ignore_mouse_mode_toggle;
1580
1581         ArdourButton internal_edit_button;
1582         void         toggle_internal_editing ();
1583
1584         bool                     mouse_select_button_release (GdkEventButton*);
1585
1586         Gtk::VBox                automation_box;
1587         Gtk::Button              automation_mode_button;
1588
1589         Gtk::ComboBoxText edit_mode_selector;
1590         Gtk::VBox         edit_mode_box;
1591         std::vector<std::string> edit_mode_strings;
1592
1593         void set_edit_mode (ARDOUR::EditMode);
1594         void cycle_edit_mode ();
1595         void edit_mode_selection_done ();
1596
1597         Gtk::ComboBoxText snap_type_selector;
1598         Gtk::ComboBoxText snap_mode_selector;
1599         Gtk::HBox         snap_box;
1600
1601         std::vector<std::string> snap_type_strings;
1602         std::vector<std::string> snap_mode_strings;
1603
1604         void snap_type_selection_done ();
1605         void snap_mode_selection_done ();
1606         void snap_mode_chosen (Editing::SnapMode);
1607         void snap_type_chosen (Editing::SnapType);
1608
1609         Glib::RefPtr<Gtk::RadioAction> snap_type_action (Editing::SnapType);
1610         Glib::RefPtr<Gtk::RadioAction> snap_mode_action (Editing::SnapMode);
1611
1612         Gtk::ComboBoxText zoom_focus_selector;
1613         Gtk::VBox         zoom_focus_box;
1614
1615         std::vector<std::string> zoom_focus_strings;
1616
1617         void zoom_focus_selection_done ();
1618         void zoom_focus_chosen (Editing::ZoomFocus);
1619
1620         Glib::RefPtr<Gtk::RadioAction> zoom_focus_action (Editing::ZoomFocus);
1621
1622         Gtk::HBox           _zoom_box;
1623         Gtkmm2ext::TearOff* _zoom_tearoff;
1624         void                zoom_adjustment_changed();
1625
1626         void setup_toolbar ();
1627
1628         void setup_tooltips ();
1629
1630         Gtkmm2ext::TearOff*     _tools_tearoff;
1631         Gtk::HBox                toolbar_hbox;
1632         Gtk::EventBox            toolbar_base;
1633         Gtk::Frame               toolbar_frame;
1634         Gtk::Viewport           _toolbar_viewport;
1635
1636         /* midi toolbar */
1637
1638         Gtk::HBox                panic_box;
1639
1640         void setup_midi_toolbar ();
1641
1642         /* selection process */
1643
1644         Selection* selection;
1645         Selection* cut_buffer;
1646
1647         void time_selection_changed ();
1648         void track_selection_changed ();
1649         void region_selection_changed ();
1650         sigc::connection editor_regions_selection_changed_connection;
1651         void sensitize_all_region_actions (bool);
1652         void sensitize_the_right_region_actions ();
1653         bool _all_region_actions_sensitized;
1654         /** Flag to block region action handlers from doing what they normally do;
1655          *  I tried Gtk::Action::block_activate() but this doesn't work (ie it doesn't
1656          *  block) when setting a ToggleAction's active state.
1657          */
1658         bool _ignore_region_action;
1659         bool _last_region_menu_was_main;
1660         void point_selection_changed ();
1661         void marker_selection_changed ();
1662
1663         void cancel_selection ();
1664         void cancel_time_selection ();
1665
1666         bool get_smart_mode() const;
1667
1668         bool audio_region_selection_covers (framepos_t where);
1669
1670         /* transport range select process */
1671
1672         ArdourCanvas::Rectangle*  cd_marker_bar_drag_rect;
1673         ArdourCanvas::Rectangle*  range_bar_drag_rect;
1674         ArdourCanvas::Rectangle*  transport_bar_drag_rect;
1675
1676 #ifdef GTKOSX
1677         ArdourCanvas::Rectangle     *bogus_background_rect;
1678 #endif
1679         ArdourCanvas::Rectangle     *transport_bar_range_rect;
1680         ArdourCanvas::Rectangle     *transport_bar_preroll_rect;
1681         ArdourCanvas::Rectangle     *transport_bar_postroll_rect;
1682         ArdourCanvas::Rectangle     *transport_loop_range_rect;
1683         ArdourCanvas::Rectangle     *transport_punch_range_rect;
1684         ArdourCanvas::Line     *transport_punchin_line;
1685         ArdourCanvas::Line     *transport_punchout_line;
1686         ArdourCanvas::Rectangle     *transport_preroll_rect;
1687         ArdourCanvas::Rectangle     *transport_postroll_rect;
1688
1689         ARDOUR::Location*  transport_loop_location();
1690         ARDOUR::Location*  transport_punch_location();
1691
1692         ARDOUR::Location   *temp_location;
1693
1694         /* object rubberband select process */
1695
1696         void select_all_within (framepos_t, framepos_t, double, double, TrackViewList const &, Selection::Operation, bool);
1697
1698         ArdourCanvas::Rectangle   *rubberband_rect;
1699
1700         /* mouse zoom process */
1701
1702         ArdourCanvas::Rectangle   *zoom_rect;
1703         void reposition_zoom_rect (framepos_t start, framepos_t end);
1704
1705         EditorRouteGroups* _route_groups;
1706         EditorRoutes* _routes;
1707         EditorRegions* _regions;
1708         EditorSnapshots* _snapshots;
1709         EditorLocations* _locations;
1710
1711         /* diskstream/route display management */
1712         Glib::RefPtr<Gdk::Pixbuf> rec_enabled_icon;
1713         Glib::RefPtr<Gdk::Pixbuf> rec_disabled_icon;
1714
1715         Glib::RefPtr<Gtk::TreeSelection> route_display_selection;
1716
1717         bool sync_track_view_list_and_routes ();
1718
1719         Gtk::VBox           list_vpacker;
1720
1721         /* autoscrolling */
1722
1723         bool autoscroll_active;
1724         int autoscroll_timeout_tag;
1725         int autoscroll_x;
1726         int autoscroll_y;
1727         int last_autoscroll_x;
1728         int last_autoscroll_y;
1729         uint32_t autoscroll_cnt;
1730         framecnt_t autoscroll_x_distance;
1731         double autoscroll_y_distance;
1732
1733         bool _autoscroll_fudging;
1734         int autoscroll_fudge_threshold () const;
1735
1736         static gint _autoscroll_canvas (void *);
1737         bool autoscroll_canvas ();
1738         void start_canvas_autoscroll (int x, int y);
1739         void stop_canvas_autoscroll ();
1740
1741         /* trimming */
1742         void point_trim (GdkEvent *, framepos_t);
1743
1744         void trim_region_front();
1745         void trim_region_back();
1746         void trim_region (bool front);
1747
1748         void trim_region_to_loop ();
1749         void trim_region_to_punch ();
1750         void trim_region_to_location (const ARDOUR::Location&, const char* cmd);
1751
1752         void trim_to_region(bool forward);
1753         void trim_region_to_previous_region_end();
1754         void trim_region_to_next_region_start();
1755
1756         bool show_gain_after_trim;
1757
1758         /* Drag-n-Drop */
1759
1760         int convert_drop_to_paths (
1761                 std::vector<std::string>&           paths,
1762                 const Glib::RefPtr<Gdk::DragContext>& context,
1763                 gint                                  x,
1764                 gint                                  y,
1765                 const Gtk::SelectionData&             data,
1766                 guint                                 info,
1767                 guint                                 time);
1768
1769         void track_canvas_drag_data_received (
1770                 const Glib::RefPtr<Gdk::DragContext>& context,
1771                 gint                                  x,
1772                 gint                                  y,
1773                 const Gtk::SelectionData&             data,
1774                 guint                                 info,
1775                 guint                                 time);
1776
1777         void drop_paths (
1778                 const Glib::RefPtr<Gdk::DragContext>& context,
1779                 gint                                  x,
1780                 gint                                  y,
1781                 const Gtk::SelectionData&             data,
1782                 guint                                 info,
1783                 guint                                 time);
1784
1785         void drop_regions (
1786                 const Glib::RefPtr<Gdk::DragContext>& context,
1787                 gint                                  x,
1788                 gint                                  y,
1789                 const Gtk::SelectionData&             data,
1790                 guint                                 info,
1791                 guint                                 time);
1792
1793         void drop_routes (
1794                 const Glib::RefPtr<Gdk::DragContext>& context,
1795                 gint                x,
1796                 gint                y,
1797                 const Gtk::SelectionData& data,
1798                 guint               info,
1799                 guint               time);
1800
1801         /* audio export */
1802
1803         int  write_region_selection(RegionSelection&);
1804         bool write_region (std::string path, boost::shared_ptr<ARDOUR::AudioRegion>);
1805         void bounce_region_selection (bool with_processing);
1806         void bounce_range_selection (bool replace, bool enable_processing);
1807         void external_edit_region ();
1808
1809         int write_audio_selection (TimeSelection&);
1810         bool write_audio_range (ARDOUR::AudioPlaylist&, const ARDOUR::ChanCount& channels, std::list<ARDOUR::AudioRange>&);
1811
1812         void write_selection ();
1813
1814         XMLNode *before; /* used in *_reversible_command */
1815
1816         void update_title ();
1817         void update_title_s (const std::string & snapshot_name);
1818
1819         void instant_save ();
1820
1821         boost::shared_ptr<ARDOUR::AudioRegion> last_audition_region;
1822
1823         /* freeze operations */
1824
1825         ARDOUR::InterThreadInfo freeze_status;
1826         static void* _freeze_thread (void*);
1827         void* freeze_thread ();
1828
1829         void freeze_route ();
1830         void unfreeze_route ();
1831
1832         /* duplication */
1833
1834         void duplicate_range (bool with_dialog);
1835
1836         /** computes the timeline frame (sample) of an event whose coordinates
1837          * are in canvas units (pixels, scroll offset included).
1838          */
1839         framepos_t canvas_event_frame (GdkEvent const *, double* px = 0, double* py = 0) const;
1840
1841         /** computes the timeline frame (sample) of an event whose coordinates
1842          * are in window units (pixels, no scroll offset).
1843          */
1844         framepos_t window_event_frame (GdkEvent const *, double* px = 0, double* py = 0) const;
1845
1846         /* returns false if mouse pointer is not in track or marker canvas
1847          */
1848         bool mouse_frame (framepos_t&, bool& in_track_canvas) const;
1849
1850         TimeFXDialog* current_timefx;
1851         static void* timefx_thread (void *arg);
1852         void do_timefx ();
1853
1854         int time_stretch (RegionSelection&, float fraction);
1855         int pitch_shift (RegionSelection&, float cents);
1856         void pitch_shift_region ();
1857
1858         void transpose_region ();
1859
1860         /* editor-mixer strip */
1861
1862         MixerStrip *current_mixer_strip;
1863         bool show_editor_mixer_when_tracks_arrive;
1864         Gtk::VBox current_mixer_strip_vbox;
1865         void cms_new (boost::shared_ptr<ARDOUR::Route>);
1866         void current_mixer_strip_hidden ();
1867
1868         void detach_tearoff (Gtk::Box* b, Gtk::Window* w);
1869         void reattach_tearoff (Gtk::Box* b, Gtk::Window* w, int32_t n);
1870 #ifdef GTKOSX
1871         void ensure_all_elements_drawn ();
1872 #endif
1873         /* nudging tracks */
1874
1875         void nudge_track (bool use_edit_point, bool forwards);
1876
1877         static const int32_t default_width = 995;
1878         static const int32_t default_height = 765;
1879
1880         /* nudge */
1881
1882         ArdourButton      nudge_forward_button;
1883         ArdourButton      nudge_backward_button;
1884         Gtk::HBox        nudge_hbox;
1885         Gtk::VBox        nudge_vbox;
1886         AudioClock*       nudge_clock;
1887
1888         bool nudge_forward_release (GdkEventButton*);
1889         bool nudge_backward_release (GdkEventButton*);
1890
1891         /* audio filters */
1892
1893         void apply_filter (ARDOUR::Filter&, std::string cmd, ProgressReporter* progress = 0);
1894
1895         Command* apply_midi_note_edit_op_to_region (ARDOUR::MidiOperator& op, MidiRegionView& mrv);
1896         void apply_midi_note_edit_op (ARDOUR::MidiOperator& op);
1897
1898         /* handling cleanup */
1899
1900         int playlist_deletion_dialog (boost::shared_ptr<ARDOUR::Playlist>);
1901
1902         PBD::ScopedConnectionList session_connections;
1903
1904         /* tracking step changes of track height */
1905
1906         TimeAxisView* current_stepping_trackview;
1907         ARDOUR::microseconds_t last_track_height_step_timestamp;
1908         gint track_height_step_timeout();
1909         sigc::connection step_timeout;
1910
1911         TimeAxisView* entered_track;
1912         /** If the mouse is over a RegionView or one of its child canvas items, this is set up
1913             to point to the RegionView.  Otherwise it is 0.
1914         */
1915         RegionView*   entered_regionview;
1916
1917         bool clear_entered_track;
1918         bool left_track_canvas (GdkEventCrossing*);
1919         bool entered_track_canvas (GdkEventCrossing*);
1920         void set_entered_track (TimeAxisView*);
1921         void set_entered_regionview (RegionView*);
1922         void ensure_track_visible (TimeAxisView*);
1923         gint left_automation_track ();
1924
1925         void reset_canvas_action_sensitivity (bool);
1926         void set_gain_envelope_visibility ();
1927         void set_region_gain_visibility (RegionView*);
1928         void toggle_gain_envelope_active ();
1929         void reset_region_gain_envelopes ();
1930
1931         bool on_key_press_event (GdkEventKey*);
1932         bool on_key_release_event (GdkEventKey*);
1933
1934         void session_state_saved (std::string);
1935
1936         Glib::RefPtr<Gtk::Action>              undo_action;
1937         Glib::RefPtr<Gtk::Action>              redo_action;
1938
1939         void history_changed ();
1940
1941         Gtk::HBox      status_bar_hpacker;
1942
1943         Editing::EditPoint _edit_point;
1944
1945         Gtk::ComboBoxText edit_point_selector;
1946
1947         void set_edit_point_preference (Editing::EditPoint ep, bool force = false);
1948         void cycle_edit_point (bool with_marker);
1949         void set_edit_point ();
1950         void edit_point_selection_done ();
1951         void edit_point_chosen (Editing::EditPoint);
1952         Glib::RefPtr<Gtk::RadioAction> edit_point_action (Editing::EditPoint);
1953         std::vector<std::string> edit_point_strings;
1954
1955         void selected_marker_moved (ARDOUR::Location*);
1956
1957         bool get_edit_op_range (framepos_t& start, framepos_t& end) const;
1958
1959         void get_regions_at (RegionSelection&, framepos_t where, const TrackViewList& ts) const;
1960         void get_regions_after (RegionSelection&, framepos_t where, const TrackViewList& ts) const;
1961
1962         RegionSelection get_regions_from_selection_and_edit_point ();
1963         RegionSelection get_regions_from_selection_and_entered ();
1964
1965         void start_updating_meters ();
1966         void stop_updating_meters ();
1967         bool meters_running;
1968
1969         void select_next_route ();
1970         void select_prev_route ();
1971
1972         void snap_to_internal (framepos_t& first, int32_t direction = 0, bool for_mark = false);
1973         void timecode_snap_to_internal (framepos_t& first, int32_t direction = 0, bool for_mark = false);
1974
1975         RhythmFerret* rhythm_ferret;
1976
1977         void fit_tracks (TrackViewList &);
1978         void fit_selected_tracks ();
1979         void set_track_height (Height);
1980
1981         void remove_tracks ();
1982         void toggle_tracks_active ();
1983
1984         bool _have_idled;
1985         int resize_idle_id;
1986         static gboolean _idle_resize (gpointer);
1987         bool idle_resize();
1988         int32_t _pending_resize_amount;
1989         TimeAxisView* _pending_resize_view;
1990
1991         void visible_order_range (int*, int*) const;
1992
1993         void located ();
1994
1995         /** true if we've made a locate request that hasn't yet been processed */
1996         bool _pending_locate_request;
1997
1998         /** if true, there is a pending Session locate which is the initial one when loading a session;
1999             we need to know this so that we don't (necessarily) set the viewport to show the playhead
2000             initially.
2001         */
2002         bool _pending_initial_locate;
2003
2004         Gtk::HBox _summary_hbox;
2005         EditorSummary* _summary;
2006
2007         void region_view_added (RegionView *);
2008         void region_view_removed ();
2009
2010         EditorGroupTabs* _group_tabs;
2011         void fit_route_group (ARDOUR::RouteGroup *);
2012
2013         void step_edit_status_change (bool);
2014         void start_step_editing ();
2015         void stop_step_editing ();
2016         bool check_step_edit ();
2017         sigc::connection step_edit_connection;
2018
2019         double _last_motion_y;
2020
2021         RegionLayeringOrderEditor* layering_order_editor;
2022         void update_region_layering_order_editor ();
2023
2024         /** Track that was the source for the last cut/copy operation.  Used as a place
2025             to paste things iff there is no selected track.
2026         */
2027         TimeAxisView* _last_cut_copy_source_track;
2028
2029         /** true if a change in Selection->regions should change the selection in the region list.
2030             See EditorRegions::selection_changed.
2031         */
2032         bool _region_selection_change_updates_region_list;
2033
2034         void setup_fade_images ();
2035         std::map<ARDOUR::FadeShape, Gtk::Image*> _fade_in_images;
2036         std::map<ARDOUR::FadeShape, Gtk::Image*> _fade_out_images;
2037         std::map<ARDOUR::FadeShape, Gtk::Image*> _xfade_in_images;
2038         std::map<ARDOUR::FadeShape, Gtk::Image*> _xfade_out_images;
2039
2040         Gtk::MenuItem& action_menu_item (std::string const &);
2041         void action_pre_activated (Glib::RefPtr<Gtk::Action> const &);
2042
2043         void set_canvas_cursor_for_region_view (double, RegionView *);
2044
2045         MouseCursors* _cursors;
2046
2047         void follow_mixer_selection ();
2048         bool _following_mixer_selection;
2049
2050         int time_fx (ARDOUR::RegionList&, float val, bool pitching);
2051         void note_edit_done (int, EditNoteDialog*);
2052         void toggle_sound_midi_notes ();
2053
2054         /** Flag for a bit of a hack wrt control point selection; see set_selected_control_point_from_click */
2055         bool _control_point_toggled_on_press;
2056
2057         /** This is used by TimeAxisView to keep a track of the TimeAxisView that is currently being
2058             stepped in height using ScrollZoomVerticalModifier+Scrollwheel.  When a scroll event
2059             occurs, we do the step on this _stepping_axis_view if it is non-0 (and we set up this
2060             _stepping_axis_view with the TimeAxisView underneath the mouse if it is 0).  Then Editor
2061             resets _stepping_axis_view when the modifier key is released.  In this (hacky) way,
2062             pushing the modifier key and moving the scroll wheel will operate on the same track
2063             until the key is released (rather than skipping about to whatever happens to be
2064             underneath the mouse at the time).
2065         */
2066         TimeAxisView* _stepping_axis_view;
2067         void zoom_vertical_modifier_released();
2068
2069         friend class Drag;
2070         friend class RegionDrag;
2071         friend class RegionMoveDrag;
2072         friend class RegionSpliceDrag;
2073         friend class TrimDrag;
2074         friend class MeterMarkerDrag;
2075         friend class TempoMarkerDrag;
2076         friend class CursorDrag;
2077         friend class FadeInDrag;
2078         friend class FadeOutDrag;
2079         friend class MarkerDrag;
2080         friend class RegionGainDrag;
2081         friend class ControlPointDrag;
2082         friend class LineDrag;
2083         friend class RubberbandSelectDrag;
2084         friend class EditorRubberbandSelectDrag;
2085         friend class TimeFXDrag;
2086         friend class ScrubDrag;
2087         friend class SelectionDrag;
2088         friend class RangeMarkerBarDrag;
2089         friend class MouseZoomDrag;
2090         friend class RegionCreateDrag;
2091         friend class RegionMotionDrag;
2092         friend class RegionInsertDrag;
2093         friend class VideoTimeLineDrag;
2094
2095         friend class EditorSummary;
2096         friend class EditorGroupTabs;
2097
2098         friend class EditorRoutes;
2099         friend class RhythmFerret;
2100 };
2101
2102 #endif /* __ardour_editor_h__ */