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