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