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