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