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