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