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