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