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