Right-clicking on the Loop/Punch ruler should "Do Something".
[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, bool is_xrun=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   protected:
528         void map_transport_state ();
529         void map_position_change (framepos_t);
530
531         void on_realize();
532
533         void suspend_route_redisplay ();
534         void resume_route_redisplay ();
535
536   private:
537
538         void color_handler ();
539
540         bool                 constructed;
541
542         // to keep track of the playhead position for control_scroll
543         boost::optional<framepos_t> _control_scroll_target;
544
545         PlaylistSelector* _playlist_selector;
546
547         typedef std::pair<TimeAxisView*,XMLNode*> TAVState;
548
549         struct VisualState {
550             VisualState (bool with_tracks);
551             ~VisualState ();
552             double              y_position;
553             framecnt_t          samples_per_pixel;
554             framepos_t          leftmost_frame;
555             Editing::ZoomFocus  zoom_focus;
556             GUIObjectState*     gui_state;
557         };
558
559         std::list<VisualState*> undo_visual_stack;
560         std::list<VisualState*> redo_visual_stack;
561         VisualState* current_visual_state (bool with_tracks = true);
562         void undo_visual_state ();
563         void redo_visual_state ();
564         void use_visual_state (VisualState&);
565         bool no_save_visual;
566         void swap_visual_state ();
567
568         std::vector<VisualState*> visual_states;
569         void start_visual_state_op (uint32_t n);
570         void cancel_visual_state_op (uint32_t n);
571
572         framepos_t         leftmost_frame;
573         framecnt_t         samples_per_pixel;
574         Editing::ZoomFocus zoom_focus;
575
576         void set_samples_per_pixel (framecnt_t);
577
578         Editing::MouseMode mouse_mode;
579         Editing::SnapType  pre_internal_snap_type;
580         Editing::SnapMode  pre_internal_snap_mode;
581         Editing::SnapType  internal_snap_type;
582         Editing::SnapMode  internal_snap_mode;
583         Editing::MouseMode effective_mouse_mode () const;
584
585         enum JoinObjectRangeState {
586                 JOIN_OBJECT_RANGE_NONE,
587                 /** `join object/range' mode is active and the mouse is over a place where object mode should happen */
588                 JOIN_OBJECT_RANGE_OBJECT,
589                 /** `join object/range' mode is active and the mouse is over a place where range mode should happen */
590                 JOIN_OBJECT_RANGE_RANGE
591         };
592
593         JoinObjectRangeState _join_object_range_state;
594
595         void update_join_object_range_location (double);
596
597         boost::optional<int>  pre_notebook_shrink_pane_width;
598
599         void pane_allocation_handler (Gtk::Allocation&, Gtk::Paned*);
600
601         Gtk::Notebook _the_notebook;
602         bool _notebook_shrunk;
603         void add_notebook_page (std::string const &, Gtk::Widget &);
604         bool notebook_tab_clicked (GdkEventButton *, Gtk::Widget *);
605
606         Gtk::HPaned   edit_pane;
607         Gtk::VPaned   editor_summary_pane;
608
609         Gtk::EventBox meter_base;
610         Gtk::HBox     meter_box;
611         Gtk::EventBox marker_base;
612         Gtk::HBox     marker_box;
613         Gtk::VBox     scrollers_rulers_markers_box;
614
615         void location_changed (ARDOUR::Location *);
616         void location_flags_changed (ARDOUR::Location *);
617         void refresh_location_display ();
618         void refresh_location_display_internal (const ARDOUR::Locations::LocationList&);
619         void add_new_location (ARDOUR::Location *);
620         ArdourCanvas::Container* add_new_location_internal (ARDOUR::Location *);
621         void location_gone (ARDOUR::Location *);
622         void remove_marker (ArdourCanvas::Item&, GdkEvent*);
623         gint really_remove_marker (ARDOUR::Location* loc);
624         void goto_nth_marker (int nth);
625         void toggle_marker_lines ();
626         void set_marker_line_visibility (bool);
627
628         uint32_t location_marker_color;
629         uint32_t location_range_color;
630         uint32_t location_loop_color;
631         uint32_t location_punch_color;
632         uint32_t location_cd_marker_color;
633
634         struct LocationMarkers {
635                 Marker* start;
636                 Marker* end;
637                 bool    valid;
638
639                 LocationMarkers () : start(0), end(0), valid (true) {}
640
641                 ~LocationMarkers ();
642
643                 void hide ();
644                 void show ();
645
646                 void set_show_lines (bool);
647                 void set_selected (bool);
648                 void canvas_height_set (double);
649                 void setup_lines ();
650
651                 void set_name (const std::string&);
652                 void set_position (framepos_t start, framepos_t end = 0);
653                 void set_color_rgba (uint32_t);
654         };
655
656         LocationMarkers  *find_location_markers (ARDOUR::Location *) const;
657         ARDOUR::Location* find_location_from_marker (Marker *, bool& is_start) const;
658         Marker* find_marker_from_location_id (PBD::ID const &, bool) const;
659         Marker* entered_marker;
660         bool _show_marker_lines;
661
662         typedef std::map<ARDOUR::Location*,LocationMarkers *> LocationMarkerMap;
663         LocationMarkerMap location_markers;
664
665         void update_marker_labels ();
666         void update_marker_labels (ArdourCanvas::Container *);
667         void check_marker_label (Marker *);
668
669         /** A set of lists of Markers that are in each of the canvas groups
670          *  for the marker sections at the top of the editor.  These lists
671          *  are kept sorted in time order between marker movements, so that after
672          *  a marker has moved we can decide whether we need to update the labels
673          *  for all markers or for just a few.
674          */
675         std::map<ArdourCanvas::Container *, std::list<Marker *> > _sorted_marker_lists;
676         void remove_sorted_marker (Marker *);
677
678         void hide_marker (ArdourCanvas::Item*, GdkEvent*);
679         void clear_marker_display ();
680         void mouse_add_new_range (framepos_t);
681         void mouse_add_new_loop (framepos_t);
682         void mouse_add_new_punch (framepos_t);
683         bool choose_new_marker_name(std::string &name);
684         void update_cd_marker_display ();
685         void ensure_cd_marker_updated (LocationMarkers * lam, ARDOUR::Location * location);
686
687         TimeAxisView*      clicked_axisview;
688         RouteTimeAxisView* clicked_routeview;
689         /** The last RegionView that was clicked on, or 0 if the last click was not
690          * on a RegionView.  This is set up by the canvas event handlers in
691          * editor_canvas_events.cc
692          */
693         RegionView*        clicked_regionview;
694         RegionSelection    latest_regionviews;
695         uint32_t           clicked_selection;
696         ControlPoint*      clicked_control_point;
697
698         void sort_track_selection (TrackViewList&);
699
700         void get_equivalent_regions (RegionView* rv, std::vector<RegionView*> &, PBD::PropertyID) const;
701         RegionSelection get_equivalent_regions (RegionSelection &, PBD::PropertyID) const;
702         void mapover_tracks (sigc::slot<void,RouteTimeAxisView&,uint32_t> sl, TimeAxisView*, PBD::PropertyID) const;
703         void mapover_tracks_with_unique_playlists (sigc::slot<void,RouteTimeAxisView&,uint32_t> sl, TimeAxisView*, PBD::PropertyID) const;
704
705         /* functions to be passed to mapover_tracks(), possibly with sigc::bind()-supplied arguments */
706         void mapped_get_equivalent_regions (RouteTimeAxisView&, uint32_t, RegionView *, std::vector<RegionView*>*) const;
707         void mapped_use_new_playlist (RouteTimeAxisView&, uint32_t, std::vector<boost::shared_ptr<ARDOUR::Playlist> > const &);
708         void mapped_use_copy_playlist (RouteTimeAxisView&, uint32_t, std::vector<boost::shared_ptr<ARDOUR::Playlist> > const &);
709         void mapped_clear_playlist (RouteTimeAxisView&, uint32_t);
710         
711         void button_selection (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type);
712         bool button_release_can_deselect;
713         bool _mouse_changed_selection;
714
715         void catch_vanishing_regionview (RegionView *);
716
717         void set_selected_track (TimeAxisView&, Selection::Operation op = Selection::Set, bool no_remove=false);
718         void select_all_tracks ();
719         bool select_all_internal_edit (Selection::Operation);
720
721         bool set_selected_control_point_from_click (bool press, Selection::Operation op = Selection::Set);
722         void set_selected_track_from_click (bool press, Selection::Operation op = Selection::Set, bool no_remove=false);
723         void set_selected_track_as_side_effect (Selection::Operation op);
724         bool set_selected_regionview_from_click (bool press, Selection::Operation op = Selection::Set);
725
726         bool set_selected_regionview_from_map_event (GdkEventAny*, StreamView*, boost::weak_ptr<ARDOUR::Region>);
727         void collect_new_region_view (RegionView *);
728         void collect_and_select_new_region_view (RegionView *);
729
730         Gtk::Menu track_context_menu;
731         Gtk::Menu track_region_context_menu;
732         Gtk::Menu track_selection_context_menu;
733
734         Gtk::MenuItem* region_edit_menu_split_item;
735         Gtk::MenuItem* region_edit_menu_split_multichannel_item;
736         Gtk::Menu * track_region_edit_playlist_menu;
737         Gtk::Menu * track_edit_playlist_submenu;
738         Gtk::Menu * track_selection_edit_playlist_submenu;
739
740         GdkEvent context_click_event;
741
742         void popup_track_context_menu (int, int, ItemType, bool);
743         Gtk::Menu* build_track_context_menu ();
744         Gtk::Menu* build_track_bus_context_menu ();
745         Gtk::Menu* build_track_region_context_menu ();
746         Gtk::Menu* build_track_selection_context_menu ();
747         void add_dstream_context_items (Gtk::Menu_Helpers::MenuList&);
748         void add_bus_context_items (Gtk::Menu_Helpers::MenuList&);
749         void add_region_context_items (Gtk::Menu_Helpers::MenuList&, boost::shared_ptr<ARDOUR::Track>);
750         void add_selection_context_items (Gtk::Menu_Helpers::MenuList&);
751         Gtk::MenuItem* _popup_region_menu_item;
752
753         void popup_control_point_context_menu (ArdourCanvas::Item *, GdkEvent *);
754         Gtk::Menu _control_point_context_menu;
755
756         void popup_note_context_menu (ArdourCanvas::Item *, GdkEvent *);
757         Gtk::Menu _note_context_menu;
758
759         void add_routes (ARDOUR::RouteList&);
760         void timeaxisview_deleted (TimeAxisView *);
761
762         Gtk::HBox           global_hpacker;
763         Gtk::VBox           global_vpacker;
764         Gtk::VBox           vpacker;
765
766         /* Cursor stuff.  Do not use directly, use via CursorContext. */
767         friend class CursorContext;
768         std::vector<Gdk::Cursor*> _cursor_stack;
769         void set_canvas_cursor (Gdk::Cursor*);
770         size_t push_canvas_cursor (Gdk::Cursor*);
771         void pop_canvas_cursor ();
772
773         Gdk::Cursor* which_grabber_cursor () const;
774         Gdk::Cursor* which_track_cursor () const;
775         Gdk::Cursor* which_mode_cursor () const;
776         Gdk::Cursor* which_trim_cursor (bool left_side) const;
777         Gdk::Cursor* which_canvas_cursor (ItemType type) const;
778
779         /** Push the appropriate enter/cursor context on item entry. */
780         void choose_canvas_cursor_on_entry (ItemType);
781
782         /** Update all enter cursors based on current settings. */
783         void update_all_enter_cursors ();
784
785         ArdourCanvas::GtkCanvas* _track_canvas;
786         ArdourCanvas::GtkCanvasViewport* _track_canvas_viewport;
787
788         bool within_track_canvas;
789
790         friend class VerboseCursor;
791         VerboseCursor* _verbose_cursor;
792
793         void parameter_changed (std::string);
794         void ui_parameter_changed (std::string);
795
796         Gtk::EventBox             time_bars_event_box;
797         Gtk::VBox                 time_bars_vbox;
798
799         ArdourCanvas::Pixbuf     *logo_item;
800 #if 0    
801     /* these will be needed when we have canvas rulers */
802         ArdourCanvas::Container      *minsec_group;
803         ArdourCanvas::Container      *bbt_group;
804         ArdourCanvas::Container      *timecode_group;
805         ArdourCanvas::Container      *frame_group;
806 #endif
807
808         ArdourCanvas::Container      *tempo_group;
809         ArdourCanvas::Container      *meter_group;
810         ArdourCanvas::Container      *marker_group;
811         ArdourCanvas::Container      *range_marker_group;
812         ArdourCanvas::Container      *transport_marker_group;
813         ArdourCanvas::Container*      cd_marker_group;
814
815         /* parent for groups which themselves contain time markers */
816         ArdourCanvas::Container*     _time_markers_group;
817
818         /* The group containing all other groups that are scrolled vertically
819            and horizontally.
820         */
821         ArdourCanvas::ScrollGroup* hv_scroll_group;
822
823         /* The group containing all other groups that are scrolled horizontally ONLY
824         */
825         ArdourCanvas::ScrollGroup* h_scroll_group;
826
827         /* Scroll group for cursors, scrolled horizontally, above everything else
828         */
829         ArdourCanvas::ScrollGroup* cursor_scroll_group;
830
831         /* The group containing all trackviews. */
832         ArdourCanvas::Container* no_scroll_group;
833
834         /* The group containing all trackviews. */
835         ArdourCanvas::Container* _trackview_group;
836
837         /* The group holding things (mostly regions) while dragging so they
838          * are on top of everything else
839          */
840         ArdourCanvas::Container* _drag_motion_group;
841
842         /* a rect that sits at the bottom of all tracks to act as a drag-no-drop/clickable
843          * target area.
844          */
845         ArdourCanvas::Rectangle* _canvas_drop_zone;
846         bool canvas_drop_zone_event (GdkEvent* event);
847
848         enum RulerType {
849                 ruler_metric_timecode = 0,
850                 ruler_metric_bbt = 1,
851                 ruler_metric_samples = 2,
852                 ruler_metric_minsec = 3,
853
854                 ruler_time_tempo = 4,
855                 ruler_time_meter = 5,
856                 ruler_time_marker = 6,
857                 ruler_time_range_marker = 7,
858                 ruler_time_transport_marker = 8,
859                 ruler_time_cd_marker = 9,
860                 ruler_video_timeline = 10,
861         };
862
863         Glib::RefPtr<Gtk::ToggleAction> ruler_timecode_action;
864         Glib::RefPtr<Gtk::ToggleAction> ruler_bbt_action;
865         Glib::RefPtr<Gtk::ToggleAction> ruler_samples_action;
866         Glib::RefPtr<Gtk::ToggleAction> ruler_minsec_action;
867         Glib::RefPtr<Gtk::ToggleAction> ruler_tempo_action;
868         Glib::RefPtr<Gtk::ToggleAction> ruler_meter_action;
869         Glib::RefPtr<Gtk::ToggleAction> ruler_marker_action;
870         Glib::RefPtr<Gtk::ToggleAction> ruler_range_action;
871         Glib::RefPtr<Gtk::ToggleAction> ruler_loop_punch_action;
872         Glib::RefPtr<Gtk::ToggleAction> ruler_cd_marker_action;
873         bool                            no_ruler_shown_update;
874
875         Gtk::Widget * ruler_grabbed_widget;
876
877         RulerDialog* ruler_dialog;
878
879         void initialize_rulers ();
880         void update_just_timecode ();
881         void compute_fixed_ruler_scale (); //calculates the RulerScale of the fixed rulers
882         void update_fixed_rulers ();
883         void update_tempo_based_rulers (ARDOUR::TempoMap::BBTPointList::const_iterator& begin,
884                                         ARDOUR::TempoMap::BBTPointList::const_iterator& end);
885         void popup_ruler_menu (framepos_t where = 0, ItemType type = RegionItem);
886         void update_ruler_visibility ();
887         void set_ruler_visible (RulerType, bool);
888         void toggle_ruler_visibility (RulerType rt);
889         void ruler_toggled (int);
890         bool ruler_label_button_release (GdkEventButton*);
891         void store_ruler_visibility ();
892         void restore_ruler_visibility ();
893
894
895
896                 enum MinsecRulerScale {
897                 minsec_show_msecs,
898                 minsec_show_seconds,
899                 minsec_show_minutes,
900                 minsec_show_hours,
901                 minsec_show_many_hours
902         };
903
904         MinsecRulerScale minsec_ruler_scale;
905
906         framecnt_t minsec_mark_interval;
907         gint minsec_mark_modulo;
908         gint minsec_nmarks;
909         void set_minsec_ruler_scale (framepos_t, framepos_t);
910
911         enum TimecodeRulerScale {
912                 timecode_show_bits,
913                 timecode_show_frames,
914                 timecode_show_seconds,
915                 timecode_show_minutes,
916                 timecode_show_hours,
917                 timecode_show_many_hours
918         };
919
920         TimecodeRulerScale timecode_ruler_scale;
921
922         gint timecode_mark_modulo;
923         gint timecode_nmarks;
924         void set_timecode_ruler_scale (framepos_t, framepos_t);
925
926         framecnt_t _samples_ruler_interval;
927         void set_samples_ruler_scale (framepos_t, framepos_t);
928
929         enum BBTRulerScale {
930                 bbt_show_many,
931                 bbt_show_64,
932                 bbt_show_16,
933                 bbt_show_4,
934                 bbt_show_1,
935                 bbt_show_beats,
936                 bbt_show_ticks,
937                 bbt_show_ticks_detail,
938                 bbt_show_ticks_super_detail
939         };
940
941         BBTRulerScale bbt_ruler_scale;
942
943         uint32_t bbt_bars;
944         gint bbt_nmarks;
945         uint32_t bbt_bar_helper_on;
946         uint32_t bbt_accent_modulo;
947         void compute_bbt_ruler_scale (framepos_t lower, framepos_t upper,
948                                       ARDOUR::TempoMap::BBTPointList::const_iterator current_bbt_points_begin,
949                                       ARDOUR::TempoMap::BBTPointList::const_iterator current_bbt_points_end);
950
951         ArdourCanvas::Ruler* timecode_ruler;
952         ArdourCanvas::Ruler* bbt_ruler;
953         ArdourCanvas::Ruler* samples_ruler;
954         ArdourCanvas::Ruler* minsec_ruler;
955
956         static double timebar_height;
957         guint32 visible_timebars;
958         Gtk::Menu          *editor_ruler_menu;
959
960         ArdourCanvas::Rectangle* tempo_bar;
961         ArdourCanvas::Rectangle* meter_bar;
962         ArdourCanvas::Rectangle* marker_bar;
963         ArdourCanvas::Rectangle* range_marker_bar;
964         ArdourCanvas::Rectangle* transport_marker_bar;
965         ArdourCanvas::Rectangle* cd_marker_bar;
966
967         Gtk::Label  minsec_label;
968         Gtk::Label  bbt_label;
969         Gtk::Label  timecode_label;
970         Gtk::Label  samples_label;
971         Gtk::Label  tempo_label;
972         Gtk::Label  meter_label;
973         Gtk::Label  mark_label;
974         Gtk::Label  range_mark_label;
975         Gtk::Label  transport_mark_label;
976         Gtk::Label  cd_mark_label;
977
978         /* videtimline related actions */
979         Gtk::Label                videotl_label;
980         ArdourCanvas::Container*      videotl_group;
981         Glib::RefPtr<Gtk::ToggleAction> ruler_video_action;
982         Glib::RefPtr<Gtk::ToggleAction> xjadeo_proc_action;
983         Glib::RefPtr<Gtk::ToggleAction> xjadeo_ontop_action;
984         Glib::RefPtr<Gtk::ToggleAction> xjadeo_timecode_action;
985         Glib::RefPtr<Gtk::ToggleAction> xjadeo_frame_action;
986         Glib::RefPtr<Gtk::ToggleAction> xjadeo_osdbg_action;
987         Glib::RefPtr<Gtk::ToggleAction> xjadeo_fullscreen_action;
988         Glib::RefPtr<Gtk::ToggleAction> xjadeo_letterbox_action;
989         Glib::RefPtr<Gtk::Action> xjadeo_zoom_100;
990         void set_xjadeo_proc ();
991         void toggle_xjadeo_proc (int state=-1);
992         void set_close_video_sensitive (bool onoff);
993         void set_xjadeo_sensitive (bool onoff);
994         void set_xjadeo_viewoption (int);
995         void toggle_xjadeo_viewoption (int what, int state=-1);
996         void toggle_ruler_video (bool onoff) {ruler_video_action->set_active(onoff);}
997         int videotl_bar_height; /* in units of timebar_height; default: 4 */
998         int get_videotl_bar_height () const { return videotl_bar_height; }
999         void toggle_region_video_lock ();
1000
1001         friend class EditorCursor;
1002
1003         EditorCursor*        playhead_cursor;
1004
1005         framepos_t get_region_boundary (framepos_t pos, int32_t dir, bool with_selection, bool only_onscreen);
1006
1007         void    cursor_to_region_boundary (bool with_selection, int32_t dir);
1008         void    cursor_to_next_region_boundary (bool with_selection);
1009         void    cursor_to_previous_region_boundary (bool with_selection);
1010         void    cursor_to_next_region_point (EditorCursor*, ARDOUR::RegionPoint);
1011         void    cursor_to_previous_region_point (EditorCursor*, ARDOUR::RegionPoint);
1012         void    cursor_to_region_point (EditorCursor*, ARDOUR::RegionPoint, int32_t dir);
1013         void    cursor_to_selection_start (EditorCursor *);
1014         void    cursor_to_selection_end   (EditorCursor *);
1015
1016         void    selected_marker_to_region_boundary (bool with_selection, int32_t dir);
1017         void    selected_marker_to_next_region_boundary (bool with_selection);
1018         void    selected_marker_to_previous_region_boundary (bool with_selection);
1019         void    selected_marker_to_next_region_point (ARDOUR::RegionPoint);
1020         void    selected_marker_to_previous_region_point (ARDOUR::RegionPoint);
1021         void    selected_marker_to_region_point (ARDOUR::RegionPoint, int32_t dir);
1022         void    selected_marker_to_selection_start ();
1023         void    selected_marker_to_selection_end   ();
1024
1025         void    select_all_selectables_using_cursor (EditorCursor *, bool);
1026         void    select_all_selectables_using_edit (bool);
1027         void    select_all_selectables_between (bool within);
1028         void    select_range_between ();
1029
1030         boost::shared_ptr<ARDOUR::Region> find_next_region (ARDOUR::framepos_t, ARDOUR::RegionPoint, int32_t dir, TrackViewList&, TimeAxisView ** = 0);
1031         ARDOUR::framepos_t find_next_region_boundary (ARDOUR::framepos_t, int32_t dir, const TrackViewList&);
1032
1033         std::vector<ARDOUR::framepos_t> region_boundary_cache;
1034         void build_region_boundary_cache ();
1035
1036         Gtk::HBox           toplevel_hpacker;
1037
1038         Gtk::HBox           top_hbox;
1039         Gtk::HBox           bottom_hbox;
1040
1041         Gtk::Table          edit_packer;
1042
1043         /** the adjustment that controls the overall editor vertical scroll position */
1044         Gtk::Adjustment     vertical_adjustment;
1045         Gtk::Adjustment     horizontal_adjustment;
1046
1047         Gtk::Adjustment     unused_adjustment; // yes, really; Gtk::Layout constructor requires refs
1048         Gtk::Layout         controls_layout;
1049         bool control_layout_scroll (GdkEventScroll* ev);
1050         void reset_controls_layout_width ();
1051         void reset_controls_layout_height (int32_t height);
1052
1053         enum Direction {
1054                 LEFT,
1055                 RIGHT,
1056                 UP,
1057                 DOWN
1058         };
1059
1060         bool scroll_press (Direction);
1061         void scroll_release ();
1062         sigc::connection _scroll_connection;
1063         int _scroll_callbacks;
1064
1065         double _visible_canvas_width;
1066         double _visible_canvas_height; ///< height of the visible area of the track canvas
1067         double _full_canvas_height;    ///< full height of the canvas
1068
1069         bool track_canvas_map_handler (GdkEventAny*);
1070
1071         bool edit_controls_button_release (GdkEventButton*);
1072         Gtk::Menu *edit_controls_left_menu;
1073         Gtk::Menu *edit_controls_right_menu;
1074
1075         Gtk::VBox           track_canvas_vbox;
1076         Gtk::VBox           edit_controls_vbox;
1077         Gtk::HBox           edit_controls_hbox;
1078
1079         void control_vertical_zoom_in_all ();
1080         void control_vertical_zoom_out_all ();
1081         void control_vertical_zoom_in_selected ();
1082         void control_vertical_zoom_out_selected ();
1083         void control_step_tracks_up ();
1084         void control_step_tracks_down ();
1085         void control_view (uint32_t);
1086         void control_scroll (float);
1087         void control_select (uint32_t rid, Selection::Operation);
1088         void control_unselect ();
1089         void access_action (std::string,std::string);
1090         bool deferred_control_scroll (framepos_t);
1091         sigc::connection control_scroll_connection;
1092
1093         void tie_vertical_scrolling ();
1094         void set_horizontal_position (double);
1095         double horizontal_position () const;
1096
1097         struct VisualChange {
1098                 enum Type {
1099                         TimeOrigin = 0x1,
1100                         ZoomLevel = 0x2,
1101                         YOrigin = 0x4
1102                 };
1103
1104                 Type       pending;
1105                 framepos_t time_origin;
1106                 framecnt_t samples_per_pixel;
1107                 double     y_origin;
1108
1109                 int idle_handler_id;
1110                 /** true if we are currently in the idle handler */
1111                 bool being_handled;
1112
1113                 VisualChange() : pending ((VisualChange::Type) 0), time_origin (0), samples_per_pixel (0), idle_handler_id (-1), being_handled (false) {}
1114                 void add (Type t) {
1115                         pending = Type (pending | t);
1116                 }
1117         };
1118
1119         VisualChange pending_visual_change;
1120
1121         static int _idle_visual_changer (void *arg);
1122         int idle_visual_changer ();
1123         void visual_changer (const VisualChange&);
1124         void ensure_visual_change_idle_handler ();
1125
1126         /* track views */
1127         TrackViewList track_views;
1128         std::pair<TimeAxisView*, double> trackview_by_y_position (double, bool trackview_relative_offset = true) const;
1129         RouteTimeAxisView* axis_view_from_route (boost::shared_ptr<ARDOUR::Route>) const;
1130
1131         TrackViewList get_tracks_for_range_action () const;
1132
1133         sigc::connection super_rapid_screen_update_connection;
1134         framepos_t last_update_frame;
1135         void center_screen_internal (framepos_t, float);
1136
1137         void super_rapid_screen_update ();
1138
1139         void session_going_away ();
1140
1141         framepos_t cut_buffer_start;
1142         framecnt_t cut_buffer_length;
1143
1144         boost::shared_ptr<CursorContext> _press_cursor_ctx;  ///< Button press cursor context
1145
1146         boost::weak_ptr<ARDOUR::Trimmable> _trimmable;
1147         boost::weak_ptr<ARDOUR::Movable> _movable;
1148
1149         bool typed_event (ArdourCanvas::Item*, GdkEvent*, ItemType);
1150         bool button_press_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1151         bool button_press_handler_1 (ArdourCanvas::Item *, GdkEvent *, ItemType);
1152         bool button_press_handler_2 (ArdourCanvas::Item *, GdkEvent *, ItemType);
1153         bool button_release_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1154         bool button_double_click_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1155         bool button_press_dispatch (GdkEventButton*);
1156         bool button_release_dispatch (GdkEventButton*);
1157         bool motion_handler (ArdourCanvas::Item*, GdkEvent*, bool from_autoscroll = false);
1158         bool enter_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1159         bool leave_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1160         bool key_press_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1161         bool key_release_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1162
1163         Gtkmm2ext::Bindings* button_bindings;
1164         XMLNode* button_settings () const;
1165
1166         /* KEYMAP HANDLING */
1167
1168         void register_actions ();
1169         void register_region_actions ();
1170
1171         void load_bindings ();
1172         Gtkmm2ext::ActionMap editor_action_map;
1173         Gtkmm2ext::Bindings  key_bindings;
1174
1175         /* CUT/COPY/PASTE */
1176
1177         framepos_t last_paste_pos;
1178         unsigned   paste_count;
1179
1180         void cut_copy (Editing::CutCopyOp);
1181         bool can_cut_copy () const;
1182         void cut_copy_points (Editing::CutCopyOp, Evoral::Beats earliest=Evoral::Beats(), bool midi=false);
1183         void cut_copy_regions (Editing::CutCopyOp, RegionSelection&);
1184         void cut_copy_ranges (Editing::CutCopyOp);
1185         void cut_copy_midi (Editing::CutCopyOp);
1186
1187         void mouse_paste ();
1188         void paste_internal (framepos_t position, float times);
1189
1190         /* EDITING OPERATIONS */
1191
1192         void reset_point_selection ();
1193         void toggle_region_lock ();
1194         void toggle_opaque_region ();
1195         void toggle_record_enable ();
1196         void toggle_solo ();
1197         void toggle_solo_isolate ();
1198         void toggle_mute ();
1199         void toggle_region_lock_style ();
1200
1201         enum LayerOperation {
1202                 Raise,
1203                 RaiseToTop,
1204                 Lower,
1205                 LowerToBottom
1206         };
1207
1208         void do_layer_operation (LayerOperation);
1209         void raise_region ();
1210         void raise_region_to_top ();
1211         void change_region_layering_order (bool from_context_menu);
1212         void lower_region ();
1213         void lower_region_to_bottom ();
1214         void split_region_at_transients ();
1215         void crop_region_to_selection ();
1216         void crop_region_to (framepos_t start, framepos_t end);
1217         void set_sync_point (framepos_t, const RegionSelection&);
1218         void set_region_sync_position ();
1219         void remove_region_sync();
1220         void align_regions (ARDOUR::RegionPoint);
1221         void align_regions_relative (ARDOUR::RegionPoint point);
1222         void align_region (boost::shared_ptr<ARDOUR::Region>, ARDOUR::RegionPoint point, framepos_t position);
1223         void align_region_internal (boost::shared_ptr<ARDOUR::Region>, ARDOUR::RegionPoint point, framepos_t position);
1224         void remove_selected_regions ();
1225         void remove_clicked_region ();
1226         void show_region_properties ();
1227         void show_midi_list_editor ();
1228         void rename_region ();
1229         void duplicate_some_regions (RegionSelection&, float times);
1230         void duplicate_selection (float times);
1231         void region_fill_selection ();
1232         void combine_regions ();
1233         void uncombine_regions ();
1234
1235         void region_fill_track ();
1236         void audition_playlist_region_standalone (boost::shared_ptr<ARDOUR::Region>);
1237         void audition_playlist_region_via_route (boost::shared_ptr<ARDOUR::Region>, ARDOUR::Route&);
1238         void split_multichannel_region();
1239         void reverse_region ();
1240         void strip_region_silence ();
1241         void normalize_region ();
1242         void reset_region_scale_amplitude ();
1243         void adjust_region_gain (bool up);
1244         void quantize_region ();
1245         void quantize_regions (const RegionSelection& rs);
1246         void legatize_region (bool shrink_only);
1247         void legatize_regions (const RegionSelection& rs, bool shrink_only);
1248         void transform_region ();
1249         void transform_regions (const RegionSelection& rs);
1250         void insert_patch_change (bool from_context);
1251         void fork_region ();
1252
1253         void do_insert_time ();
1254         void insert_time (framepos_t, framecnt_t, Editing::InsertTimeOption, bool, bool, bool, bool, bool, bool);
1255
1256         void tab_to_transient (bool forward);
1257
1258         void set_tempo_from_region ();
1259         void use_range_as_bar ();
1260
1261         void define_one_bar (framepos_t start, framepos_t end);
1262
1263         void audition_region_from_region_list ();
1264         void hide_region_from_region_list ();
1265         void show_region_in_region_list ();
1266
1267         void naturalize_region ();
1268
1269         void reset_focus ();
1270
1271         void split_region ();
1272
1273         void delete_ ();
1274         void cut ();
1275         void copy ();
1276         void paste (float times, bool from_context_menu = false);
1277
1278         void place_transient ();
1279         void remove_transient (ArdourCanvas::Item* item);
1280         void snap_regions_to_grid ();
1281         void close_region_gaps ();
1282
1283         void keyboard_paste ();
1284
1285         void region_from_selection ();
1286         void create_region_from_selection (std::vector<boost::shared_ptr<ARDOUR::Region> >&);
1287
1288         void play_from_start ();
1289         void play_from_edit_point ();
1290         void play_from_edit_point_and_return ();
1291         void play_selected_region ();
1292         void play_edit_range ();
1293         void play_location (ARDOUR::Location&);
1294         void loop_location (ARDOUR::Location&);
1295
1296         void calc_extra_zoom_edges(framepos_t &start, framepos_t &end);
1297         void temporal_zoom_selection (bool both_axes = false);
1298         void temporal_zoom_region (bool both_axes);
1299         void temporal_zoom_session ();
1300         void temporal_zoom (framecnt_t samples_per_pixel);
1301         void temporal_zoom_by_frame (framepos_t start, framepos_t end);
1302         void temporal_zoom_to_frame (bool coarser, framepos_t frame);
1303
1304         void insert_region_list_selection (float times);
1305
1306         /* import & embed */
1307
1308         void add_external_audio_action (Editing::ImportMode);
1309         void external_audio_dialog ();
1310         void session_import_dialog ();
1311
1312         int  check_whether_and_how_to_import(std::string, bool all_or_nothing = true);
1313         bool check_multichannel_status (const std::vector<std::string>& paths);
1314
1315         SoundFileOmega* sfbrowser;
1316
1317         void bring_in_external_audio (Editing::ImportMode mode,  framepos_t& pos);
1318
1319         bool  idle_drop_paths  (std::vector<std::string> paths, framepos_t frame, double ypos, bool copy);
1320         void  drop_paths_part_two  (const std::vector<std::string>& paths, framepos_t frame, double ypos, bool copy);
1321
1322         int import_sndfiles (std::vector<std::string>              paths,
1323                              Editing::ImportDisposition            disposition,
1324                              Editing::ImportMode                   mode,
1325                              ARDOUR::SrcQuality                    quality,
1326                              framepos_t&                           pos,
1327                              int                                   target_regions,
1328                              int                                   target_tracks,
1329                              boost::shared_ptr<ARDOUR::Track>&     track,
1330                              bool                                  replace,
1331                              boost::shared_ptr<ARDOUR::PluginInfo> instrument = boost::shared_ptr<ARDOUR::PluginInfo>());
1332
1333         int embed_sndfiles (std::vector<std::string>              paths,
1334                             bool                                  multiple_files,
1335                             bool&                                 check_sample_rate,
1336                             Editing::ImportDisposition            disposition,
1337                             Editing::ImportMode                   mode,
1338                             framepos_t&                           pos,
1339                             int                                   target_regions,
1340                             int                                   target_tracks,
1341                             boost::shared_ptr<ARDOUR::Track>&     track,
1342                             boost::shared_ptr<ARDOUR::PluginInfo> instrument = boost::shared_ptr<ARDOUR::PluginInfo>());
1343
1344         int add_sources (std::vector<std::string>              paths,
1345                          ARDOUR::SourceList&                   sources,
1346                          framepos_t&                           pos,
1347                          Editing::ImportDisposition            disposition,
1348                          Editing::ImportMode                   mode,
1349                          int                                   target_regions,
1350                          int                                   target_tracks,
1351                          boost::shared_ptr<ARDOUR::Track>&     track,
1352                          bool                                  add_channel_suffix,
1353                          boost::shared_ptr<ARDOUR::PluginInfo> instrument = boost::shared_ptr<ARDOUR::PluginInfo>());
1354
1355         int finish_bringing_in_material (boost::shared_ptr<ARDOUR::Region>     region,
1356                                          uint32_t                              in_chans,
1357                                          uint32_t                              out_chans,
1358                                          framepos_t&                           pos,
1359                                          Editing::ImportMode                   mode,
1360                                          boost::shared_ptr<ARDOUR::Track>&     existing_track,
1361                                          const std::string&                    new_track_name,
1362                                          boost::shared_ptr<ARDOUR::PluginInfo> instrument);
1363
1364         boost::shared_ptr<ARDOUR::AudioTrack> get_nth_selected_audio_track (int nth) const;
1365         boost::shared_ptr<ARDOUR::MidiTrack> get_nth_selected_midi_track (int nth) const;
1366
1367         void toggle_midi_input_active (bool flip_others);
1368
1369         ARDOUR::InterThreadInfo* current_interthread_info;
1370
1371         AnalysisWindow* analysis_window;
1372
1373         /* import specific info */
1374
1375         struct EditorImportStatus : public ARDOUR::ImportStatus {
1376             Editing::ImportMode mode;
1377             framepos_t pos;
1378             int target_tracks;
1379             int target_regions;
1380             boost::shared_ptr<ARDOUR::Track> track;
1381             bool replace;
1382         };
1383
1384         EditorImportStatus import_status;
1385         static void *_import_thread (void *);
1386         void* import_thread ();
1387         void finish_import ();
1388
1389         /* to support this ... */
1390
1391         void import_audio (bool as_tracks);
1392         void do_import (std::vector<std::string> paths, bool split, bool as_tracks);
1393
1394         void move_to_start ();
1395         void move_to_end ();
1396         void center_playhead ();
1397         void center_edit_point ();
1398         void playhead_forward_to_grid ();
1399         void playhead_backward_to_grid ();
1400         void scroll_playhead (bool forward);
1401         void scroll_backward (float pages=0.8f);
1402         void scroll_forward (float pages=0.8f);
1403         void scroll_tracks_down ();
1404         void scroll_tracks_up ();
1405         void set_mark ();
1406         void clear_markers ();
1407         void clear_ranges ();
1408         void clear_locations ();
1409         void unhide_markers ();
1410         void unhide_ranges ();
1411         void jump_forward_to_mark ();
1412         void jump_backward_to_mark ();
1413         void cursor_align (bool playhead_to_edit);
1414         void toggle_skip_playback ();
1415
1416         void remove_last_capture ();
1417         void select_all_selectables_using_time_selection ();
1418         void select_all_selectables_using_loop();
1419         void select_all_selectables_using_punch();
1420         void set_selection_from_range (ARDOUR::Location&);
1421         void set_selection_from_punch ();
1422         void set_selection_from_loop ();
1423         void set_selection_from_region ();
1424
1425         void add_location_mark (framepos_t where);
1426         void add_location_from_region ();
1427         void add_locations_from_region ();
1428         void add_location_from_selection ();
1429         void set_loop_from_selection (bool play);
1430         void set_punch_from_selection ();
1431         void set_punch_from_region ();
1432
1433         void set_session_extents_from_selection ();
1434
1435         void set_loop_from_region (bool play);
1436
1437         void set_loop_range (framepos_t start, framepos_t end, std::string cmd);
1438         void set_punch_range (framepos_t start, framepos_t end, std::string cmd);
1439
1440         void add_location_from_playhead_cursor ();
1441         void remove_location_at_playhead_cursor ();
1442         bool select_new_marker;
1443
1444         void reverse_selection ();
1445         void edit_envelope ();
1446
1447         double last_scrub_x;
1448         int scrubbing_direction;
1449         int scrub_reversals;
1450         int scrub_reverse_distance;
1451         void scrub (framepos_t, double);
1452
1453         void keyboard_selection_begin ();
1454         void keyboard_selection_finish (bool add);
1455         bool have_pending_keyboard_selection;
1456         framepos_t pending_keyboard_selection_start;
1457
1458         void move_range_selection_start_or_end_to_region_boundary (bool, bool);
1459
1460         Editing::SnapType _snap_type;
1461         Editing::SnapMode _snap_mode;
1462
1463         /// Snap threshold in pixels
1464         double snap_threshold;
1465
1466         bool ignore_gui_changes;
1467
1468         DragManager* _drags;
1469
1470         void escape ();
1471         void lock ();
1472         void unlock ();
1473         Gtk::Dialog* lock_dialog;
1474
1475         struct timeval last_event_time;
1476         bool generic_event_handler (GdkEvent*);
1477         bool lock_timeout_callback ();
1478         void start_lock_event_timing ();
1479
1480         Gtk::Menu fade_context_menu;
1481
1482         Gtk::Menu xfade_in_context_menu;
1483         Gtk::Menu xfade_out_context_menu;
1484         void popup_xfade_in_context_menu (int, int, ArdourCanvas::Item*, ItemType);
1485         void popup_xfade_out_context_menu (int, int, ArdourCanvas::Item*, ItemType);
1486         void fill_xfade_menu (Gtk::Menu_Helpers::MenuList& items, bool start);
1487
1488         void set_fade_in_shape (ARDOUR::FadeShape);
1489         void set_fade_out_shape (ARDOUR::FadeShape);
1490
1491         void set_fade_length (bool in);
1492         void set_fade_in_active (bool);
1493         void set_fade_out_active (bool);
1494
1495         void fade_range ();
1496
1497         std::set<boost::shared_ptr<ARDOUR::Playlist> > motion_frozen_playlists;
1498
1499         bool _dragging_playhead;
1500         bool _dragging_edit_point;
1501
1502         void marker_drag_motion_callback (GdkEvent*);
1503         void marker_drag_finished_callback (GdkEvent*);
1504
1505         gint mouse_rename_region (ArdourCanvas::Item*, GdkEvent*);
1506
1507         void add_region_drag (ArdourCanvas::Item*, GdkEvent*, RegionView*);
1508         void start_create_region_grab (ArdourCanvas::Item*, GdkEvent*);
1509         void add_region_copy_drag (ArdourCanvas::Item*, GdkEvent*, RegionView*);
1510         void add_region_brush_drag (ArdourCanvas::Item*, GdkEvent*, RegionView*);
1511         void start_selection_grab (ArdourCanvas::Item*, GdkEvent*);
1512
1513         void region_view_item_click (AudioRegionView&, GdkEventButton*);
1514
1515         bool can_remove_control_point (ArdourCanvas::Item *);
1516         void remove_control_point (ArdourCanvas::Item *);
1517
1518         void mouse_brush_insert_region (RegionView*, framepos_t pos);
1519
1520         /* Canvas event handlers */
1521
1522         bool canvas_scroll_event (GdkEventScroll* event, bool from_canvas);
1523         bool canvas_control_point_event (GdkEvent* event,ArdourCanvas::Item*, ControlPoint*);
1524         bool canvas_line_event (GdkEvent* event,ArdourCanvas::Item*, AutomationLine*);
1525         bool canvas_selection_rect_event (GdkEvent* event,ArdourCanvas::Item*, SelectionRect*);
1526         bool canvas_selection_start_trim_event (GdkEvent* event,ArdourCanvas::Item*, SelectionRect*);
1527         bool canvas_selection_end_trim_event (GdkEvent* event,ArdourCanvas::Item*, SelectionRect*);
1528         bool canvas_start_xfade_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1529         bool canvas_end_xfade_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1530         bool canvas_fade_in_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1531         bool canvas_fade_in_handle_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*, bool trim = false);
1532         bool canvas_fade_out_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1533         bool canvas_fade_out_handle_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*, bool trim = false);
1534         bool canvas_region_view_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1535         bool canvas_wave_view_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1536         bool canvas_frame_handle_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1537         bool canvas_region_view_name_highlight_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1538         bool canvas_region_view_name_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1539         bool canvas_feature_line_event (GdkEvent* event, ArdourCanvas::Item*, RegionView*);
1540         bool canvas_stream_view_event (GdkEvent* event,ArdourCanvas::Item*, RouteTimeAxisView*);
1541         bool canvas_marker_event (GdkEvent* event,ArdourCanvas::Item*, Marker*);
1542         bool canvas_tempo_marker_event (GdkEvent* event,ArdourCanvas::Item*, TempoMarker*);
1543         bool canvas_meter_marker_event (GdkEvent* event,ArdourCanvas::Item*, MeterMarker*);
1544         bool canvas_automation_track_event(GdkEvent* event, ArdourCanvas::Item*, AutomationTimeAxisView*);
1545         bool canvas_note_event (GdkEvent* event, ArdourCanvas::Item *);
1546
1547         bool canvas_ruler_event (GdkEvent* event, ArdourCanvas::Item *, ItemType);
1548         bool canvas_tempo_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1549         bool canvas_meter_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1550         bool canvas_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1551         bool canvas_range_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1552         bool canvas_transport_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1553         bool canvas_cd_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1554
1555         bool canvas_videotl_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1556         void update_video_timeline (bool flush = false);
1557         void set_video_timeline_height (const int);
1558         bool is_video_timeline_locked ();
1559         void toggle_video_timeline_locked ();
1560         void set_video_timeline_locked (const bool);
1561         void queue_visual_videotimeline_update ();
1562         void embed_audio_from_video (std::string, framepos_t n = 0, bool lock_position_to_video = true);
1563
1564         PBD::Signal0<void> EditorFreeze;
1565         PBD::Signal0<void> EditorThaw;
1566
1567   private:
1568         friend class DragManager;
1569         friend class EditorRouteGroups;
1570         friend class EditorRegions;
1571
1572         /* non-public event handlers */
1573
1574         bool canvas_playhead_cursor_event (GdkEvent* event, ArdourCanvas::Item*);
1575         bool track_canvas_scroll (GdkEventScroll* event);
1576
1577         bool track_canvas_button_press_event (GdkEventButton* event);
1578         bool track_canvas_button_release_event (GdkEventButton* event);
1579         bool track_canvas_motion_notify_event (GdkEventMotion* event);
1580
1581         Gtk::Allocation _canvas_viewport_allocation;
1582         void track_canvas_viewport_allocate (Gtk::Allocation alloc);
1583         void track_canvas_viewport_size_allocated ();
1584         bool track_canvas_drag_motion (Glib::RefPtr<Gdk::DragContext> const &, int, int, guint);
1585         bool track_canvas_key_press (GdkEventKey *);
1586         bool track_canvas_key_release (GdkEventKey *);
1587
1588         void set_playhead_cursor ();
1589
1590         void toggle_region_mute ();
1591
1592         void initialize_canvas ();
1593
1594         /* display control */
1595
1596         bool _show_measures;
1597         /// true if the editor should follow the playhead, otherwise false
1598         bool _follow_playhead;
1599         /// true if we scroll the tracks rather than the playhead
1600         bool _stationary_playhead;
1601         /// true if we are in fullscreen mode
1602         bool _maximised;
1603
1604         TempoLines* tempo_lines;
1605
1606         ArdourCanvas::Container* global_rect_group;
1607         ArdourCanvas::Container* time_line_group;
1608
1609         void hide_measures ();
1610         void draw_measures (ARDOUR::TempoMap::BBTPointList::const_iterator& begin,
1611                             ARDOUR::TempoMap::BBTPointList::const_iterator& end);
1612
1613         void new_tempo_section ();
1614
1615         void mouse_add_new_tempo_event (framepos_t where);
1616         void mouse_add_new_meter_event (framepos_t where);
1617
1618         void remove_tempo_marker (ArdourCanvas::Item*);
1619         void remove_meter_marker (ArdourCanvas::Item*);
1620         gint real_remove_tempo_marker (ARDOUR::TempoSection*);
1621         gint real_remove_meter_marker (ARDOUR::MeterSection*);
1622
1623         void edit_tempo_section (ARDOUR::TempoSection*);
1624         void edit_meter_section (ARDOUR::MeterSection*);
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__ */