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