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