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