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