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