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