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