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