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