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