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