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