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