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