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