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