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