564f4c282a32e52fc4c53013630077960a4810e3
[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 <glibmm/ustring.h>
29
30 #include <boost/optional.hpp>
31
32 #include <libgnomecanvasmm/canvas.h>
33 #include <libgnomecanvasmm/group.h>
34 #include <libgnomecanvasmm/line.h>
35 #include <libgnomecanvasmm/pixbuf.h>
36
37 #include <cmath>
38
39 #include <gtkmm/layout.h>
40 #include <gtkmm/comboboxtext.h>
41
42 #include <gtkmm2ext/selector.h>
43 #include <gtkmm2ext/click_box.h>
44 #include <gtkmm2ext/dndtreeview.h>
45
46 #include <pbd/stateful.h>
47 #include <ardour/session.h>
48 #include <ardour/tempo.h>
49 #include <ardour/stretch.h>
50 #include <ardour/location.h>
51 #include <ardour/audioregion.h>
52
53 #include "audio_clock.h"
54 #include "gtk-custom-ruler.h"
55 #include "ardour_dialog.h"
56 #include "public_editor.h"
57 #include "editing.h"
58 #include "enums.h"
59 #include "editor_items.h"
60 #include "region_selection.h"
61 #include "canvas.h"
62 #include "time_axis_view.h"
63 #include "draginfo.h"
64
65 namespace Gtkmm2ext {
66         class TearOff;
67 }
68
69 namespace ARDOUR {
70         class AudioDiskstream;
71         class RouteGroup;
72         class Playlist;
73         class AudioPlaylist;
74         class Region;
75         class Location;
76         class TempoSection;
77         class NamedSelection;
78         class Session;
79         class AudioFilter;
80         class Crossfade;
81 }
82
83 namespace LADSPA {
84         class Plugin;
85 }
86
87 class TimeAxisView;
88 class RouteTimeAxisView;
89 class AudioTimeAxisView;
90 class AutomationTimeAxisView;
91 class AudioRegionView;
92 class CrossfadeView;
93 class PluginSelector;
94 class PlaylistSelector;
95 class Marker;
96 class GroupedButtons;
97 class AutomationLine;
98 class UIExportSpecification;
99 class ExportDialog;
100 class Selection;
101 class TempoLines;
102 class TimeSelection;
103 class TrackSelection;
104 class AutomationSelection;
105 class MixerStrip;
106 class StreamView;
107 class AudioStreamView;
108 class ControlPoint;
109 class SoundFileOmega;
110 class RhythmFerret;
111 #ifdef FFT_ANALYSIS
112 class AnalysisWindow;
113 #endif
114
115 /* <CMT Additions> */
116 class ImageFrameView;
117 class ImageFrameTimeAxisView;
118 class ImageFrameTimeAxis;
119 class MarkerTimeAxis ;
120 class MarkerView ;
121 class ImageFrameSocketHandler ;
122 class TimeAxisViewItem ;
123 /* </CMT Additions> */
124
125
126 class Editor : public PublicEditor
127 {
128   public:
129         Editor ();
130         ~Editor ();
131
132         void             connect_to_session (ARDOUR::Session *);
133         ARDOUR::Session* current_session() const { return session; }
134         void             first_idle ();
135         virtual bool have_idled() const { return _have_idled; }
136
137         nframes64_t leftmost_position() const { return leftmost_frame; }
138         nframes64_t current_page_frames() const {
139                 return (nframes64_t) floor (canvas_width * frames_per_unit);
140         }
141
142         void cycle_snap_mode ();
143         void cycle_snap_choice ();
144         void set_snap_to (Editing::SnapType);
145         void set_snap_mode (Editing::SnapMode);
146         void set_snap_threshold (double pixel_distance) {snap_threshold = pixel_distance;}
147
148         void undo (uint32_t n = 1);
149         void redo (uint32_t n = 1);
150
151         XMLNode& get_state ();
152         int set_state (const XMLNode& );
153
154         void set_mouse_mode (Editing::MouseMode, bool force=true);
155         void step_mouse_mode (bool next);
156         Editing::MouseMode current_mouse_mode () { return mouse_mode; }
157
158         void add_imageframe_time_axis(const std::string & track_name, void*) ;
159         void add_imageframe_marker_time_axis(const std::string & track_name, TimeAxisView* marked_track, void*) ;
160         void connect_to_image_compositor() ;
161         void scroll_timeaxis_to_imageframe_item(const TimeAxisViewItem* item) ;
162         TimeAxisView* get_named_time_axis(const std::string & name) ;
163         void foreach_time_axis_view (sigc::slot<void,TimeAxisView&>);
164         void add_to_idle_resize (TimeAxisView*, uint32_t);
165
166         void consider_auditioning (boost::shared_ptr<ARDOUR::Region>);
167         void hide_a_region (boost::shared_ptr<ARDOUR::Region>);
168         void remove_a_region (boost::shared_ptr<ARDOUR::Region>);
169
170 #ifdef USE_RUBBERBAND
171         std::vector<std::string> rb_opt_strings;
172 #endif
173
174         /* option editor-access */
175
176         void set_show_waveforms (bool yn);
177         bool show_waveforms() const { return _show_waveforms; }
178
179         void set_waveform_scale (Editing::WaveformScale);
180
181         void set_show_waveforms_recording (bool yn);
182         bool show_waveforms_recording() const { return _show_waveforms_recording; }
183         
184         /* things that need to be public to be used in the main menubar */
185
186         void new_region_from_selection ();
187         void separate_regions_between (const TimeSelection&);
188         void separate_region_from_selection ();
189         void separate_region_from_punch ();
190         void separate_region_from_loop ();
191         void separate_regions_using_location (ARDOUR::Location&);
192         void toggle_playback (bool with_abort);
193         void transition_to_rolling (bool forward);
194
195         /* undo related */
196
197         nframes64_t unit_to_frame (double unit) const {
198                 return (nframes64_t) rint (unit * frames_per_unit);
199         }
200         
201         double frame_to_unit (nframes64_t frame) const {
202                 return rint ((double) frame / (double) frames_per_unit);
203         }
204
205         double frame_to_unit (double frame) const {
206                 return rint (frame / frames_per_unit);
207         }
208
209         /* NOTE: these functions assume that the "pixel" coordinate is
210            the result of using the world->canvas affine transform on a
211            world coordinate. These coordinates already take into
212            account any scrolling carried out by adjusting the
213            xscroll_adjustment.  
214         */
215
216         nframes64_t pixel_to_frame (double pixel) const {
217                 
218                 /* pixel can be less than zero when motion events
219                    are processed. since we've already run the world->canvas
220                    affine, that means that the location *really* is "off
221                    to the right" and thus really is "before the start".
222                 */
223
224                 if (pixel >= 0) {
225                         return (nframes64_t) rint (pixel * frames_per_unit * GNOME_CANVAS(track_canvas->gobj())->pixels_per_unit);
226                 } else {
227                         return 0;
228                 }
229         }
230
231         gulong frame_to_pixel (nframes64_t frame) const {
232                 return (gulong) rint ((frame / (frames_per_unit *  GNOME_CANVAS(track_canvas->gobj())->pixels_per_unit)));
233         }
234
235         void flush_canvas ();
236
237         /* selection */
238
239         Selection& get_selection() const { return *selection; }
240         Selection& get_cut_buffer() const { return *cut_buffer; }
241
242         bool extend_selection_to_track (TimeAxisView&);
243
244         void play_selection ();
245         void select_all_in_track (Selection::Operation op);
246         void select_all (Selection::Operation op);
247         void invert_selection_in_track ();
248         void invert_selection ();
249         void deselect_all ();
250
251         /* tempo */
252
253         void set_show_measures (bool yn);
254         bool show_measures () const { return _show_measures; }
255
256 #ifdef FFT_ANALYSIS
257         /* analysis window */
258         void analyze_region_selection();
259         void analyze_range_selection();
260 #endif
261
262         /* export */
263
264         /* these initiate export ... */
265         
266         void export_session();
267         void export_selection();
268
269         void add_toplevel_controls (Gtk::Container&);
270         Gtk::HBox& get_status_bar_packer()  { return status_bar_hpacker; }
271
272         void      set_zoom_focus (Editing::ZoomFocus);
273         Editing::ZoomFocus get_zoom_focus () const { return zoom_focus; }
274         double   get_current_zoom () const { return frames_per_unit; }
275
276         void temporal_zoom_step (bool coarser);
277
278         /* stuff that AudioTimeAxisView and related classes use */
279
280         PlaylistSelector& playlist_selector() const;
281         void route_name_changed (TimeAxisView *);
282         void clear_playlist (boost::shared_ptr<ARDOUR::Playlist>);
283
284         void new_playlists (TimeAxisView*);
285         void copy_playlists (TimeAxisView*);
286         void clear_playlists (TimeAxisView*);
287
288         TrackViewList* get_valid_views (TimeAxisView*, ARDOUR::RouteGroup* grp = 0);
289         void get_onscreen_tracks (TrackViewList&);
290
291         Width editor_mixer_strip_width;
292         void maybe_add_mixer_strip_width (XMLNode&);
293         void show_editor_mixer (bool yn);
294         void create_editor_mixer ();
295         void set_selected_mixer_strip (TimeAxisView&);
296         void hide_track_in_display (TimeAxisView& tv, bool temporary = false);
297         void show_track_in_display (TimeAxisView& tv);
298
299         /* nudge is initiated by transport controls owned by ARDOUR_UI */
300
301         void nudge_forward (bool next, bool force_playhead);
302         void nudge_backward (bool next, bool force_playhead);
303
304         /* nudge initiated from context menu */
305
306         void nudge_forward_capture_offset ();
307         void nudge_backward_capture_offset ();
308
309         /* playhead/screen stuff */
310         
311         void set_follow_playhead (bool yn);
312         void toggle_follow_playhead ();
313         bool follow_playhead() const { return _follow_playhead; }
314         bool dragging_playhead () const { return _dragging_playhead; }
315
316         void toggle_waveform_visibility ();
317         void toggle_waveforms_while_recording ();
318         void toggle_measure_visibility ();
319         void toggle_logo_visibility ();
320
321         double get_physical_screen_width () const { return physical_screen_width; };
322         double physical_screen_width;
323         double physical_screen_height;
324
325         /* SMPTE timecode & video sync */
326
327         void smpte_fps_chosen (ARDOUR::SmpteFormat format);
328         void video_pullup_chosen (ARDOUR::Session::PullupFormat pullup);
329         void subframes_per_frame_chosen (uint32_t);
330
331         void update_smpte_mode();
332         void update_video_pullup();
333         void update_subframes_per_frame ();
334
335         /* fades & xfades */
336
337         void toggle_region_fades ();
338         void toggle_region_fades_visible ();
339         void toggle_selected_region_fades (int dir);
340         void update_region_fade_visibility ();
341
342         void toggle_auto_xfade ();
343         void toggle_xfades_active ();
344         void toggle_xfade_visibility ();
345         bool xfade_visibility() const { return _xfade_visibility; }
346         void update_xfade_visibility ();
347         void update_crossfade_model ();
348         void set_crossfade_model (ARDOUR::CrossfadeModel);
349
350         /* layers */
351         void set_layer_model (ARDOUR::LayerModel);
352         void update_layering_model ();
353         
354         void toggle_link_region_and_track_selection ();
355
356         /* redirect shared ops menu. caller must free returned menu */
357
358         Gtk::Menu* redirect_menu ();
359
360         /* floating windows/transient */
361
362         void ensure_float (Gtk::Window&);
363
364         void show_window ();
365
366         void scroll_tracks_down_line ();
367         void scroll_tracks_up_line ();
368
369         void move_selected_tracks (bool up);
370
371         bool new_regionviews_display_gain () { return _new_regionviews_show_envelope; }
372         void prepare_for_cleanup ();
373         void finish_cleanup ();
374
375         void maximise_editing_space();
376         void restore_editing_space();
377
378         void reset_x_origin (nframes64_t);
379         void reset_zoom (double);
380         void reposition_and_zoom (nframes64_t, double);
381
382         nframes64_t get_preferred_edit_position (bool ignore_playhead = false);
383
384         bool update_mouse_speed ();
385         bool decelerate_mouse_speed ();
386
387         void toggle_meter_updating();
388
389         void show_rhythm_ferret();
390
391         void goto_visual_state (uint32_t);
392         void save_visual_state (uint32_t);
393
394         void queue_draw_resize_line (int at);
395         void start_resize_line_ops ();
396         void end_resize_line_ops ();
397
398   protected:
399         void map_transport_state ();
400         void map_position_change (nframes64_t);
401
402         void on_realize();
403         bool on_expose_event (GdkEventExpose*);
404
405   private:
406         
407         ARDOUR::Session     *session;
408         bool                 constructed;
409   
410         // to keep track of the playhead position for control_scroll
411         boost::optional<nframes64_t> _control_scroll_target;
412
413         PlaylistSelector* _playlist_selector;
414
415         typedef std::pair<TimeAxisView*,XMLNode*> TAVState;
416
417         struct VisualState {
418             double              y_position;
419             double              frames_per_unit;
420             nframes64_t         leftmost_frame;
421             Editing::ZoomFocus  zoom_focus;
422             bool                zoomed_to_region;
423             std::list<TAVState> track_states;
424         };
425         
426         std::list<VisualState*> undo_visual_stack;
427         std::list<VisualState*> redo_visual_stack;
428         VisualState* current_visual_state (bool with_tracks = true);
429         void undo_visual_state ();
430         void redo_visual_state ();
431         void use_visual_state (VisualState&);
432         bool no_save_visual;
433         void swap_visual_state ();
434         
435         std::vector<VisualState*> visual_states;
436         sigc::connection visual_state_op_connection;
437         void start_visual_state_op (uint32_t n);
438         void cancel_visual_state_op (uint32_t n);
439         bool end_visual_state_op (uint32_t n);
440
441         nframes64_t leftmost_frame;
442         double      frames_per_unit;
443         Editing::ZoomFocus zoom_focus;
444
445         void set_frames_per_unit (double);
446         void post_zoom ();
447
448         Editing::MouseMode mouse_mode;
449
450         int  post_maximal_editor_width;
451         int  post_maximal_pane_position;
452         int  pre_maximal_pane_position;
453         int  pre_maximal_editor_width;
454         void pane_allocation_handler (Gtk::Allocation&, Gtk::Paned*);
455
456         Gtk::Notebook the_notebook;
457         Gtk::HPaned   edit_pane;
458
459         Gtk::EventBox meter_base;
460         Gtk::HBox     meter_box;
461         Gtk::EventBox marker_base;
462         Gtk::HBox     marker_box;
463         Gtk::VBox     scrollers_rulers_markers_box;
464
465         void location_changed (ARDOUR::Location *);
466         void location_flags_changed (ARDOUR::Location *, void *);
467         void refresh_location_display ();
468         void refresh_location_display_s (ARDOUR::Change);
469         void refresh_location_display_internal (ARDOUR::Locations::LocationList&);
470         void add_new_location (ARDOUR::Location *);
471         void location_gone (ARDOUR::Location *);
472         void remove_marker (ArdourCanvas::Item&, GdkEvent*);
473         gint really_remove_marker (ARDOUR::Location* loc);
474         void goto_nth_marker (int nth);
475
476         uint32_t location_marker_color;
477         uint32_t location_range_color;
478         uint32_t location_loop_color;
479         uint32_t location_punch_color;
480         uint32_t location_cd_marker_color;
481
482         struct LocationMarkers {
483             Marker* start;
484             Marker* end;
485             bool    valid;
486
487             LocationMarkers () : start(0), end(0), valid (true) {}
488             
489             ~LocationMarkers ();
490
491             void hide();
492             void show ();
493             void set_name (const string&);
494             void set_position (nframes64_t start, nframes64_t end = 0);
495             void set_color_rgba (uint32_t);
496         };
497
498         LocationMarkers  *find_location_markers (ARDOUR::Location *) const;
499         ARDOUR::Location* find_location_from_marker (Marker *, bool& is_start) const;
500         Marker* entered_marker;
501
502         typedef std::map<ARDOUR::Location*,LocationMarkers *> LocationMarkerMap;
503         LocationMarkerMap location_markers;
504
505         void hide_marker (ArdourCanvas::Item*, GdkEvent*);
506         void clear_marker_display ();
507         void mouse_add_new_marker (nframes64_t where, bool is_cd=false, bool is_xrun=false);
508         bool choose_new_marker_name(string &name);
509         void update_cd_marker_display ();
510         void ensure_cd_marker_updated (LocationMarkers * lam, ARDOUR::Location * location);
511
512         TimeAxisView*      clicked_trackview;
513         AudioTimeAxisView* clicked_audio_trackview;
514         RegionView*        clicked_regionview;
515         RegionSelection    latest_regionviews;
516         uint32_t           clicked_selection;
517         CrossfadeView*     clicked_crossfadeview;
518         ControlPoint*      clicked_control_point;
519
520         void sort_track_selection (TrackSelection* sel = 0);
521
522         void get_relevant_audio_tracks (std::set<AudioTimeAxisView*>& relevant_tracks);
523         void get_equivalent_regions (RegionView* rv, std::vector<RegionView*>&);
524         void mapover_audio_tracks (sigc::slot<void,AudioTimeAxisView&,uint32_t> sl, TimeAxisView*);
525
526         /* functions to be passed to mapover_audio_tracks(), possibly with sigc::bind()-supplied arguments */
527
528         void mapped_get_equivalent_regions (RouteTimeAxisView&, uint32_t, RegionView*, vector<RegionView*>*);
529         void mapped_use_new_playlist (AudioTimeAxisView&, uint32_t, vector<boost::shared_ptr<ARDOUR::Playlist> > const &);
530         void mapped_use_copy_playlist (AudioTimeAxisView&, uint32_t, vector<boost::shared_ptr<ARDOUR::Playlist> > const &);
531         void mapped_clear_playlist (AudioTimeAxisView&, uint32_t);
532
533         /* end */
534
535         void button_selection (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type);
536         bool button_release_can_deselect;
537
538         void catch_vanishing_regionview (RegionView *);
539
540         void set_selected_track (TimeAxisView&, Selection::Operation op = Selection::Set, bool no_remove=false);
541         void select_all_tracks ();
542         
543         bool set_selected_control_point_from_click (Selection::Operation op = Selection::Set, bool no_remove=false);
544         void set_selected_track_from_click (bool press, Selection::Operation op = Selection::Set, bool no_remove=false);
545         void set_selected_track_as_side_effect (bool force = false);
546         bool set_selected_regionview_from_click (bool press, Selection::Operation op = Selection::Set, bool no_track_remove=false);
547
548         void set_selected_regionview_from_region_list (boost::shared_ptr<ARDOUR::Region> region, Selection::Operation op = Selection::Set);
549         bool set_selected_regionview_from_map_event (GdkEventAny*, StreamView*, boost::weak_ptr<ARDOUR::Region>);
550         void collect_new_region_view (RegionView *);
551
552         Gtk::Menu track_context_menu;
553         Gtk::Menu track_region_context_menu;
554         Gtk::Menu track_selection_context_menu;
555         Gtk::Menu track_crossfade_context_menu;
556
557         Gtk::MenuItem* region_edit_menu_split_item;
558         Gtk::MenuItem* region_edit_menu_split_multichannel_item;
559         Gtk::Menu * track_region_edit_playlist_menu;
560         Gtk::Menu * track_edit_playlist_submenu;
561         Gtk::Menu * track_selection_edit_playlist_submenu;
562         
563         void popup_track_context_menu (int, int, ItemType, bool, nframes64_t);
564         Gtk::Menu* build_track_context_menu (nframes64_t);
565         Gtk::Menu* build_track_bus_context_menu (nframes64_t);
566         Gtk::Menu* build_track_region_context_menu (nframes64_t frame);
567         Gtk::Menu* build_track_crossfade_context_menu (nframes64_t);
568         Gtk::Menu* build_track_selection_context_menu (nframes64_t);
569         void add_dstream_context_items (Gtk::Menu_Helpers::MenuList&);
570         void add_bus_context_items (Gtk::Menu_Helpers::MenuList&);
571         void add_region_context_items (AudioStreamView*, boost::shared_ptr<ARDOUR::Region>, Gtk::Menu_Helpers::MenuList&);
572         void add_crossfade_context_items (AudioStreamView*, boost::shared_ptr<ARDOUR::Crossfade>, Gtk::Menu_Helpers::MenuList&, bool many);
573         void add_selection_context_items (Gtk::Menu_Helpers::MenuList&);
574
575         void handle_new_route (ARDOUR::Session::RouteList&);
576         void remove_route (TimeAxisView *);
577         bool route_removal;
578
579         Gtk::HBox           global_hpacker;
580         Gtk::VBox           global_vpacker;
581         Gtk::VBox           vpacker;
582
583         bool need_resize_line;
584         int  resize_line_y;
585         int  old_resize_line_y;
586
587         Gdk::Cursor*          current_canvas_cursor;
588         void set_canvas_cursor ();
589         Gdk::Cursor* which_grabber_cursor ();
590
591         ArdourCanvas::Canvas* track_canvas;
592         ArdourCanvas::Text* verbose_canvas_cursor;
593         bool                 verbose_cursor_visible;
594
595         void parameter_changed (const char *);
596         
597         bool track_canvas_motion (GdkEvent*);
598
599         void set_verbose_canvas_cursor (const string &, double x, double y);
600         void set_verbose_canvas_cursor_text (const string &);
601         void show_verbose_canvas_cursor();
602         void hide_verbose_canvas_cursor();
603
604         bool verbose_cursor_on; // so far unused
605
606         Gtk::EventBox      time_canvas_event_box;
607         Gtk::EventBox      track_canvas_event_box;
608         Gtk::EventBox      time_button_event_box;
609         Gtk::EventBox      ruler_label_event_box;
610
611         ArdourCanvas::Pixbuf*     logo_item;
612         ArdourCanvas::Group*      minsec_group;
613         ArdourCanvas::Group*      bbt_group;
614         ArdourCanvas::Group*      smpte_group;
615         ArdourCanvas::Group*      frame_group;
616         ArdourCanvas::Group*      tempo_group;
617         ArdourCanvas::Group*      meter_group;
618         ArdourCanvas::Group*      marker_group;
619         ArdourCanvas::Group*      range_marker_group;
620         ArdourCanvas::Group*      transport_marker_group;
621         ArdourCanvas::Group*      cd_marker_group;
622
623         ArdourCanvas::Group*      timebar_group;
624
625         /* These bars never need to be scrolled */
626         ArdourCanvas::Group*      meter_bar_group;
627         ArdourCanvas::Group*      tempo_bar_group;
628         ArdourCanvas::Group*      marker_bar_group;
629         ArdourCanvas::Group*      range_marker_bar_group;
630         ArdourCanvas::Group*      transport_marker_bar_group;
631         ArdourCanvas::Group*      cd_marker_bar_group;
632
633         ArdourCanvas::Group* _background_group;
634         /* 
635            The _master_group is the group containing all items
636            that require horizontal scrolling..
637            It is primarily used to separate canvas items 
638            that require horizontal scrolling from those that do not. 
639         */
640         ArdourCanvas::Group* _master_group;
641         /* 
642            The _trackview_group is the group containing all trackviews.
643            It is only scrolled vertically.
644         */
645         ArdourCanvas::Group* _trackview_group;
646         /* 
647            This canvas group is used for region motion.
648            It sits on top of the _trackview_group 
649         */
650         ArdourCanvas::Group* _region_motion_group;
651         
652         enum RulerType {
653                 ruler_metric_smpte = 0,
654                 ruler_metric_bbt = 1,
655                 ruler_metric_frames = 2,
656                 ruler_metric_minsec = 3,
657
658                 ruler_time_tempo = 4,
659                 ruler_time_meter = 5,
660                 ruler_time_marker = 6,
661                 ruler_time_range_marker = 7,
662                 ruler_time_transport_marker = 8,
663                 ruler_time_cd_marker = 9,
664         };
665
666         static GtkCustomMetric ruler_metrics[4];
667         Glib::RefPtr<Gtk::ToggleAction> ruler_timecode_action;
668         Glib::RefPtr<Gtk::ToggleAction> ruler_bbt_action;
669         Glib::RefPtr<Gtk::ToggleAction> ruler_samples_action;
670         Glib::RefPtr<Gtk::ToggleAction> ruler_minsec_action;
671         Glib::RefPtr<Gtk::ToggleAction> ruler_tempo_action;
672         Glib::RefPtr<Gtk::ToggleAction> ruler_meter_action;
673         Glib::RefPtr<Gtk::ToggleAction> ruler_marker_action;
674         Glib::RefPtr<Gtk::ToggleAction> ruler_range_action;
675         Glib::RefPtr<Gtk::ToggleAction> ruler_loop_punch_action;
676         Glib::RefPtr<Gtk::ToggleAction> ruler_cd_marker_action;
677         bool                   no_ruler_shown_update;
678         
679         gint ruler_button_press (GdkEventButton*);
680         gint ruler_button_release (GdkEventButton*);
681         gint ruler_mouse_motion (GdkEventMotion*);
682         bool ruler_scroll (GdkEventScroll* event);
683
684         gint ruler_pressed_button;
685         Gtk::Widget * ruler_grabbed_widget;
686         
687         void initialize_rulers ();
688         void update_just_smpte ();
689         void update_fixed_rulers ();
690         void update_tempo_based_rulers (); 
691         void popup_ruler_menu (nframes64_t where = 0, ItemType type = RegionItem);
692         void update_ruler_visibility ();
693         void set_ruler_visible (RulerType, bool);
694         void toggle_ruler_visibility (RulerType rt);
695         void ruler_toggled (int);
696         gint ruler_label_button_release (GdkEventButton*);
697         void store_ruler_visibility ();
698         void restore_ruler_visibility ();
699         
700         static gint _metric_get_smpte (GtkCustomRulerMark **, gdouble, gdouble, gint);
701         static gint _metric_get_bbt (GtkCustomRulerMark **, gdouble, gdouble, gint);
702         static gint _metric_get_frames (GtkCustomRulerMark **, gdouble, gdouble, gint);
703         static gint _metric_get_minsec (GtkCustomRulerMark **, gdouble, gdouble, gint);
704         
705         gint metric_get_smpte (GtkCustomRulerMark **, gdouble, gdouble, gint);
706         gint metric_get_bbt (GtkCustomRulerMark **, gdouble, gdouble, gint);
707         gint metric_get_frames (GtkCustomRulerMark **, gdouble, gdouble, gint);
708         gint metric_get_minsec (GtkCustomRulerMark **, gdouble, gdouble, gint);
709
710         Gtk::Widget        *_ruler_separator;
711         GtkWidget          *_smpte_ruler;
712         GtkWidget          *_bbt_ruler;
713         GtkWidget          *_frames_ruler;
714         GtkWidget          *_minsec_ruler;
715         Gtk::Widget        *smpte_ruler;
716         Gtk::Widget        *bbt_ruler;
717         Gtk::Widget        *frames_ruler;
718         Gtk::Widget        *minsec_ruler;
719         static Editor      *ruler_editor;
720
721         static const double timebar_height;
722         guint32 visible_timebars;
723         gdouble canvas_timebars_vsize;
724         gdouble get_canvas_timebars_vsize () const { return canvas_timebars_vsize; }
725         Gtk::Menu          *editor_ruler_menu;
726         
727         ArdourCanvas::SimpleRect* tempo_bar;
728         ArdourCanvas::SimpleRect* meter_bar;
729         ArdourCanvas::SimpleRect* marker_bar;
730         ArdourCanvas::SimpleRect* range_marker_bar;
731         ArdourCanvas::SimpleRect* transport_marker_bar;
732         ArdourCanvas::SimpleRect* cd_marker_bar;
733
734         
735         ArdourCanvas::SimpleLine* tempo_line;
736         ArdourCanvas::SimpleLine* meter_line;
737         ArdourCanvas::SimpleLine* marker_line;
738         ArdourCanvas::SimpleLine* range_marker_line;
739         ArdourCanvas::SimpleLine* transport_marker_line;
740         ArdourCanvas::SimpleLine* cd_marker_line;
741
742         Gtk::Label  minsec_label;
743         Gtk::Label  bbt_label;
744         Gtk::Label  smpte_label;
745         Gtk::Label  frame_label;
746         Gtk::Label  tempo_label;
747         Gtk::Label  meter_label;
748         Gtk::Label  mark_label;
749         Gtk::Label  range_mark_label;
750         Gtk::Label  transport_mark_label;
751         Gtk::Label  cd_mark_label;
752         
753
754         Gtk::VBox          time_button_vbox;
755         Gtk::HBox          time_button_hbox;
756
757         struct Cursor {
758             Editor&               editor;
759             ArdourCanvas::Points  points;
760             ArdourCanvas::Line    canvas_item;
761             nframes64_t           current_frame;
762             double                length;
763
764             Cursor (Editor&, bool (Editor::*)(GdkEvent*,ArdourCanvas::Item*));
765             ~Cursor ();
766
767             void set_position (nframes64_t);
768             void set_length (double units);
769             void set_y_axis (double position);
770         };
771
772         friend struct Cursor; /* it needs access to several private
773                                  fields. XXX fix me.
774                               */
775
776         Cursor* playhead_cursor;
777         ArdourCanvas::Group* cursor_group;
778
779         nframes64_t get_region_boundary (nframes64_t pos, int32_t dir, bool with_selection, bool only_onscreen);
780
781         void    cursor_to_region_boundary (bool with_selection, int32_t dir);
782         void    cursor_to_next_region_boundary (bool with_selection);
783         void    cursor_to_previous_region_boundary (bool with_selection);
784         void    cursor_to_next_region_point (Cursor*, ARDOUR::RegionPoint);
785         void    cursor_to_previous_region_point (Cursor*, ARDOUR::RegionPoint);
786         void    cursor_to_region_point (Cursor*, ARDOUR::RegionPoint, int32_t dir);
787         void    cursor_to_selection_start (Cursor *);
788         void    cursor_to_selection_end   (Cursor *);
789
790         void    selected_marker_to_region_boundary (bool with_selection, int32_t dir);
791         void    selected_marker_to_next_region_boundary (bool with_selection);
792         void    selected_marker_to_previous_region_boundary (bool with_selection);
793         void    selected_marker_to_next_region_point (ARDOUR::RegionPoint);
794         void    selected_marker_to_previous_region_point (ARDOUR::RegionPoint);
795         void    selected_marker_to_region_point (ARDOUR::RegionPoint, int32_t dir);
796         void    selected_marker_to_selection_start ();
797         void    selected_marker_to_selection_end   ();
798
799         void    select_all_selectables_using_cursor (Cursor *, bool);
800         void    select_all_selectables_using_edit (bool);
801         void    select_all_selectables_between (bool within);
802         void    select_range_between ();
803
804         boost::shared_ptr<ARDOUR::Region> find_next_region (nframes64_t, ARDOUR::RegionPoint, int32_t dir, TrackViewList&, TimeAxisView ** = 0);
805         nframes64_t find_next_region_boundary (nframes64_t, int32_t dir, const TrackViewList&);
806
807         vector<nframes64_t> region_boundary_cache;
808         void build_region_boundary_cache ();
809
810         Gtk::HBox           top_hbox;
811         Gtk::HBox           bottom_hbox;
812         
813         Gtk::Table          edit_packer;
814         Gtk::VScrollbar     edit_vscrollbar;
815
816         Gtk::Adjustment     vertical_adjustment;
817         Gtk::Adjustment     horizontal_adjustment;
818
819         Gtk::Layout         controls_layout;
820         bool control_layout_scroll (GdkEventScroll* ev);
821         void controls_layout_size_request (Gtk::Requisition*);
822         sigc::connection controls_layout_size_request_connection;
823
824         Gtk::HScrollbar     edit_hscrollbar;
825         bool                _dragging_hscrollbar;
826
827         void reset_hscrollbar_stepping ();
828         
829         bool hscrollbar_button_press (GdkEventButton*);
830         bool hscrollbar_button_release (GdkEventButton*);
831         void hscrollbar_allocate (Gtk::Allocation &alloc);
832
833         double canvas_width;
834         double canvas_height;
835         double full_canvas_height;
836
837         bool track_canvas_map_handler (GdkEventAny*);
838
839         gint edit_controls_button_release (GdkEventButton*);
840         Gtk::Menu *edit_controls_left_menu;
841         Gtk::Menu *edit_controls_right_menu;
842
843         Gtk::VBox           ruler_label_vbox;
844         Gtk::VBox           track_canvas_vbox;
845         Gtk::VBox           time_canvas_vbox;
846         Gtk::VBox           edit_controls_vbox;
847         Gtk::HBox           edit_controls_hbox;
848
849         void control_scroll (float);
850         void access_action (std::string,std::string);
851         bool deferred_control_scroll (nframes64_t);
852         sigc::connection control_scroll_connection;
853
854         gdouble get_trackview_group_vertical_offset () const { return vertical_adjustment.get_value () - canvas_timebars_vsize;}
855         
856         ArdourCanvas::Group* get_background_group () const { return _background_group; }
857         ArdourCanvas::Group* get_trackview_group () const { return _trackview_group; }
858         double last_trackview_group_vertical_offset;
859         void tie_vertical_scrolling ();
860         void scroll_canvas_horizontally ();
861         void scroll_canvas_vertically ();
862
863         struct VisualChange {
864             enum Type { 
865                     TimeOrigin = 0x1,
866                     ZoomLevel = 0x2
867             };
868
869             Type pending;
870             nframes64_t time_origin;
871             double frames_per_unit;
872
873             int idle_handler_id;
874
875             VisualChange() : pending ((VisualChange::Type) 0), time_origin (0), frames_per_unit (0), idle_handler_id (-1) {}
876         };
877
878
879         VisualChange pending_visual_change;
880
881         static int _idle_visual_changer (void *arg);
882         int idle_visual_changer ();
883
884         void queue_visual_change (nframes64_t);
885         void queue_visual_change (double);
886
887         void end_location_changed (ARDOUR::Location*);
888
889         struct RegionListDisplayModelColumns : public Gtk::TreeModel::ColumnRecord {
890             RegionListDisplayModelColumns() {
891                     add (name);
892                     add (region);
893                     add (color_);
894             }
895             Gtk::TreeModelColumn<Glib::ustring> name;
896             Gtk::TreeModelColumn<boost::shared_ptr<ARDOUR::Region> > region;
897             Gtk::TreeModelColumn<Gdk::Color> color_;
898         };
899             
900         RegionListDisplayModelColumns          region_list_columns;
901         Gtkmm2ext::DnDTreeView<boost::shared_ptr<ARDOUR::Region> > region_list_display;
902         
903         Glib::RefPtr<Gtk::TreeStore>           region_list_model;
904         Glib::RefPtr<Gtk::ToggleAction>        toggle_full_region_list_action;
905         Glib::RefPtr<Gtk::ToggleAction>        toggle_show_auto_regions_action;
906
907         void region_list_selection_changed ();
908         bool region_list_selection_filter (const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreeModel::Path& path, bool yn);
909         void region_name_edit (const Glib::ustring&, const Glib::ustring&);
910         void get_regions_corresponding_to (boost::shared_ptr<ARDOUR::Region> region, std::vector<RegionView*>& regions);
911
912         Gtk::Menu          *region_list_menu;
913         Gtk::ScrolledWindow region_list_scroller;
914         Gtk::Frame          region_list_frame;
915
916         bool region_list_display_key_press (GdkEventKey *);
917         bool region_list_display_key_release (GdkEventKey *);
918         bool region_list_display_button_press (GdkEventButton *);
919         bool region_list_display_button_release (GdkEventButton *);
920         void region_list_clear ();
921         void region_list_selection_mapover (sigc::slot<void,boost::shared_ptr<ARDOUR::Region> >);
922         void build_region_list_menu ();
923         void show_region_list_display_context_menu (int button, int time);
924
925         bool show_automatic_regions_in_region_list;
926         Editing::RegionListSortType region_list_sort_type;
927
928         void reset_region_list_sort_direction (bool);
929         void reset_region_list_sort_type (Editing::RegionListSortType);
930
931         void toggle_full_region_list ();
932         void toggle_show_auto_regions ();
933
934         int region_list_sorter (Gtk::TreeModel::iterator, Gtk::TreeModel::iterator);
935
936         /* snapshots */
937
938         Gtk::ScrolledWindow      snapshot_display_scroller;
939         struct SnapshotDisplayModelColumns : public Gtk::TreeModel::ColumnRecord {
940             SnapshotDisplayModelColumns() { 
941                     add (visible_name);
942                     add (real_name);
943             }
944             Gtk::TreeModelColumn<Glib::ustring> visible_name;
945             Gtk::TreeModelColumn<Glib::ustring> real_name;
946         };
947
948         SnapshotDisplayModelColumns snapshot_display_columns;
949         Glib::RefPtr<Gtk::ListStore> snapshot_display_model;
950         Gtk::TreeView snapshot_display;
951         Gtk::Menu snapshot_context_menu;
952
953         bool snapshot_display_button_press (GdkEventButton*);
954         void snapshot_display_selection_changed ();
955         void redisplay_snapshots();
956         void popup_snapshot_context_menu (int, int32_t, Glib::ustring);
957
958         /* named selections */
959
960         struct NamedSelectionDisplayModelColumns : public Gtk::TreeModel::ColumnRecord {
961             NamedSelectionDisplayModelColumns() { 
962                     add (text);
963                     add (selection);
964             }
965             Gtk::TreeModelColumn<Glib::ustring>  text;
966             Gtk::TreeModelColumn<ARDOUR::NamedSelection*>    selection;
967         };
968
969         NamedSelectionDisplayModelColumns named_selection_columns;
970         Glib::RefPtr<Gtk::TreeStore>     named_selection_model;
971
972         Gtkmm2ext::DnDTreeView<ARDOUR::NamedSelection*> named_selection_display;
973         Gtk::ScrolledWindow    named_selection_scroller;
974
975         void create_named_selection ();
976         void paste_named_selection (float times);
977         void remove_selected_named_selections ();
978         void remove_snapshot (Glib::ustring);
979         void rename_snapshot (Glib::ustring);
980
981         void handle_new_named_selection ();
982         void add_named_selection_to_named_selection_display (ARDOUR::NamedSelection&);
983         void redisplay_named_selections ();
984
985         bool named_selection_display_button_release (GdkEventButton *ev);
986         bool named_selection_display_key_release (GdkEventKey *ev);
987         void named_selection_display_selection_changed ();
988
989         /* track views */
990         TrackViewList  track_views;
991         TimeAxisView     *trackview_by_y_position (double ypos);
992
993         static Gdk::Cursor* cross_hair_cursor;
994         static Gdk::Cursor* trimmer_cursor;
995         static Gdk::Cursor* selector_cursor;
996         static Gdk::Cursor* grabber_cursor;
997         static Gdk::Cursor* grabber_edit_point_cursor;
998         static Gdk::Cursor* zoom_cursor;
999         static Gdk::Cursor* time_fx_cursor;
1000         static Gdk::Cursor* fader_cursor;
1001         static Gdk::Cursor* speaker_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 scroll_connection;
1009         nframes64_t last_update_frame;
1010         void center_screen (nframes64_t);
1011         void center_screen_internal (nframes64_t, float);
1012         
1013         void update_current_screen ();
1014         
1015         void session_going_away ();
1016
1017         nframes64_t cut_buffer_start;
1018         nframes64_t cut_buffer_length;
1019
1020         bool typed_event (ArdourCanvas::Item*, GdkEvent*, ItemType);
1021         bool button_press_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1022         bool button_release_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1023         bool motion_handler (ArdourCanvas::Item*, GdkEvent*, ItemType, bool from_autoscroll = false);
1024         bool enter_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1025         bool leave_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
1026         
1027         /* KEYMAP HANDLING */
1028
1029         void register_actions ();
1030
1031         int ensure_cursor (nframes64_t* pos);
1032
1033         void handle_new_audio_region (boost::weak_ptr<ARDOUR::AudioRegion>);
1034         void handle_new_audio_regions (vector<boost::weak_ptr<ARDOUR::AudioRegion> >& );
1035         void handle_audio_region_removed (boost::weak_ptr<ARDOUR::AudioRegion>);
1036         void add_audio_region_to_region_display (boost::shared_ptr<ARDOUR::AudioRegion>);
1037         void add_audio_regions_to_region_display (std::vector<boost::weak_ptr<ARDOUR::AudioRegion> > & );
1038         void region_hidden (boost::shared_ptr<ARDOUR::Region>);
1039         void redisplay_regions ();
1040         bool no_region_list_redisplay;
1041         void insert_into_tmp_audio_regionlist(boost::shared_ptr<ARDOUR::AudioRegion>);
1042
1043         list<boost::shared_ptr<ARDOUR::AudioRegion> > tmp_audio_region_list;
1044
1045         void cut_copy (Editing::CutCopyOp);
1046         void cut_copy_points (Editing::CutCopyOp);
1047         void cut_copy_regions (Editing::CutCopyOp, RegionSelection&);
1048         void cut_copy_ranges (Editing::CutCopyOp);
1049
1050         void mouse_paste ();
1051         void paste_internal (nframes64_t position, float times);
1052
1053         /* EDITING OPERATIONS */
1054         
1055         void reset_point_selection ();
1056         void toggle_region_mute ();
1057         void toggle_region_lock ();
1058         void toggle_region_opaque ();
1059         void toggle_record_enable ();
1060         void set_region_lock_style (ARDOUR::Region::PositionLockStyle);
1061         void raise_region ();
1062         void raise_region_to_top ();
1063         void lower_region ();
1064         void lower_region_to_bottom ();
1065         void split_region ();
1066         void split_region_at (nframes64_t);
1067         void split_regions_at (nframes64_t, RegionSelection&);
1068         void split_region_at_transients ();
1069         void split_region_at_points (boost::shared_ptr<ARDOUR::Region>, ARDOUR::AnalysisFeatureList&, bool can_ferret);
1070         void crop_region_to_selection ();
1071         void crop_region_to (nframes64_t start, nframes64_t end);
1072         void set_sync_point (nframes64_t, const RegionSelection&);
1073         void set_region_sync_from_edit_point ();
1074         void remove_region_sync();
1075         void align_selection (ARDOUR::RegionPoint, nframes64_t position, const RegionSelection&);
1076         void align_selection_relative (ARDOUR::RegionPoint point, nframes64_t position, const RegionSelection&);
1077         void align_region (boost::shared_ptr<ARDOUR::Region>, ARDOUR::RegionPoint point, nframes64_t position);
1078         void align_region_internal (boost::shared_ptr<ARDOUR::Region>, ARDOUR::RegionPoint point, nframes64_t position);
1079         void remove_region ();
1080         void remove_clicked_region ();
1081         void edit_region ();
1082         void rename_region ();
1083         void duplicate_some_regions (RegionSelection&, float times);
1084         void duplicate_selection (float times);
1085         void region_fill_selection ();
1086
1087         void region_fill_track ();
1088         void audition_playlist_region_standalone (boost::shared_ptr<ARDOUR::Region>);
1089         void audition_playlist_region_via_route (boost::shared_ptr<ARDOUR::Region>, ARDOUR::Route&);
1090         void split_multichannel_region();
1091         void reverse_region ();
1092         void normalize_region ();
1093         void denormalize_region ();
1094         void adjust_region_scale_amplitude (bool up);
1095
1096         void do_insert_time ();
1097         void insert_time (nframes64_t pos, nframes64_t distance, Editing::InsertTimeOption opt, bool ignore_music_glue, bool markers_too);
1098
1099         void tab_to_transient (bool forward);
1100
1101         void use_region_as_bar ();
1102         void use_range_as_bar ();
1103
1104         void define_one_bar (nframes64_t start, nframes64_t end);
1105
1106         void audition_region_from_region_list ();
1107         void hide_region_from_region_list ();
1108         void remove_region_from_region_list ();
1109
1110         void align (ARDOUR::RegionPoint);
1111         void align_relative (ARDOUR::RegionPoint);
1112         void naturalize ();
1113
1114         void reset_focus ();
1115
1116         void split ();
1117
1118         void cut ();
1119         void copy ();
1120         void paste (float times);
1121
1122         int  get_prefix (float&, bool&);
1123
1124         void keyboard_paste ();
1125         void keyboard_insert_region_list_selection ();
1126
1127         void region_from_selection ();
1128         void create_region_from_selection (std::vector<boost::shared_ptr<ARDOUR::AudioRegion> >&);
1129
1130         void play_from_start ();
1131         void play_from_edit_point ();
1132         void play_from_edit_point_and_return ();
1133         void play_selected_region ();
1134         void play_edit_range ();
1135         void loop_selected_region ();
1136         void play_location (ARDOUR::Location&);
1137         void loop_location (ARDOUR::Location&);
1138
1139         void temporal_zoom_selection ();
1140         void temporal_zoom_region (bool both_axes);
1141         void toggle_zoom_region (bool both_axes);
1142         bool zoomed_to_region;
1143         void temporal_zoom_session ();
1144         void temporal_zoom (gdouble scale);
1145         void temporal_zoom_by_frame (nframes64_t start, nframes64_t end, const string & op);
1146         void temporal_zoom_to_frame (bool coarser, nframes64_t frame);
1147
1148         void amplitude_zoom (gdouble scale);
1149         void amplitude_zoom_step (bool in);
1150
1151         void insert_region_list_drag (boost::shared_ptr<ARDOUR::AudioRegion>, int x, int y);
1152         void insert_region_list_selection (float times);
1153
1154         void add_external_audio_action (Editing::ImportMode);
1155         void external_audio_dialog ();
1156
1157         int  check_whether_and_how_to_import(string, bool all_or_nothing = true);
1158         bool check_multichannel_status (const std::vector<Glib::ustring>& paths);
1159
1160         SoundFileOmega* sfbrowser;
1161         
1162         void bring_in_external_audio (Editing::ImportMode mode,  nframes64_t& pos);
1163
1164         bool  idle_drop_paths  (std::vector<Glib::ustring> paths, nframes64_t frame, double ypos);
1165         void  drop_paths_part_two  (const std::vector<Glib::ustring>& paths, nframes64_t frame, double ypos);
1166         
1167         void do_import (vector<Glib::ustring> paths, Editing::ImportDisposition, Editing::ImportMode mode, ARDOUR::SrcQuality, nframes64_t&);
1168         void do_embed (vector<Glib::ustring> paths, Editing::ImportDisposition, Editing::ImportMode mode,  nframes64_t&);
1169
1170         int  import_sndfiles (vector<Glib::ustring> paths, Editing::ImportMode mode,  ARDOUR::SrcQuality, nframes64_t& pos,
1171                               int target_regions, int target_tracks, boost::shared_ptr<ARDOUR::AudioTrack>, bool, uint32_t total);
1172         int  embed_sndfiles (vector<Glib::ustring> paths, bool multiple_files, bool& check_sample_rate, Editing::ImportMode mode, 
1173                              nframes64_t& pos, int target_regions, int target_tracks, boost::shared_ptr<ARDOUR::AudioTrack>);
1174
1175         int add_sources (vector<Glib::ustring> paths, ARDOUR::SourceList& sources, nframes64_t& pos, Editing::ImportMode,
1176                          int target_regions, int target_tracks, boost::shared_ptr<ARDOUR::AudioTrack>&, bool add_channel_suffix);
1177         int finish_bringing_in_audio (boost::shared_ptr<ARDOUR::AudioRegion> region, uint32_t, uint32_t,  nframes64_t& pos, Editing::ImportMode mode,
1178                                       boost::shared_ptr<ARDOUR::AudioTrack>& existing_track);
1179
1180         boost::shared_ptr<ARDOUR::AudioTrack> get_nth_selected_audio_track (int nth) const;
1181
1182         /* generic interthread progress window */
1183         
1184         ArdourDialog* interthread_progress_window;
1185         Gtk::Label interthread_progress_label;
1186         Gtk::VBox interthread_progress_vbox;
1187         Gtk::ProgressBar interthread_progress_bar;
1188         Gtk::Button interthread_cancel_button;
1189         Gtk::Label interthread_cancel_label;
1190         sigc::connection  interthread_progress_connection;
1191         void interthread_cancel_clicked ();
1192         void build_interthread_progress_window ();
1193         ARDOUR::InterThreadInfo* current_interthread_info;
1194
1195 #ifdef FFT_ANALYSIS
1196         AnalysisWindow* analysis_window;
1197 #endif
1198
1199         /* import specific info */
1200
1201         struct EditorImportStatus : public ARDOUR::Session::import_status {
1202             Editing::ImportMode mode;
1203             nframes64_t pos;
1204             int target_tracks;
1205             int target_regions;
1206             boost::shared_ptr<ARDOUR::AudioTrack> track;
1207             bool replace;
1208         };
1209
1210         EditorImportStatus import_status;
1211         gint import_progress_timeout (void *);
1212         static void *_import_thread (void *);
1213         void* import_thread ();
1214         void finish_import ();
1215
1216         /* to support this ... */
1217
1218         void import_audio (bool as_tracks);
1219         void do_import (vector<Glib::ustring> paths, bool split, bool as_tracks);
1220
1221         void move_to_start ();
1222         void move_to_end ();
1223         void goto_frame ();
1224         void center_playhead ();
1225         void center_edit_point ();
1226         void edit_cursor_backward ();
1227         void edit_cursor_forward ();
1228         void playhead_forward_to_grid ();
1229         void playhead_backward_to_grid ();
1230         void playhead_backward ();
1231         void playhead_forward ();
1232         void scroll_playhead (bool forward);
1233         void scroll_backward (float pages=0.8f);
1234         void scroll_forward (float pages=0.8f);
1235         void scroll_tracks_down ();
1236         void scroll_tracks_up ();
1237         void delete_sample_forward ();
1238         void delete_sample_backward ();
1239         void delete_screen ();
1240         void search_backwards ();
1241         void search_forwards ();
1242         void set_mark ();
1243         void clear_markers ();
1244         void clear_ranges ();
1245         void clear_locations ();
1246         void unhide_markers ();
1247         void unhide_ranges ();
1248         void jump_forward_to_mark ();
1249         void jump_backward_to_mark ();
1250         void cursor_align (bool playhead_to_edit);
1251
1252         void remove_last_capture ();
1253         void select_all_selectables_using_time_selection ();
1254         void select_all_selectables_using_loop();
1255         void select_all_selectables_using_punch();
1256         void set_selection_from_range (ARDOUR::Location&);
1257         void set_selection_from_punch ();
1258         void set_selection_from_loop ();
1259         void set_selection_from_audio_region ();
1260
1261         void add_location_mark (nframes64_t where);
1262         void add_location_from_audio_region ();
1263         void add_locations_from_audio_region ();
1264         void add_location_from_selection ();
1265         void set_loop_from_selection (bool play);
1266         void set_punch_from_selection ();
1267         void set_punch_from_region ();
1268
1269         void set_loop_from_edit_range (bool play);
1270         void set_loop_from_region (bool play);
1271         void set_punch_from_edit_range ();
1272
1273         void set_loop_range (nframes64_t start, nframes64_t end, std::string cmd);
1274         void set_punch_range (nframes64_t start, nframes64_t end, std::string cmd);
1275
1276         void add_location_from_playhead_cursor ();
1277         bool select_new_marker;
1278
1279         void reverse_selection ();
1280         void edit_envelope ();
1281
1282         void start_scrolling ();
1283         void stop_scrolling ();
1284
1285         bool _scrubbing;
1286         double last_scrub_x;
1287         int scrubbing_direction;
1288         int scrub_reversals;
1289         int scrub_reverse_distance;
1290         void scrub ();
1291
1292         void keyboard_selection_begin ();
1293         void keyboard_selection_finish (bool add);
1294         bool have_pending_keyboard_selection;
1295         nframes64_t pending_keyboard_selection_start;
1296
1297         boost::shared_ptr<ARDOUR::Region> select_region_for_operation (int dir, TimeAxisView **tv);
1298         void extend_selection_to_end_of_region (bool next);
1299         void extend_selection_to_start_of_region (bool previous);
1300
1301         Editing::SnapType snap_type;
1302         Editing::SnapMode snap_mode;
1303         double snap_threshold;
1304
1305         void handle_gui_changes (const string &, void *);
1306         bool ignore_gui_changes;
1307
1308         void    hide_all_tracks (bool with_select);
1309
1310         DragInfo drag_info;
1311         LineDragInfo current_line_drag_info;
1312
1313         void start_grab (GdkEvent*, Gdk::Cursor* cursor = 0);
1314         bool end_grab (ArdourCanvas::Item*, GdkEvent*);
1315         void swap_grab (ArdourCanvas::Item*, Gdk::Cursor* cursor, uint32_t time);
1316         void break_drag ();
1317         void finalize_drag ();
1318
1319         Gtk::Menu fade_context_menu;
1320         void popup_fade_context_menu (int, int, ArdourCanvas::Item*, ItemType);
1321
1322         void region_gain_motion_callback (ArdourCanvas::Item*, GdkEvent*);
1323
1324         void start_fade_in_grab (ArdourCanvas::Item*, GdkEvent*);
1325         void start_fade_out_grab (ArdourCanvas::Item*, GdkEvent*);
1326         void fade_in_drag_motion_callback (ArdourCanvas::Item*, GdkEvent*);
1327         void fade_out_drag_motion_callback (ArdourCanvas::Item*, GdkEvent*);
1328         void fade_in_drag_finished_callback (ArdourCanvas::Item*, GdkEvent*);
1329         void fade_out_drag_finished_callback (ArdourCanvas::Item*, GdkEvent*);
1330
1331         void set_fade_in_shape (ARDOUR::AudioRegion::FadeShape);
1332         void set_fade_out_shape (ARDOUR::AudioRegion::FadeShape);
1333         
1334         void set_fade_length (bool in);
1335         void toggle_fade_active (bool in);
1336         void set_fade_in_active (bool);
1337         void set_fade_out_active (bool);
1338         
1339         std::set<boost::shared_ptr<ARDOUR::Playlist> > motion_frozen_playlists;
1340         RegionSelection pre_drag_region_selection;
1341         void region_drag_motion_callback (ArdourCanvas::Item*, GdkEvent*);
1342         void region_drag_finished_callback (ArdourCanvas::Item*, GdkEvent*);
1343         bool check_region_drag_possible (AudioTimeAxisView**);
1344         void possibly_copy_regions_during_grab (GdkEvent*);
1345         void region_drag_splice_motion_callback (ArdourCanvas::Item*, GdkEvent*);
1346         void region_drag_splice_finished_callback (ArdourCanvas::Item*, GdkEvent*);
1347
1348         bool _dragging_playhead;
1349         bool _dragging_edit_point;
1350
1351         void cursor_drag_motion_callback (ArdourCanvas::Item*, GdkEvent*);
1352         void cursor_drag_finished_callback (ArdourCanvas::Item*, GdkEvent*);
1353         void cursor_drag_finished_ensure_locate_callback (ArdourCanvas::Item*, GdkEvent*);
1354         void marker_drag_motion_callback (ArdourCanvas::Item*, GdkEvent*);
1355         void marker_drag_finished_callback (ArdourCanvas::Item*, GdkEvent*);
1356         void control_point_drag_motion_callback (ArdourCanvas::Item*, GdkEvent*);
1357         void control_point_drag_finished_callback (ArdourCanvas::Item*, GdkEvent*);
1358         void line_drag_motion_callback (ArdourCanvas::Item*, GdkEvent*);
1359         void line_drag_finished_callback (ArdourCanvas::Item*, GdkEvent*);
1360
1361         void tempo_marker_drag_motion_callback (ArdourCanvas::Item*, GdkEvent*);
1362         void tempo_marker_drag_finished_callback (ArdourCanvas::Item*, GdkEvent*);
1363         void meter_marker_drag_motion_callback (ArdourCanvas::Item*, GdkEvent*);
1364         void meter_marker_drag_finished_callback (ArdourCanvas::Item*, GdkEvent*);
1365
1366         gint mouse_rename_region (ArdourCanvas::Item*, GdkEvent*);
1367
1368         void start_region_grab (ArdourCanvas::Item*, GdkEvent*);
1369         void start_region_copy_grab (ArdourCanvas::Item*, GdkEvent*);
1370         void start_region_brush_grab (ArdourCanvas::Item*, GdkEvent*);
1371         void start_selection_grab (ArdourCanvas::Item*, GdkEvent*);
1372         void start_cursor_grab (ArdourCanvas::Item*, GdkEvent*);
1373         void start_cursor_grab_no_stop (ArdourCanvas::Item*, GdkEvent*);
1374         void start_marker_grab (ArdourCanvas::Item*, GdkEvent*);
1375         void start_control_point_grab (ArdourCanvas::Item*, GdkEvent*);
1376         void start_line_grab_from_regionview (ArdourCanvas::Item*, GdkEvent*);
1377         void start_line_grab_from_line (ArdourCanvas::Item*, GdkEvent*);
1378         void start_line_grab (AutomationLine *, GdkEvent*);
1379         void start_tempo_marker_grab (ArdourCanvas::Item*, GdkEvent*);
1380         void start_tempo_marker_copy_grab (ArdourCanvas::Item*, GdkEvent*);
1381         void start_meter_marker_grab (ArdourCanvas::Item*, GdkEvent*);
1382         void start_meter_marker_copy_grab (ArdourCanvas::Item*, GdkEvent*);
1383
1384         void region_view_item_click (AudioRegionView&, GdkEventButton*);
1385
1386         void remove_gain_control_point (ArdourCanvas::Item*, GdkEvent*);
1387         void remove_control_point (ArdourCanvas::Item*, GdkEvent*);
1388
1389         void mouse_brush_insert_region (RegionView*, nframes64_t pos);
1390         void brush (nframes64_t);
1391
1392         void show_verbose_time_cursor (nframes64_t frame, double offset = 0, double xpos=-1, double ypos=-1);
1393         void show_verbose_duration_cursor (nframes64_t start, nframes64_t end, double offset = 0, double xpos=-1, double ypos=-1);
1394         double clamp_verbose_cursor_x (double);
1395         double clamp_verbose_cursor_y (double);
1396
1397         /* Canvas event handlers */
1398
1399         bool canvas_control_point_event (GdkEvent* event,ArdourCanvas::Item*, ControlPoint*);
1400         bool canvas_line_event (GdkEvent* event,ArdourCanvas::Item*, AutomationLine*);
1401         bool canvas_selection_rect_event (GdkEvent* event,ArdourCanvas::Item*, SelectionRect*);
1402         bool canvas_selection_start_trim_event (GdkEvent* event,ArdourCanvas::Item*, SelectionRect*);
1403         bool canvas_selection_end_trim_event (GdkEvent* event,ArdourCanvas::Item*, SelectionRect*);
1404         bool canvas_crossfade_view_event (GdkEvent* event,ArdourCanvas::Item*, CrossfadeView*);
1405         bool canvas_fade_in_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1406         bool canvas_fade_in_handle_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1407         bool canvas_fade_out_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1408         bool canvas_fade_out_handle_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1409         
1410
1411         // These variables are used to detect a feedback loop and break it to avoid a gui hang
1412 private:
1413         ArdourCanvas::Item *last_item_entered;
1414         int last_item_entered_n;
1415 public:
1416
1417         bool canvas_region_view_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1418         bool canvas_region_view_name_highlight_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1419         bool canvas_region_view_name_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1420         bool canvas_stream_view_event (GdkEvent* event,ArdourCanvas::Item*, RouteTimeAxisView*);
1421         bool canvas_marker_event (GdkEvent* event,ArdourCanvas::Item*, Marker*);
1422         bool canvas_zoom_rect_event (GdkEvent* event,ArdourCanvas::Item*);
1423         bool canvas_tempo_marker_event (GdkEvent* event,ArdourCanvas::Item*, TempoMarker*);
1424         bool canvas_meter_marker_event (GdkEvent* event,ArdourCanvas::Item*, MeterMarker*);
1425         bool canvas_automation_track_event(GdkEvent* event, ArdourCanvas::Item*, AutomationTimeAxisView*) ;
1426
1427         bool canvas_tempo_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1428         bool canvas_meter_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1429         bool canvas_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1430         bool canvas_range_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1431         bool canvas_transport_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1432         bool canvas_cd_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1433
1434         bool canvas_imageframe_item_view_event(GdkEvent* event, ArdourCanvas::Item*,ImageFrameView*);
1435         bool canvas_imageframe_view_event(GdkEvent* event, ArdourCanvas::Item*,ImageFrameTimeAxis*);
1436         bool canvas_imageframe_start_handle_event(GdkEvent* event, ArdourCanvas::Item*,ImageFrameView*);
1437         bool canvas_imageframe_end_handle_event(GdkEvent* event, ArdourCanvas::Item*,ImageFrameView*);
1438         bool canvas_marker_time_axis_view_event(GdkEvent* event, ArdourCanvas::Item*,MarkerTimeAxis*);
1439         bool canvas_markerview_item_view_event(GdkEvent* event, ArdourCanvas::Item*,MarkerView*);
1440         bool canvas_markerview_start_handle_event(GdkEvent* event, ArdourCanvas::Item*,MarkerView*);
1441         bool canvas_markerview_end_handle_event(GdkEvent* event, ArdourCanvas::Item*,MarkerView*);
1442
1443         /* non-public event handlers */
1444
1445         bool canvas_playhead_cursor_event (GdkEvent* event, ArdourCanvas::Item*);
1446         bool track_canvas_scroll (GdkEventScroll* event);
1447
1448         bool track_canvas_scroll_event (GdkEventScroll* event);
1449         bool track_canvas_button_press_event (GdkEventButton* event);
1450         bool track_canvas_button_release_event (GdkEventButton* event);
1451         bool track_canvas_motion_notify_event (GdkEventMotion* event);
1452
1453         Gtk::Allocation canvas_allocation;
1454         void track_canvas_allocate (Gtk::Allocation alloc);
1455         bool track_canvas_size_allocated ();
1456
1457         void set_playhead_cursor ();
1458
1459         void kbd_driver (sigc::slot<void,GdkEvent*>, bool use_track_canvas = true, bool use_time_canvas = true, bool can_select = true);
1460         void kbd_mute_unmute_region ();
1461         void kbd_brush ();
1462
1463         void kbd_do_brush (GdkEvent*);
1464         void kbd_do_audition (GdkEvent*);
1465
1466         void handle_new_duration ();
1467         void initialize_canvas ();
1468
1469         /* display control */
1470         
1471         bool _show_measures;
1472         bool _show_waveforms;
1473         bool _follow_playhead;
1474         bool _show_waveforms_recording;
1475         
1476         ARDOUR::TempoMap::BBTPointList *current_bbt_points;
1477         
1478         TempoLines* tempo_lines;
1479         
1480         ArdourCanvas::Group* time_line_group;
1481         ArdourCanvas::SimpleLine* get_time_line ();
1482         void hide_measures ();
1483         void draw_measures ();
1484         bool redraw_measures ();
1485
1486         void new_tempo_section ();
1487
1488         void mouse_add_new_tempo_event (nframes64_t where);
1489         void mouse_add_new_meter_event (nframes64_t where);
1490
1491         void remove_tempo_marker (ArdourCanvas::Item*);
1492         void remove_meter_marker (ArdourCanvas::Item*);
1493         gint real_remove_tempo_marker (ARDOUR::TempoSection*);
1494         gint real_remove_meter_marker (ARDOUR::MeterSection*);
1495         
1496         void edit_tempo_section (ARDOUR::TempoSection*);
1497         void edit_meter_section (ARDOUR::MeterSection*);
1498         void edit_tempo_marker (ArdourCanvas::Item*);
1499         void edit_meter_marker (ArdourCanvas::Item*);
1500         
1501         void marker_menu_edit ();
1502         void marker_menu_remove ();
1503         void marker_menu_rename ();
1504         void marker_menu_lock (bool yn);
1505         void marker_menu_hide ();
1506         void marker_menu_loop_range ();
1507         void marker_menu_select_all_selectables_using_range ();
1508         void marker_menu_select_using_range ();
1509         void marker_menu_separate_regions_using_location ();
1510         void marker_menu_play_from ();
1511         void marker_menu_play_range ();
1512         void marker_menu_set_playhead ();
1513         void marker_menu_set_from_playhead ();
1514         void marker_menu_set_from_selection ();
1515         void marker_menu_range_to_next ();
1516         void marker_menu_export_range ();
1517         void new_transport_marker_menu_set_loop ();
1518         void new_transport_marker_menu_set_punch ();
1519         void update_loop_range_view (bool visibility=false);
1520         void update_punch_range_view (bool visibility=false);
1521         void new_transport_marker_menu_popdown ();
1522         void marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
1523         void tm_marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
1524         void transport_marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
1525         void new_transport_marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
1526         void build_range_marker_menu (bool loop_or_punch);
1527         void build_marker_menu (bool start_or_end);
1528         void build_tm_marker_menu ();
1529         void build_new_transport_marker_menu ();
1530
1531         Gtk::Menu* tm_marker_menu;
1532         Gtk::Menu* marker_menu;
1533         Gtk::Menu* start_end_marker_menu;
1534         Gtk::Menu* range_marker_menu;
1535         Gtk::Menu* transport_marker_menu;
1536         Gtk::Menu* new_transport_marker_menu;
1537         Gtk::Menu* cd_marker_menu;
1538         ArdourCanvas::Item* marker_menu_item;
1539
1540         typedef list<Marker*> Marks;
1541         Marks metric_marks;
1542
1543         void remove_metric_marks ();
1544         void draw_metric_marks (const ARDOUR::Metrics& metrics);
1545
1546         void compute_current_bbt_points (nframes_t left, nframes_t right);
1547         void tempo_map_changed (ARDOUR::Change);
1548         void redisplay_tempo (bool immediate_redraw);
1549         
1550         void snap_to (nframes64_t& first, int32_t direction = 0, bool for_mark = false);
1551
1552         uint32_t bbt_beat_subdivision;
1553
1554         /* toolbar */
1555
1556         void editor_mixer_button_toggled ();
1557
1558         AudioClock               edit_point_clock;
1559         AudioClock               zoom_range_clock;
1560         Gtk::Button              zoom_in_button;
1561         Gtk::Button              zoom_out_button;
1562         Gtk::Button              zoom_out_full_button;
1563         Gtk::Button              zoom_onetoone_button;
1564
1565         Gtk::VBox                toolbar_clock_vbox;
1566         Gtk::VBox                toolbar_selection_clock_vbox; 
1567         Gtk::Table               toolbar_selection_clock_table;
1568         Gtk::Label               toolbar_selection_cursor_label;
1569         
1570         Gtk::HBox                mouse_mode_button_box;
1571         Gtkmm2ext::TearOff*      mouse_mode_tearoff;
1572         Gtk::ToggleButton        mouse_select_button;
1573         Gtk::ToggleButton        mouse_move_button;
1574         Gtk::ToggleButton        mouse_gain_button;
1575         Gtk::ToggleButton        mouse_zoom_button;
1576         Gtk::ToggleButton        mouse_timefx_button;
1577         Gtk::ToggleButton        mouse_audition_button;
1578         GroupedButtons          *mouse_mode_button_set;
1579         void                     mouse_mode_toggled (Editing::MouseMode m);
1580         bool                     ignore_mouse_mode_toggle;
1581
1582         gint                     mouse_select_button_release (GdkEventButton*);
1583
1584         Gtk::VBox                automation_box;
1585         Gtk::Button              automation_mode_button;
1586         Gtk::ToggleButton        global_automation_button;
1587
1588         Gtk::ComboBoxText edit_mode_selector;
1589         Gtk::VBox         edit_mode_box;
1590
1591         void set_edit_mode (ARDOUR::EditMode);
1592         void cycle_edit_mode ();
1593         void edit_mode_selection_done ();
1594
1595         Gtk::ComboBoxText snap_type_selector;
1596         Gtk::ComboBoxText snap_mode_selector;
1597         Gtk::HBox         snap_box;
1598
1599         std::vector<std::string> snap_type_strings;
1600         std::vector<std::string> snap_mode_strings;
1601
1602         void snap_type_selection_done ();
1603         void snap_mode_selection_done ();
1604         void snap_mode_chosen (Editing::SnapMode);
1605         void snap_type_chosen (Editing::SnapType);
1606
1607         Glib::RefPtr<Gtk::RadioAction> snap_type_action (Editing::SnapType);
1608         Glib::RefPtr<Gtk::RadioAction> snap_mode_action (Editing::SnapMode);
1609
1610         Gtk::ComboBoxText zoom_focus_selector;
1611         Gtk::VBox         zoom_focus_box;
1612
1613         std::vector<std::string> zoom_focus_strings;
1614         
1615         void zoom_focus_selection_done ();
1616         void zoom_focus_chosen (Editing::ZoomFocus);
1617
1618         Glib::RefPtr<Gtk::RadioAction> zoom_focus_action (Editing::ZoomFocus);
1619
1620         Gtk::HBox           zoom_box;
1621
1622         void                zoom_adjustment_changed();
1623
1624         void                edit_point_clock_changed();
1625         
1626         void setup_toolbar ();
1627
1628         Gtkmm2ext::TearOff*       tools_tearoff;
1629         Gtk::HBox                toolbar_hbox;
1630         Gtk::EventBox            toolbar_base;
1631         Gtk::Frame               toolbar_frame;
1632
1633         /* selection process */
1634
1635         Selection* selection;
1636         Selection* cut_buffer;
1637
1638         void time_selection_changed ();
1639         void track_selection_changed ();
1640         void region_selection_changed ();
1641         void sensitize_the_right_region_actions (bool have_selected_regions);
1642         void point_selection_changed ();
1643         void marker_selection_changed ();
1644
1645         enum SelectionOp {
1646                 CreateSelection,
1647                 SelectionStartTrim,
1648                 SelectionEndTrim,
1649                 SelectionMove
1650         } selection_op;
1651
1652         void start_selection_op (ArdourCanvas::Item* item, GdkEvent* event, SelectionOp);
1653         void drag_selection (ArdourCanvas::Item* item, GdkEvent* event);
1654         void end_selection_op (ArdourCanvas::Item* item, GdkEvent* event);
1655         void cancel_selection ();
1656
1657         void region_selection_op (void (ARDOUR::Region::*pmf)(void));
1658         void region_selection_op (void (ARDOUR::Region::*pmf)(void*), void*);
1659         void region_selection_op (void (ARDOUR::Region::*pmf)(bool), bool);
1660
1661         bool audio_region_selection_covers (nframes64_t where);
1662
1663         /* transport range select process */
1664         enum RangeMarkerOp {
1665                 CreateRangeMarker,
1666                 CreateTransportMarker,
1667                 CreateCDMarker
1668         } range_marker_op;
1669
1670         void start_range_markerbar_op (ArdourCanvas::Item* item, GdkEvent* event, RangeMarkerOp);
1671         void drag_range_markerbar_op (ArdourCanvas::Item* item, GdkEvent* event);
1672         void end_range_markerbar_op (ArdourCanvas::Item* item, GdkEvent* event);
1673
1674         ArdourCanvas::SimpleRect*  cd_marker_bar_drag_rect;
1675         ArdourCanvas::SimpleRect*  range_bar_drag_rect;
1676         ArdourCanvas::SimpleRect*  transport_bar_drag_rect;
1677         ArdourCanvas::Line*        marker_drag_line;
1678         ArdourCanvas::Points       marker_drag_line_points;
1679         ArdourCanvas::SimpleRect*  range_marker_drag_rect;
1680
1681         void update_marker_drag_item (ARDOUR::Location *);
1682 #ifdef GTKOSX
1683         ArdourCanvas::SimpleRect     *bogus_background_rect;
1684 #endif
1685         ArdourCanvas::SimpleRect     *transport_bar_range_rect;
1686         ArdourCanvas::SimpleRect     *transport_bar_preroll_rect;
1687         ArdourCanvas::SimpleRect     *transport_bar_postroll_rect;
1688         ArdourCanvas::SimpleRect     *transport_loop_range_rect;
1689         ArdourCanvas::SimpleRect     *transport_punch_range_rect;
1690         ArdourCanvas::SimpleLine     *transport_punchin_line;
1691         ArdourCanvas::SimpleLine     *transport_punchout_line;
1692         ArdourCanvas::SimpleRect     *transport_preroll_rect;
1693         ArdourCanvas::SimpleRect     *transport_postroll_rect;
1694
1695         ARDOUR::Location*  transport_loop_location();
1696         ARDOUR::Location*  transport_punch_location();
1697
1698         ARDOUR::Location   *temp_location;
1699         
1700         /* object rubberband select process */
1701         
1702         void start_rubberband_select (ArdourCanvas::Item* item, GdkEvent* event);
1703         void drag_rubberband_select (ArdourCanvas::Item* item, GdkEvent* event);
1704         void end_rubberband_select (ArdourCanvas::Item* item, GdkEvent* event);
1705
1706         bool select_all_within (nframes64_t start, nframes64_t end, gdouble topy, gdouble boty, const TrackViewList&, Selection::Operation op);
1707         
1708         ArdourCanvas::SimpleRect   *rubberband_rect;
1709         
1710         /* mouse zoom process */
1711
1712         void start_mouse_zoom (ArdourCanvas::Item* item, GdkEvent* event);
1713         void drag_mouse_zoom (ArdourCanvas::Item* item, GdkEvent* event);
1714         void end_mouse_zoom (ArdourCanvas::Item* item, GdkEvent* event);
1715
1716         ArdourCanvas::SimpleRect   *zoom_rect;
1717         void reposition_zoom_rect (nframes64_t start, nframes64_t end);
1718         
1719         /* diskstream/route display management */
1720
1721         struct RouteDisplayModelColumns : public Gtk::TreeModel::ColumnRecord {
1722             RouteDisplayModelColumns() { 
1723                     add (text);
1724                     add (visible);
1725                     add (temporary_visible);
1726                     add (tv);
1727                     add (route);
1728             }
1729             Gtk::TreeModelColumn<Glib::ustring>  text;
1730             Gtk::TreeModelColumn<bool>           visible;
1731             Gtk::TreeModelColumn<bool>           temporary_visible;
1732             Gtk::TreeModelColumn<TimeAxisView*>  tv;
1733             Gtk::TreeModelColumn<boost::shared_ptr<ARDOUR::Route> >  route;
1734         };
1735
1736         RouteDisplayModelColumns         route_display_columns;
1737         Glib::RefPtr<Gtk::ListStore>     route_display_model;
1738         Glib::RefPtr<Gtk::TreeSelection> route_display_selection;
1739
1740         Gtkmm2ext::DnDTreeView<boost::shared_ptr<ARDOUR::Route> > route_list_display; 
1741         Gtk::ScrolledWindow                   route_list_scroller;
1742         Gtk::Menu*                            route_list_menu;
1743
1744         void update_route_visibility ();
1745
1746         void sync_order_keys (const char*);
1747         bool route_redisplay_does_not_sync_order_keys;
1748         bool route_redisplay_does_not_reset_order_keys;
1749
1750         bool route_list_display_button_press (GdkEventButton*);
1751         void route_list_display_drag_data_received  (const Glib::RefPtr<Gdk::DragContext>& context,
1752                                                      gint                x,
1753                                                      gint                y,
1754                                                      const Gtk::SelectionData& data,
1755                                                      guint               info,
1756                                                      guint               time);
1757
1758         bool route_list_selection_filter (const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreeModel::Path& path, bool yn);
1759
1760         void route_list_change (const Gtk::TreeModel::Path&,const Gtk::TreeModel::iterator&);
1761         void route_list_delete (const Gtk::TreeModel::Path&);
1762         void track_list_reorder (const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator& iter, int* new_order);
1763
1764         void initial_route_list_display ();
1765         void redisplay_route_list();
1766         bool ignore_route_list_reorder;
1767         bool no_route_list_redisplay;
1768         bool sync_track_view_list_and_route_list ();
1769
1770         void build_route_list_menu ();
1771         void show_route_list_menu ();
1772
1773         void show_all_routes ();
1774         void hide_all_routes ();
1775         void show_all_audiotracks ();
1776         void hide_all_audiotracks ();
1777         void show_all_audiobus ();
1778         void hide_all_audiobus ();
1779
1780         void set_all_tracks_visibility (bool yn);
1781         void set_all_audio_visibility (int type, bool yn);
1782
1783         /* edit group management */
1784
1785         struct GroupListModelColumns : public Gtk::TreeModel::ColumnRecord {
1786                 GroupListModelColumns () {
1787                        add (is_active);
1788                        add (is_visible);
1789                        add (text);
1790                        add (routegroup);
1791                 }
1792                 Gtk::TreeModelColumn<bool> is_active;
1793                 Gtk::TreeModelColumn<bool> is_visible;
1794                 Gtk::TreeModelColumn<std::string> text;
1795                 Gtk::TreeModelColumn<ARDOUR::RouteGroup*>   routegroup;
1796         };
1797
1798         GroupListModelColumns group_columns;
1799         Glib::RefPtr<Gtk::ListStore> group_model;
1800         Glib::RefPtr<Gtk::TreeSelection> group_selection;
1801
1802         Gtk::TreeView          edit_group_display;
1803         Gtk::ScrolledWindow    edit_group_display_scroller;
1804         Gtk::Menu*             edit_group_list_menu;
1805
1806         void build_edit_group_list_menu ();
1807         void activate_all_edit_groups ();
1808         void disable_all_edit_groups ();
1809
1810         bool in_edit_group_row_change;
1811         void edit_group_row_change (const Gtk::TreeModel::Path&,const Gtk::TreeModel::iterator&);
1812         void edit_group_name_edit (const Glib::ustring&, const Glib::ustring&);
1813         void new_edit_group ();
1814         void edit_group_list_button_clicked ();
1815         gint edit_group_list_button_press_event (GdkEventButton* ev);
1816         void add_edit_group (ARDOUR::RouteGroup* group);
1817         void remove_selected_edit_group ();
1818         void edit_groups_changed ();
1819         void group_flags_changed (void*, ARDOUR::RouteGroup*);
1820
1821         Gtk::VBox           list_vpacker;
1822
1823         /* autoscrolling */
1824
1825         bool autoscroll_active;
1826         int autoscroll_timeout_tag;
1827         int autoscroll_x;
1828         int autoscroll_y;
1829         int last_autoscroll_x;
1830         int last_autoscroll_y;
1831         uint32_t autoscroll_cnt;
1832         nframes64_t autoscroll_x_distance;
1833         double autoscroll_y_distance;
1834
1835         static gint _autoscroll_canvas (void *);
1836         bool autoscroll_canvas ();
1837         void start_canvas_autoscroll (int x, int y);
1838         void stop_canvas_autoscroll ();
1839         void maybe_autoscroll (GdkEventMotion*);
1840         void maybe_autoscroll_horizontally (GdkEventMotion*);
1841         bool allow_vertical_scroll;
1842
1843         /* trimming */
1844         enum TrimOp {
1845                 StartTrim,
1846                 EndTrim,
1847                 ContentsTrim,
1848         } trim_op;
1849
1850         void start_trim (ArdourCanvas::Item*, GdkEvent*);
1851         void point_trim (GdkEvent*);
1852         void trim_motion_callback (ArdourCanvas::Item*, GdkEvent*);
1853         void single_contents_trim (RegionView&, nframes64_t, bool, bool, bool);
1854         void single_start_trim (RegionView&, nframes64_t, bool, bool);
1855         void single_end_trim (RegionView&, nframes64_t, bool, bool);
1856
1857         void trim_finished_callback (ArdourCanvas::Item*, GdkEvent*);
1858         void thaw_region_after_trim (RegionView& rv);
1859
1860         void trim_region_front();
1861         void trim_region_back();
1862         void trim_region (bool front);
1863
1864         void trim_region_to_edit_point ();
1865         void trim_region_from_edit_point ();
1866         void trim_region_to_loop ();
1867         void trim_region_to_punch ();
1868         void trim_region_to_location (const ARDOUR::Location&, const char* cmd);
1869
1870         bool show_gain_after_trim;
1871
1872         /* Drag-n-Drop */
1873
1874         int convert_drop_to_paths (std::vector<Glib::ustring>& paths,
1875                                    const Glib::RefPtr<Gdk::DragContext>& context,
1876                                    gint                x,
1877                                    gint                y,
1878                                    const Gtk::SelectionData& data,
1879                                    guint               info,
1880                                    guint               time);
1881
1882         void  track_canvas_drag_data_received  (const Glib::RefPtr<Gdk::DragContext>& context,
1883                                                 gint                x,
1884                                                 gint                y,
1885                                                 const Gtk::SelectionData& data,
1886                                                 guint               info,
1887                                                 guint               time);
1888         
1889         void  region_list_display_drag_data_received  (const Glib::RefPtr<Gdk::DragContext>& context,
1890                                                        gint                x,
1891                                                        gint                y,
1892                                                        const Gtk::SelectionData& data,
1893                                                        guint               info,
1894                                                        guint               time);
1895
1896         void  drop_paths  (const Glib::RefPtr<Gdk::DragContext>& context,
1897                            gint                x,
1898                            gint                y,
1899                            const Gtk::SelectionData& data,
1900                            guint               info,
1901                            guint               time);
1902
1903         void  drop_regions  (const Glib::RefPtr<Gdk::DragContext>& context,
1904                              gint                x,
1905                              gint                y,
1906                              const Gtk::SelectionData& data,
1907                              guint               info,
1908                              guint               time);
1909
1910         /* audio export */
1911
1912         ExportDialog *export_dialog;
1913         ExportDialog *export_range_markers_dialog;
1914         
1915         void export_range (nframes64_t start, nframes64_t end);
1916         void export_range_markers ();
1917
1918         int  write_region_selection(RegionSelection&);
1919         bool write_region (string path, boost::shared_ptr<ARDOUR::AudioRegion>);
1920         void export_region ();
1921         void bounce_region_selection ();
1922         void bounce_range_selection (bool replace, bool enable_processing = true);
1923         void external_edit_region ();
1924
1925         int write_audio_selection (TimeSelection&);
1926         bool write_audio_range (ARDOUR::AudioPlaylist&, uint32_t channels, list<ARDOUR::AudioRange>&);
1927
1928         void write_selection ();
1929
1930         /* history */
1931
1932         UndoAction get_memento() const;
1933
1934         XMLNode *before; /* used in *_reversible_command */
1935         void begin_reversible_command (string cmd_name);
1936         void commit_reversible_command ();
1937
1938         void update_title ();   
1939         void update_title_s (const string & snapshot_name);
1940
1941         struct State {
1942             Selection* selection;
1943             double     frames_per_unit;
1944
1945             State();
1946             ~State();
1947         };
1948
1949         void store_state (State&) const;
1950         void restore_state (State *);
1951
1952         void instant_save ();
1953
1954         boost::shared_ptr<ARDOUR::AudioRegion> last_audition_region;
1955         
1956         /* freeze operations */
1957
1958         ARDOUR::InterThreadInfo freeze_status;
1959         gint freeze_progress_timeout (void *);
1960         static void* _freeze_thread (void*);
1961         void* freeze_thread ();
1962
1963         void freeze_route ();
1964         void unfreeze_route ();
1965
1966         /* edit-group solo + mute */
1967
1968         void set_edit_group_solo (ARDOUR::Route&, bool);
1969         void set_edit_group_mute (ARDOUR::Route&, bool);
1970
1971         /* duplication */
1972
1973         void duplicate_dialog (bool with_dialog);
1974         
1975         nframes64_t event_frame (GdkEvent*, double* px = 0, double* py = 0) const;
1976
1977         /* returns false if mouse pointer is not in track or marker canvas
1978          */
1979         bool mouse_frame (nframes64_t&, bool& in_track_canvas) const;
1980
1981         void time_fx_motion (ArdourCanvas::Item*, GdkEvent*);
1982         void start_time_fx (ArdourCanvas::Item*, GdkEvent*);
1983         void end_time_fx (ArdourCanvas::Item*, GdkEvent*);
1984
1985         struct TimeFXDialog : public ArdourDialog {
1986             ARDOUR::TimeFXRequest request;
1987             Editor&               editor;
1988             bool                  pitching;
1989             Gtk::Adjustment       pitch_octave_adjustment;
1990             Gtk::Adjustment       pitch_semitone_adjustment;
1991             Gtk::Adjustment       pitch_cent_adjustment;
1992             Gtk::SpinButton       pitch_octave_spinner;
1993             Gtk::SpinButton       pitch_semitone_spinner;
1994             Gtk::SpinButton       pitch_cent_spinner;
1995             RegionSelection       regions;
1996             Gtk::ProgressBar      progress_bar;
1997
1998             /* SoundTouch */
1999             Gtk::ToggleButton     quick_button;
2000             Gtk::ToggleButton     antialias_button;
2001             Gtk::HBox             upper_button_box;
2002
2003             /* RubberBand */
2004             Gtk::ComboBoxText     stretch_opts_selector;
2005             Gtk::Label            stretch_opts_label;
2006             Gtk::ToggleButton     precise_button;
2007             Gtk::ToggleButton     preserve_formants_button;
2008             Gtk::HBox             opts_box;
2009
2010             Gtk::Button*          cancel_button;
2011             Gtk::Button*          action_button;
2012             Gtk::VBox             packer;
2013             int                   status;
2014
2015             TimeFXDialog (Editor& e, bool for_pitch);
2016
2017             gint update_progress ();
2018             sigc::connection first_cancel;
2019             sigc::connection first_delete;
2020             void cancel_in_progress ();
2021             gint delete_in_progress (GdkEventAny*);
2022         };
2023
2024         /* "whats mine is yours" */
2025
2026         friend class TimeFXDialog;
2027
2028         TimeFXDialog* current_timefx;
2029
2030         static void* timefx_thread (void *arg);
2031         void do_timefx (TimeFXDialog&);
2032
2033         int time_stretch (RegionSelection&, float fraction);
2034         int pitch_shift (RegionSelection&, float cents);
2035         void pitch_shift_regions ();
2036         int time_fx (RegionSelection&, float val, bool pitching);
2037
2038         /* editor-mixer strip */
2039
2040         MixerStrip *current_mixer_strip;
2041         bool show_editor_mixer_when_tracks_arrive;
2042         Gtk::VBox current_mixer_strip_vbox;
2043         void cms_deleted ();
2044         void current_mixer_strip_hidden ();
2045         void current_mixer_strip_removed ();
2046
2047         void detach_tearoff (Gtk::Box* b, Gtk::Window* w);
2048         void reattach_tearoff (Gtk::Box* b, Gtk::Window* w, int32_t n);
2049 #ifdef GTKOSX
2050         void ensure_all_elements_drawn ();
2051 #endif
2052         /* nudging tracks */
2053
2054         void nudge_track (bool use_edit_point, bool forwards);
2055
2056         /* xfades */
2057
2058         bool _xfade_visibility;
2059         
2060         /* <CMT Additions> */
2061         void handle_new_imageframe_time_axis_view(const string & track_name, void* src) ;
2062         void handle_new_imageframe_marker_time_axis_view(const string & track_name, TimeAxisView* marked_track) ;
2063
2064         void start_imageframe_grab(ArdourCanvas::Item*, GdkEvent*) ;
2065         void start_markerview_grab(ArdourCanvas::Item*, GdkEvent*) ;
2066
2067         void imageframe_drag_motion_callback(ArdourCanvas::Item*, GdkEvent*) ;
2068         void markerview_drag_motion_callback(ArdourCanvas::Item*, GdkEvent*) ;
2069         void timeaxis_item_drag_finished_callback(ArdourCanvas::Item*, GdkEvent*) ;
2070
2071         gint canvas_imageframe_item_view_event(ArdourCanvas::Item* item, GdkEvent* event, ImageFrameView* ifv);
2072         gint canvas_imageframe_view_event(ArdourCanvas::Item* item, GdkEvent* event, ImageFrameTimeAxis* ifta);
2073         gint canvas_imageframe_start_handle_event(ArdourCanvas::Item* item, GdkEvent* event, ImageFrameView* ifv);
2074         gint canvas_imageframe_end_handle_event(ArdourCanvas::Item* item, GdkEvent* event, ImageFrameView* ifv);
2075
2076         gint canvas_marker_time_axis_view_event(ArdourCanvas::Item* item, GdkEvent* event, MarkerTimeAxis* mta);
2077         gint canvas_markerview_item_view_event(ArdourCanvas::Item* item, GdkEvent* event, MarkerView* mv);
2078         gint canvas_markerview_start_handle_event(ArdourCanvas::Item* item, GdkEvent* event, MarkerView* mv);
2079         gint canvas_markerview_end_handle_event(ArdourCanvas::Item* item, GdkEvent* event, MarkerView* mv);
2080
2081         void imageframe_start_handle_op(ArdourCanvas::Item* item, GdkEvent* event) ;
2082         void imageframe_end_handle_op(ArdourCanvas::Item* item, GdkEvent* event) ;
2083         void imageframe_start_handle_trim_motion(ArdourCanvas::Item* item, GdkEvent* event) ;
2084         void imageframe_start_handle_end_trim(ArdourCanvas::Item* item, GdkEvent* event) ;
2085         void imageframe_end_handle_trim_motion(ArdourCanvas::Item* item, GdkEvent* event) ;
2086         void imageframe_end_handle_end_trim(ArdourCanvas::Item* item, GdkEvent* event) ;
2087         
2088         void markerview_item_start_handle_op(ArdourCanvas::Item* item, GdkEvent* event) ;
2089         void markerview_item_end_handle_op(ArdourCanvas::Item* item, GdkEvent* event) ;
2090         void markerview_start_handle_trim_motion(ArdourCanvas::Item* item, GdkEvent* event) ;
2091         void markerview_start_handle_end_trim(ArdourCanvas::Item* item, GdkEvent* event) ;
2092         void markerview_end_handle_trim_motion(ArdourCanvas::Item* item, GdkEvent* event) ;
2093         void markerview_end_handle_end_trim(ArdourCanvas::Item* item, GdkEvent* event) ;
2094
2095         void popup_imageframe_edit_menu(int button, int32_t time, ArdourCanvas::Item* ifv, bool with_frame) ;
2096         void popup_marker_time_axis_edit_menu(int button, int32_t time, ArdourCanvas::Item* ifv, bool with_frame) ;
2097
2098         ImageFrameSocketHandler* image_socket_listener ;
2099         /* </CMT Additions> */
2100
2101         void toggle_xfade_active (boost::weak_ptr<ARDOUR::Crossfade>);
2102         void toggle_xfade_length (boost::weak_ptr<ARDOUR::Crossfade>);
2103         void edit_xfade (boost::weak_ptr<ARDOUR::Crossfade>);
2104         void xfade_edit_left_region ();
2105         void xfade_edit_right_region ();
2106
2107         static const int32_t default_width = 995;
2108         static const int32_t default_height = 765;
2109
2110         /* nudge */
2111
2112         Gtk::Button      nudge_forward_button;
2113         Gtk::Button      nudge_backward_button;
2114         Gtk::HBox        nudge_hbox;
2115         Gtk::VBox        nudge_vbox;
2116         AudioClock       nudge_clock;
2117
2118         nframes64_t get_nudge_distance (nframes64_t pos, nframes64_t& next);
2119
2120         bool nudge_forward_release (GdkEventButton*);
2121         bool nudge_backward_release (GdkEventButton*);
2122         
2123         /* audio filters */
2124
2125         void apply_filter (ARDOUR::AudioFilter&, string cmd);
2126
2127         /* handling cleanup */
2128
2129         int playlist_deletion_dialog (boost::shared_ptr<ARDOUR::Playlist>);
2130
2131         vector<sigc::connection> session_connections;
2132
2133         /* tracking step changes of track height */
2134
2135         TimeAxisView* current_stepping_trackview;
2136         ARDOUR::microseconds_t last_track_height_step_timestamp;
2137         gint track_height_step_timeout();
2138         sigc::connection step_timeout;
2139
2140         TimeAxisView* entered_track;
2141         RegionView*   entered_regionview;
2142
2143
2144         void ensure_entered_track_selected (bool op_acts_on_objects = false);
2145         bool clear_entered_track;
2146         bool left_track_canvas (GdkEventCrossing*);
2147         bool entered_track_canvas (GdkEventCrossing*);
2148         void set_entered_track (TimeAxisView*);
2149         void set_entered_regionview (RegionView*);
2150         void ensure_track_visible (TimeAxisView*);
2151         gint left_automation_track ();
2152
2153         bool _new_regionviews_show_envelope;
2154
2155         void reset_canvas_action_sensitivity (bool);
2156         void toggle_gain_envelope_visibility ();
2157         void toggle_gain_envelope_active ();
2158         void reset_region_gain_envelopes ();
2159
2160         bool on_key_press_event (GdkEventKey*);
2161         bool on_key_release_event (GdkEventKey*);
2162
2163         void session_state_saved (string);
2164
2165         Glib::RefPtr<Gtk::Action>              undo_action;
2166         Glib::RefPtr<Gtk::Action>              redo_action;
2167
2168         void history_changed ();
2169         void color_handler ();
2170         
2171         Gtk::HBox      status_bar_hpacker;
2172
2173         Editing::EditPoint _edit_point;
2174
2175         Gtk::ComboBoxText edit_point_selector;
2176
2177         void set_edit_point_preference (Editing::EditPoint ep, bool force = false);
2178         void cycle_edit_point (bool with_marker);
2179         void set_edit_point ();
2180         void edit_point_selection_done ();
2181         void edit_point_chosen (Editing::EditPoint);
2182         Glib::RefPtr<Gtk::RadioAction> edit_point_action (Editing::EditPoint);
2183         std::vector<std::string> edit_point_strings;
2184
2185         void selected_marker_moved (ARDOUR::Location*);
2186         sigc::connection edit_point_clock_connection_a;
2187         sigc::connection edit_point_clock_connection_b;
2188
2189         bool get_edit_op_range (nframes64_t& start, nframes64_t& end) const;
2190
2191         void get_regions_at (RegionSelection&, nframes64_t where, const TrackSelection& ts) const;
2192         void get_regions_after (RegionSelection&, nframes64_t where, const TrackSelection& ts) const;
2193         
2194         void get_regions_for_action (RegionSelection&, bool allowed_entered_regionview = false);
2195
2196         sigc::connection fast_screen_update_connection;
2197         gint start_updating ();
2198         gint stop_updating ();
2199         void fast_update_strips ();
2200         bool meters_running;
2201
2202         void select_next_route ();
2203         void select_prev_route ();
2204
2205         void snap_to_internal (nframes64_t& first, int32_t direction = 0, bool for_mark = false);
2206
2207         RhythmFerret* rhythm_ferret;
2208
2209         void fit_tracks ();
2210         void set_track_height (uint32_t h);
2211         void set_track_height_largest ();
2212         void set_track_height_large ();
2213         void set_track_height_larger ();
2214         void set_track_height_normal ();
2215         void set_track_height_smaller ();
2216         void set_track_height_small ();
2217
2218         void remove_tracks ();
2219         void toggle_tracks_active ();
2220         void waveform_scale_chosen (Editing::WaveformScale);
2221
2222         bool _have_idled;
2223         int resize_idle_id;
2224         int32_t resize_idle_target;
2225         bool idle_resize();
2226         friend gboolean _idle_resize (gpointer);
2227         std::vector<TimeAxisView*> pending_resizes;
2228 };
2229
2230 #endif /* __ardour_editor_h__ */