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