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