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