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