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