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