fd090edee10150c5839f3d7361a032fe87720a17
[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 <sys/time.h>
24
25 #include <cmath>
26 #include <list>
27 #include <map>
28 #include <set>
29 #include <string>
30 #include <vector>
31
32 #include <boost/optional.hpp>
33
34 #include <gtkmm/comboboxtext.h>
35 #include <gtkmm/layout.h>
36
37 #include "gtkmm2ext/selector.h"
38 #include "gtkmm2ext/click_box.h"
39 #include "gtkmm2ext/dndtreeview.h"
40 #include "gtkmm2ext/stateful_button.h"
41 #include "gtkmm2ext/bindings.h"
42
43 #include "pbd/stateful.h"
44 #include "pbd/signals.h"
45
46 #include "ardour/import_status.h"
47 #include "ardour/tempo.h"
48 #include "ardour/location.h"
49 #include "ardour/types.h"
50
51 #include "canvas/fwd.h"
52 #include "canvas/ruler.h"
53
54 #include "ardour_button.h"
55 #include "ardour_dialog.h"
56 #include "ardour_dropdown.h"
57 #include "public_editor.h"
58 #include "editing.h"
59 #include "enums.h"
60 #include "editor_items.h"
61 #include "region_selection.h"
62 #include "selection_memento.h"
63
64 namespace Gtkmm2ext {
65         class TearOff;
66         class Bindings;
67 }
68
69 namespace ARDOUR {
70         class RouteGroup;
71         class Playlist;
72         class AudioPlaylist;
73         class AudioRegion;
74         class Region;
75         class Location;
76         class TempoSection;
77         class Session;
78         class Filter;
79         class ChanCount;
80         class MidiOperator;
81         class Track;
82         class MidiTrack;
83         class AudioTrack;
84 }
85
86 namespace LADSPA {
87         class Plugin;
88 }
89
90 class AnalysisWindow;
91 class AudioClock;
92 class AudioRegionView;
93 class AudioStreamView;
94 class AudioTimeAxisView;
95 class AutomationLine;
96 class AutomationSelection;
97 class AutomationTimeAxisView;
98 class BundleManager;
99 class ButtonJoiner;
100 class ControlPoint;
101 class CursorContext;
102 class DragManager;
103 class EditNoteDialog;
104 class EditorCursor;
105 class EditorGroupTabs;
106 class EditorLocations;
107 class EditorRegions;
108 class EditorRoutes;
109 class EditorRouteGroups;
110 class EditorSnapshots;
111 class EditorSummary;
112 class GroupedButtons;
113 class GUIObjectState;
114 class Marker;
115 class MidiRegionView;
116 class MixerStrip;
117 class MouseCursors;
118 class NoteBase;
119 class PlaylistSelector;
120 class PluginSelector;
121 class ProgressReporter;
122 class RhythmFerret;
123 class RulerDialog;
124 class Selection;
125 class SoundFileOmega;
126 class StreamView;
127 class TempoLines;
128 class TimeAxisView;
129 class TimeFXDialog;
130 class TimeSelection;
131 class RegionLayeringOrderEditor;
132 class VerboseCursor;
133
134 class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARDOUR::SessionHandlePtr
135 {
136  public:
137         Editor ();
138         ~Editor ();
139
140         void             set_session (ARDOUR::Session *);
141         ARDOUR::Session* session() const { return _session; }
142
143         void             first_idle ();
144         virtual bool     have_idled () const { return _have_idled; }
145
146         framepos_t leftmost_sample() const { return leftmost_frame; }
147
148         framecnt_t current_page_samples() const {
149                 return (framecnt_t) _visible_canvas_width * samples_per_pixel;
150         }
151
152         double visible_canvas_height () const {
153                 return _visible_canvas_height;
154         }
155         double trackviews_height () const;
156
157         void cycle_snap_mode ();
158         void next_snap_choice ();
159         void next_snap_choice_music_only ();
160         void next_snap_choice_music_and_time ();
161         void prev_snap_choice ();
162         void prev_snap_choice_music_only ();
163         void prev_snap_choice_music_and_time ();
164         void set_snap_to (Editing::SnapType);
165         void set_snap_mode (Editing::SnapMode);
166         void set_snap_threshold (double pixel_distance) {snap_threshold = pixel_distance;}
167
168         Editing::SnapMode  snap_mode () const;
169         Editing::SnapType  snap_type () const;
170
171         void undo (uint32_t n = 1);
172         void redo (uint32_t n = 1);
173
174         XMLNode& get_state ();
175         int set_state (const XMLNode&, int version);
176
177         void set_mouse_mode (Editing::MouseMode, bool force=true);
178         void step_mouse_mode (bool next);
179         Editing::MouseMode current_mouse_mode () const { return mouse_mode; }
180         Editing::MidiEditMode current_midi_edit_mode () const;
181         void remove_midi_note (ArdourCanvas::Item *, GdkEvent *);
182
183         bool internal_editing() const;
184
185         void foreach_time_axis_view (sigc::slot<void,TimeAxisView&>);
186         void add_to_idle_resize (TimeAxisView*, int32_t);
187
188         RouteTimeAxisView* get_route_view_by_route_id (const PBD::ID& id) const;
189
190         void consider_auditioning (boost::shared_ptr<ARDOUR::Region>);
191         void hide_a_region (boost::shared_ptr<ARDOUR::Region>);
192         void show_a_region (boost::shared_ptr<ARDOUR::Region>);
193
194 #ifdef USE_RUBBERBAND
195         std::vector<std::string> rb_opt_strings;
196         int rb_current_opt;
197 #endif
198
199         /* things that need to be public to be used in the main menubar */
200
201         void new_region_from_selection ();
202         void separate_regions_between (const TimeSelection&);
203         void separate_region_from_selection ();
204         void separate_under_selected_regions ();
205         void separate_region_from_punch ();
206         void separate_region_from_loop ();
207         void separate_regions_using_location (ARDOUR::Location&);
208         void transition_to_rolling (bool forward);
209
210         /* NOTE: these functions assume that the "pixel" coordinate is
211            in canvas coordinates. These coordinates already take into
212            account any scrolling offsets.
213         */
214
215         framepos_t pixel_to_sample_from_event (double pixel) const {
216
217                 /* pixel can be less than zero when motion events
218                    are processed. since we've already run the world->canvas
219                    affine, that means that the location *really* is "off
220                    to the right" and thus really is "before the start".
221                 */
222
223                 if (pixel >= 0) {
224                         return pixel * samples_per_pixel;
225                 } else {
226                         return 0;
227                 }
228         }
229
230         framepos_t pixel_to_sample (double pixel) const {
231                 return pixel * samples_per_pixel;
232         }
233
234         double sample_to_pixel (framepos_t sample) const {
235                 return round (sample / (double) samples_per_pixel);
236         }
237
238         double sample_to_pixel_unrounded (framepos_t sample) const {
239                 return sample / (double) samples_per_pixel;
240         }
241
242         /* selection */
243
244         Selection& get_selection() const { return *selection; }
245         bool get_selection_extents ( framepos_t &start, framepos_t &end );  // the time extents of the current selection, whether Range, Region(s), Control Points, or Notes
246         Selection& get_cut_buffer() const { return *cut_buffer; }
247         void track_mixer_selection ();
248
249         bool extend_selection_to_track (TimeAxisView&);
250
251         void play_selection ();
252         framepos_t get_preroll ();
253         void maybe_locate_with_edit_preroll (framepos_t);
254         void play_with_preroll ();
255         void select_all_in_track (Selection::Operation op);
256         void select_all_objects (Selection::Operation op);
257         void invert_selection_in_track ();
258         void invert_selection ();
259         void deselect_all ();
260         long select_range (framepos_t, framepos_t);
261
262         void set_selected_regionview_from_region_list (boost::shared_ptr<ARDOUR::Region> region, Selection::Operation op = Selection::Set);
263
264         /* tempo */
265
266         void set_show_measures (bool yn);
267         bool show_measures () const { return _show_measures; }
268
269         /* analysis window */
270
271         void analyze_region_selection();
272         void analyze_range_selection();
273
274         /* export */
275
276         void export_audio ();
277         void stem_export ();
278         void export_selection ();
279         void export_range ();
280         void export_region ();
281
282         void add_transport_frame (Gtk::Container&);
283         void add_toplevel_menu (Gtk::Container&);
284         Gtk::HBox& get_status_bar_packer()  { return status_bar_hpacker; }
285
286         void               set_zoom_focus (Editing::ZoomFocus);
287         Editing::ZoomFocus get_zoom_focus () const { return zoom_focus; }
288         framecnt_t         get_current_zoom () const { return samples_per_pixel; }
289         void               cycle_zoom_focus ();
290         void temporal_zoom_step (bool coarser);
291         void ensure_time_axis_view_is_visible (TimeAxisView const & tav, bool at_top);
292         void tav_zoom_step (bool coarser);
293         void tav_zoom_smooth (bool coarser, bool force_all);
294
295         /* stuff that AudioTimeAxisView and related classes use */
296
297         PlaylistSelector& playlist_selector() const;
298         void clear_playlist (boost::shared_ptr<ARDOUR::Playlist>);
299
300         void new_playlists (TimeAxisView* v);
301         void copy_playlists (TimeAxisView* v);
302         void clear_playlists (TimeAxisView* v);
303
304         void get_onscreen_tracks (TrackViewList&);
305
306         Width editor_mixer_strip_width;
307         void maybe_add_mixer_strip_width (XMLNode&);
308         void show_editor_mixer (bool yn);
309         void create_editor_mixer ();
310         void show_editor_list (bool yn);
311         void set_selected_mixer_strip (TimeAxisView&);
312         void mixer_strip_width_changed ();
313         void hide_track_in_display (TimeAxisView* tv, bool apply_to_selection = false);
314
315         /* nudge is initiated by transport controls owned by ARDOUR_UI */
316
317         framecnt_t get_nudge_distance (framepos_t pos, framecnt_t& next);
318         framecnt_t get_paste_offset (framepos_t pos, unsigned paste_count, framecnt_t duration);
319         unsigned get_grid_beat_divisions(framepos_t position);
320         Evoral::Beats get_grid_type_as_beats (bool& success, framepos_t position);
321
322         void nudge_forward (bool next, bool force_playhead);
323         void nudge_backward (bool next, bool force_playhead);
324
325         /* nudge initiated from context menu */
326
327         void nudge_forward_capture_offset ();
328         void nudge_backward_capture_offset ();
329
330         void sequence_regions ();
331
332         /* playhead/screen stuff */
333
334         void set_stationary_playhead (bool yn);
335         void toggle_stationary_playhead ();
336         bool stationary_playhead() const { return _stationary_playhead; }
337
338         void set_follow_playhead (bool yn, bool catch_up = true);
339         void toggle_follow_playhead ();
340         bool follow_playhead() const { return _follow_playhead; }
341         bool dragging_playhead () const { return _dragging_playhead; }
342
343         void toggle_zero_line_visibility ();
344         void set_summary ();
345         void set_group_tabs ();
346         void toggle_measure_visibility ();
347         void toggle_logo_visibility ();
348
349         /* fades */
350
351         void toggle_region_fades (int dir);
352         void update_region_fade_visibility ();
353
354         /* redirect shared ops menu. caller must free returned menu */
355
356         Gtk::Menu* redirect_menu ();
357
358         /* floating windows/transient */
359
360         void ensure_float (Gtk::Window&);
361
362         void show_window ();
363
364         void scroll_tracks_down_line ();
365         void scroll_tracks_up_line ();
366         bool scroll_up_one_track ();
367         bool scroll_down_one_track ();
368
369         void prepare_for_cleanup ();
370         void finish_cleanup ();
371
372         void maximise_editing_space();
373         void restore_editing_space();
374
375         void update_tearoff_visibility();
376         void reattach_all_tearoffs ();
377
378         double get_y_origin () const;
379         void reset_x_origin (framepos_t);
380         void reset_x_origin_to_follow_playhead ();
381         void reset_y_origin (double);
382         void reset_zoom (framecnt_t);
383         void reposition_and_zoom (framepos_t, double);
384
385         framepos_t get_preferred_edit_position (bool ignore_playhead = false,
386                                                 bool use_context_click = false,
387                                                 bool from_outside_canvas = false);
388
389         bool update_mouse_speed ();
390         bool decelerate_mouse_speed ();
391
392         void toggle_meter_updating();
393
394         void show_rhythm_ferret();
395
396         void goto_visual_state (uint32_t);
397         void save_visual_state (uint32_t);
398
399         void queue_draw_resize_line (int at);
400         void start_resize_line_ops ();
401         void end_resize_line_ops ();
402
403         TrackViewList const & get_track_views () {
404                 return track_views;
405         }
406
407         int get_regionview_count_from_region_list (boost::shared_ptr<ARDOUR::Region>);
408
409         void do_import (std::vector<std::string>              paths,
410                         Editing::ImportDisposition            disposition,
411                         Editing::ImportMode                   mode,
412                         ARDOUR::SrcQuality                    quality,
413                         framepos_t&                           pos,
414                         boost::shared_ptr<ARDOUR::PluginInfo> instrument = boost::shared_ptr<ARDOUR::PluginInfo>());
415
416         void do_embed (std::vector<std::string>              paths,
417                        Editing::ImportDisposition            disposition,
418                        Editing::ImportMode                   mode,
419                        framepos_t&                           pos,
420                        boost::shared_ptr<ARDOUR::PluginInfo> instrument = boost::shared_ptr<ARDOUR::PluginInfo>());
421
422         void get_regions_corresponding_to (boost::shared_ptr<ARDOUR::Region> region, std::vector<RegionView*>& regions, bool src_comparison);
423
424         void get_regionviews_by_id (PBD::ID const id, RegionSelection & regions) const;
425         void get_per_region_note_selection (std::list<std::pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > >&) const;
426
427         void center_screen (framepos_t);
428
429         TrackViewList axis_views_from_routes (boost::shared_ptr<ARDOUR::RouteList>) const;
430
431         Gtkmm2ext::TearOff* mouse_mode_tearoff () const { return _mouse_mode_tearoff; }
432         Gtkmm2ext::TearOff* tools_tearoff () const { return _tools_tearoff; }
433
434         void snap_to (framepos_t&       first,
435                       ARDOUR::RoundMode direction = ARDOUR::RoundNearest,
436                       bool              for_mark  = false);
437
438         void snap_to_with_modifier (framepos_t&       first,
439                                     GdkEvent const *  ev,
440                                     ARDOUR::RoundMode direction = ARDOUR::RoundNearest,
441                                     bool              for_mark  = false);
442
443         void snap_to (framepos_t&       first,
444                       framepos_t&       last,
445                       ARDOUR::RoundMode direction = ARDOUR::RoundNearest,
446                       bool              for_mark  = false);
447
448         void begin_selection_op_history ();
449         void begin_reversible_selection_op (std::string cmd_name);
450         void commit_reversible_selection_op ();
451         void undo_selection_op ();
452         void redo_selection_op ();
453         void begin_reversible_command (std::string cmd_name);
454         void begin_reversible_command (GQuark);
455         void abort_reversible_command ();
456         void commit_reversible_command ();
457
458         DragManager* drags () const {
459                 return _drags;
460         }
461
462         void maybe_autoscroll (bool, bool, bool);
463         bool autoscroll_active() const;
464
465         Gdk::Cursor* get_canvas_cursor () const;
466
467         void set_current_trimmable (boost::shared_ptr<ARDOUR::Trimmable>);
468         void set_current_movable (boost::shared_ptr<ARDOUR::Movable>);
469
470         MouseCursors const * cursors () const {
471                 return _cursors;
472         }
473
474         VerboseCursor* verbose_cursor () const {
475                 return _verbose_cursor;
476         }
477
478         double clamp_verbose_cursor_x (double);
479         double clamp_verbose_cursor_y (double);
480
481         void get_pointer_position (double &, double &) const;
482
483         /** Context for mouse entry (stored in a stack). */
484         struct EnterContext {
485                 ItemType                         item_type;
486                 boost::shared_ptr<CursorContext> cursor_ctx;
487         };
488
489         /** Get the topmost enter context for the given item type.
490          *
491          * This is used to change the cursor associated with a given enter context,
492          * which may not be on the top of the stack.
493          */
494         EnterContext* get_enter_context(ItemType type);
495
496         TimeAxisView* stepping_axis_view () {
497                 return _stepping_axis_view;
498         }
499         
500         void set_stepping_axis_view (TimeAxisView* v) {
501                 _stepping_axis_view = v;
502         }
503
504         ArdourCanvas::Container* get_trackview_group () const { return _trackview_group; }
505         ArdourCanvas::Container* get_noscroll_group () const { return no_scroll_group; }
506         ArdourCanvas::ScrollGroup* get_hscroll_group () const { return h_scroll_group; }
507         ArdourCanvas::ScrollGroup* get_hvscroll_group () const { return hv_scroll_group; }
508         ArdourCanvas::ScrollGroup* get_cursor_scroll_group () const { return cursor_scroll_group; }
509
510         ArdourCanvas::GtkCanvasViewport* get_track_canvas () const;
511
512         void override_visible_track_count ();
513
514         /* Ruler metrics methods */
515
516         void metric_get_timecode (std::vector<ArdourCanvas::Ruler::Mark>&, gdouble, gdouble, gint);
517         void metric_get_bbt (std::vector<ArdourCanvas::Ruler::Mark>&, gdouble, gdouble, gint);
518         void metric_get_samples (std::vector<ArdourCanvas::Ruler::Mark>&, gdouble, gdouble, gint);
519         void metric_get_minsec (std::vector<ArdourCanvas::Ruler::Mark>&, gdouble, gdouble, gint);
520
521         /* editing operations that need to be public */
522         void mouse_add_new_marker (framepos_t where, bool is_cd=false);
523         void split_regions_at (framepos_t, RegionSelection&);
524         void split_region_at_points (boost::shared_ptr<ARDOUR::Region>, ARDOUR::AnalysisFeatureList&, bool can_ferret, bool select_new = false);
525         RegionSelection get_regions_from_selection_and_mouse (framepos_t);
526         
527         void mouse_add_new_tempo_event (framepos_t where);
528         void mouse_add_new_meter_event (framepos_t where);
529         void edit_tempo_section (ARDOUR::TempoSection*);
530         void edit_meter_section (ARDOUR::MeterSection*);
531
532   protected:
533         void map_transport_state ();
534         void map_position_change (framepos_t);
535
536         void on_realize();
537
538         void suspend_route_redisplay ();
539         void resume_route_redisplay ();
540
541   private:
542
543         void color_handler ();
544
545         bool                 constructed;
546
547         // to keep track of the playhead position for control_scroll
548         boost::optional<framepos_t> _control_scroll_target;
549
550         PlaylistSelector* _playlist_selector;
551
552         typedef std::pair<TimeAxisView*,XMLNode*> TAVState;
553
554         struct VisualState {
555             VisualState (bool with_tracks);
556             ~VisualState ();
557             double              y_position;
558             framecnt_t          samples_per_pixel;
559             framepos_t          leftmost_frame;
560             Editing::ZoomFocus  zoom_focus;
561             GUIObjectState*     gui_state;
562         };
563
564         std::list<VisualState*> undo_visual_stack;
565         std::list<VisualState*> redo_visual_stack;
566         VisualState* current_visual_state (bool with_tracks = true);
567         void undo_visual_state ();
568         void redo_visual_state ();
569         void use_visual_state (VisualState&);
570         bool no_save_visual;
571         void swap_visual_state ();
572
573         std::vector<VisualState*> visual_states;
574         void start_visual_state_op (uint32_t n);
575         void cancel_visual_state_op (uint32_t n);
576
577         framepos_t         leftmost_frame;
578         framecnt_t         samples_per_pixel;
579         Editing::ZoomFocus zoom_focus;
580
581         void set_samples_per_pixel (framecnt_t);
582
583         Editing::MouseMode mouse_mode;
584         Editing::SnapType  pre_internal_snap_type;
585         Editing::SnapMode  pre_internal_snap_mode;
586         Editing::SnapType  internal_snap_type;
587         Editing::SnapMode  internal_snap_mode;
588         Editing::MouseMode effective_mouse_mode () const;
589
590         enum JoinObjectRangeState {
591                 JOIN_OBJECT_RANGE_NONE,
592                 /** `join object/range' mode is active and the mouse is over a place where object mode should happen */
593                 JOIN_OBJECT_RANGE_OBJECT,
594                 /** `join object/range' mode is active and the mouse is over a place where range mode should happen */
595                 JOIN_OBJECT_RANGE_RANGE
596         };
597
598         JoinObjectRangeState _join_object_range_state;
599
600         void update_join_object_range_location (double);
601
602         boost::optional<int>  pre_notebook_shrink_pane_width;
603
604         void pane_allocation_handler (Gtk::Allocation&, Gtk::Paned*);
605
606         Gtk::Notebook _the_notebook;
607         bool _notebook_shrunk;
608         void add_notebook_page (std::string const &, Gtk::Widget &);
609         bool notebook_tab_clicked (GdkEventButton *, Gtk::Widget *);
610
611         Gtk::HPaned   edit_pane;
612         Gtk::VPaned   editor_summary_pane;
613
614         Gtk::EventBox meter_base;
615         Gtk::HBox     meter_box;
616         Gtk::EventBox marker_base;
617         Gtk::HBox     marker_box;
618         Gtk::VBox     scrollers_rulers_markers_box;
619
620         void location_changed (ARDOUR::Location *);
621         void location_flags_changed (ARDOUR::Location *);
622         void refresh_location_display ();
623         void refresh_location_display_internal (const ARDOUR::Locations::LocationList&);
624         void add_new_location (ARDOUR::Location *);
625         ArdourCanvas::Container* add_new_location_internal (ARDOUR::Location *);
626         void location_gone (ARDOUR::Location *);
627         void remove_marker (ArdourCanvas::Item&, GdkEvent*);
628         gint really_remove_marker (ARDOUR::Location* loc);
629         void goto_nth_marker (int nth);
630         void toggle_marker_lines ();
631         void set_marker_line_visibility (bool);
632
633         uint32_t location_marker_color;
634         uint32_t location_range_color;
635         uint32_t location_loop_color;
636         uint32_t location_punch_color;
637         uint32_t location_cd_marker_color;
638
639         struct LocationMarkers {
640                 Marker* start;
641                 Marker* end;
642                 bool    valid;
643
644                 LocationMarkers () : start(0), end(0), valid (true) {}
645
646                 ~LocationMarkers ();
647
648                 void hide ();
649                 void show ();
650
651                 void set_show_lines (bool);
652                 void set_selected (bool);
653                 void canvas_height_set (double);
654                 void setup_lines ();
655
656                 void set_name (const std::string&);
657                 void set_position (framepos_t start, framepos_t end = 0);
658                 void set_color_rgba (uint32_t);
659         };
660
661         LocationMarkers  *find_location_markers (ARDOUR::Location *) const;
662         ARDOUR::Location* find_location_from_marker (Marker *, bool& is_start) const;
663         Marker* find_marker_from_location_id (PBD::ID const &, bool) const;
664         Marker* entered_marker;
665         bool _show_marker_lines;
666
667         typedef std::map<ARDOUR::Location*,LocationMarkers *> LocationMarkerMap;
668         LocationMarkerMap location_markers;
669
670         void update_marker_labels ();
671         void update_marker_labels (ArdourCanvas::Container *);
672         void check_marker_label (Marker *);
673
674         /** A set of lists of Markers that are in each of the canvas groups
675          *  for the marker sections at the top of the editor.  These lists
676          *  are kept sorted in time order between marker movements, so that after
677          *  a marker has moved we can decide whether we need to update the labels
678          *  for all markers or for just a few.
679          */
680         std::map<ArdourCanvas::Container *, std::list<Marker *> > _sorted_marker_lists;
681         void remove_sorted_marker (Marker *);
682
683         void hide_marker (ArdourCanvas::Item*, GdkEvent*);
684         void clear_marker_display ();
685         void mouse_add_new_range (framepos_t);
686         bool choose_new_marker_name(std::string &name);
687         void update_cd_marker_display ();
688         void ensure_cd_marker_updated (LocationMarkers * lam, ARDOUR::Location * location);
689
690         TimeAxisView*      clicked_axisview;
691         RouteTimeAxisView* clicked_routeview;
692         /** The last RegionView that was clicked on, or 0 if the last click was not
693          * on a RegionView.  This is set up by the canvas event handlers in
694          * editor_canvas_events.cc
695          */
696         RegionView*        clicked_regionview;
697         RegionSelection    latest_regionviews;
698         uint32_t           clicked_selection;
699         ControlPoint*      clicked_control_point;
700
701         void sort_track_selection (TrackViewList&);
702
703         void get_equivalent_regions (RegionView* rv, std::vector<RegionView*> &, PBD::PropertyID) const;
704         RegionSelection get_equivalent_regions (RegionSelection &, PBD::PropertyID) const;
705         void mapover_tracks (sigc::slot<void,RouteTimeAxisView&,uint32_t> sl, TimeAxisView*, PBD::PropertyID) const;
706         void mapover_tracks_with_unique_playlists (sigc::slot<void,RouteTimeAxisView&,uint32_t> sl, TimeAxisView*, PBD::PropertyID) const;
707
708         /* functions to be passed to mapover_tracks(), possibly with sigc::bind()-supplied arguments */
709         void mapped_get_equivalent_regions (RouteTimeAxisView&, uint32_t, RegionView *, std::vector<RegionView*>*) const;
710         void mapped_use_new_playlist (RouteTimeAxisView&, uint32_t, std::vector<boost::shared_ptr<ARDOUR::Playlist> > const &);
711         void mapped_use_copy_playlist (RouteTimeAxisView&, uint32_t, std::vector<boost::shared_ptr<ARDOUR::Playlist> > const &);
712         void mapped_clear_playlist (RouteTimeAxisView&, uint32_t);
713         
714         void button_selection (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type);
715         bool button_release_can_deselect;
716         bool _mouse_changed_selection;
717
718         void catch_vanishing_regionview (RegionView *);
719
720         void set_selected_track (TimeAxisView&, Selection::Operation op = Selection::Set, bool no_remove=false);
721         void select_all_tracks ();
722         bool select_all_internal_edit (Selection::Operation);
723
724         bool set_selected_control_point_from_click (bool press, Selection::Operation op = Selection::Set);
725         void set_selected_track_from_click (bool press, Selection::Operation op = Selection::Set, bool no_remove=false);
726         void set_selected_track_as_side_effect (Selection::Operation op);
727         bool set_selected_regionview_from_click (bool press, Selection::Operation op = Selection::Set);
728
729         bool set_selected_regionview_from_map_event (GdkEventAny*, StreamView*, boost::weak_ptr<ARDOUR::Region>);
730         void collect_new_region_view (RegionView *);
731         void collect_and_select_new_region_view (RegionView *);
732
733         Gtk::Menu track_context_menu;
734         Gtk::Menu track_region_context_menu;
735         Gtk::Menu track_selection_context_menu;
736
737         Gtk::MenuItem* region_edit_menu_split_item;
738         Gtk::MenuItem* region_edit_menu_split_multichannel_item;
739         Gtk::Menu * track_region_edit_playlist_menu;
740         Gtk::Menu * track_edit_playlist_submenu;
741         Gtk::Menu * track_selection_edit_playlist_submenu;
742
743         GdkEvent context_click_event;
744
745         void popup_track_context_menu (int, int, ItemType, bool);
746         Gtk::Menu* build_track_context_menu ();
747         Gtk::Menu* build_track_bus_context_menu ();
748         Gtk::Menu* build_track_region_context_menu ();
749         Gtk::Menu* build_track_selection_context_menu ();
750         void add_dstream_context_items (Gtk::Menu_Helpers::MenuList&);
751         void add_bus_context_items (Gtk::Menu_Helpers::MenuList&);
752         void add_region_context_items (Gtk::Menu_Helpers::MenuList&, boost::shared_ptr<ARDOUR::Track>);
753         void add_selection_context_items (Gtk::Menu_Helpers::MenuList&);
754         Gtk::MenuItem* _popup_region_menu_item;
755
756         void popup_control_point_context_menu (ArdourCanvas::Item *, GdkEvent *);
757         Gtk::Menu _control_point_context_menu;
758
759         void popup_note_context_menu (ArdourCanvas::Item *, GdkEvent *);
760         Gtk::Menu _note_context_menu;
761
762         void add_routes (ARDOUR::RouteList&);
763         void timeaxisview_deleted (TimeAxisView *);
764
765         Gtk::HBox           global_hpacker;
766         Gtk::VBox           global_vpacker;
767         Gtk::VBox           vpacker;
768
769         /* Cursor stuff.  Do not use directly, use via CursorContext. */
770         friend class CursorContext;
771         std::vector<Gdk::Cursor*> _cursor_stack;
772         void set_canvas_cursor (Gdk::Cursor*);
773         size_t push_canvas_cursor (Gdk::Cursor*);
774         void pop_canvas_cursor ();
775
776         Gdk::Cursor* which_grabber_cursor () const;
777         Gdk::Cursor* which_track_cursor () const;
778         Gdk::Cursor* which_mode_cursor () const;
779         Gdk::Cursor* which_trim_cursor (bool left_side) const;
780         Gdk::Cursor* which_canvas_cursor (ItemType type) const;
781
782         /** Push the appropriate enter/cursor context on item entry. */
783         void choose_canvas_cursor_on_entry (ItemType);
784
785         /** Update all enter cursors based on current settings. */
786         void update_all_enter_cursors ();
787
788         ArdourCanvas::GtkCanvas* _track_canvas;
789         ArdourCanvas::GtkCanvasViewport* _track_canvas_viewport;
790
791         bool within_track_canvas;
792
793         friend class VerboseCursor;
794         VerboseCursor* _verbose_cursor;
795
796         void parameter_changed (std::string);
797         void ui_parameter_changed (std::string);
798
799         Gtk::EventBox             time_bars_event_box;
800         Gtk::VBox                 time_bars_vbox;
801
802         ArdourCanvas::Pixbuf     *logo_item;
803 #if 0    
804     /* these will be needed when we have canvas rulers */
805         ArdourCanvas::Container      *minsec_group;
806         ArdourCanvas::Container      *bbt_group;
807         ArdourCanvas::Container      *timecode_group;
808         ArdourCanvas::Container      *frame_group;
809 #endif
810
811         ArdourCanvas::Container      *tempo_group;
812         ArdourCanvas::Container      *meter_group;
813         ArdourCanvas::Container      *marker_group;
814         ArdourCanvas::Container      *range_marker_group;
815         ArdourCanvas::Container      *transport_marker_group;
816         ArdourCanvas::Container*      cd_marker_group;
817
818         /* parent for groups which themselves contain time markers */
819         ArdourCanvas::Container*     _time_markers_group;
820
821         /* The group containing all other groups that are scrolled vertically
822            and horizontally.
823         */
824         ArdourCanvas::ScrollGroup* hv_scroll_group;
825
826         /* The group containing all other groups that are scrolled horizontally ONLY
827         */
828         ArdourCanvas::ScrollGroup* h_scroll_group;
829
830         /* Scroll group for cursors, scrolled horizontally, above everything else
831         */
832         ArdourCanvas::ScrollGroup* cursor_scroll_group;
833
834         /* The group containing all trackviews. */
835         ArdourCanvas::Container* no_scroll_group;
836
837         /* The group containing all trackviews. */
838         ArdourCanvas::Container* _trackview_group;
839
840         /* The group holding things (mostly regions) while dragging so they
841          * are on top of everything else
842          */
843         ArdourCanvas::Container* _drag_motion_group;
844
845         /* a rect that sits at the bottom of all tracks to act as a drag-no-drop/clickable
846          * target area.
847          */
848         ArdourCanvas::Rectangle* _canvas_drop_zone;
849         bool canvas_drop_zone_event (GdkEvent* event);
850
851         enum RulerType {
852                 ruler_metric_timecode = 0,
853                 ruler_metric_bbt = 1,
854                 ruler_metric_samples = 2,
855                 ruler_metric_minsec = 3,
856
857                 ruler_time_tempo = 4,
858                 ruler_time_meter = 5,
859                 ruler_time_marker = 6,
860                 ruler_time_range_marker = 7,
861                 ruler_time_transport_marker = 8,
862                 ruler_time_cd_marker = 9,
863                 ruler_video_timeline = 10,
864         };
865
866         Glib::RefPtr<Gtk::ToggleAction> ruler_timecode_action;
867         Glib::RefPtr<Gtk::ToggleAction> ruler_bbt_action;
868         Glib::RefPtr<Gtk::ToggleAction> ruler_samples_action;
869         Glib::RefPtr<Gtk::ToggleAction> ruler_minsec_action;
870         Glib::RefPtr<Gtk::ToggleAction> ruler_tempo_action;
871         Glib::RefPtr<Gtk::ToggleAction> ruler_meter_action;
872         Glib::RefPtr<Gtk::ToggleAction> ruler_marker_action;
873         Glib::RefPtr<Gtk::ToggleAction> ruler_range_action;
874         Glib::RefPtr<Gtk::ToggleAction> ruler_loop_punch_action;
875         Glib::RefPtr<Gtk::ToggleAction> ruler_cd_marker_action;
876         bool                            no_ruler_shown_update;
877
878         Gtk::Widget * ruler_grabbed_widget;
879
880         RulerDialog* ruler_dialog;
881
882         void initialize_rulers ();
883         void update_just_timecode ();
884         void compute_fixed_ruler_scale (); //calculates the RulerScale of the fixed rulers
885         void update_fixed_rulers ();
886         void update_tempo_based_rulers (ARDOUR::TempoMap::BBTPointList::const_iterator& begin,
887                                         ARDOUR::TempoMap::BBTPointList::const_iterator& end);
888         void popup_ruler_menu (framepos_t where = 0, ItemType type = RegionItem);
889         void update_ruler_visibility ();
890         void set_ruler_visible (RulerType, bool);
891         void toggle_ruler_visibility (RulerType rt);
892         void ruler_toggled (int);
893         bool ruler_label_button_release (GdkEventButton*);
894         void store_ruler_visibility ();
895         void restore_ruler_visibility ();
896
897
898
899                 enum MinsecRulerScale {
900                 minsec_show_msecs,
901                 minsec_show_seconds,
902                 minsec_show_minutes,
903                 minsec_show_hours,
904                 minsec_show_many_hours
905         };
906
907         MinsecRulerScale minsec_ruler_scale;
908
909         framecnt_t minsec_mark_interval;
910         gint minsec_mark_modulo;
911         gint minsec_nmarks;
912         void set_minsec_ruler_scale (framepos_t, framepos_t);
913
914         enum TimecodeRulerScale {
915                 timecode_show_bits,
916                 timecode_show_frames,
917                 timecode_show_seconds,
918                 timecode_show_minutes,
919                 timecode_show_hours,
920                 timecode_show_many_hours
921         };
922
923         TimecodeRulerScale timecode_ruler_scale;
924
925         gint timecode_mark_modulo;
926         gint timecode_nmarks;
927         void set_timecode_ruler_scale (framepos_t, framepos_t);
928
929         framecnt_t _samples_ruler_interval;
930         void set_samples_ruler_scale (framepos_t, framepos_t);
931
932         enum BBTRulerScale {
933                 bbt_show_many,
934                 bbt_show_64,
935                 bbt_show_16,
936                 bbt_show_4,
937                 bbt_show_1,
938                 bbt_show_beats,
939                 bbt_show_ticks,
940                 bbt_show_ticks_detail,
941                 bbt_show_ticks_super_detail
942         };
943
944         BBTRulerScale bbt_ruler_scale;
945
946         uint32_t bbt_bars;
947         gint bbt_nmarks;
948         uint32_t bbt_bar_helper_on;
949         uint32_t bbt_accent_modulo;
950         void compute_bbt_ruler_scale (framepos_t lower, framepos_t upper,
951                                       ARDOUR::TempoMap::BBTPointList::const_iterator current_bbt_points_begin,
952                                       ARDOUR::TempoMap::BBTPointList::const_iterator current_bbt_points_end);
953
954         ArdourCanvas::Ruler* timecode_ruler;
955         ArdourCanvas::Ruler* bbt_ruler;
956         ArdourCanvas::Ruler* samples_ruler;
957         ArdourCanvas::Ruler* minsec_ruler;
958
959         static double timebar_height;
960         guint32 visible_timebars;
961         Gtk::Menu          *editor_ruler_menu;
962
963         ArdourCanvas::Rectangle* tempo_bar;
964         ArdourCanvas::Rectangle* meter_bar;
965         ArdourCanvas::Rectangle* marker_bar;
966         ArdourCanvas::Rectangle* range_marker_bar;
967         ArdourCanvas::Rectangle* transport_marker_bar;
968         ArdourCanvas::Rectangle* cd_marker_bar;
969
970         Gtk::Label  minsec_label;
971         Gtk::Label  bbt_label;
972         Gtk::Label  timecode_label;
973         Gtk::Label  samples_label;
974         Gtk::Label  tempo_label;
975         Gtk::Label  meter_label;
976         Gtk::Label  mark_label;
977         Gtk::Label  range_mark_label;
978         Gtk::Label  transport_mark_label;
979         Gtk::Label  cd_mark_label;
980
981         /* videtimline related actions */
982         Gtk::Label                videotl_label;
983         ArdourCanvas::Container*      videotl_group;
984         Glib::RefPtr<Gtk::ToggleAction> ruler_video_action;
985         Glib::RefPtr<Gtk::ToggleAction> xjadeo_proc_action;
986         Glib::RefPtr<Gtk::ToggleAction> xjadeo_ontop_action;
987         Glib::RefPtr<Gtk::ToggleAction> xjadeo_timecode_action;
988         Glib::RefPtr<Gtk::ToggleAction> xjadeo_frame_action;
989         Glib::RefPtr<Gtk::ToggleAction> xjadeo_osdbg_action;
990         Glib::RefPtr<Gtk::ToggleAction> xjadeo_fullscreen_action;
991         Glib::RefPtr<Gtk::ToggleAction> xjadeo_letterbox_action;
992         Glib::RefPtr<Gtk::Action> xjadeo_zoom_100;
993         void set_xjadeo_proc ();
994         void toggle_xjadeo_proc (int state=-1);
995         void set_close_video_sensitive (bool onoff);
996         void set_xjadeo_sensitive (bool onoff);
997         void set_xjadeo_viewoption (int);
998         void toggle_xjadeo_viewoption (int what, int state=-1);
999         void toggle_ruler_video (bool onoff) {ruler_video_action->set_active(onoff);}
1000         int videotl_bar_height; /* in units of timebar_height; default: 4 */
1001         int get_videotl_bar_height () const { return videotl_bar_height; }
1002         void export_video (bool range = false);
1003         void toggle_region_video_lock ();
1004
1005         friend class EditorCursor;
1006
1007         EditorCursor*        playhead_cursor;
1008
1009         framepos_t get_region_boundary (framepos_t pos, int32_t dir, bool with_selection, bool only_onscreen);
1010
1011         void    cursor_to_region_boundary (bool with_selection, int32_t dir);
1012         void    cursor_to_next_region_boundary (bool with_selection);
1013         void    cursor_to_previous_region_boundary (bool with_selection);
1014         void    cursor_to_next_region_point (EditorCursor*, ARDOUR::RegionPoint);
1015         void    cursor_to_previous_region_point (EditorCursor*, ARDOUR::RegionPoint);
1016         void    cursor_to_region_point (EditorCursor*, ARDOUR::RegionPoint, int32_t dir);
1017         void    cursor_to_selection_start (EditorCursor *);
1018         void    cursor_to_selection_end   (EditorCursor *);
1019
1020         void    selected_marker_to_region_boundary (bool with_selection, int32_t dir);
1021         void    selected_marker_to_next_region_boundary (bool with_selection);
1022         void    selected_marker_to_previous_region_boundary (bool with_selection);
1023         void    selected_marker_to_next_region_point (ARDOUR::RegionPoint);
1024         void    selected_marker_to_previous_region_point (ARDOUR::RegionPoint);
1025         void    selected_marker_to_region_point (ARDOUR::RegionPoint, int32_t dir);
1026         void    selected_marker_to_selection_start ();
1027         void    selected_marker_to_selection_end   ();
1028
1029         void    select_all_selectables_using_cursor (EditorCursor *, bool);
1030         void    select_all_selectables_using_edit (bool);
1031         void    select_all_selectables_between (bool within);
1032         void    select_range_between ();
1033
1034         boost::shared_ptr<ARDOUR::Region> find_next_region (ARDOUR::framepos_t, ARDOUR::RegionPoint, int32_t dir, TrackViewList&, TimeAxisView ** = 0);
1035         ARDOUR::framepos_t find_next_region_boundary (ARDOUR::framepos_t, int32_t dir, const TrackViewList&);
1036
1037         std::vector<ARDOUR::framepos_t> region_boundary_cache;
1038         void build_region_boundary_cache ();
1039
1040         Gtk::HBox           toplevel_hpacker;
1041
1042         Gtk::HBox           top_hbox;
1043         Gtk::HBox           bottom_hbox;
1044
1045         Gtk::Table          edit_packer;
1046
1047         /** the adjustment that controls the overall editor vertical scroll position */
1048         Gtk::Adjustment     vertical_adjustment;
1049         Gtk::Adjustment     horizontal_adjustment;
1050
1051         Gtk::Adjustment     unused_adjustment; // yes, really; Gtk::Layout constructor requires refs
1052         Gtk::Layout         controls_layout;
1053         bool control_layout_scroll (GdkEventScroll* ev);
1054         void reset_controls_layout_width ();
1055         void reset_controls_layout_height (int32_t height);
1056
1057         enum Direction {
1058                 LEFT,
1059                 RIGHT,
1060                 UP,
1061                 DOWN
1062         };
1063
1064         bool scroll_press (Direction);
1065         void scroll_release ();
1066         sigc::connection _scroll_connection;
1067         int _scroll_callbacks;
1068
1069         double _visible_canvas_width;
1070         double _visible_canvas_height; ///< height of the visible area of the track canvas
1071         double _full_canvas_height;    ///< full height of the canvas
1072
1073         bool track_canvas_map_handler (GdkEventAny*);
1074
1075         bool edit_controls_button_release (GdkEventButton*);
1076         Gtk::Menu *edit_controls_left_menu;
1077         Gtk::Menu *edit_controls_right_menu;
1078
1079         Gtk::VBox           track_canvas_vbox;
1080         Gtk::VBox           edit_controls_vbox;
1081         Gtk::HBox           edit_controls_hbox;
1082
1083         void control_vertical_zoom_in_all ();
1084         void control_vertical_zoom_out_all ();
1085         void control_vertical_zoom_in_selected ();
1086         void control_vertical_zoom_out_selected ();
1087         void control_step_tracks_up ();
1088         void control_step_tracks_down ();
1089         void control_view (uint32_t);
1090         void control_scroll (float);
1091         void control_select (uint32_t rid, Selection::Operation);
1092         void control_unselect ();
1093         void access_action (std::string,std::string);
1094         bool deferred_control_scroll (framepos_t);
1095         sigc::connection control_scroll_connection;
1096
1097         void tie_vertical_scrolling ();
1098         void set_horizontal_position (double);
1099         double horizontal_position () const;
1100
1101         struct VisualChange {
1102                 enum Type {
1103                         TimeOrigin = 0x1,
1104                         ZoomLevel = 0x2,
1105                         YOrigin = 0x4
1106                 };
1107
1108                 Type       pending;
1109                 framepos_t time_origin;
1110                 framecnt_t samples_per_pixel;
1111                 double     y_origin;
1112
1113                 int idle_handler_id;
1114                 /** true if we are currently in the idle handler */
1115                 bool being_handled;
1116
1117                 VisualChange() : pending ((VisualChange::Type) 0), time_origin (0), samples_per_pixel (0), idle_handler_id (-1), being_handled (false) {}
1118                 void add (Type t) {
1119                         pending = Type (pending | t);
1120                 }
1121         };
1122
1123         VisualChange pending_visual_change;
1124
1125         static int _idle_visual_changer (void *arg);
1126         int idle_visual_changer ();
1127         void visual_changer (const VisualChange&);
1128         void ensure_visual_change_idle_handler ();
1129
1130         /* track views */
1131         TrackViewList track_views;
1132         std::pair<TimeAxisView*, double> trackview_by_y_position (double, bool trackview_relative_offset = true) const;
1133         RouteTimeAxisView* axis_view_from_route (boost::shared_ptr<ARDOUR::Route>) const;
1134
1135         TrackViewList get_tracks_for_range_action () const;
1136
1137         sigc::connection super_rapid_screen_update_connection;
1138         framepos_t last_update_frame;
1139         void center_screen_internal (framepos_t, float);
1140
1141         void super_rapid_screen_update ();
1142
1143         void session_going_away ();
1144
1145         framepos_t cut_buffer_start;
1146         framecnt_t cut_buffer_length;
1147
1148         boost::shared_ptr<CursorContext> _press_cursor_ctx;  ///< Button press cursor context
1149
1150         boost::weak_ptr<ARDOUR::Trimmable> _trimmable;
1151         boost::weak_ptr<ARDOUR::Movable> _movable;
1152
1153         bool typed_event (ArdourCanvas::Item*, GdkEvent*, ItemType);
1154         bool button_press_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1155         bool button_press_handler_1 (ArdourCanvas::Item *, GdkEvent *, ItemType);
1156         bool button_press_handler_2 (ArdourCanvas::Item *, GdkEvent *, ItemType);
1157         bool button_release_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1158         bool button_double_click_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1159         bool button_press_dispatch (GdkEventButton*);
1160         bool button_release_dispatch (GdkEventButton*);
1161         bool motion_handler (ArdourCanvas::Item*, GdkEvent*, bool from_autoscroll = false);
1162         bool enter_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1163         bool leave_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1164         bool key_press_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1165         bool key_release_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1166
1167         Gtkmm2ext::Bindings* button_bindings;
1168         XMLNode* button_settings () const;
1169
1170         /* KEYMAP HANDLING */
1171
1172         void register_actions ();
1173         void register_region_actions ();
1174
1175         void load_bindings ();
1176         Gtkmm2ext::ActionMap editor_action_map;
1177         Gtkmm2ext::Bindings  key_bindings;
1178
1179         /* CUT/COPY/PASTE */
1180
1181         framepos_t last_paste_pos;
1182         unsigned   paste_count;
1183
1184         void cut_copy (Editing::CutCopyOp);
1185         bool can_cut_copy () const;
1186         void cut_copy_points (Editing::CutCopyOp, Evoral::Beats earliest=Evoral::Beats(), bool midi=false);
1187         void cut_copy_regions (Editing::CutCopyOp, RegionSelection&);
1188         void cut_copy_ranges (Editing::CutCopyOp);
1189         void cut_copy_midi (Editing::CutCopyOp);
1190
1191         void mouse_paste ();
1192         void paste_internal (framepos_t position, float times);
1193
1194         /* EDITING OPERATIONS */
1195
1196         void reset_point_selection ();
1197         void toggle_region_lock ();
1198         void toggle_opaque_region ();
1199         void toggle_record_enable ();
1200         void toggle_solo ();
1201         void toggle_solo_isolate ();
1202         void toggle_mute ();
1203         void toggle_region_lock_style ();
1204
1205         enum LayerOperation {
1206                 Raise,
1207                 RaiseToTop,
1208                 Lower,
1209                 LowerToBottom
1210         };
1211
1212         void do_layer_operation (LayerOperation);
1213         void raise_region ();
1214         void raise_region_to_top ();
1215         void change_region_layering_order (bool from_context_menu);
1216         void lower_region ();
1217         void lower_region_to_bottom ();
1218         void split_region_at_transients ();
1219         void crop_region_to_selection ();
1220         void crop_region_to (framepos_t start, framepos_t end);
1221         void set_sync_point (framepos_t, const RegionSelection&);
1222         void set_region_sync_position ();
1223         void remove_region_sync();
1224         void align_regions (ARDOUR::RegionPoint);
1225         void align_regions_relative (ARDOUR::RegionPoint point);
1226         void align_region (boost::shared_ptr<ARDOUR::Region>, ARDOUR::RegionPoint point, framepos_t position);
1227         void align_region_internal (boost::shared_ptr<ARDOUR::Region>, ARDOUR::RegionPoint point, framepos_t position);
1228         void remove_selected_regions ();
1229         void remove_clicked_region ();
1230         void show_region_properties ();
1231         void show_midi_list_editor ();
1232         void rename_region ();
1233         void duplicate_some_regions (RegionSelection&, float times);
1234         void duplicate_selection (float times);
1235         void region_fill_selection ();
1236         void combine_regions ();
1237         void uncombine_regions ();
1238
1239         void region_fill_track ();
1240         void audition_playlist_region_standalone (boost::shared_ptr<ARDOUR::Region>);
1241         void audition_playlist_region_via_route (boost::shared_ptr<ARDOUR::Region>, ARDOUR::Route&);
1242         void split_multichannel_region();
1243         void reverse_region ();
1244         void strip_region_silence ();
1245         void normalize_region ();
1246         void reset_region_scale_amplitude ();
1247         void adjust_region_gain (bool up);
1248         void quantize_region ();
1249         void quantize_regions (const RegionSelection& rs);
1250         void legatize_region (bool shrink_only);
1251         void legatize_regions (const RegionSelection& rs, bool shrink_only);
1252         void transform_region ();
1253         void transform_regions (const RegionSelection& rs);
1254         void insert_patch_change (bool from_context);
1255         void fork_region ();
1256
1257         void do_insert_time ();
1258         void insert_time (framepos_t, framecnt_t, Editing::InsertTimeOption, bool, bool, bool, bool, bool, bool);
1259
1260         void tab_to_transient (bool forward);
1261
1262         void set_tempo_from_region ();
1263         void use_range_as_bar ();
1264
1265         void define_one_bar (framepos_t start, framepos_t end);
1266
1267         void audition_region_from_region_list ();
1268         void hide_region_from_region_list ();
1269         void show_region_in_region_list ();
1270
1271         void naturalize_region ();
1272
1273         void reset_focus ();
1274
1275         void split_region ();
1276
1277         void delete_ ();
1278         void cut ();
1279         void copy ();
1280         void paste (float times, bool from_context_menu = false);
1281
1282         void place_transient ();
1283         void remove_transient (ArdourCanvas::Item* item);
1284         void snap_regions_to_grid ();
1285         void close_region_gaps ();
1286
1287         void keyboard_paste ();
1288
1289         void region_from_selection ();
1290         void create_region_from_selection (std::vector<boost::shared_ptr<ARDOUR::Region> >&);
1291
1292         void play_from_start ();
1293         void play_from_edit_point ();
1294         void play_from_edit_point_and_return ();
1295         void play_selected_region ();
1296         void play_edit_range ();
1297         void play_location (ARDOUR::Location&);
1298         void loop_location (ARDOUR::Location&);
1299
1300         void calc_extra_zoom_edges(framepos_t &start, framepos_t &end);
1301         void temporal_zoom_selection (bool both_axes = false);
1302         void temporal_zoom_region (bool both_axes);
1303         void temporal_zoom_session ();
1304         void temporal_zoom (framecnt_t samples_per_pixel);
1305         void temporal_zoom_by_frame (framepos_t start, framepos_t end);
1306         void temporal_zoom_to_frame (bool coarser, framepos_t frame);
1307
1308         void insert_region_list_selection (float times);
1309
1310         /* import & embed */
1311
1312         void add_external_audio_action (Editing::ImportMode);
1313         void external_audio_dialog ();
1314         void session_import_dialog ();
1315
1316         int  check_whether_and_how_to_import(std::string, bool all_or_nothing = true);
1317         bool check_multichannel_status (const std::vector<std::string>& paths);
1318
1319         SoundFileOmega* sfbrowser;
1320
1321         void bring_in_external_audio (Editing::ImportMode mode,  framepos_t& pos);
1322
1323         bool  idle_drop_paths  (std::vector<std::string> paths, framepos_t frame, double ypos, bool copy);
1324         void  drop_paths_part_two  (const std::vector<std::string>& paths, framepos_t frame, double ypos, bool copy);
1325
1326         int import_sndfiles (std::vector<std::string>              paths,
1327                              Editing::ImportDisposition            disposition,
1328                              Editing::ImportMode                   mode,
1329                              ARDOUR::SrcQuality                    quality,
1330                              framepos_t&                           pos,
1331                              int                                   target_regions,
1332                              int                                   target_tracks,
1333                              boost::shared_ptr<ARDOUR::Track>&     track,
1334                              bool                                  replace,
1335                              boost::shared_ptr<ARDOUR::PluginInfo> instrument = boost::shared_ptr<ARDOUR::PluginInfo>());
1336
1337         int embed_sndfiles (std::vector<std::string>              paths,
1338                             bool                                  multiple_files,
1339                             bool&                                 check_sample_rate,
1340                             Editing::ImportDisposition            disposition,
1341                             Editing::ImportMode                   mode,
1342                             framepos_t&                           pos,
1343                             int                                   target_regions,
1344                             int                                   target_tracks,
1345                             boost::shared_ptr<ARDOUR::Track>&     track,
1346                             boost::shared_ptr<ARDOUR::PluginInfo> instrument = boost::shared_ptr<ARDOUR::PluginInfo>());
1347
1348         int add_sources (std::vector<std::string>              paths,
1349                          ARDOUR::SourceList&                   sources,
1350                          framepos_t&                           pos,
1351                          Editing::ImportDisposition            disposition,
1352                          Editing::ImportMode                   mode,
1353                          int                                   target_regions,
1354                          int                                   target_tracks,
1355                          boost::shared_ptr<ARDOUR::Track>&     track,
1356                          bool                                  add_channel_suffix,
1357                          boost::shared_ptr<ARDOUR::PluginInfo> instrument = boost::shared_ptr<ARDOUR::PluginInfo>());
1358
1359         int finish_bringing_in_material (boost::shared_ptr<ARDOUR::Region>     region,
1360                                          uint32_t                              in_chans,
1361                                          uint32_t                              out_chans,
1362                                          framepos_t&                           pos,
1363                                          Editing::ImportMode                   mode,
1364                                          boost::shared_ptr<ARDOUR::Track>&     existing_track,
1365                                          const std::string&                    new_track_name,
1366                                          boost::shared_ptr<ARDOUR::PluginInfo> instrument);
1367
1368         boost::shared_ptr<ARDOUR::AudioTrack> get_nth_selected_audio_track (int nth) const;
1369         boost::shared_ptr<ARDOUR::MidiTrack> get_nth_selected_midi_track (int nth) const;
1370
1371         void toggle_midi_input_active (bool flip_others);
1372
1373         ARDOUR::InterThreadInfo* current_interthread_info;
1374
1375         AnalysisWindow* analysis_window;
1376
1377         /* import specific info */
1378
1379         struct EditorImportStatus : public ARDOUR::ImportStatus {
1380             Editing::ImportMode mode;
1381             framepos_t pos;
1382             int target_tracks;
1383             int target_regions;
1384             boost::shared_ptr<ARDOUR::Track> track;
1385             bool replace;
1386         };
1387
1388         EditorImportStatus import_status;
1389         static void *_import_thread (void *);
1390         void* import_thread ();
1391         void finish_import ();
1392
1393         /* to support this ... */
1394
1395         void import_audio (bool as_tracks);
1396         void do_import (std::vector<std::string> paths, bool split, bool as_tracks);
1397
1398         void move_to_start ();
1399         void move_to_end ();
1400         void center_playhead ();
1401         void center_edit_point ();
1402         void playhead_forward_to_grid ();
1403         void playhead_backward_to_grid ();
1404         void scroll_playhead (bool forward);
1405         void scroll_backward (float pages=0.8f);
1406         void scroll_forward (float pages=0.8f);
1407         void scroll_tracks_down ();
1408         void scroll_tracks_up ();
1409         void set_mark ();
1410         void clear_markers ();
1411         void clear_ranges ();
1412         void clear_locations ();
1413         void unhide_markers ();
1414         void unhide_ranges ();
1415         void jump_forward_to_mark ();
1416         void jump_backward_to_mark ();
1417         void cursor_align (bool playhead_to_edit);
1418         void toggle_skip_playback ();
1419
1420         void remove_last_capture ();
1421         void select_all_selectables_using_time_selection ();
1422         void select_all_selectables_using_loop();
1423         void select_all_selectables_using_punch();
1424         void set_selection_from_range (ARDOUR::Location&);
1425         void set_selection_from_punch ();
1426         void set_selection_from_loop ();
1427         void set_selection_from_region ();
1428
1429         void add_location_mark (framepos_t where);
1430         void add_location_from_region ();
1431         void add_locations_from_region ();
1432         void add_location_from_selection ();
1433         void set_loop_from_selection (bool play);
1434         void set_punch_from_selection ();
1435         void set_punch_from_region ();
1436
1437         void set_session_extents_from_selection ();
1438
1439         void set_loop_from_region (bool play);
1440
1441         void set_loop_range (framepos_t start, framepos_t end, std::string cmd);
1442         void set_punch_range (framepos_t start, framepos_t end, std::string cmd);
1443
1444         void add_location_from_playhead_cursor ();
1445         void remove_location_at_playhead_cursor ();
1446         bool select_new_marker;
1447
1448         void reverse_selection ();
1449         void edit_envelope ();
1450
1451         double last_scrub_x;
1452         int scrubbing_direction;
1453         int scrub_reversals;
1454         int scrub_reverse_distance;
1455         void scrub (framepos_t, double);
1456
1457         void keyboard_selection_begin ();
1458         void keyboard_selection_finish (bool add);
1459         bool have_pending_keyboard_selection;
1460         framepos_t pending_keyboard_selection_start;
1461
1462         void move_range_selection_start_or_end_to_region_boundary (bool, bool);
1463
1464         Editing::SnapType _snap_type;
1465         Editing::SnapMode _snap_mode;
1466
1467         /// Snap threshold in pixels
1468         double snap_threshold;
1469
1470         bool ignore_gui_changes;
1471
1472         DragManager* _drags;
1473
1474         void escape ();
1475         void lock ();
1476         void unlock ();
1477         Gtk::Dialog* lock_dialog;
1478
1479         struct timeval last_event_time;
1480         bool generic_event_handler (GdkEvent*);
1481         bool lock_timeout_callback ();
1482         void start_lock_event_timing ();
1483
1484         Gtk::Menu fade_context_menu;
1485
1486         Gtk::Menu xfade_in_context_menu;
1487         Gtk::Menu xfade_out_context_menu;
1488         void popup_xfade_in_context_menu (int, int, ArdourCanvas::Item*, ItemType);
1489         void popup_xfade_out_context_menu (int, int, ArdourCanvas::Item*, ItemType);
1490         void fill_xfade_menu (Gtk::Menu_Helpers::MenuList& items, bool start);
1491
1492         void set_fade_in_shape (ARDOUR::FadeShape);
1493         void set_fade_out_shape (ARDOUR::FadeShape);
1494
1495         void set_fade_length (bool in);
1496         void set_fade_in_active (bool);
1497         void set_fade_out_active (bool);
1498
1499         void fade_range ();
1500
1501         std::set<boost::shared_ptr<ARDOUR::Playlist> > motion_frozen_playlists;
1502
1503         bool _dragging_playhead;
1504         bool _dragging_edit_point;
1505
1506         void marker_drag_motion_callback (GdkEvent*);
1507         void marker_drag_finished_callback (GdkEvent*);
1508
1509         gint mouse_rename_region (ArdourCanvas::Item*, GdkEvent*);
1510
1511         void add_region_drag (ArdourCanvas::Item*, GdkEvent*, RegionView*);
1512         void start_create_region_grab (ArdourCanvas::Item*, GdkEvent*);
1513         void add_region_copy_drag (ArdourCanvas::Item*, GdkEvent*, RegionView*);
1514         void add_region_brush_drag (ArdourCanvas::Item*, GdkEvent*, RegionView*);
1515         void start_selection_grab (ArdourCanvas::Item*, GdkEvent*);
1516
1517         void region_view_item_click (AudioRegionView&, GdkEventButton*);
1518
1519         bool can_remove_control_point (ArdourCanvas::Item *);
1520         void remove_control_point (ArdourCanvas::Item *);
1521
1522         void mouse_brush_insert_region (RegionView*, framepos_t pos);
1523
1524         /* Canvas event handlers */
1525
1526         bool canvas_scroll_event (GdkEventScroll* event, bool from_canvas);
1527         bool canvas_control_point_event (GdkEvent* event,ArdourCanvas::Item*, ControlPoint*);
1528         bool canvas_line_event (GdkEvent* event,ArdourCanvas::Item*, AutomationLine*);
1529         bool canvas_selection_rect_event (GdkEvent* event,ArdourCanvas::Item*, SelectionRect*);
1530         bool canvas_selection_start_trim_event (GdkEvent* event,ArdourCanvas::Item*, SelectionRect*);
1531         bool canvas_selection_end_trim_event (GdkEvent* event,ArdourCanvas::Item*, SelectionRect*);
1532         bool canvas_start_xfade_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1533         bool canvas_end_xfade_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1534         bool canvas_fade_in_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1535         bool canvas_fade_in_handle_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*, bool trim = false);
1536         bool canvas_fade_out_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1537         bool canvas_fade_out_handle_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*, bool trim = false);
1538         bool canvas_region_view_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1539         bool canvas_wave_view_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1540         bool canvas_frame_handle_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1541         bool canvas_region_view_name_highlight_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1542         bool canvas_region_view_name_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1543         bool canvas_feature_line_event (GdkEvent* event, ArdourCanvas::Item*, RegionView*);
1544         bool canvas_stream_view_event (GdkEvent* event,ArdourCanvas::Item*, RouteTimeAxisView*);
1545         bool canvas_marker_event (GdkEvent* event,ArdourCanvas::Item*, Marker*);
1546         bool canvas_tempo_marker_event (GdkEvent* event,ArdourCanvas::Item*, TempoMarker*);
1547         bool canvas_meter_marker_event (GdkEvent* event,ArdourCanvas::Item*, MeterMarker*);
1548         bool canvas_automation_track_event(GdkEvent* event, ArdourCanvas::Item*, AutomationTimeAxisView*);
1549         bool canvas_note_event (GdkEvent* event, ArdourCanvas::Item *);
1550
1551         bool canvas_ruler_event (GdkEvent* event, ArdourCanvas::Item *, ItemType);
1552         bool canvas_tempo_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1553         bool canvas_meter_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1554         bool canvas_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1555         bool canvas_range_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1556         bool canvas_transport_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1557         bool canvas_cd_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1558
1559         bool canvas_videotl_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1560         void update_video_timeline (bool flush = false);
1561         void set_video_timeline_height (const int);
1562         bool is_video_timeline_locked ();
1563         void toggle_video_timeline_locked ();
1564         void set_video_timeline_locked (const bool);
1565         void queue_visual_videotimeline_update ();
1566         void embed_audio_from_video (std::string, framepos_t n = 0, bool lock_position_to_video = true);
1567
1568         PBD::Signal0<void> EditorFreeze;
1569         PBD::Signal0<void> EditorThaw;
1570
1571   private:
1572         friend class DragManager;
1573         friend class EditorRouteGroups;
1574         friend class EditorRegions;
1575
1576         /* non-public event handlers */
1577
1578         bool canvas_playhead_cursor_event (GdkEvent* event, ArdourCanvas::Item*);
1579         bool track_canvas_scroll (GdkEventScroll* event);
1580
1581         bool track_canvas_button_press_event (GdkEventButton* event);
1582         bool track_canvas_button_release_event (GdkEventButton* event);
1583         bool track_canvas_motion_notify_event (GdkEventMotion* event);
1584
1585         Gtk::Allocation _canvas_viewport_allocation;
1586         void track_canvas_viewport_allocate (Gtk::Allocation alloc);
1587         void track_canvas_viewport_size_allocated ();
1588         bool track_canvas_drag_motion (Glib::RefPtr<Gdk::DragContext> const &, int, int, guint);
1589         bool track_canvas_key_press (GdkEventKey *);
1590         bool track_canvas_key_release (GdkEventKey *);
1591
1592         void set_playhead_cursor ();
1593
1594         void toggle_region_mute ();
1595
1596         void initialize_canvas ();
1597
1598         /* display control */
1599
1600         bool _show_measures;
1601         /// true if the editor should follow the playhead, otherwise false
1602         bool _follow_playhead;
1603         /// true if we scroll the tracks rather than the playhead
1604         bool _stationary_playhead;
1605         /// true if we are in fullscreen mode
1606         bool _maximised;
1607
1608         TempoLines* tempo_lines;
1609
1610         ArdourCanvas::Container* global_rect_group;
1611         ArdourCanvas::Container* time_line_group;
1612
1613         void hide_measures ();
1614         void draw_measures (ARDOUR::TempoMap::BBTPointList::const_iterator& begin,
1615                             ARDOUR::TempoMap::BBTPointList::const_iterator& end);
1616
1617         void new_tempo_section ();
1618
1619
1620         void remove_tempo_marker (ArdourCanvas::Item*);
1621         void remove_meter_marker (ArdourCanvas::Item*);
1622         gint real_remove_tempo_marker (ARDOUR::TempoSection*);
1623         gint real_remove_meter_marker (ARDOUR::MeterSection*);
1624
1625         void edit_tempo_marker (TempoMarker&);
1626         void edit_meter_marker (MeterMarker&);
1627         void edit_control_point (ArdourCanvas::Item*);
1628         void edit_notes (MidiRegionView*);
1629
1630         void marker_menu_edit ();
1631         void marker_menu_remove ();
1632         void marker_menu_rename ();
1633         void rename_marker (Marker *marker);
1634         void toggle_marker_menu_lock ();
1635         void toggle_marker_menu_glue ();
1636         void marker_menu_hide ();
1637         void marker_menu_loop_range ();
1638         void marker_menu_select_all_selectables_using_range ();
1639         void marker_menu_select_using_range ();
1640         void marker_menu_separate_regions_using_location ();
1641         void marker_menu_play_from ();
1642         void marker_menu_play_range ();
1643         void marker_menu_set_playhead ();
1644         void marker_menu_set_from_playhead ();
1645         void marker_menu_set_from_selection (bool force_regions);
1646         void marker_menu_range_to_next ();
1647         void marker_menu_zoom_to_range ();
1648         void new_transport_marker_menu_set_loop ();
1649         void new_transport_marker_menu_set_punch ();
1650         void update_loop_range_view ();
1651         void update_punch_range_view ();
1652         void new_transport_marker_menu_popdown ();
1653         void marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
1654         void tempo_or_meter_marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
1655         void new_transport_marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
1656         void build_range_marker_menu (bool, bool);
1657         void build_marker_menu (ARDOUR::Location *);
1658         void build_tempo_or_meter_marker_menu (bool);
1659         void build_new_transport_marker_menu ();
1660         void dynamic_cast_marker_object (void*, MeterMarker**, TempoMarker**) const;
1661
1662         Gtk::Menu* tempo_or_meter_marker_menu;
1663         Gtk::Menu* marker_menu;
1664         Gtk::Menu* range_marker_menu;
1665         Gtk::Menu* transport_marker_menu;
1666         Gtk::Menu* new_transport_marker_menu;
1667         Gtk::Menu* cd_marker_menu;
1668         ArdourCanvas::Item* marker_menu_item;
1669
1670         typedef std::list<Marker*> Marks;
1671         Marks metric_marks;
1672
1673         void remove_metric_marks ();
1674         void draw_metric_marks (const ARDOUR::Metrics& metrics);
1675
1676         void compute_current_bbt_points (framepos_t left, framepos_t right, 
1677                                          ARDOUR::TempoMap::BBTPointList::const_iterator& begin,
1678                                          ARDOUR::TempoMap::BBTPointList::const_iterator& end);
1679
1680         void tempo_map_changed (const PBD::PropertyChange&);
1681         void redisplay_tempo (bool immediate_redraw);
1682
1683         uint32_t bbt_beat_subdivision;
1684
1685         /* toolbar */
1686
1687         Gtk::ToggleButton editor_mixer_button;
1688         Gtk::ToggleButton editor_list_button;
1689         void editor_mixer_button_toggled ();
1690         void editor_list_button_toggled ();
1691
1692         ArdourButton              zoom_in_button;
1693         ArdourButton              zoom_out_button;
1694         ArdourButton              zoom_out_full_button;
1695
1696         ArdourButton              tav_expand_button;
1697         ArdourButton              tav_shrink_button;
1698         ArdourDropdown            visible_tracks_selector;
1699         ArdourDropdown            zoom_preset_selector;
1700
1701         int32_t                   _visible_track_count;
1702         void build_track_count_menu ();
1703         void set_visible_track_count (int32_t);
1704
1705         void set_zoom_preset(int64_t);
1706
1707         Gtk::VBox                toolbar_clock_vbox;
1708         Gtk::VBox                toolbar_selection_clock_vbox;
1709         Gtk::Table               toolbar_selection_clock_table;
1710         Gtk::Label               toolbar_selection_cursor_label;
1711
1712         Gtkmm2ext::TearOff*      _mouse_mode_tearoff;
1713         ArdourButton mouse_select_button;
1714         ArdourButton mouse_draw_button;
1715         ArdourButton mouse_move_button;
1716         ArdourButton mouse_timefx_button;
1717         ArdourButton mouse_content_button;
1718         ArdourButton mouse_audition_button;
1719         ArdourButton mouse_cut_button;
1720
1721         ArdourButton smart_mode_button;
1722         Glib::RefPtr<Gtk::ToggleAction> smart_mode_action;
1723
1724         void                     mouse_mode_toggled (Editing::MouseMode m);
1725         void                     mouse_mode_object_range_toggled ();
1726         bool                     ignore_mouse_mode_toggle;
1727
1728         bool                     mouse_select_button_release (GdkEventButton*);
1729
1730         Gtk::VBox                automation_box;
1731         Gtk::Button              automation_mode_button;
1732
1733         //edit mode menu stuff
1734         ArdourDropdown  edit_mode_selector;
1735         void edit_mode_selection_done ( ARDOUR::EditMode m );
1736         void build_edit_mode_menu ();
1737         Gtk::VBox         edit_mode_box;
1738
1739         void set_edit_mode (ARDOUR::EditMode);
1740         void cycle_edit_mode ();
1741
1742         ArdourDropdown snap_type_selector;
1743         void build_snap_type_menu ();
1744
1745         ArdourDropdown snap_mode_selector;
1746         void build_snap_mode_menu ();
1747         Gtk::HBox         snap_box;
1748
1749         std::vector<std::string> snap_type_strings;
1750         std::vector<std::string> snap_mode_strings;
1751
1752         void snap_type_selection_done (Editing::SnapType);
1753         void snap_mode_selection_done (Editing::SnapMode);
1754         void snap_mode_chosen (Editing::SnapMode);
1755         void snap_type_chosen (Editing::SnapType);
1756
1757         Glib::RefPtr<Gtk::RadioAction> snap_type_action (Editing::SnapType);
1758         Glib::RefPtr<Gtk::RadioAction> snap_mode_action (Editing::SnapMode);
1759
1760         //zoom focus meu stuff
1761         ArdourDropdown  zoom_focus_selector;
1762         void zoom_focus_selection_done ( Editing::ZoomFocus f );
1763         void build_zoom_focus_menu ();
1764         std::vector<std::string> zoom_focus_strings;
1765
1766         void zoom_focus_chosen (Editing::ZoomFocus);
1767
1768         Glib::RefPtr<Gtk::RadioAction> zoom_focus_action (Editing::ZoomFocus);
1769
1770         Gtk::HBox           _zoom_box;
1771         Gtkmm2ext::TearOff* _zoom_tearoff;
1772         void                zoom_adjustment_changed();
1773
1774         void setup_toolbar ();
1775
1776         void setup_tooltips ();
1777
1778         Gtkmm2ext::TearOff*     _tools_tearoff;
1779         Gtk::HBox                toolbar_hbox;
1780         Gtk::EventBox            toolbar_base;
1781         Gtk::Frame               toolbar_frame;
1782         Gtk::Viewport           _toolbar_viewport;
1783
1784         /* midi toolbar */
1785
1786         Gtk::HBox                panic_box;
1787
1788         void setup_midi_toolbar ();
1789
1790         /* selection process */
1791
1792         Selection* selection;
1793         Selection* cut_buffer;
1794         SelectionMemento* _selection_memento;
1795
1796         void time_selection_changed ();
1797         void update_time_selection_display ();
1798         void track_selection_changed ();
1799         void region_selection_changed ();
1800         sigc::connection editor_regions_selection_changed_connection;
1801         void sensitize_all_region_actions (bool);
1802         void sensitize_the_right_region_actions ();
1803         bool _all_region_actions_sensitized;
1804         /** Flag to block region action handlers from doing what they normally do;
1805          *  I tried Gtk::Action::block_activate() but this doesn't work (ie it doesn't
1806          *  block) when setting a ToggleAction's active state.
1807          */
1808         bool _ignore_region_action;
1809         bool _last_region_menu_was_main;
1810         void point_selection_changed ();
1811         void marker_selection_changed ();
1812
1813         bool _ignore_follow_edits;
1814
1815         void cancel_selection ();
1816         void cancel_time_selection ();
1817
1818         bool get_smart_mode() const;
1819
1820         bool audio_region_selection_covers (framepos_t where);
1821
1822         /* transport range select process */
1823
1824         ArdourCanvas::Rectangle*  cd_marker_bar_drag_rect;
1825         ArdourCanvas::Rectangle*  range_bar_drag_rect;
1826         ArdourCanvas::Rectangle*  transport_bar_drag_rect;
1827
1828 #ifdef GTKOSX
1829         ArdourCanvas::Rectangle     *bogus_background_rect;
1830 #endif
1831         ArdourCanvas::Rectangle     *transport_bar_range_rect;
1832         ArdourCanvas::Rectangle     *transport_bar_preroll_rect;
1833         ArdourCanvas::Rectangle     *transport_bar_postroll_rect;
1834         ArdourCanvas::Rectangle     *transport_loop_range_rect;
1835         ArdourCanvas::Rectangle     *transport_punch_range_rect;
1836         ArdourCanvas::Line     *transport_punchin_line;
1837         ArdourCanvas::Line     *transport_punchout_line;
1838         ArdourCanvas::Rectangle     *transport_preroll_rect;
1839         ArdourCanvas::Rectangle     *transport_postroll_rect;
1840
1841         ARDOUR::Location*  transport_loop_location();
1842         ARDOUR::Location*  transport_punch_location();
1843
1844         ARDOUR::Location   *temp_location;
1845
1846         /* object rubberband select process */
1847
1848         void select_all_within (framepos_t, framepos_t, double, double, TrackViewList const &, Selection::Operation, bool);
1849
1850         ArdourCanvas::Rectangle   *rubberband_rect;
1851
1852         EditorRouteGroups* _route_groups;
1853         EditorRoutes* _routes;
1854         EditorRegions* _regions;
1855         EditorSnapshots* _snapshots;
1856         EditorLocations* _locations;
1857
1858         /* diskstream/route display management */
1859         Glib::RefPtr<Gdk::Pixbuf> rec_enabled_icon;
1860         Glib::RefPtr<Gdk::Pixbuf> rec_disabled_icon;
1861
1862         Glib::RefPtr<Gtk::TreeSelection> route_display_selection;
1863
1864         bool sync_track_view_list_and_routes ();
1865
1866         Gtk::VBox           list_vpacker;
1867
1868         /* autoscrolling */
1869
1870         sigc::connection autoscroll_connection;
1871         bool autoscroll_horizontal_allowed;
1872         bool autoscroll_vertical_allowed;
1873         uint32_t autoscroll_cnt;
1874         Gtk::Widget* autoscroll_widget;
1875         ArdourCanvas::Rect autoscroll_boundary;
1876
1877         bool autoscroll_canvas ();
1878         void start_canvas_autoscroll (bool allow_horiz, bool allow_vert, const ArdourCanvas::Rect& boundary);
1879         void stop_canvas_autoscroll ();
1880
1881         /* trimming */
1882         void point_trim (GdkEvent *, framepos_t);
1883
1884         void trim_region_front();
1885         void trim_region_back();
1886         void trim_region (bool front);
1887
1888         void trim_region_to_loop ();
1889         void trim_region_to_punch ();
1890         void trim_region_to_location (const ARDOUR::Location&, const char* cmd);
1891
1892         void trim_to_region(bool forward);
1893         void trim_region_to_previous_region_end();
1894         void trim_region_to_next_region_start();
1895
1896         bool show_gain_after_trim;
1897
1898         /* Drag-n-Drop */
1899
1900         int convert_drop_to_paths (
1901                 std::vector<std::string>&           paths,
1902                 const Glib::RefPtr<Gdk::DragContext>& context,
1903                 gint                                  x,
1904                 gint                                  y,
1905                 const Gtk::SelectionData&             data,
1906                 guint                                 info,
1907                 guint                                 time);
1908
1909         void track_canvas_drag_data_received (
1910                 const Glib::RefPtr<Gdk::DragContext>& context,
1911                 gint                                  x,
1912                 gint                                  y,
1913                 const Gtk::SelectionData&             data,
1914                 guint                                 info,
1915                 guint                                 time);
1916
1917         void drop_paths (
1918                 const Glib::RefPtr<Gdk::DragContext>& context,
1919                 gint                                  x,
1920                 gint                                  y,
1921                 const Gtk::SelectionData&             data,
1922                 guint                                 info,
1923                 guint                                 time);
1924
1925         void drop_regions (
1926                 const Glib::RefPtr<Gdk::DragContext>& context,
1927                 gint                                  x,
1928                 gint                                  y,
1929                 const Gtk::SelectionData&             data,
1930                 guint                                 info,
1931                 guint                                 time);
1932
1933         void drop_routes (
1934                 const Glib::RefPtr<Gdk::DragContext>& context,
1935                 gint                x,
1936                 gint                y,
1937                 const Gtk::SelectionData& data,
1938                 guint               info,
1939                 guint               time);
1940
1941         /* audio export */
1942
1943         int  write_region_selection(RegionSelection&);
1944         bool write_region (std::string path, boost::shared_ptr<ARDOUR::AudioRegion>);
1945         void bounce_region_selection (bool with_processing);
1946         void bounce_range_selection (bool replace, bool enable_processing);
1947         void external_edit_region ();
1948
1949         int write_audio_selection (TimeSelection&);
1950         bool write_audio_range (ARDOUR::AudioPlaylist&, const ARDOUR::ChanCount& channels, std::list<ARDOUR::AudioRange>&);
1951
1952         void write_selection ();
1953
1954         uint32_t selection_op_cmd_depth;
1955         uint32_t selection_op_history_it;
1956
1957         std::list<XMLNode *> selection_op_history; /* used in *_reversible_selection_op */
1958         std::list<XMLNode *> before; /* used in *_reversible_command */
1959
1960         void update_title ();
1961         void update_title_s (const std::string & snapshot_name);
1962
1963         void instant_save ();
1964
1965         boost::shared_ptr<ARDOUR::AudioRegion> last_audition_region;
1966
1967         /* freeze operations */
1968
1969         ARDOUR::InterThreadInfo freeze_status;
1970         static void* _freeze_thread (void*);
1971         void* freeze_thread ();
1972
1973         void freeze_route ();
1974         void unfreeze_route ();
1975
1976         /* duplication */
1977
1978         void duplicate_range (bool with_dialog);
1979
1980         /** computes the timeline frame (sample) of an event whose coordinates
1981          * are in canvas units (pixels, scroll offset included).
1982          */
1983         framepos_t canvas_event_sample (GdkEvent const *, double* px = 0, double* py = 0) const;
1984
1985         /** computes the timeline frame (sample) of an event whose coordinates
1986          * are in window units (pixels, no scroll offset).
1987          */
1988         framepos_t window_event_sample (GdkEvent const *, double* px = 0, double* py = 0) const;
1989
1990         /* returns false if mouse pointer is not in track or marker canvas
1991          */
1992         bool mouse_frame (framepos_t&, bool& in_track_canvas) const;
1993
1994         TimeFXDialog* current_timefx;
1995         static void* timefx_thread (void *arg);
1996         void do_timefx ();
1997
1998         int time_stretch (RegionSelection&, float fraction);
1999         int pitch_shift (RegionSelection&, float cents);
2000         void pitch_shift_region ();
2001
2002         void transpose_region ();
2003
2004         /* editor-mixer strip */
2005
2006         MixerStrip *current_mixer_strip;
2007         bool show_editor_mixer_when_tracks_arrive;
2008         Gtk::VBox current_mixer_strip_vbox;
2009         void cms_new (boost::shared_ptr<ARDOUR::Route>);
2010         void current_mixer_strip_hidden ();
2011
2012         void detach_tearoff (Gtk::Box* b, Gtk::Window* w);
2013         void reattach_tearoff (Gtk::Box* b, Gtk::Window* w, int32_t n);
2014 #ifdef GTKOSX
2015         void ensure_all_elements_drawn ();
2016 #endif
2017         /* nudging tracks */
2018
2019         void nudge_track (bool use_edit_point, bool forwards);
2020
2021         static const int32_t default_width = 995;
2022         static const int32_t default_height = 765;
2023
2024         /* nudge */
2025
2026         ArdourButton      nudge_forward_button;
2027         ArdourButton      nudge_backward_button;
2028         Gtk::HBox        nudge_hbox;
2029         Gtk::VBox        nudge_vbox;
2030         AudioClock*       nudge_clock;
2031
2032         bool nudge_forward_release (GdkEventButton*);
2033         bool nudge_backward_release (GdkEventButton*);
2034
2035         /* audio filters */
2036
2037         void apply_filter (ARDOUR::Filter&, std::string cmd, ProgressReporter* progress = 0);
2038
2039         Command* apply_midi_note_edit_op_to_region (ARDOUR::MidiOperator& op, MidiRegionView& mrv);
2040         void apply_midi_note_edit_op (ARDOUR::MidiOperator& op, const RegionSelection& rs);
2041
2042         /* handling cleanup */
2043
2044         int playlist_deletion_dialog (boost::shared_ptr<ARDOUR::Playlist>);
2045
2046         PBD::ScopedConnectionList session_connections;
2047
2048         /* tracking step changes of track height */
2049
2050         TimeAxisView* current_stepping_trackview;
2051         ARDOUR::microseconds_t last_track_height_step_timestamp;
2052         gint track_height_step_timeout();
2053         sigc::connection step_timeout;
2054
2055         TimeAxisView* entered_track;
2056         /** If the mouse is over a RegionView or one of its child canvas items, this is set up
2057             to point to the RegionView.  Otherwise it is 0.
2058         */
2059         RegionView*   entered_regionview;
2060
2061         std::vector<EnterContext> _enter_stack;
2062
2063         bool clear_entered_track;
2064         bool left_track_canvas (GdkEventCrossing*);
2065         bool entered_track_canvas (GdkEventCrossing*);
2066         void set_entered_track (TimeAxisView*);
2067         void set_entered_regionview (RegionView*);
2068         gint left_automation_track ();
2069
2070         void reset_canvas_action_sensitivity (bool);
2071         void set_gain_envelope_visibility ();
2072         void set_region_gain_visibility (RegionView*);
2073         void toggle_gain_envelope_active ();
2074         void reset_region_gain_envelopes ();
2075
2076         bool on_key_press_event (GdkEventKey*);
2077         bool on_key_release_event (GdkEventKey*);
2078
2079         void session_state_saved (std::string);
2080
2081         Glib::RefPtr<Gtk::Action>              undo_action;
2082         Glib::RefPtr<Gtk::Action>              redo_action;
2083         Glib::RefPtr<Gtk::Action>              alternate_redo_action;
2084         Glib::RefPtr<Gtk::Action>              alternate_alternate_redo_action;
2085         Glib::RefPtr<Gtk::Action>              selection_undo_action;
2086         Glib::RefPtr<Gtk::Action>              selection_redo_action;
2087
2088         void history_changed ();
2089
2090         Gtk::HBox      status_bar_hpacker;
2091
2092         Editing::EditPoint _edit_point;
2093
2094         ArdourDropdown edit_point_selector;
2095         void build_edit_point_menu();
2096
2097         void set_edit_point_preference (Editing::EditPoint ep, bool force = false);
2098         void cycle_edit_point (bool with_marker);
2099         void set_edit_point ();
2100         void edit_point_selection_done (Editing::EditPoint);
2101         void edit_point_chosen (Editing::EditPoint);
2102         Glib::RefPtr<Gtk::RadioAction> edit_point_action (Editing::EditPoint);
2103         std::vector<std::string> edit_point_strings;
2104         std::vector<std::string> edit_mode_strings;
2105
2106         void selected_marker_moved (ARDOUR::Location*);
2107
2108         bool get_edit_op_range (framepos_t& start, framepos_t& end) const;
2109
2110         void get_regions_at (RegionSelection&, framepos_t where, const TrackViewList& ts) const;
2111         void get_regions_after (RegionSelection&, framepos_t where, const TrackViewList& ts) const;
2112
2113         RegionSelection get_regions_from_selection_and_edit_point ();
2114         RegionSelection get_regions_from_selection_and_entered ();
2115
2116         void start_updating_meters ();
2117         void stop_updating_meters ();
2118         bool meters_running;
2119
2120         void select_next_route ();
2121         void select_prev_route ();
2122
2123         void snap_to_internal (framepos_t&       first,
2124                                ARDOUR::RoundMode direction = ARDOUR::RoundNearest,
2125                                bool              for_mark  = false);
2126
2127         void timecode_snap_to_internal (framepos_t&       first,
2128                                         ARDOUR::RoundMode direction = ARDOUR::RoundNearest,
2129                                         bool              for_mark  = false);
2130
2131         RhythmFerret* rhythm_ferret;
2132
2133         void fit_tracks (TrackViewList &);
2134         void fit_selection ();
2135         void set_track_height (Height);
2136
2137         void remove_tracks ();
2138         void toggle_tracks_active ();
2139
2140         bool _have_idled;
2141         int resize_idle_id;
2142         static gboolean _idle_resize (gpointer);
2143         bool idle_resize();
2144         int32_t _pending_resize_amount;
2145         TimeAxisView* _pending_resize_view;
2146
2147         void visible_order_range (int*, int*) const;
2148
2149         void located ();
2150
2151         /** true if we've made a locate request that hasn't yet been processed */
2152         bool _pending_locate_request;
2153
2154         /** if true, there is a pending Session locate which is the initial one when loading a session;
2155             we need to know this so that we don't (necessarily) set the viewport to show the playhead
2156             initially.
2157         */
2158         bool _pending_initial_locate;
2159
2160         Gtk::HBox _summary_hbox;
2161         EditorSummary* _summary;
2162
2163         void region_view_added (RegionView *);
2164         void region_view_removed ();
2165
2166         EditorGroupTabs* _group_tabs;
2167         void fit_route_group (ARDOUR::RouteGroup *);
2168
2169         void step_edit_status_change (bool);
2170         void start_step_editing ();
2171         void stop_step_editing ();
2172         bool check_step_edit ();
2173         sigc::connection step_edit_connection;
2174
2175         double _last_motion_y;
2176
2177         RegionLayeringOrderEditor* layering_order_editor;
2178         void update_region_layering_order_editor ();
2179
2180         /** Track that was the source for the last cut/copy operation.  Used as a place
2181             to paste things iff there is no selected track.
2182         */
2183         TimeAxisView* _last_cut_copy_source_track;
2184
2185         /** true if a change in Selection->regions should change the selection in the region list.
2186             See EditorRegions::selection_changed.
2187         */
2188         bool _region_selection_change_updates_region_list;
2189
2190         void setup_fade_images ();
2191         std::map<ARDOUR::FadeShape, Gtk::Image*> _fade_in_images;
2192         std::map<ARDOUR::FadeShape, Gtk::Image*> _fade_out_images;
2193         std::map<ARDOUR::FadeShape, Gtk::Image*> _xfade_in_images;
2194         std::map<ARDOUR::FadeShape, Gtk::Image*> _xfade_out_images;
2195
2196         Gtk::MenuItem& action_menu_item (std::string const &);
2197         void action_pre_activated (Glib::RefPtr<Gtk::Action> const &);
2198
2199         MouseCursors* _cursors;
2200
2201         void follow_mixer_selection ();
2202         bool _following_mixer_selection;
2203
2204         int time_fx (ARDOUR::RegionList&, float val, bool pitching);
2205         void note_edit_done (int, EditNoteDialog*);
2206         void toggle_sound_midi_notes ();
2207
2208         /** Flag for a bit of a hack wrt control point selection; see set_selected_control_point_from_click */
2209         bool _control_point_toggled_on_press;
2210
2211         /** This is used by TimeAxisView to keep a track of the TimeAxisView that is currently being
2212             stepped in height using ScrollZoomVerticalModifier+Scrollwheel.  When a scroll event
2213             occurs, we do the step on this _stepping_axis_view if it is non-0 (and we set up this
2214             _stepping_axis_view with the TimeAxisView underneath the mouse if it is 0).  Then Editor
2215             resets _stepping_axis_view when the modifier key is released.  In this (hacky) way,
2216             pushing the modifier key and moving the scroll wheel will operate on the same track
2217             until the key is released (rather than skipping about to whatever happens to be
2218             underneath the mouse at the time).
2219         */
2220         TimeAxisView* _stepping_axis_view;
2221         void zoom_vertical_modifier_released();
2222
2223         void bring_in_callback (Gtk::Label*, uint32_t n, uint32_t total, std::string name);
2224         void update_bring_in_message (Gtk::Label* label, uint32_t n, uint32_t total, std::string name);
2225         void bring_all_sources_into_session ();
2226
2227         friend class Drag;
2228         friend class RegionDrag;
2229         friend class RegionMoveDrag;
2230         friend class RegionSpliceDrag;
2231         friend class RegionRippleDrag;
2232         friend class TrimDrag;
2233         friend class MeterMarkerDrag;
2234         friend class TempoMarkerDrag;
2235         friend class CursorDrag;
2236         friend class FadeInDrag;
2237         friend class FadeOutDrag;
2238         friend class MarkerDrag;
2239         friend class RegionGainDrag;
2240         friend class ControlPointDrag;
2241         friend class LineDrag;
2242         friend class RubberbandSelectDrag;
2243         friend class EditorRubberbandSelectDrag;
2244         friend class TimeFXDrag;
2245         friend class ScrubDrag;
2246         friend class SelectionDrag;
2247         friend class RangeMarkerBarDrag;
2248         friend class MouseZoomDrag;
2249         friend class RegionCreateDrag;
2250         friend class RegionMotionDrag;
2251         friend class RegionInsertDrag;
2252         friend class VideoTimeLineDrag;
2253
2254         friend class EditorSummary;
2255         friend class EditorGroupTabs;
2256
2257         friend class EditorRoutes;
2258         friend class RhythmFerret;
2259 };
2260
2261 #endif /* __ardour_editor_h__ */