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