fca0bae86ee4aa01e2a6abd7355481ed7bc2a0ea
[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* entered_marker;
594         bool _show_marker_lines;
595
596         typedef std::map<ARDOUR::Location*,LocationMarkers *> LocationMarkerMap;
597         LocationMarkerMap location_markers;
598
599         void update_marker_labels ();
600         void update_marker_labels (ArdourCanvas::Group *);
601         void check_marker_label (Marker *);
602
603         /** A set of lists of Markers that are in each of the canvas groups
604          *  for the marker sections at the top of the editor.  These lists
605          *  are kept sorted in time order between marker movements, so that after
606          *  a marker has moved we can decide whether we need to update the labels
607          *  for all markers or for just a few.
608          */
609         std::map<ArdourCanvas::Group *, std::list<Marker *> > _sorted_marker_lists;
610         void remove_sorted_marker (Marker *);
611
612         void hide_marker (ArdourCanvas::Item*, GdkEvent*);
613         void clear_marker_display ();
614         void mouse_add_new_marker (framepos_t where, bool is_cd=false, bool is_xrun=false);
615         bool choose_new_marker_name(std::string &name);
616         void update_cd_marker_display ();
617         void ensure_cd_marker_updated (LocationMarkers * lam, ARDOUR::Location * location);
618
619         TimeAxisView*      clicked_axisview;
620         RouteTimeAxisView* clicked_routeview;
621         /** The last RegionView that was clicked on, or 0 if the last click was not
622          * on a RegionView.  This is set up by the canvas event handlers in
623          * editor_canvas_events.cc
624          */
625         RegionView*        clicked_regionview;
626         RegionSelection    latest_regionviews;
627         uint32_t           clicked_selection;
628         CrossfadeView*     clicked_crossfadeview;
629         ControlPoint*      clicked_control_point;
630
631         void sort_track_selection (TrackViewList* sel = 0);
632
633         void get_equivalent_regions (RegionView* rv, std::vector<RegionView*> &, PBD::PropertyID) const;
634         RegionSelection get_equivalent_regions (RegionSelection &, PBD::PropertyID) const;
635         void mapover_tracks (sigc::slot<void,RouteTimeAxisView&,uint32_t> sl, TimeAxisView*, PBD::PropertyID) const;
636
637         /* functions to be passed to mapover_tracks(), possibly with sigc::bind()-supplied arguments */
638
639         void mapped_get_equivalent_regions (RouteTimeAxisView&, uint32_t, RegionView *, std::vector<RegionView*>*) const;
640         void mapped_use_new_playlist (RouteTimeAxisView&, uint32_t, std::vector<boost::shared_ptr<ARDOUR::Playlist> > const &);
641         void mapped_use_copy_playlist (RouteTimeAxisView&, uint32_t, std::vector<boost::shared_ptr<ARDOUR::Playlist> > const &);
642         void mapped_clear_playlist (RouteTimeAxisView&, uint32_t);
643
644         /* end */
645
646         void button_selection (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type);
647         bool button_release_can_deselect;
648
649         void catch_vanishing_regionview (RegionView *);
650
651         void set_selected_track (TimeAxisView&, Selection::Operation op = Selection::Set, bool no_remove=false);
652         void select_all_tracks ();
653         void select_all_internal_edit (Selection::Operation);
654
655         bool set_selected_control_point_from_click (Selection::Operation op = Selection::Set, bool no_remove=false);
656         void set_selected_track_from_click (bool press, Selection::Operation op = Selection::Set, bool no_remove=false);
657         void set_selected_track_as_side_effect (Selection::Operation op, bool force = false);
658         bool set_selected_regionview_from_click (bool press, Selection::Operation op = Selection::Set, bool no_track_remove=false);
659
660         bool set_selected_regionview_from_map_event (GdkEventAny*, StreamView*, boost::weak_ptr<ARDOUR::Region>);
661         void collect_new_region_view (RegionView *);
662         void collect_and_select_new_region_view (RegionView *);
663
664         long select_range_around_region (RegionView *);
665
666         Gtk::Menu track_context_menu;
667         Gtk::Menu track_region_context_menu;
668         Gtk::Menu track_selection_context_menu;
669         Gtk::Menu track_crossfade_context_menu;
670
671         Gtk::MenuItem* region_edit_menu_split_item;
672         Gtk::MenuItem* region_edit_menu_split_multichannel_item;
673         Gtk::Menu * track_region_edit_playlist_menu;
674         Gtk::Menu * track_edit_playlist_submenu;
675         Gtk::Menu * track_selection_edit_playlist_submenu;
676
677         void popup_track_context_menu (int, int, ItemType, bool);
678         Gtk::Menu* build_track_context_menu ();
679         Gtk::Menu* build_track_bus_context_menu ();
680         Gtk::Menu* build_track_region_context_menu ();
681         Gtk::Menu* build_track_crossfade_context_menu ();
682         Gtk::Menu* build_track_selection_context_menu ();
683         void add_dstream_context_items (Gtk::Menu_Helpers::MenuList&);
684         void add_bus_context_items (Gtk::Menu_Helpers::MenuList&);
685         void add_region_context_items (Gtk::Menu_Helpers::MenuList&, boost::shared_ptr<ARDOUR::Track>);
686         void add_crossfade_context_items (AudioStreamView*, boost::shared_ptr<ARDOUR::Crossfade>, Gtk::Menu_Helpers::MenuList&, bool many);
687         void add_selection_context_items (Gtk::Menu_Helpers::MenuList&);
688         Gtk::MenuItem* _popup_region_menu_item;
689
690         void popup_control_point_context_menu (ArdourCanvas::Item *, GdkEvent *);
691         Gtk::Menu _control_point_context_menu;
692
693         void handle_new_route (ARDOUR::RouteList&);
694         void timeaxisview_deleted (TimeAxisView *);
695
696         Gtk::HBox           global_hpacker;
697         Gtk::VBox           global_vpacker;
698         Gtk::VBox           vpacker;
699
700         Gdk::Cursor*          current_canvas_cursor;
701         Gdk::Cursor* which_grabber_cursor ();
702         void set_canvas_cursor ();
703
704         ArdourCanvas::Canvas* track_canvas;
705
706         friend class VerboseCursor;
707         VerboseCursor* _verbose_cursor;
708
709         void parameter_changed (std::string);
710
711         bool track_canvas_motion (GdkEvent*);
712
713         Gtk::EventBox             time_canvas_event_box;
714         Gtk::EventBox             track_canvas_event_box;
715         Gtk::EventBox             time_button_event_box;
716         Gtk::EventBox             ruler_label_event_box;
717
718         ArdourCanvas::Group      *minsec_group;
719         ArdourCanvas::Pixbuf     *logo_item;
720         ArdourCanvas::Group      *bbt_group;
721         ArdourCanvas::Group      *timecode_group;
722         ArdourCanvas::Group      *frame_group;
723         ArdourCanvas::Group      *tempo_group;
724         ArdourCanvas::Group      *meter_group;
725         ArdourCanvas::Group      *marker_group;
726         ArdourCanvas::Group      *range_marker_group;
727         ArdourCanvas::Group      *transport_marker_group;
728         ArdourCanvas::Group*      cd_marker_group;
729
730         ArdourCanvas::Group*      timebar_group;
731
732         /* These bars never need to be scrolled */
733         ArdourCanvas::Group*      meter_bar_group;
734         ArdourCanvas::Group*      tempo_bar_group;
735         ArdourCanvas::Group*      marker_bar_group;
736         ArdourCanvas::Group*      range_marker_bar_group;
737         ArdourCanvas::Group*      transport_marker_bar_group;
738         ArdourCanvas::Group*      cd_marker_bar_group;
739
740         /** The group containing all items that require horizontal scrolling. */
741         ArdourCanvas::Group* _background_group;
742         /*
743            The _master_group is the group containing all items
744            that require horizontal scrolling..
745            It is primarily used to separate canvas items
746            that require horizontal scrolling from those that do not.
747         */
748         ArdourCanvas::Group* _master_group;
749
750         /* The group containing all trackviews.  Only scrolled vertically. */
751         ArdourCanvas::Group* _trackview_group;
752
753         /* The group used for region motion.  Sits on top of _trackview_group */
754         ArdourCanvas::Group* _region_motion_group;
755
756         enum RulerType {
757                 ruler_metric_timecode = 0,
758                 ruler_metric_bbt = 1,
759                 ruler_metric_samples = 2,
760                 ruler_metric_minsec = 3,
761
762                 ruler_time_tempo = 4,
763                 ruler_time_meter = 5,
764                 ruler_time_marker = 6,
765                 ruler_time_range_marker = 7,
766                 ruler_time_transport_marker = 8,
767                 ruler_time_cd_marker = 9,
768         };
769
770         static GtkCustomMetric ruler_metrics[4];
771         Glib::RefPtr<Gtk::ToggleAction> ruler_timecode_action;
772         Glib::RefPtr<Gtk::ToggleAction> ruler_bbt_action;
773         Glib::RefPtr<Gtk::ToggleAction> ruler_samples_action;
774         Glib::RefPtr<Gtk::ToggleAction> ruler_minsec_action;
775         Glib::RefPtr<Gtk::ToggleAction> ruler_tempo_action;
776         Glib::RefPtr<Gtk::ToggleAction> ruler_meter_action;
777         Glib::RefPtr<Gtk::ToggleAction> ruler_marker_action;
778         Glib::RefPtr<Gtk::ToggleAction> ruler_range_action;
779         Glib::RefPtr<Gtk::ToggleAction> ruler_loop_punch_action;
780         Glib::RefPtr<Gtk::ToggleAction> ruler_cd_marker_action;
781         bool                            no_ruler_shown_update;
782
783         bool ruler_button_press (GdkEventButton*);
784         bool ruler_button_release (GdkEventButton*);
785         bool ruler_mouse_motion (GdkEventMotion*);
786         bool ruler_scroll (GdkEventScroll* event);
787
788         Gtk::Widget * ruler_grabbed_widget;
789
790         void initialize_rulers ();
791         void update_just_timecode ();
792         void compute_fixed_ruler_scale (); //calculates the RulerScale of the fixed rulers
793         void update_fixed_rulers ();
794         void update_tempo_based_rulers ();
795         void popup_ruler_menu (framepos_t where = 0, ItemType type = RegionItem);
796         void update_ruler_visibility ();
797         void set_ruler_visible (RulerType, bool);
798         void toggle_ruler_visibility (RulerType rt);
799         void ruler_toggled (int);
800         bool ruler_label_button_release (GdkEventButton*);
801         void store_ruler_visibility ();
802         void restore_ruler_visibility ();
803
804         static gint _metric_get_timecode (GtkCustomRulerMark **, gdouble, gdouble, gint);
805         static gint _metric_get_bbt (GtkCustomRulerMark **, gdouble, gdouble, gint);
806         static gint _metric_get_samples (GtkCustomRulerMark **, gdouble, gdouble, gint);
807         static gint _metric_get_minsec (GtkCustomRulerMark **, gdouble, gdouble, gint);
808
809         enum MinsecRulerScale {
810                 minsec_show_seconds,
811                 minsec_show_minutes,
812                 minsec_show_hours,
813                 minsec_show_frames
814         };
815
816         MinsecRulerScale minsec_ruler_scale;
817
818         framecnt_t minsec_mark_interval;
819         gint minsec_mark_modulo;
820         gint minsec_nmarks;
821         void set_minsec_ruler_scale (framepos_t, framepos_t);
822
823         enum TimecodeRulerScale {
824                 timecode_show_bits,
825                 timecode_show_frames,
826                 timecode_show_seconds,
827                 timecode_show_minutes,
828                 timecode_show_hours
829         };
830
831         TimecodeRulerScale timecode_ruler_scale;
832
833         gint timecode_mark_modulo;
834         gint timecode_nmarks;
835         void set_timecode_ruler_scale (framepos_t, framepos_t);
836
837         framecnt_t _samples_ruler_interval;
838         void set_samples_ruler_scale (framepos_t, framepos_t);
839
840         enum BBTRulerScale {
841                 bbt_over,
842                 bbt_show_64,
843                 bbt_show_16,
844                 bbt_show_4,
845                 bbt_show_1,
846                 bbt_show_beats,
847                 bbt_show_ticks,
848                 bbt_show_ticks_detail,
849                 bbt_show_ticks_super_detail
850         };
851
852         BBTRulerScale bbt_ruler_scale;
853
854         uint32_t bbt_bars;
855         gint bbt_nmarks;
856         uint32_t bbt_bar_helper_on;
857         uint32_t bbt_accent_modulo;
858         void compute_bbt_ruler_scale (framepos_t lower, framepos_t upper);
859
860         gint metric_get_timecode (GtkCustomRulerMark **, gdouble, gdouble, gint);
861         gint metric_get_bbt (GtkCustomRulerMark **, gdouble, gdouble, gint);
862         gint metric_get_samples (GtkCustomRulerMark **, gdouble, gdouble, gint);
863         gint metric_get_minsec (GtkCustomRulerMark **, gdouble, gdouble, gint);
864
865         Gtk::Widget        *_ruler_separator;
866         GtkWidget          *_timecode_ruler;
867         GtkWidget          *_bbt_ruler;
868         GtkWidget          *_samples_ruler;
869         GtkWidget          *_minsec_ruler;
870         Gtk::Widget        *timecode_ruler;
871         Gtk::Widget        *bbt_ruler;
872         Gtk::Widget        *samples_ruler;
873         Gtk::Widget        *minsec_ruler;
874         static Editor      *ruler_editor;
875
876         static const double timebar_height;
877         guint32 visible_timebars;
878         gdouble canvas_timebars_vsize;
879         gdouble get_canvas_timebars_vsize () const { return canvas_timebars_vsize; }
880         Gtk::Menu          *editor_ruler_menu;
881
882         ArdourCanvas::SimpleRect* tempo_bar;
883         ArdourCanvas::SimpleRect* meter_bar;
884         ArdourCanvas::SimpleRect* marker_bar;
885         ArdourCanvas::SimpleRect* range_marker_bar;
886         ArdourCanvas::SimpleRect* transport_marker_bar;
887         ArdourCanvas::SimpleRect* cd_marker_bar;
888
889         Gtk::Label  minsec_label;
890         Gtk::Label  bbt_label;
891         Gtk::Label  timecode_label;
892         Gtk::Label  samples_label;
893         Gtk::Label  tempo_label;
894         Gtk::Label  meter_label;
895         Gtk::Label  mark_label;
896         Gtk::Label  range_mark_label;
897         Gtk::Label  transport_mark_label;
898         Gtk::Label  cd_mark_label;
899
900         Gtk::VBox          time_button_vbox;
901         Gtk::HBox          time_button_hbox;
902
903         friend class EditorCursor;
904
905         EditorCursor*        playhead_cursor;
906         ArdourCanvas::Group* cursor_group;
907
908         framepos_t get_region_boundary (framepos_t pos, int32_t dir, bool with_selection, bool only_onscreen);
909
910         void    cursor_to_region_boundary (bool with_selection, int32_t dir);
911         void    cursor_to_next_region_boundary (bool with_selection);
912         void    cursor_to_previous_region_boundary (bool with_selection);
913         void    cursor_to_next_region_point (EditorCursor*, ARDOUR::RegionPoint);
914         void    cursor_to_previous_region_point (EditorCursor*, ARDOUR::RegionPoint);
915         void    cursor_to_region_point (EditorCursor*, ARDOUR::RegionPoint, int32_t dir);
916         void    cursor_to_selection_start (EditorCursor *);
917         void    cursor_to_selection_end   (EditorCursor *);
918
919         void    selected_marker_to_region_boundary (bool with_selection, int32_t dir);
920         void    selected_marker_to_next_region_boundary (bool with_selection);
921         void    selected_marker_to_previous_region_boundary (bool with_selection);
922         void    selected_marker_to_next_region_point (ARDOUR::RegionPoint);
923         void    selected_marker_to_previous_region_point (ARDOUR::RegionPoint);
924         void    selected_marker_to_region_point (ARDOUR::RegionPoint, int32_t dir);
925         void    selected_marker_to_selection_start ();
926         void    selected_marker_to_selection_end   ();
927
928         void    select_all_selectables_using_cursor (EditorCursor *, bool);
929         void    select_all_selectables_using_edit (bool);
930         void    select_all_selectables_between (bool within);
931         void    select_range_between ();
932
933         boost::shared_ptr<ARDOUR::Region> find_next_region (ARDOUR::framepos_t, ARDOUR::RegionPoint, int32_t dir, TrackViewList&, TimeAxisView ** = 0);
934         ARDOUR::framepos_t find_next_region_boundary (ARDOUR::framepos_t, int32_t dir, const TrackViewList&);
935
936         std::vector<ARDOUR::framepos_t> region_boundary_cache;
937         void build_region_boundary_cache ();
938
939         Gtk::HBox           top_hbox;
940         Gtk::HBox           bottom_hbox;
941
942         Gtk::Table          edit_packer;
943
944         Gtk::Adjustment     vertical_adjustment;
945
946         Gtk::Layout         controls_layout;
947         bool control_layout_scroll (GdkEventScroll* ev);
948         void reset_controls_layout_width ();
949         void reset_controls_layout_height (int32_t height);
950
951         enum Direction {
952                 LEFT,
953                 RIGHT,
954                 UP,
955                 DOWN
956         };
957
958         bool scroll_press (Direction);
959         void scroll_release ();
960         sigc::connection _scroll_connection;
961         int _scroll_callbacks;
962
963         double _canvas_width;
964         double _canvas_height; ///< height of the visible area of the track canvas
965         double full_canvas_height; ///< full height of the canvas
966
967         bool track_canvas_map_handler (GdkEventAny*);
968
969         bool edit_controls_button_release (GdkEventButton*);
970         Gtk::Menu *edit_controls_left_menu;
971         Gtk::Menu *edit_controls_right_menu;
972
973         Gtk::VBox           ruler_label_vbox;
974         Gtk::VBox           track_canvas_vbox;
975         Gtk::VBox           time_canvas_vbox;
976         Gtk::VBox           edit_controls_vbox;
977         Gtk::HBox           edit_controls_hbox;
978
979         void control_scroll (float);
980         void control_select (uint32_t rid);
981         void access_action (std::string,std::string);
982         bool deferred_control_scroll (framepos_t);
983         sigc::connection control_scroll_connection;
984
985         gdouble get_trackview_group_vertical_offset () const { return vertical_adjustment.get_value () - canvas_timebars_vsize;}
986
987         ArdourCanvas::Group* get_background_group () const { return _background_group; }
988         ArdourCanvas::Group* get_trackview_group () const { return _trackview_group; }
989         double last_trackview_group_vertical_offset;
990         void tie_vertical_scrolling ();
991         void set_horizontal_position (double);
992         double horizontal_position () const;
993         void scroll_canvas_vertically ();
994
995         struct VisualChange {
996                 enum Type {
997                         TimeOrigin = 0x1,
998                         ZoomLevel = 0x2,
999                         YOrigin = 0x4
1000                 };
1001
1002                 Type pending;
1003                 framepos_t time_origin;
1004                 double frames_per_unit;
1005                 double y_origin;
1006
1007                 int idle_handler_id;
1008
1009                 VisualChange() : pending ((VisualChange::Type) 0), time_origin (0), frames_per_unit (0), idle_handler_id (-1) {}
1010                 void add (Type t) {
1011                         pending = Type (pending | t);
1012                 }
1013         };
1014
1015
1016         VisualChange pending_visual_change;
1017
1018         static int _idle_visual_changer (void *arg);
1019         int idle_visual_changer ();
1020
1021         void queue_visual_change (framepos_t);
1022         void queue_visual_change (double);
1023         void queue_visual_change_y (double);
1024         void ensure_visual_change_idle_handler ();
1025
1026         /* track views */
1027         TrackViewList track_views;
1028         std::pair<TimeAxisView*, ARDOUR::layer_t> trackview_by_y_position (double);
1029         TimeAxisView* axis_view_from_route (boost::shared_ptr<ARDOUR::Route>) const;
1030
1031         TrackViewList get_tracks_for_range_action () const;
1032
1033         sigc::connection super_rapid_screen_update_connection;
1034         framepos_t last_update_frame;
1035         void center_screen_internal (framepos_t, float);
1036
1037         void super_rapid_screen_update ();
1038
1039         void session_going_away ();
1040
1041         framepos_t cut_buffer_start;
1042         framecnt_t cut_buffer_length;
1043
1044         Gdk::Cursor* pre_press_cursor;
1045         boost::weak_ptr<ARDOUR::Trimmable> _trimmable;
1046         boost::weak_ptr<ARDOUR::Movable> _movable;
1047
1048         bool typed_event (ArdourCanvas::Item*, GdkEvent*, ItemType);
1049         bool button_press_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1050         bool button_press_handler_1 (ArdourCanvas::Item *, GdkEvent *, ItemType);
1051         bool button_press_handler_2 (ArdourCanvas::Item *, GdkEvent *, ItemType);
1052         bool button_release_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1053         bool button_press_dispatch (GdkEventButton*);
1054         bool button_release_dispatch (GdkEventButton*);
1055         bool motion_handler (ArdourCanvas::Item*, GdkEvent*, bool from_autoscroll = false);
1056         bool enter_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1057         bool leave_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1058         bool key_press_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1059         bool key_release_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1060
1061         Gtkmm2ext::Bindings* button_bindings;
1062         XMLNode* button_settings () const;
1063
1064         /* KEYMAP HANDLING */
1065
1066         void register_actions ();
1067         void register_region_actions ();
1068
1069         int ensure_cursor (framepos_t* pos);
1070
1071         void cut_copy (Editing::CutCopyOp);
1072         bool can_cut_copy () const;
1073         void cut_copy_points (Editing::CutCopyOp);
1074         void cut_copy_regions (Editing::CutCopyOp, RegionSelection&);
1075         void cut_copy_ranges (Editing::CutCopyOp);
1076         void cut_copy_midi (Editing::CutCopyOp);
1077
1078         void mouse_paste ();
1079         void paste_internal (framepos_t position, float times);
1080
1081         /* EDITING OPERATIONS */
1082
1083         void reset_point_selection ();
1084         void toggle_region_lock ();
1085         void toggle_opaque_region ();
1086         void toggle_record_enable ();
1087         void toggle_solo ();
1088         void toggle_solo_isolate ();
1089         void toggle_mute ();
1090         void toggle_region_lock_style ();
1091         void raise_region ();
1092         void raise_region_to_top ();
1093         void change_region_layering_order ();
1094         void lower_region ();
1095         void lower_region_to_bottom ();
1096         void split_regions_at (framepos_t, RegionSelection&);
1097         void split_region_at_transients ();
1098         void split_region_at_points (boost::shared_ptr<ARDOUR::Region>, ARDOUR::AnalysisFeatureList&, bool can_ferret, bool select_new = false);
1099         void crop_region_to_selection ();
1100         void crop_region_to (framepos_t start, framepos_t end);
1101         void set_sync_point (framepos_t, const RegionSelection&);
1102         void set_region_sync_position ();
1103         void remove_region_sync();
1104         void align_regions (ARDOUR::RegionPoint);
1105         void align_regions_relative (ARDOUR::RegionPoint point);
1106         void align_region (boost::shared_ptr<ARDOUR::Region>, ARDOUR::RegionPoint point, framepos_t position);
1107         void align_region_internal (boost::shared_ptr<ARDOUR::Region>, ARDOUR::RegionPoint point, framepos_t position);
1108         void remove_selected_regions ();
1109         void remove_clicked_region ();
1110         void show_region_properties ();
1111         void show_midi_list_editor ();
1112         void rename_region ();
1113         void duplicate_some_regions (RegionSelection&, float times);
1114         void duplicate_selection (float times);
1115         void region_fill_selection ();
1116         void combine_regions ();
1117         void uncombine_regions ();
1118
1119         void region_fill_track ();
1120         void audition_playlist_region_standalone (boost::shared_ptr<ARDOUR::Region>);
1121         void audition_playlist_region_via_route (boost::shared_ptr<ARDOUR::Region>, ARDOUR::Route&);
1122         void split_multichannel_region();
1123         void reverse_region ();
1124         void strip_region_silence ();
1125         void normalize_region ();
1126         void reset_region_scale_amplitude ();
1127         void adjust_region_gain (bool up);
1128         void quantize_region ();
1129         void insert_patch_change ();
1130         void fork_region ();
1131
1132         void do_insert_time ();
1133         void insert_time (framepos_t, framecnt_t, Editing::InsertTimeOption, bool, bool, bool, bool, bool, bool);
1134
1135         void tab_to_transient (bool forward);
1136
1137         void set_tempo_from_region ();
1138         void use_range_as_bar ();
1139
1140         void define_one_bar (framepos_t start, framepos_t end);
1141
1142         void audition_region_from_region_list ();
1143         void hide_region_from_region_list ();
1144         void show_region_in_region_list ();
1145
1146         void naturalize_region ();
1147
1148         void reset_focus ();
1149
1150         void split_region ();
1151
1152         void delete_ ();
1153         void cut ();
1154         void copy ();
1155         void paste (float times);
1156
1157         void place_transient ();
1158         void remove_transient (ArdourCanvas::Item* item);
1159         void snap_regions_to_grid ();
1160         void close_region_gaps ();
1161
1162         void keyboard_paste ();
1163
1164         void region_from_selection ();
1165         void create_region_from_selection (std::vector<boost::shared_ptr<ARDOUR::Region> >&);
1166
1167         void play_from_start ();
1168         void play_from_edit_point ();
1169         void play_from_edit_point_and_return ();
1170         void play_selected_region ();
1171         void play_edit_range ();
1172         void play_location (ARDOUR::Location&);
1173         void loop_location (ARDOUR::Location&);
1174
1175         void temporal_zoom_selection ();
1176         void temporal_zoom_region (bool both_axes);
1177         void zoom_to_region (bool both_axes);
1178         void temporal_zoom_session ();
1179         void temporal_zoom (gdouble scale);
1180         void temporal_zoom_by_frame (framepos_t start, framepos_t end, const std::string & op);
1181         void temporal_zoom_to_frame (bool coarser, framepos_t frame);
1182
1183         void insert_region_list_drag (boost::shared_ptr<ARDOUR::Region>, int x, int y);
1184         void insert_region_list_selection (float times);
1185
1186         void insert_route_list_drag (boost::shared_ptr<ARDOUR::Route>, int x, int y);
1187
1188         /* import & embed */
1189
1190         void add_external_audio_action (Editing::ImportMode);
1191         void external_audio_dialog ();
1192         void session_import_dialog ();
1193
1194         int  check_whether_and_how_to_import(std::string, bool all_or_nothing = true);
1195         bool check_multichannel_status (const std::vector<std::string>& paths);
1196
1197         SoundFileOmega* sfbrowser;
1198
1199         void bring_in_external_audio (Editing::ImportMode mode,  framepos_t& pos);
1200
1201         bool  idle_drop_paths  (std::vector<std::string> paths, framepos_t frame, double ypos);
1202         void  drop_paths_part_two  (const std::vector<std::string>& paths, framepos_t frame, double ypos);
1203
1204         int  import_sndfiles (std::vector<std::string> paths, Editing::ImportMode mode,  ARDOUR::SrcQuality, framepos_t& pos,
1205                               int target_regions, int target_tracks, boost::shared_ptr<ARDOUR::Track>&, bool);
1206         int  embed_sndfiles (std::vector<std::string> paths, bool multiple_files, bool& check_sample_rate, Editing::ImportMode mode,
1207                              framepos_t& pos, int target_regions, int target_tracks, boost::shared_ptr<ARDOUR::Track>&);
1208
1209         int add_sources (std::vector<std::string> paths, ARDOUR::SourceList& sources, framepos_t& pos, Editing::ImportMode,
1210                          int target_regions, int target_tracks, boost::shared_ptr<ARDOUR::Track>&, bool add_channel_suffix);
1211         int finish_bringing_in_material (boost::shared_ptr<ARDOUR::Region> region, uint32_t, uint32_t,  framepos_t& pos, Editing::ImportMode mode,
1212                                       boost::shared_ptr<ARDOUR::Track>& existing_track);
1213
1214         boost::shared_ptr<ARDOUR::AudioTrack> get_nth_selected_audio_track (int nth) const;
1215         boost::shared_ptr<ARDOUR::MidiTrack> get_nth_selected_midi_track (int nth) const;
1216
1217         ARDOUR::InterThreadInfo* current_interthread_info;
1218
1219         AnalysisWindow* analysis_window;
1220
1221         /* import specific info */
1222
1223         struct EditorImportStatus : public ARDOUR::ImportStatus {
1224             Editing::ImportMode mode;
1225             framepos_t pos;
1226             int target_tracks;
1227             int target_regions;
1228             boost::shared_ptr<ARDOUR::Track> track;
1229             bool replace;
1230         };
1231
1232         EditorImportStatus import_status;
1233         static void *_import_thread (void *);
1234         void* import_thread ();
1235         void finish_import ();
1236
1237         /* to support this ... */
1238
1239         void import_audio (bool as_tracks);
1240         void do_import (std::vector<std::string> paths, bool split, bool as_tracks);
1241
1242         void move_to_start ();
1243         void move_to_end ();
1244         void center_playhead ();
1245         void center_edit_point ();
1246         void playhead_forward_to_grid ();
1247         void playhead_backward_to_grid ();
1248         void scroll_playhead (bool forward);
1249         void scroll_backward (float pages=0.8f);
1250         void scroll_forward (float pages=0.8f);
1251         void scroll_tracks_down ();
1252         void scroll_tracks_up ();
1253         void set_mark ();
1254         void clear_markers ();
1255         void clear_ranges ();
1256         void clear_locations ();
1257         void unhide_markers ();
1258         void unhide_ranges ();
1259         void jump_forward_to_mark ();
1260         void jump_backward_to_mark ();
1261         void cursor_align (bool playhead_to_edit);
1262
1263         void remove_last_capture ();
1264         void select_all_selectables_using_time_selection ();
1265         void select_all_selectables_using_loop();
1266         void select_all_selectables_using_punch();
1267         void set_selection_from_range (ARDOUR::Location&);
1268         void set_selection_from_punch ();
1269         void set_selection_from_loop ();
1270         void set_selection_from_region ();
1271
1272         void add_location_mark (framepos_t where);
1273         void add_location_from_region ();
1274         void add_locations_from_region ();
1275         void add_location_from_selection ();
1276         void set_loop_from_selection (bool play);
1277         void set_punch_from_selection ();
1278         void set_punch_from_region ();
1279
1280         void set_loop_from_edit_range (bool play);
1281         void set_loop_from_region (bool play);
1282         void set_punch_from_edit_range ();
1283
1284         void set_loop_range (framepos_t start, framepos_t end, std::string cmd);
1285         void set_punch_range (framepos_t start, framepos_t end, std::string cmd);
1286
1287         void add_location_from_playhead_cursor ();
1288         bool select_new_marker;
1289
1290         void reverse_selection ();
1291         void edit_envelope ();
1292
1293         double last_scrub_x;
1294         int scrubbing_direction;
1295         int scrub_reversals;
1296         int scrub_reverse_distance;
1297         void scrub (framepos_t, double);
1298
1299         void keyboard_selection_begin ();
1300         void keyboard_selection_finish (bool add);
1301         bool have_pending_keyboard_selection;
1302         framepos_t pending_keyboard_selection_start;
1303
1304         void move_range_selection_start_or_end_to_region_boundary (bool, bool);
1305
1306         Editing::SnapType _snap_type;
1307         Editing::SnapMode _snap_mode;
1308
1309         /// Snap threshold in pixels
1310         double snap_threshold;
1311
1312         bool ignore_gui_changes;
1313
1314         DragManager* _drags;
1315
1316         void escape ();
1317
1318         Gtk::Menu fade_context_menu;
1319         void popup_fade_context_menu (int, int, ArdourCanvas::Item*, ItemType);
1320
1321         void set_fade_in_shape (ARDOUR::FadeShape);
1322         void set_fade_out_shape (ARDOUR::FadeShape);
1323
1324         void set_fade_length (bool in);
1325         void set_fade_in_active (bool);
1326         void set_fade_out_active (bool);
1327
1328         std::set<boost::shared_ptr<ARDOUR::Playlist> > motion_frozen_playlists;
1329
1330         bool _dragging_playhead;
1331         bool _dragging_edit_point;
1332
1333         void marker_drag_motion_callback (GdkEvent*);
1334         void marker_drag_finished_callback (GdkEvent*);
1335
1336         gint mouse_rename_region (ArdourCanvas::Item*, GdkEvent*);
1337
1338         void add_region_drag (ArdourCanvas::Item*, GdkEvent*, RegionView*);
1339         void start_create_region_grab (ArdourCanvas::Item*, GdkEvent*);
1340         void add_region_copy_drag (ArdourCanvas::Item*, GdkEvent*, RegionView*);
1341         void add_region_brush_drag (ArdourCanvas::Item*, GdkEvent*, RegionView*);
1342         void start_selection_grab (ArdourCanvas::Item*, GdkEvent*);
1343
1344         void region_view_item_click (AudioRegionView&, GdkEventButton*);
1345
1346         bool can_remove_control_point (ArdourCanvas::Item *);
1347         void remove_control_point (ArdourCanvas::Item *);
1348
1349         void mouse_brush_insert_region (RegionView*, framepos_t pos);
1350
1351         /* Canvas event handlers */
1352
1353         bool canvas_control_point_event (GdkEvent* event,ArdourCanvas::Item*, ControlPoint*);
1354         bool canvas_line_event (GdkEvent* event,ArdourCanvas::Item*, AutomationLine*);
1355         bool canvas_selection_rect_event (GdkEvent* event,ArdourCanvas::Item*, SelectionRect*);
1356         bool canvas_selection_start_trim_event (GdkEvent* event,ArdourCanvas::Item*, SelectionRect*);
1357         bool canvas_selection_end_trim_event (GdkEvent* event,ArdourCanvas::Item*, SelectionRect*);
1358         bool canvas_crossfade_view_event (GdkEvent* event,ArdourCanvas::Item*, CrossfadeView*);
1359         bool canvas_fade_in_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1360         bool canvas_fade_in_handle_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1361         bool canvas_fade_out_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1362         bool canvas_fade_out_handle_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1363         bool canvas_region_view_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1364         bool canvas_frame_handle_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1365         bool canvas_region_view_name_highlight_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1366         bool canvas_region_view_name_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1367         bool canvas_feature_line_event (GdkEvent* event, ArdourCanvas::Item*, RegionView*);
1368         bool canvas_stream_view_event (GdkEvent* event,ArdourCanvas::Item*, RouteTimeAxisView*);
1369         bool canvas_marker_event (GdkEvent* event,ArdourCanvas::Item*, Marker*);
1370         bool canvas_zoom_rect_event (GdkEvent* event,ArdourCanvas::Item*);
1371         bool canvas_tempo_marker_event (GdkEvent* event,ArdourCanvas::Item*, TempoMarker*);
1372         bool canvas_meter_marker_event (GdkEvent* event,ArdourCanvas::Item*, MeterMarker*);
1373         bool canvas_automation_track_event(GdkEvent* event, ArdourCanvas::Item*, AutomationTimeAxisView*) ;
1374         bool canvas_note_event (GdkEvent* event, ArdourCanvas::Item*);
1375
1376         bool canvas_tempo_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1377         bool canvas_meter_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1378         bool canvas_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1379         bool canvas_range_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1380         bool canvas_transport_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1381         bool canvas_cd_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1382
1383         bool canvas_imageframe_item_view_event(GdkEvent* event, ArdourCanvas::Item*,ImageFrameView*);
1384         bool canvas_imageframe_view_event(GdkEvent* event, ArdourCanvas::Item*,ImageFrameTimeAxis*);
1385         bool canvas_imageframe_start_handle_event(GdkEvent* event, ArdourCanvas::Item*,ImageFrameView*);
1386         bool canvas_imageframe_end_handle_event(GdkEvent* event, ArdourCanvas::Item*,ImageFrameView*);
1387         bool canvas_marker_time_axis_view_event(GdkEvent* event, ArdourCanvas::Item*,MarkerTimeAxis*);
1388         bool canvas_markerview_item_view_event(GdkEvent* event, ArdourCanvas::Item*,MarkerView*);
1389         bool canvas_markerview_start_handle_event(GdkEvent* event, ArdourCanvas::Item*,MarkerView*);
1390         bool canvas_markerview_end_handle_event(GdkEvent* event, ArdourCanvas::Item*,MarkerView*);
1391
1392         PBD::Signal0<void> EditorFreeze;
1393         PBD::Signal0<void> EditorThaw;
1394
1395   private:
1396         friend class DragManager;
1397         friend class EditorRouteGroups;
1398         friend class EditorRegions;
1399
1400         ArdourCanvas::Item *last_item_entered;
1401         /** true if the mouse is over a place where region trim can happen */
1402         bool _over_region_trim_target;
1403
1404         /* non-public event handlers */
1405
1406         bool canvas_playhead_cursor_event (GdkEvent* event, ArdourCanvas::Item*);
1407         bool track_canvas_scroll (GdkEventScroll* event);
1408
1409         bool track_canvas_scroll_event (GdkEventScroll* event);
1410         bool track_canvas_button_press_event (GdkEventButton* event);
1411         bool track_canvas_button_release_event (GdkEventButton* event);
1412         bool track_canvas_motion_notify_event (GdkEventMotion* event);
1413
1414         Gtk::Allocation canvas_allocation;
1415         void track_canvas_allocate (Gtk::Allocation alloc);
1416         bool track_canvas_size_allocated ();
1417         bool track_canvas_drag_motion (Glib::RefPtr<Gdk::DragContext> const &, int, int, guint);
1418         bool track_canvas_key_press (GdkEventKey *);
1419         bool track_canvas_key_release (GdkEventKey *);
1420
1421         void set_playhead_cursor ();
1422
1423         void toggle_region_mute ();
1424
1425         void initialize_canvas ();
1426
1427         /* display control */
1428
1429         bool _show_measures;
1430         /// true if the editor should follow the playhead, otherwise false
1431         bool _follow_playhead;
1432         /// true if we scroll the tracks rather than the playhead
1433         bool _stationary_playhead;
1434
1435         ARDOUR::TempoMap::BBTPointList *current_bbt_points;
1436
1437         TempoLines* tempo_lines;
1438
1439         ArdourCanvas::Group* time_line_group;
1440
1441         void hide_measures ();
1442         void draw_measures ();
1443         bool redraw_measures ();
1444
1445         void new_tempo_section ();
1446
1447         void mouse_add_new_tempo_event (framepos_t where);
1448         void mouse_add_new_meter_event (framepos_t where);
1449
1450         void remove_tempo_marker (ArdourCanvas::Item*);
1451         void remove_meter_marker (ArdourCanvas::Item*);
1452         gint real_remove_tempo_marker (ARDOUR::TempoSection*);
1453         gint real_remove_meter_marker (ARDOUR::MeterSection*);
1454
1455         void edit_tempo_section (ARDOUR::TempoSection*);
1456         void edit_meter_section (ARDOUR::MeterSection*);
1457         void edit_tempo_marker (ArdourCanvas::Item*);
1458         void edit_meter_marker (ArdourCanvas::Item*);
1459         void edit_control_point (ArdourCanvas::Item*);
1460         void edit_note (ArdourCanvas::Item *);
1461
1462         void marker_menu_edit ();
1463         void marker_menu_remove ();
1464         void marker_menu_rename ();
1465         void toggle_marker_menu_lock ();
1466         void toggle_marker_menu_glue ();
1467         void marker_menu_hide ();
1468         void marker_menu_loop_range ();
1469         void marker_menu_select_all_selectables_using_range ();
1470         void marker_menu_select_using_range ();
1471         void marker_menu_separate_regions_using_location ();
1472         void marker_menu_play_from ();
1473         void marker_menu_play_range ();
1474         void marker_menu_set_playhead ();
1475         void marker_menu_set_from_playhead ();
1476         void marker_menu_set_from_selection ();
1477         void marker_menu_range_to_next ();
1478         void new_transport_marker_menu_set_loop ();
1479         void new_transport_marker_menu_set_punch ();
1480         void update_loop_range_view (bool visibility=false);
1481         void update_punch_range_view (bool visibility=false);
1482         void new_transport_marker_menu_popdown ();
1483         void marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
1484         void tempo_or_meter_marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
1485         void transport_marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
1486         void new_transport_marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
1487         void build_range_marker_menu (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         Gtk::ToggleButton        global_automation_button;
1555
1556         Gtk::ComboBoxText edit_mode_selector;
1557         Gtk::VBox         edit_mode_box;
1558         std::vector<std::string> edit_mode_strings;
1559
1560         void set_edit_mode (ARDOUR::EditMode);
1561         void cycle_edit_mode ();
1562         void edit_mode_selection_done ();
1563
1564         Gtk::ComboBoxText snap_type_selector;
1565         Gtk::ComboBoxText snap_mode_selector;
1566         Gtk::HBox         snap_box;
1567
1568         std::vector<std::string> snap_type_strings;
1569         std::vector<std::string> snap_mode_strings;
1570
1571         void snap_type_selection_done ();
1572         void snap_mode_selection_done ();
1573         void snap_mode_chosen (Editing::SnapMode);
1574         void snap_type_chosen (Editing::SnapType);
1575
1576         Glib::RefPtr<Gtk::RadioAction> snap_type_action (Editing::SnapType);
1577         Glib::RefPtr<Gtk::RadioAction> snap_mode_action (Editing::SnapMode);
1578
1579         Gtk::ComboBoxText zoom_focus_selector;
1580         Gtk::VBox         zoom_focus_box;
1581
1582         std::vector<std::string> zoom_focus_strings;
1583
1584         void zoom_focus_selection_done ();
1585         void zoom_focus_chosen (Editing::ZoomFocus);
1586
1587         Glib::RefPtr<Gtk::RadioAction> zoom_focus_action (Editing::ZoomFocus);
1588
1589         Gtk::HBox           _zoom_box;
1590         Gtkmm2ext::TearOff* _zoom_tearoff;
1591         void                zoom_adjustment_changed();
1592
1593         void setup_toolbar ();
1594
1595         void setup_tooltips ();
1596
1597         Gtkmm2ext::TearOff*     _tools_tearoff;
1598         Gtk::HBox                toolbar_hbox;
1599         Gtk::EventBox            toolbar_base;
1600         Gtk::Frame               toolbar_frame;
1601         Gtk::Viewport           _toolbar_viewport;
1602
1603         /* midi toolbar */
1604
1605         Gtk::HBox                panic_box;
1606         Gtk::Button              midi_panic_button;
1607         Gtk::ToggleButton        midi_sound_notes;
1608         void                     midi_panic ();
1609         bool                     sound_notes () const { return midi_sound_notes.get_active(); }
1610
1611         void setup_midi_toolbar ();
1612
1613         /* selection process */
1614
1615         Selection* selection;
1616         Selection* cut_buffer;
1617
1618         void time_selection_changed ();
1619         void track_selection_changed ();
1620         void region_selection_changed ();
1621         sigc::connection editor_regions_selection_changed_connection;
1622         void sensitize_all_region_actions (bool);
1623         void sensitize_the_right_region_actions ();
1624         bool _all_region_actions_sensitized;
1625         /** Flag to block region action handlers from doing what they normally do;
1626          *  I tried Gtk::Action::block_activate() but this doesn't work (ie it doesn't
1627          *  block) when setting a ToggleAction's active state.
1628          */
1629         bool _ignore_region_action;
1630         bool _last_region_menu_was_main;
1631         void point_selection_changed ();
1632         void marker_selection_changed ();
1633
1634         void cancel_selection ();
1635
1636         bool audio_region_selection_covers (framepos_t where);
1637
1638         /* transport range select process */
1639
1640         ArdourCanvas::SimpleRect*  cd_marker_bar_drag_rect;
1641         ArdourCanvas::SimpleRect*  range_bar_drag_rect;
1642         ArdourCanvas::SimpleRect*  transport_bar_drag_rect;
1643
1644 #ifdef GTKOSX
1645         ArdourCanvas::SimpleRect     *bogus_background_rect;
1646 #endif
1647         ArdourCanvas::SimpleRect     *transport_bar_range_rect;
1648         ArdourCanvas::SimpleRect     *transport_bar_preroll_rect;
1649         ArdourCanvas::SimpleRect     *transport_bar_postroll_rect;
1650         ArdourCanvas::SimpleRect     *transport_loop_range_rect;
1651         ArdourCanvas::SimpleRect     *transport_punch_range_rect;
1652         ArdourCanvas::SimpleLine     *transport_punchin_line;
1653         ArdourCanvas::SimpleLine     *transport_punchout_line;
1654         ArdourCanvas::SimpleRect     *transport_preroll_rect;
1655         ArdourCanvas::SimpleRect     *transport_postroll_rect;
1656
1657         ARDOUR::Location*  transport_loop_location();
1658         ARDOUR::Location*  transport_punch_location();
1659
1660         ARDOUR::Location   *temp_location;
1661
1662         /* object rubberband select process */
1663
1664         void select_all_within (framepos_t, framepos_t, double, double, TrackViewList const &, Selection::Operation, bool);
1665
1666         ArdourCanvas::SimpleRect   *rubberband_rect;
1667
1668         /* mouse zoom process */
1669
1670         ArdourCanvas::SimpleRect   *zoom_rect;
1671         void reposition_zoom_rect (framepos_t start, framepos_t end);
1672
1673         EditorRouteGroups* _route_groups;
1674         EditorRoutes* _routes;
1675         EditorRegions* _regions;
1676         EditorSnapshots* _snapshots;
1677         EditorLocations* _locations;
1678
1679         /* diskstream/route display management */
1680         Glib::RefPtr<Gdk::Pixbuf> rec_enabled_icon;
1681         Glib::RefPtr<Gdk::Pixbuf> rec_disabled_icon;
1682
1683         Glib::RefPtr<Gtk::TreeSelection> route_display_selection;
1684
1685         bool sync_track_view_list_and_routes ();
1686
1687         Gtk::VBox           list_vpacker;
1688
1689         /* autoscrolling */
1690
1691         bool autoscroll_active;
1692         int autoscroll_timeout_tag;
1693         int autoscroll_x;
1694         int autoscroll_y;
1695         int last_autoscroll_x;
1696         int last_autoscroll_y;
1697         uint32_t autoscroll_cnt;
1698         framecnt_t autoscroll_x_distance;
1699         double autoscroll_y_distance;
1700
1701         static gint _autoscroll_canvas (void *);
1702         bool autoscroll_canvas ();
1703         void start_canvas_autoscroll (int x, int y);
1704         void stop_canvas_autoscroll ();
1705
1706         /* trimming */
1707         void point_trim (GdkEvent *, framepos_t);
1708
1709         void trim_region_front();
1710         void trim_region_back();
1711         void trim_region (bool front);
1712
1713         void trim_region_to_loop ();
1714         void trim_region_to_punch ();
1715         void trim_region_to_location (const ARDOUR::Location&, const char* cmd);
1716
1717         void trim_to_region(bool forward);
1718         void trim_region_to_previous_region_end();
1719         void trim_region_to_next_region_start();
1720
1721         bool show_gain_after_trim;
1722
1723         /* Drag-n-Drop */
1724
1725         int convert_drop_to_paths (
1726                 std::vector<std::string>&           paths,
1727                 const Glib::RefPtr<Gdk::DragContext>& context,
1728                 gint                                  x,
1729                 gint                                  y,
1730                 const Gtk::SelectionData&             data,
1731                 guint                                 info,
1732                 guint                                 time);
1733
1734         void track_canvas_drag_data_received (
1735                 const Glib::RefPtr<Gdk::DragContext>& context,
1736                 gint                                  x,
1737                 gint                                  y,
1738                 const Gtk::SelectionData&             data,
1739                 guint                                 info,
1740                 guint                                 time);
1741
1742         void drop_paths (
1743                 const Glib::RefPtr<Gdk::DragContext>& context,
1744                 gint                                  x,
1745                 gint                                  y,
1746                 const Gtk::SelectionData&             data,
1747                 guint                                 info,
1748                 guint                                 time);
1749
1750         void drop_regions (
1751                 const Glib::RefPtr<Gdk::DragContext>& context,
1752                 gint                                  x,
1753                 gint                                  y,
1754                 const Gtk::SelectionData&             data,
1755                 guint                                 info,
1756                 guint                                 time);
1757
1758         void drop_routes (
1759                 const Glib::RefPtr<Gdk::DragContext>& context,
1760                 gint                x,
1761                 gint                y,
1762                 const Gtk::SelectionData& data,
1763                 guint               info,
1764                 guint               time);
1765
1766         /* audio export */
1767
1768         int  write_region_selection(RegionSelection&);
1769         bool write_region (std::string path, boost::shared_ptr<ARDOUR::AudioRegion>);
1770         void bounce_region_selection (bool with_processing);
1771         void bounce_range_selection (bool replace, bool enable_processing);
1772         void external_edit_region ();
1773
1774         int write_audio_selection (TimeSelection&);
1775         bool write_audio_range (ARDOUR::AudioPlaylist&, const ARDOUR::ChanCount& channels, std::list<ARDOUR::AudioRange>&);
1776
1777         void write_selection ();
1778
1779         XMLNode *before; /* used in *_reversible_command */
1780
1781         void update_title ();
1782         void update_title_s (const std::string & snapshot_name);
1783
1784         struct State {
1785             Selection* selection;
1786             double frames_per_unit;
1787
1788             State (PublicEditor const * e);
1789             ~State ();
1790         };
1791
1792         void instant_save ();
1793
1794         boost::shared_ptr<ARDOUR::AudioRegion> last_audition_region;
1795
1796         /* freeze operations */
1797
1798         ARDOUR::InterThreadInfo freeze_status;
1799         static void* _freeze_thread (void*);
1800         void* freeze_thread ();
1801
1802         void freeze_route ();
1803         void unfreeze_route ();
1804
1805         /* duplication */
1806
1807         void duplicate_dialog (bool with_dialog);
1808
1809         framepos_t event_frame (GdkEvent const *, double* px = 0, double* py = 0) const;
1810
1811         /* returns false if mouse pointer is not in track or marker canvas
1812          */
1813         bool mouse_frame (framepos_t&, bool& in_track_canvas) const;
1814
1815         /* "whats mine is yours" */
1816
1817         TimeFXDialog* current_timefx;
1818
1819         static void* timefx_thread (void *arg);
1820         void do_timefx (TimeFXDialog&);
1821
1822         int time_stretch (RegionSelection&, float fraction);
1823         int pitch_shift (RegionSelection&, float cents);
1824         void pitch_shift_region ();
1825         int time_fx (RegionSelection&, float val, bool pitching);
1826
1827         void transpose_region ();
1828
1829         /* editor-mixer strip */
1830
1831         MixerStrip *current_mixer_strip;
1832         bool show_editor_mixer_when_tracks_arrive;
1833         Gtk::VBox current_mixer_strip_vbox;
1834         void cms_new (boost::shared_ptr<ARDOUR::Route>);
1835         void current_mixer_strip_hidden ();
1836
1837         void detach_tearoff (Gtk::Box* b, Gtk::Window* w);
1838         void reattach_tearoff (Gtk::Box* b, Gtk::Window* w, int32_t n);
1839 #ifdef GTKOSX
1840         void ensure_all_elements_drawn ();
1841 #endif
1842         /* nudging tracks */
1843
1844         void nudge_track (bool use_edit_point, bool forwards);
1845
1846         /* xfades */
1847
1848         bool _xfade_visibility;
1849
1850 #ifdef WITH_CMT
1851         void handle_new_imageframe_time_axis_view(const std::string & track_name, void* src) ;
1852         void handle_new_imageframe_marker_time_axis_view(const std::string & track_name, TimeAxisView* marked_track) ;
1853
1854         void start_imageframe_grab(ArdourCanvas::Item*, GdkEvent*) ;
1855         void start_markerview_grab(ArdourCanvas::Item*, GdkEvent*) ;
1856
1857         void imageframe_drag_motion_callback(ArdourCanvas::Item*, GdkEvent*) ;
1858         void markerview_drag_motion_callback(ArdourCanvas::Item*, GdkEvent*) ;
1859         void timeaxis_item_drag_finished_callback(ArdourCanvas::Item*, GdkEvent*) ;
1860
1861         gint canvas_imageframe_item_view_event(ArdourCanvas::Item* item, GdkEvent* event, ImageFrameView* ifv);
1862         gint canvas_imageframe_view_event(ArdourCanvas::Item* item, GdkEvent* event, ImageFrameTimeAxis* ifta);
1863         gint canvas_imageframe_start_handle_event(ArdourCanvas::Item* item, GdkEvent* event, ImageFrameView* ifv);
1864         gint canvas_imageframe_end_handle_event(ArdourCanvas::Item* item, GdkEvent* event, ImageFrameView* ifv);
1865
1866         gint canvas_marker_time_axis_view_event(ArdourCanvas::Item* item, GdkEvent* event, MarkerTimeAxis* mta);
1867         gint canvas_markerview_item_view_event(ArdourCanvas::Item* item, GdkEvent* event, MarkerView* mv);
1868         gint canvas_markerview_start_handle_event(ArdourCanvas::Item* item, GdkEvent* event, MarkerView* mv);
1869         gint canvas_markerview_end_handle_event(ArdourCanvas::Item* item, GdkEvent* event, MarkerView* mv);
1870
1871         void imageframe_start_handle_op(ArdourCanvas::Item* item, GdkEvent* event) ;
1872         void imageframe_end_handle_op(ArdourCanvas::Item* item, GdkEvent* event) ;
1873         void imageframe_start_handle_trim_motion(ArdourCanvas::Item* item, GdkEvent* event) ;
1874         void imageframe_start_handle_end_trim(ArdourCanvas::Item* item, GdkEvent* event) ;
1875         void imageframe_end_handle_trim_motion(ArdourCanvas::Item* item, GdkEvent* event) ;
1876         void imageframe_end_handle_end_trim(ArdourCanvas::Item* item, GdkEvent* event) ;
1877
1878         void markerview_item_start_handle_op(ArdourCanvas::Item* item, GdkEvent* event) ;
1879         void markerview_item_end_handle_op(ArdourCanvas::Item* item, GdkEvent* event) ;
1880         void markerview_start_handle_trim_motion(ArdourCanvas::Item* item, GdkEvent* event) ;
1881         void markerview_start_handle_end_trim(ArdourCanvas::Item* item, GdkEvent* event) ;
1882         void markerview_end_handle_trim_motion(ArdourCanvas::Item* item, GdkEvent* event) ;
1883         void markerview_end_handle_end_trim(ArdourCanvas::Item* item, GdkEvent* event) ;
1884
1885         void popup_imageframe_edit_menu(int button, int32_t time, ArdourCanvas::Item* ifv, bool with_frame) ;
1886         void popup_marker_time_axis_edit_menu(int button, int32_t time, ArdourCanvas::Item* ifv, bool with_frame) ;
1887
1888         ImageFrameSocketHandler* image_socket_listener ;
1889 #endif
1890
1891         void toggle_xfade_active (boost::weak_ptr<ARDOUR::Crossfade>);
1892         void toggle_xfade_length (boost::weak_ptr<ARDOUR::Crossfade>);
1893         void edit_xfade (boost::weak_ptr<ARDOUR::Crossfade>);
1894         void xfade_edit_left_region ();
1895         void xfade_edit_right_region ();
1896
1897         static const int32_t default_width = 995;
1898         static const int32_t default_height = 765;
1899
1900         /* nudge */
1901
1902         Gtk::Button      nudge_forward_button;
1903         Gtk::Button      nudge_backward_button;
1904         Gtk::HBox        nudge_hbox;
1905         Gtk::VBox        nudge_vbox;
1906         AudioClock*       nudge_clock;
1907
1908         bool nudge_forward_release (GdkEventButton*);
1909         bool nudge_backward_release (GdkEventButton*);
1910
1911         /* audio filters */
1912
1913         void apply_filter (ARDOUR::Filter&, std::string cmd, ProgressReporter* progress = 0);
1914
1915         Command* apply_midi_note_edit_op_to_region (ARDOUR::MidiOperator& op, MidiRegionView& mrv);
1916         void apply_midi_note_edit_op (ARDOUR::MidiOperator& op);
1917
1918         /* handling cleanup */
1919
1920         int playlist_deletion_dialog (boost::shared_ptr<ARDOUR::Playlist>);
1921
1922         PBD::ScopedConnectionList session_connections;
1923
1924         /* tracking step changes of track height */
1925
1926         TimeAxisView* current_stepping_trackview;
1927         ARDOUR::microseconds_t last_track_height_step_timestamp;
1928         gint track_height_step_timeout();
1929         sigc::connection step_timeout;
1930
1931         TimeAxisView* entered_track;
1932         /** If the mouse is over a RegionView or one of its child canvas items, this is set up
1933             to point to the RegionView.  Otherwise it is 0.
1934         */
1935         RegionView*   entered_regionview;
1936
1937
1938         void ensure_entered_track_selected (bool op_acts_on_objects = false);
1939         bool clear_entered_track;
1940         bool left_track_canvas (GdkEventCrossing*);
1941         bool entered_track_canvas (GdkEventCrossing*);
1942         void set_entered_track (TimeAxisView*);
1943         void set_entered_regionview (RegionView*);
1944         void ensure_track_visible (TimeAxisView*);
1945         gint left_automation_track ();
1946
1947         void reset_canvas_action_sensitivity (bool);
1948         void toggle_gain_envelope_visibility ();
1949         void toggle_gain_envelope_active ();
1950         void reset_region_gain_envelopes ();
1951
1952         bool on_key_press_event (GdkEventKey*);
1953         bool on_key_release_event (GdkEventKey*);
1954
1955         void session_state_saved (std::string);
1956
1957         Glib::RefPtr<Gtk::Action>              undo_action;
1958         Glib::RefPtr<Gtk::Action>              redo_action;
1959
1960         void history_changed ();
1961
1962         Gtk::HBox      status_bar_hpacker;
1963
1964         Editing::EditPoint _edit_point;
1965
1966         Gtk::ComboBoxText edit_point_selector;
1967
1968         void set_edit_point_preference (Editing::EditPoint ep, bool force = false);
1969         void cycle_edit_point (bool with_marker);
1970         void set_edit_point ();
1971         void edit_point_selection_done ();
1972         void edit_point_chosen (Editing::EditPoint);
1973         Glib::RefPtr<Gtk::RadioAction> edit_point_action (Editing::EditPoint);
1974         std::vector<std::string> edit_point_strings;
1975
1976         void selected_marker_moved (ARDOUR::Location*);
1977
1978         bool get_edit_op_range (framepos_t& start, framepos_t& end) const;
1979
1980         void get_regions_at (RegionSelection&, framepos_t where, const TrackViewList& ts) const;
1981         void get_regions_after (RegionSelection&, framepos_t where, const TrackViewList& ts) const;
1982
1983         RegionSelection get_regions_from_selection ();
1984         RegionSelection get_regions_from_selection_and_edit_point ();
1985         RegionSelection get_regions_from_selection_and_entered ();
1986
1987         void start_updating_meters ();
1988         void stop_updating_meters ();
1989         bool meters_running;
1990
1991         void select_next_route ();
1992         void select_prev_route ();
1993
1994         void snap_to_internal (framepos_t& first, int32_t direction = 0, bool for_mark = false);
1995         void timecode_snap_to_internal (framepos_t& first, int32_t direction = 0, bool for_mark = false);
1996
1997         RhythmFerret* rhythm_ferret;
1998
1999         void fit_tracks (TrackViewList &);
2000         void fit_selected_tracks ();
2001         void set_track_height (Height);
2002
2003         void remove_tracks ();
2004         void toggle_tracks_active ();
2005
2006         bool _have_idled;
2007         int resize_idle_id;
2008         static gboolean _idle_resize (gpointer);
2009         bool idle_resize();
2010         int32_t _pending_resize_amount;
2011         TimeAxisView* _pending_resize_view;
2012
2013         void visible_order_range (int*, int*) const;
2014
2015         void located ();
2016
2017         /** true if we've made a locate request that hasn't yet been processed */
2018         bool _pending_locate_request;
2019
2020         /** if true, there is a pending Session locate which is the initial one when loading a session;
2021             we need to know this so that we don't (necessarily) set the viewport to show the playhead
2022             initially.
2023         */
2024         bool _pending_initial_locate;
2025
2026         Gtk::HBox _summary_hbox;
2027         EditorSummary* _summary;
2028
2029         void region_view_added (RegionView *);
2030         void region_view_removed ();
2031
2032         void update_canvas_now ();
2033
2034         EditorGroupTabs* _group_tabs;
2035         void fit_route_group (ARDOUR::RouteGroup *);
2036
2037         void step_edit_status_change (bool);
2038         void start_step_editing ();
2039         void stop_step_editing ();
2040         bool check_step_edit ();
2041         sigc::connection step_edit_connection;
2042
2043         double _last_motion_y;
2044
2045         RegionLayeringOrderEditor* layering_order_editor;
2046         void update_region_layering_order_editor ();
2047
2048         /** Track that was the source for the last cut/copy operation.  Used as a place
2049             to paste things iff there is no selected track.
2050         */
2051         TimeAxisView* _last_cut_copy_source_track;
2052
2053         /** true if a change in Selection->regions should change the selection in the region list.
2054             See EditorRegions::selection_changed.
2055         */
2056         bool _region_selection_change_updates_region_list;
2057
2058         void setup_fade_images ();
2059         std::map<ARDOUR::FadeShape, Gtk::Image*> _fade_in_images;
2060         std::map<ARDOUR::FadeShape, Gtk::Image*> _fade_out_images;
2061
2062         Gtk::MenuItem& action_menu_item (std::string const &);
2063         void action_pre_activated (Glib::RefPtr<Gtk::Action> const &);
2064
2065         void set_canvas_cursor_for_region_view (double, RegionView *);
2066
2067         MouseCursors* _cursors;
2068
2069         void resize_text_widgets ();
2070
2071         friend class Drag;
2072         friend class RegionDrag;
2073         friend class RegionMoveDrag;
2074         friend class RegionSpliceDrag;
2075         friend class TrimDrag;
2076         friend class MeterMarkerDrag;
2077         friend class TempoMarkerDrag;
2078         friend class CursorDrag;
2079         friend class FadeInDrag;
2080         friend class FadeOutDrag;
2081         friend class MarkerDrag;
2082         friend class RegionGainDrag;
2083         friend class ControlPointDrag;
2084         friend class LineDrag;
2085         friend class RubberbandSelectDrag;
2086         friend class TimeFXDrag;
2087         friend class ScrubDrag;
2088         friend class SelectionDrag;
2089         friend class RangeMarkerBarDrag;
2090         friend class MouseZoomDrag;
2091         friend class RegionCreateDrag;
2092         friend class RegionMotionDrag;
2093         friend class RegionInsertDrag;
2094
2095         friend class EditorSummary;
2096         friend class EditorGroupTabs;
2097
2098         friend class EditorRoutes;
2099         friend class RhythmFerret;
2100 };
2101
2102 #endif /* __ardour_editor_h__ */