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