Merge with 2.0-ongoing R2943.
[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, bool force_playhead);
300         void nudge_backward (bool next, bool force_playhead);
301
302         /* nudge initiated from context menu */
303
304         void nudge_forward_capture_offset ();
305         void nudge_backward_capture_offset ();
306
307         /* playhead/screen stuff */
308         
309         void set_follow_playhead (bool yn);
310         void toggle_follow_playhead ();
311         bool follow_playhead() const { return _follow_playhead; }
312         bool dragging_playhead () const { return _dragging_playhead; }
313
314         void toggle_waveform_visibility ();
315         void toggle_waveforms_while_recording ();
316         void toggle_measure_visibility ();
317         void toggle_logo_visibility ();
318
319         /* SMPTE timecode & video sync */
320
321         void smpte_fps_chosen (ARDOUR::SmpteFormat format);
322         void video_pullup_chosen (ARDOUR::Session::PullupFormat pullup);
323         void subframes_per_frame_chosen (uint32_t);
324
325         void update_smpte_mode();
326         void update_video_pullup();
327         void update_subframes_per_frame ();
328         /* xfades */
329
330         void toggle_auto_xfade ();
331         void toggle_xfades_active ();
332         void toggle_xfade_visibility ();
333         bool xfade_visibility() const { return _xfade_visibility; }
334         void update_xfade_visibility ();
335         void update_crossfade_model ();
336         void set_crossfade_model (ARDOUR::CrossfadeModel);
337
338         /* layers */
339         void set_layer_model (ARDOUR::LayerModel);
340         void update_layering_model ();
341         
342         void toggle_link_region_and_track_selection ();
343
344         /* redirect shared ops menu. caller must free returned menu */
345
346         Gtk::Menu* redirect_menu ();
347
348         /* floating windows/transient */
349
350         void ensure_float (Gtk::Window&);
351
352         void show_window ();
353
354         void scroll_tracks_down_line ();
355         void scroll_tracks_up_line ();
356
357         bool new_regionviews_display_gain () { return _new_regionviews_show_envelope; }
358         void prepare_for_cleanup ();
359
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 adjust_region_scale_amplitude (bool up);
1052         void quantize_region ();
1053
1054         void audition_region_from_region_list ();
1055         void hide_region_from_region_list ();
1056         void remove_region_from_region_list ();
1057
1058         void align (ARDOUR::RegionPoint);
1059         void align_relative (ARDOUR::RegionPoint);
1060         void naturalize ();
1061
1062         void reset_focus ();
1063
1064         void split ();
1065
1066         void cut ();
1067         void copy ();
1068         void paste (float times);
1069
1070         int  get_prefix (float&, bool&);
1071
1072         void keyboard_paste ();
1073         void keyboard_insert_region_list_selection ();
1074
1075         void region_from_selection ();
1076         void create_region_from_selection (std::vector<boost::shared_ptr<ARDOUR::AudioRegion> >&);
1077
1078         void play_from_start ();
1079         void play_from_edit_point ();
1080         void play_from_edit_point_and_return ();
1081         void play_selected_region ();
1082         void play_edit_range ();
1083         void loop_selected_region ();
1084         void play_location (ARDOUR::Location&);
1085         void loop_location (ARDOUR::Location&);
1086
1087         void temporal_zoom_selection ();
1088         void temporal_zoom_region ();
1089         void toggle_zoom_region ();
1090         bool zoomed_to_region;
1091         void temporal_zoom_session ();
1092         void temporal_zoom (gdouble scale);
1093         void temporal_zoom_by_frame (nframes_t start, nframes_t end, const string & op);
1094         void temporal_zoom_to_frame (bool coarser, nframes_t frame);
1095
1096         void amplitude_zoom (gdouble scale);
1097         void amplitude_zoom_step (bool in);
1098
1099         void insert_region_list_drag (boost::shared_ptr<ARDOUR::Region>, int x, int y);
1100         void insert_region_list_selection (float times);
1101
1102         /* import & embed */
1103         
1104         void add_external_audio_action (Editing::ImportMode);
1105         void external_audio_dialog ();
1106         bool check_multichannel_status (const std::vector<Glib::ustring>& paths);
1107
1108         SoundFileOmega* sfbrowser;
1109         
1110         void bring_in_external_audio (Editing::ImportMode mode,  nframes64_t& pos);
1111         void do_import (vector<Glib::ustring> paths, Editing::ImportDisposition, Editing::ImportMode mode, ARDOUR::SrcQuality, nframes64_t&);
1112
1113         void _do_embed (vector<Glib::ustring> paths, Editing::ImportDisposition, Editing::ImportMode mode,  nframes64_t&);
1114         void do_embed (vector<Glib::ustring> paths, Editing::ImportDisposition, Editing::ImportMode mode,  nframes64_t&);
1115         bool idle_do_embed (vector<Glib::ustring> paths, Editing::ImportDisposition, Editing::ImportMode mode,  nframes64_t&);
1116
1117         int  import_sndfiles (vector<Glib::ustring> paths, Editing::ImportMode mode,  ARDOUR::SrcQuality, nframes64_t& pos,
1118                               int target_regions, int target_tracks, boost::shared_ptr<ARDOUR::AudioTrack>&);
1119         int  embed_sndfiles (vector<Glib::ustring> paths, bool multiple_files, bool& check_sample_rate, Editing::ImportMode mode, 
1120                              nframes64_t& pos, int target_regions, int target_tracks, boost::shared_ptr<ARDOUR::AudioTrack>&);
1121
1122         int add_sources (vector<Glib::ustring> paths, ARDOUR::SourceList& sources, nframes64_t& pos, Editing::ImportMode,
1123                          int target_regions, int target_tracks, boost::shared_ptr<ARDOUR::AudioTrack>&, bool add_channel_suffix);
1124         int finish_bringing_in_audio (boost::shared_ptr<ARDOUR::AudioRegion> region, uint32_t, uint32_t,  nframes64_t& pos, Editing::ImportMode mode,
1125                                       boost::shared_ptr<ARDOUR::AudioTrack>& existing_track);
1126
1127         boost::shared_ptr<ARDOUR::AudioTrack> get_nth_selected_audio_track (int nth) const;
1128
1129         /* generic interthread progress window */
1130         
1131         ArdourDialog* interthread_progress_window;
1132         Gtk::Label interthread_progress_label;
1133         Gtk::VBox interthread_progress_vbox;
1134         Gtk::ProgressBar interthread_progress_bar;
1135         Gtk::Button interthread_cancel_button;
1136         Gtk::Label interthread_cancel_label;
1137         sigc::connection  interthread_progress_connection;
1138         void interthread_cancel_clicked ();
1139         void build_interthread_progress_window ();
1140         ARDOUR::InterThreadInfo* current_interthread_info;
1141
1142 #ifdef FFT_ANALYSIS
1143         AnalysisWindow* analysis_window;
1144 #endif
1145
1146         /* import specific info */
1147
1148         ARDOUR::Session::import_status import_status;
1149         gint import_progress_timeout (void *);
1150         static void *_import_thread (void *);
1151         void* import_thread ();
1152
1153         /* to support this ... */
1154
1155         void import_audio (bool as_tracks);
1156         void do_import (vector<Glib::ustring> paths, bool split, bool as_tracks);
1157
1158         void move_to_start ();
1159         void move_to_end ();
1160         void goto_frame ();
1161         void center_playhead ();
1162         void center_edit_point ();
1163         void edit_cursor_backward ();
1164         void edit_cursor_forward ();
1165         void playhead_backward ();
1166         void playhead_forward ();
1167         void scroll_playhead (bool forward);
1168         void scroll_backward (float pages=0.8f);
1169         void scroll_forward (float pages=0.8f);
1170         void scroll_tracks_down ();
1171         void scroll_tracks_up ();
1172         void delete_sample_forward ();
1173         void delete_sample_backward ();
1174         void delete_screen ();
1175         void search_backwards ();
1176         void search_forwards ();
1177         void set_mark ();
1178         void clear_markers ();
1179         void clear_ranges ();
1180         void clear_locations ();
1181         void unhide_markers ();
1182         void unhide_ranges ();
1183         void jump_forward_to_mark ();
1184         void jump_backward_to_mark ();
1185         void cursor_align (bool playhead_to_edit);
1186
1187         void remove_last_capture ();
1188         void select_all_selectables_using_time_selection ();
1189         void select_all_selectables_using_loop();
1190         void select_all_selectables_using_punch();
1191         void set_selection_from_range (ARDOUR::Location&);
1192         void set_selection_from_punch ();
1193         void set_selection_from_loop ();
1194         void set_selection_from_region ();
1195
1196         void add_location_mark (nframes64_t where);
1197         void add_location_from_audio_region ();
1198         void add_location_from_selection ();
1199         void set_loop_from_selection (bool play);
1200         void set_punch_from_selection ();
1201         void set_punch_from_region ();
1202
1203         void set_loop_from_edit_range (bool play);
1204         void set_loop_from_region (bool play);
1205         void set_punch_from_edit_range ();
1206
1207         void set_loop_range (nframes_t start, nframes_t end, std::string cmd);
1208         void set_punch_range (nframes_t start, nframes_t end, std::string cmd);
1209
1210         void add_location_from_playhead_cursor ();
1211         bool select_new_marker;
1212
1213         void reverse_selection ();
1214         void edit_envelope ();
1215
1216         void start_scrolling ();
1217         void stop_scrolling ();
1218
1219         bool _scrubbing;
1220         double last_scrub_x;
1221         int scrubbing_direction;
1222         int scrub_reversals;
1223         int scrub_reverse_distance;
1224
1225         void keyboard_selection_begin ();
1226         void keyboard_selection_finish (bool add);
1227         bool have_pending_keyboard_selection;
1228         nframes_t pending_keyboard_selection_start;
1229
1230         boost::shared_ptr<ARDOUR::Region> select_region_for_operation (int dir, TimeAxisView **tv);
1231         void extend_selection_to_end_of_region (bool next);
1232         void extend_selection_to_start_of_region (bool previous);
1233
1234         Editing::SnapType snap_type;
1235         Editing::SnapMode snap_mode;
1236
1237         /// Snap threshold in pixels
1238         double snap_threshold;
1239
1240         void handle_gui_changes (const string &, void *);
1241
1242         void    hide_all_tracks (bool with_select);
1243
1244         DragInfo drag_info;
1245         LineDragInfo current_line_drag_info;
1246
1247         void start_grab (GdkEvent*, Gdk::Cursor* cursor = 0);
1248         bool end_grab (ArdourCanvas::Item*, GdkEvent*);
1249         void swap_grab (ArdourCanvas::Item*, Gdk::Cursor* cursor, uint32_t time);
1250
1251         Gtk::Menu fade_context_menu;
1252         void popup_fade_context_menu (int, int, ArdourCanvas::Item*, ItemType);
1253
1254         void start_fade_in_grab (ArdourCanvas::Item*, GdkEvent*);
1255         void start_fade_out_grab (ArdourCanvas::Item*, GdkEvent*);
1256         void fade_in_drag_motion_callback (ArdourCanvas::Item*, GdkEvent*);
1257         void fade_out_drag_motion_callback (ArdourCanvas::Item*, GdkEvent*);
1258         void fade_in_drag_finished_callback (ArdourCanvas::Item*, GdkEvent*);
1259         void fade_out_drag_finished_callback (ArdourCanvas::Item*, GdkEvent*);
1260
1261         void set_fade_in_shape (ARDOUR::AudioRegion::FadeShape);
1262         void set_fade_out_shape (ARDOUR::AudioRegion::FadeShape);
1263         
1264         void set_fade_length (bool in);
1265         void toggle_fade_active (bool in);
1266         void set_fade_in_active (bool);
1267         void set_fade_out_active (bool);
1268         
1269         std::set<boost::shared_ptr<ARDOUR::Playlist> > motion_frozen_playlists;
1270         RegionSelection pre_drag_region_selection;
1271         void region_drag_motion_callback (ArdourCanvas::Item*, GdkEvent*);
1272         void region_drag_finished_callback (ArdourCanvas::Item*, GdkEvent*);
1273         void create_region_drag_motion_callback (ArdourCanvas::Item*, GdkEvent*);
1274         void create_region_drag_finished_callback (ArdourCanvas::Item*, GdkEvent*);
1275         bool check_region_drag_possible (RouteTimeAxisView**);
1276         void possibly_copy_regions_during_grab (GdkEvent*);
1277         void region_drag_splice_motion_callback (ArdourCanvas::Item*, GdkEvent*);
1278         void region_drag_splice_finished_callback (ArdourCanvas::Item*, GdkEvent*);
1279
1280         bool _dragging_playhead;
1281         bool _dragging_edit_point;
1282
1283         void cursor_drag_motion_callback (ArdourCanvas::Item*, GdkEvent*);
1284         void cursor_drag_finished_callback (ArdourCanvas::Item*, GdkEvent*);
1285         void marker_drag_motion_callback (ArdourCanvas::Item*, GdkEvent*);
1286         void marker_drag_finished_callback (ArdourCanvas::Item*, GdkEvent*);
1287         void control_point_drag_motion_callback (ArdourCanvas::Item*, GdkEvent*);
1288         void control_point_drag_finished_callback (ArdourCanvas::Item*, GdkEvent*);
1289         void line_drag_motion_callback (ArdourCanvas::Item*, GdkEvent*);
1290         void line_drag_finished_callback (ArdourCanvas::Item*, GdkEvent*);
1291
1292         void tempo_marker_drag_motion_callback (ArdourCanvas::Item*, GdkEvent*);
1293         void tempo_marker_drag_finished_callback (ArdourCanvas::Item*, GdkEvent*);
1294         void meter_marker_drag_motion_callback (ArdourCanvas::Item*, GdkEvent*);
1295         void meter_marker_drag_finished_callback (ArdourCanvas::Item*, GdkEvent*);
1296
1297         gint mouse_rename_region (ArdourCanvas::Item*, GdkEvent*);
1298
1299         void start_region_grab (ArdourCanvas::Item*, GdkEvent*);
1300         void start_create_region_grab (ArdourCanvas::Item*, GdkEvent*);
1301         void start_region_copy_grab (ArdourCanvas::Item*, GdkEvent*);
1302         void start_region_brush_grab (ArdourCanvas::Item*, GdkEvent*);
1303         void start_selection_grab (ArdourCanvas::Item*, GdkEvent*);
1304         void start_cursor_grab (ArdourCanvas::Item*, GdkEvent*);
1305         void start_marker_grab (ArdourCanvas::Item*, GdkEvent*);
1306         void start_control_point_grab (ArdourCanvas::Item*, GdkEvent*);
1307         void start_line_grab_from_regionview (ArdourCanvas::Item*, GdkEvent*);
1308         void start_line_grab_from_line (ArdourCanvas::Item*, GdkEvent*);
1309         void start_line_grab (AutomationLine *, GdkEvent*);
1310         void start_tempo_marker_grab (ArdourCanvas::Item*, GdkEvent*);
1311         void start_tempo_marker_copy_grab (ArdourCanvas::Item*, GdkEvent*);
1312         void start_meter_marker_grab (ArdourCanvas::Item*, GdkEvent*);
1313         void start_meter_marker_copy_grab (ArdourCanvas::Item*, GdkEvent*);
1314
1315         void region_view_item_click (AudioRegionView&, GdkEventButton*);
1316
1317         void remove_gain_control_point (ArdourCanvas::Item*, GdkEvent*);
1318         void remove_control_point (ArdourCanvas::Item*, GdkEvent*);
1319
1320         void mouse_brush_insert_region (RegionView*, nframes_t pos);
1321         void brush (nframes_t);
1322
1323         void show_verbose_time_cursor (nframes_t frame, double offset = 0, double xpos=-1, double ypos=-1);
1324         void show_verbose_duration_cursor (nframes_t start, nframes_t end, double offset = 0, double xpos=-1, double ypos=-1);
1325
1326         /* Canvas event handlers */
1327
1328         bool canvas_control_point_event (GdkEvent* event,ArdourCanvas::Item*, ControlPoint*);
1329         bool canvas_line_event (GdkEvent* event,ArdourCanvas::Item*, AutomationLine*);
1330         bool canvas_selection_rect_event (GdkEvent* event,ArdourCanvas::Item*, SelectionRect*);
1331         bool canvas_selection_start_trim_event (GdkEvent* event,ArdourCanvas::Item*, SelectionRect*);
1332         bool canvas_selection_end_trim_event (GdkEvent* event,ArdourCanvas::Item*, SelectionRect*);
1333         bool canvas_crossfade_view_event (GdkEvent* event,ArdourCanvas::Item*, CrossfadeView*);
1334         bool canvas_fade_in_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1335         bool canvas_fade_in_handle_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1336         bool canvas_fade_out_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1337         bool canvas_fade_out_handle_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*);
1338         bool canvas_region_view_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1339         bool canvas_region_view_name_highlight_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1340         bool canvas_region_view_name_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
1341         bool canvas_stream_view_event (GdkEvent* event,ArdourCanvas::Item*, RouteTimeAxisView*);
1342         bool canvas_marker_event (GdkEvent* event,ArdourCanvas::Item*, Marker*);
1343         bool canvas_zoom_rect_event (GdkEvent* event,ArdourCanvas::Item*);
1344         bool canvas_tempo_marker_event (GdkEvent* event,ArdourCanvas::Item*, TempoMarker*);
1345         bool canvas_meter_marker_event (GdkEvent* event,ArdourCanvas::Item*, MeterMarker*);
1346         bool canvas_automation_track_event(GdkEvent* event, ArdourCanvas::Item*, AutomationTimeAxisView*) ;
1347
1348         bool canvas_tempo_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1349         bool canvas_meter_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1350         bool canvas_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1351         bool canvas_range_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1352         bool canvas_transport_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1353         bool canvas_cd_marker_bar_event (GdkEvent* event, ArdourCanvas::Item*);
1354
1355         bool canvas_imageframe_item_view_event(GdkEvent* event, ArdourCanvas::Item*,ImageFrameView*);
1356         bool canvas_imageframe_view_event(GdkEvent* event, ArdourCanvas::Item*,ImageFrameTimeAxis*);
1357         bool canvas_imageframe_start_handle_event(GdkEvent* event, ArdourCanvas::Item*,ImageFrameView*);
1358         bool canvas_imageframe_end_handle_event(GdkEvent* event, ArdourCanvas::Item*,ImageFrameView*);
1359         bool canvas_marker_time_axis_view_event(GdkEvent* event, ArdourCanvas::Item*,MarkerTimeAxis*);
1360         bool canvas_markerview_item_view_event(GdkEvent* event, ArdourCanvas::Item*,MarkerView*);
1361         bool canvas_markerview_start_handle_event(GdkEvent* event, ArdourCanvas::Item*,MarkerView*);
1362         bool canvas_markerview_end_handle_event(GdkEvent* event, ArdourCanvas::Item*,MarkerView*);
1363
1364         /* non-public event handlers */
1365
1366         bool canvas_playhead_cursor_event (GdkEvent* event, ArdourCanvas::Item*);
1367         bool track_canvas_scroll (GdkEventScroll* event);
1368         bool time_canvas_scroll (GdkEventScroll* event);
1369
1370         bool track_canvas_scroll_event (GdkEventScroll* event);
1371         bool track_canvas_button_press_event (GdkEventButton* event);
1372         bool track_canvas_button_release_event (GdkEventButton* event);
1373         bool track_canvas_motion_notify_event (GdkEventMotion* event);
1374
1375         bool time_canvas_scroll_event (GdkEventScroll* event);
1376
1377         Gtk::Allocation canvas_allocation;
1378         bool canvas_idle_queued;
1379         void track_canvas_allocate (Gtk::Allocation alloc);
1380         bool track_canvas_size_allocated ();
1381
1382         void set_playhead_cursor ();
1383
1384         void kbd_driver (sigc::slot<void,GdkEvent*>, bool use_track_canvas = true, bool use_time_canvas = true, bool can_select = true);
1385         void kbd_mute_unmute_region ();
1386         void kbd_brush ();
1387
1388         void kbd_do_brush (GdkEvent*);
1389         void kbd_do_audition (GdkEvent*);
1390
1391         void handle_new_duration ();
1392         void initialize_canvas ();
1393         int canvas_hroizontally_scrolled_handler_id;
1394         void reset_horizontally_scrolling_region (Gtk::Allocation* alloc = 0);
1395         void reset_scrolling_region (Gtk::Allocation* alloc = 0);
1396
1397         /* display control */
1398         
1399         bool _show_measures;
1400         /// true to show waveforms, otherwise false
1401         bool _show_waveforms;
1402         /// true if the editor should follow the playhead, otherwise false
1403         bool _follow_playhead;
1404         /// true if waveforms should be shown while recording audio tracks, otherwise false
1405         bool _show_waveforms_recording;
1406         
1407         ARDOUR::TempoMap::BBTPointList *current_bbt_points;
1408         
1409         ArdourCanvas::Group* time_line_group;
1410         ArdourCanvas::Group* marker_time_line_group;
1411         
1412         TempoLines* tempo_lines;
1413         TempoLines* marker_tempo_lines;
1414
1415         void hide_measures ();
1416         void draw_measures ();
1417         bool redraw_measures ();
1418
1419         void new_tempo_section ();
1420
1421         void mouse_add_new_tempo_event (nframes_t where);
1422         void mouse_add_new_meter_event (nframes_t where);
1423
1424         void remove_tempo_marker (ArdourCanvas::Item*);
1425         void remove_meter_marker (ArdourCanvas::Item*);
1426         gint real_remove_tempo_marker (ARDOUR::TempoSection*);
1427         gint real_remove_meter_marker (ARDOUR::MeterSection*);
1428         
1429         void edit_tempo_section (ARDOUR::TempoSection*);
1430         void edit_meter_section (ARDOUR::MeterSection*);
1431         void edit_tempo_marker (ArdourCanvas::Item*);
1432         void edit_meter_marker (ArdourCanvas::Item*);
1433         
1434         void marker_menu_edit ();
1435         void marker_menu_remove ();
1436         void marker_menu_rename ();
1437         void marker_menu_lock (bool yn);
1438         void marker_menu_hide ();
1439         void marker_menu_loop_range ();
1440         void marker_menu_select_all_selectables_using_range ();
1441         void marker_menu_select_using_range ();
1442         void marker_menu_separate_regions_using_location ();
1443         void marker_menu_play_from ();
1444         void marker_menu_play_range ();
1445         void marker_menu_set_playhead ();
1446         void marker_menu_set_from_playhead ();
1447         void marker_menu_set_from_selection ();
1448         void new_transport_marker_menu_set_loop ();
1449         void new_transport_marker_menu_set_punch ();
1450         void update_loop_range_view (bool visibility=false);
1451         void update_punch_range_view (bool visibility=false);
1452         gint new_transport_marker_menu_popdown (GdkEventAny*);
1453         void marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
1454         void tm_marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
1455         void transport_marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
1456         void new_transport_marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
1457         void build_range_marker_menu (bool loop_or_punch);
1458         void build_marker_menu (bool start_or_end);
1459         void build_tm_marker_menu ();
1460         void build_new_transport_marker_menu ();
1461
1462         Gtk::Menu* tm_marker_menu;
1463         Gtk::Menu* marker_menu;
1464         Gtk::Menu* start_end_marker_menu;
1465         Gtk::Menu* range_marker_menu;
1466         Gtk::Menu* transport_marker_menu;
1467         Gtk::Menu* new_transport_marker_menu;
1468         Gtk::Menu* cd_marker_menu;
1469         ArdourCanvas::Item* marker_menu_item;
1470
1471         typedef list<Marker*> Marks;
1472         Marks metric_marks;
1473
1474         void remove_metric_marks ();
1475         void draw_metric_marks (const ARDOUR::Metrics& metrics);
1476
1477         void compute_current_bbt_points (nframes_t left, nframes_t right);
1478         int tempo_map_change_idle_handler_id;
1479         void tempo_map_changed (ARDOUR::Change);
1480         void redisplay_tempo (bool immediate_redraw);
1481         
1482         void snap_to (nframes64_t& first, int32_t direction = 0, bool for_mark = false);
1483         void snap_to (nframes_t& first, int32_t direction = 0, bool for_mark = false) {
1484                 /* XXX remove this function when everything moves to 64 bit frame counts */
1485                 nframes64_t first64 = first;
1486                 snap_to (first64, direction, for_mark);
1487                 first = (nframes_t) first64;
1488         }
1489         
1490         double snap_length_beats (nframes_t start);
1491
1492         uint32_t bbt_beat_subdivision;
1493
1494         /* toolbar */
1495         
1496         Gtk::ToggleButton editor_mixer_button;
1497         Gtk::ToggleButton editor_list_button;
1498
1499         void editor_mixer_button_toggled ();
1500         void editor_list_button_toggled ();
1501
1502         AudioClock               edit_point_clock;
1503         AudioClock               zoom_range_clock;
1504         Gtk::Button              zoom_in_button;
1505         Gtk::Button              zoom_out_button;
1506         Gtk::Button              zoom_out_full_button;
1507         Gtk::Button              zoom_onetoone_button;
1508
1509         Gtk::VBox                toolbar_clock_vbox;
1510         Gtk::VBox                toolbar_selection_clock_vbox; 
1511         Gtk::Table               toolbar_selection_clock_table;
1512         Gtk::Label               toolbar_selection_cursor_label;
1513         
1514         Gtk::HBox                mouse_mode_button_box;
1515         Gtkmm2ext::TearOff*      mouse_mode_tearoff;
1516         Gtk::ToggleButton        mouse_select_button;
1517         Gtk::ToggleButton        mouse_move_button;
1518         Gtk::ToggleButton        mouse_gain_button;
1519         Gtk::ToggleButton        mouse_zoom_button;
1520         Gtk::ToggleButton        mouse_timefx_button;
1521         Gtk::ToggleButton        mouse_audition_button;
1522         Gtk::ToggleButton        mouse_note_button;
1523         GroupedButtons          *mouse_mode_button_set;
1524         void                     mouse_mode_toggled (Editing::MouseMode m);
1525         bool                     ignore_mouse_mode_toggle;
1526
1527         gint                     mouse_select_button_release (GdkEventButton*);
1528
1529         Gtk::VBox                automation_box;
1530         Gtk::Button              automation_mode_button;
1531         Gtk::ToggleButton        global_automation_button;
1532
1533         Gtk::ComboBoxText edit_mode_selector;
1534         Gtk::VBox         edit_mode_box;
1535
1536         void set_edit_mode (ARDOUR::EditMode);
1537         void cycle_edit_mode ();
1538         void edit_mode_selection_done ();
1539
1540         Gtk::ComboBoxText snap_type_selector;
1541         Gtk::ComboBoxText snap_mode_selector;
1542         Gtk::HBox         snap_box;
1543
1544         std::vector<std::string> snap_type_strings;
1545         std::vector<std::string> snap_mode_strings;
1546
1547         void snap_type_selection_done ();
1548         void snap_mode_selection_done ();
1549         void snap_mode_chosen (Editing::SnapMode);
1550         void snap_type_chosen (Editing::SnapType);
1551
1552         Glib::RefPtr<Gtk::RadioAction> snap_type_action (Editing::SnapType);
1553         Glib::RefPtr<Gtk::RadioAction> snap_mode_action (Editing::SnapMode);
1554
1555         Gtk::ComboBoxText zoom_focus_selector;
1556         Gtk::VBox         zoom_focus_box;
1557
1558         std::vector<std::string> zoom_focus_strings;
1559         
1560         void zoom_focus_selection_done ();
1561         void zoom_focus_chosen (Editing::ZoomFocus);
1562
1563         Glib::RefPtr<Gtk::RadioAction> zoom_focus_action (Editing::ZoomFocus);
1564
1565         Gtk::HBox           zoom_box;
1566
1567         void                zoom_adjustment_changed();
1568
1569         void                edit_point_clock_changed();
1570         
1571         void setup_toolbar ();
1572
1573         Gtkmm2ext::TearOff*      tools_tearoff;
1574         Gtk::HBox                toolbar_hbox;
1575         Gtk::EventBox            toolbar_base;
1576         Gtk::Frame               toolbar_frame;
1577
1578         /* midi toolbar */
1579
1580         Gtk::HBox                midi_tool_button_box;
1581         Gtkmm2ext::TearOff*      midi_tool_tearoff;
1582         Gtk::ToggleButton        midi_tool_pencil_button;
1583         Gtk::ToggleButton        midi_tool_select_button;
1584         Gtk::ToggleButton        midi_tool_erase_button;
1585         GroupedButtons          *midi_tool_button_set;
1586         void                     midi_edit_mode_toggled (Editing::MidiEditMode m);
1587         bool                     ignore_midi_edit_mode_toggle;
1588
1589         Gtkmm2ext::TearOff* midi_tools_tearoff;
1590         Gtk::HBox           midi_toolbar_hbox;
1591         Gtk::EventBox       midi_toolbar_base;
1592         Gtk::Frame          midi_toolbar_frame;
1593         
1594         void setup_midi_toolbar ();
1595
1596         /* selection process */
1597
1598         Selection* selection;
1599         Selection* cut_buffer;
1600
1601         void time_selection_changed ();
1602         void track_selection_changed ();
1603         void region_selection_changed ();
1604         void point_selection_changed ();
1605         void marker_selection_changed ();
1606
1607         enum SelectionOp {
1608                 CreateSelection,
1609                 SelectionStartTrim,
1610                 SelectionEndTrim,
1611                 SelectionMove
1612         } selection_op;
1613
1614         void start_selection_op (ArdourCanvas::Item* item, GdkEvent* event, SelectionOp);
1615         void drag_selection (ArdourCanvas::Item* item, GdkEvent* event);
1616         void end_selection_op (ArdourCanvas::Item* item, GdkEvent* event);
1617         void cancel_selection ();
1618
1619         void region_selection_op (void (ARDOUR::Region::*pmf)(void));
1620         void region_selection_op (void (ARDOUR::Region::*pmf)(void*), void*);
1621         void region_selection_op (void (ARDOUR::Region::*pmf)(bool), bool);
1622
1623         bool audio_region_selection_covers (nframes_t where);
1624
1625         /* transport range select process */
1626         enum RangeMarkerOp {
1627                 CreateRangeMarker,
1628                 CreateTransportMarker,
1629                 CreateCDMarker
1630         } range_marker_op;
1631
1632         void start_range_markerbar_op (ArdourCanvas::Item* item, GdkEvent* event, RangeMarkerOp);
1633         void drag_range_markerbar_op (ArdourCanvas::Item* item, GdkEvent* event);
1634         void end_range_markerbar_op (ArdourCanvas::Item* item, GdkEvent* event);
1635
1636         ArdourCanvas::SimpleRect*  range_bar_drag_rect;
1637         ArdourCanvas::SimpleRect*  transport_bar_drag_rect;
1638         ArdourCanvas::Line*        marker_drag_line;
1639         ArdourCanvas::Points       marker_drag_line_points;
1640         ArdourCanvas::SimpleRect*  range_marker_drag_rect;
1641
1642         void update_marker_drag_item (ARDOUR::Location *);
1643         
1644         ArdourCanvas::SimpleRect     *transport_bar_range_rect;
1645         ArdourCanvas::SimpleRect     *transport_bar_preroll_rect;
1646         ArdourCanvas::SimpleRect     *transport_bar_postroll_rect;
1647         ArdourCanvas::SimpleRect     *transport_loop_range_rect;
1648         ArdourCanvas::SimpleRect     *transport_punch_range_rect;
1649         ArdourCanvas::SimpleLine     *transport_punchin_line;
1650         ArdourCanvas::SimpleLine     *transport_punchout_line;
1651         ArdourCanvas::SimpleRect     *transport_preroll_rect;
1652         ArdourCanvas::SimpleRect     *transport_postroll_rect;
1653
1654         ARDOUR::Location*  transport_loop_location();
1655         ARDOUR::Location*  transport_punch_location();
1656
1657         ARDOUR::Location   *temp_location;
1658         
1659         /* object rubberband select process */
1660         
1661         void start_rubberband_select (ArdourCanvas::Item* item, GdkEvent* event);
1662         void drag_rubberband_select (ArdourCanvas::Item* item, GdkEvent* event);
1663         void end_rubberband_select (ArdourCanvas::Item* item, GdkEvent* event);
1664
1665         bool select_all_within (nframes_t start, nframes_t end, gdouble topy, gdouble boty, const TrackViewList&, Selection::Operation op);
1666         
1667         ArdourCanvas::SimpleRect   *rubberband_rect;
1668         
1669         /* mouse zoom process */
1670
1671         void start_mouse_zoom (ArdourCanvas::Item* item, GdkEvent* event);
1672         void drag_mouse_zoom (ArdourCanvas::Item* item, GdkEvent* event);
1673         void end_mouse_zoom (ArdourCanvas::Item* item, GdkEvent* event);
1674
1675         ArdourCanvas::SimpleRect   *zoom_rect;
1676         void reposition_zoom_rect (nframes_t start, nframes_t end);
1677         
1678         /* diskstream/route display management */
1679
1680         struct RouteDisplayModelColumns : public Gtk::TreeModel::ColumnRecord {
1681             RouteDisplayModelColumns() { 
1682                     add (text);
1683                     add (visible);
1684                     add (tv);
1685                     add (route);
1686             }
1687             Gtk::TreeModelColumn<Glib::ustring>  text;
1688             Gtk::TreeModelColumn<bool>           visible;
1689             Gtk::TreeModelColumn<TimeAxisView*>  tv;
1690             Gtk::TreeModelColumn<boost::shared_ptr<ARDOUR::Route> >  route;
1691         };
1692
1693         RouteDisplayModelColumns         route_display_columns;
1694         Glib::RefPtr<Gtk::ListStore>     route_display_model;
1695         Glib::RefPtr<Gtk::TreeSelection> route_display_selection;
1696
1697         Gtkmm2ext::DnDTreeView<boost::shared_ptr<ARDOUR::Route> > route_list_display; 
1698         Gtk::ScrolledWindow                   route_list_scroller;
1699         Gtk::Menu*                            route_list_menu;
1700
1701         void sync_order_keys ();
1702         bool ignore_route_order_sync;
1703
1704         bool route_list_display_button_press (GdkEventButton*);
1705         void route_list_display_drag_data_received  (const Glib::RefPtr<Gdk::DragContext>& context,
1706                                                      gint                x,
1707                                                      gint                y,
1708                                                      const Gtk::SelectionData& data,
1709                                                      guint               info,
1710                                                      guint               time);
1711
1712         bool route_list_selection_filter (const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreeModel::Path& path, bool yn);
1713
1714         void route_list_change (const Gtk::TreeModel::Path&,const Gtk::TreeModel::iterator&);
1715         void route_list_delete (const Gtk::TreeModel::Path&);
1716         void track_list_reorder (const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator& iter, int* new_order);
1717
1718         void initial_route_list_display ();
1719         void redisplay_route_list();
1720         void route_list_reordered (const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator& iter, int* what);
1721         bool ignore_route_list_reorder;
1722         bool no_route_list_redisplay;
1723
1724         void build_route_list_menu ();
1725         void show_route_list_menu ();
1726
1727         void show_all_routes ();
1728         void hide_all_routes ();
1729         void show_all_audiotracks ();
1730         void hide_all_audiotracks ();
1731         void show_all_audiobus ();
1732         void hide_all_audiobus ();
1733
1734         void set_all_tracks_visibility (bool yn);
1735         void set_all_audio_visibility (int type, bool yn);
1736
1737         /* edit group management */
1738
1739         struct GroupListModelColumns : public Gtk::TreeModel::ColumnRecord {
1740                 GroupListModelColumns () {
1741                        add (is_active);
1742                        add (is_visible);
1743                        add (text);
1744                        add (routegroup);
1745                 }
1746                 Gtk::TreeModelColumn<bool> is_active;
1747                 Gtk::TreeModelColumn<bool> is_visible;
1748                 Gtk::TreeModelColumn<std::string> text;
1749                 Gtk::TreeModelColumn<ARDOUR::RouteGroup*>   routegroup;
1750         };
1751
1752         GroupListModelColumns group_columns;
1753         Glib::RefPtr<Gtk::ListStore> group_model;
1754         Glib::RefPtr<Gtk::TreeSelection> group_selection;
1755
1756         Gtk::TreeView          edit_group_display;
1757         Gtk::ScrolledWindow    edit_group_display_scroller;
1758         Gtk::Menu*             edit_group_list_menu;
1759
1760         void build_edit_group_list_menu ();
1761         void activate_all_edit_groups ();
1762         void disable_all_edit_groups ();
1763
1764         bool in_edit_group_row_change;
1765         void edit_group_row_change (const Gtk::TreeModel::Path&,const Gtk::TreeModel::iterator&);
1766         void edit_group_name_edit (const Glib::ustring&, const Glib::ustring&);
1767         void new_edit_group ();
1768         void edit_group_list_button_clicked ();
1769         gint edit_group_list_button_press_event (GdkEventButton* ev);
1770         void add_edit_group (ARDOUR::RouteGroup* group);
1771         void remove_selected_edit_group ();
1772         void edit_groups_changed ();
1773         void group_flags_changed (void*, ARDOUR::RouteGroup*);
1774
1775         Gtk::VBox           list_vpacker;
1776
1777         /* autoscrolling */
1778
1779         bool autoscroll_active;
1780         int autoscroll_timeout_tag;
1781         int autoscroll_direction;
1782         uint32_t autoscroll_cnt;
1783         nframes_t autoscroll_distance;
1784      
1785         static gint _autoscroll_canvas (void *);
1786         bool autoscroll_canvas ();
1787         void start_canvas_autoscroll (int direction);
1788         void stop_canvas_autoscroll ();
1789         void maybe_autoscroll (GdkEvent*);
1790
1791         /* trimming */
1792         enum TrimOp {
1793                 StartTrim,
1794                 EndTrim,
1795                 ContentsTrim,
1796         } trim_op;
1797
1798         void start_trim (ArdourCanvas::Item*, GdkEvent*);
1799         void point_trim (GdkEvent*);
1800         void trim_motion_callback (ArdourCanvas::Item*, GdkEvent*);
1801         void single_contents_trim (RegionView&, nframes_t, bool, bool, bool);
1802         void single_start_trim (RegionView&, nframes_t, bool, bool);
1803         void single_end_trim (RegionView&, nframes_t, bool, bool);
1804
1805         void trim_finished_callback (ArdourCanvas::Item*, GdkEvent*);
1806         void thaw_region_after_trim (RegionView& rv);
1807
1808         void trim_region_front();
1809         void trim_region_back();
1810         void trim_region (bool front);
1811
1812         void trim_region_to_edit_point ();
1813         void trim_region_from_edit_point ();
1814         void trim_region_to_loop ();
1815         void trim_region_to_punch ();
1816         void trim_region_to_location (const ARDOUR::Location&, const char* cmd);
1817
1818         bool show_gain_after_trim;
1819
1820         /* Drag-n-Drop */
1821
1822         int convert_drop_to_paths (std::vector<Glib::ustring>& paths,
1823                                    const Glib::RefPtr<Gdk::DragContext>& context,
1824                                    gint                x,
1825                                    gint                y,
1826                                    const Gtk::SelectionData& data,
1827                                    guint               info,
1828                                    guint               time);
1829
1830         void  track_canvas_drag_data_received  (const Glib::RefPtr<Gdk::DragContext>& context,
1831                                                 gint                x,
1832                                                 gint                y,
1833                                                 const Gtk::SelectionData& data,
1834                                                 guint               info,
1835                                                 guint               time);
1836         
1837         void  region_list_display_drag_data_received  (const Glib::RefPtr<Gdk::DragContext>& context,
1838                                                        gint                x,
1839                                                        gint                y,
1840                                                        const Gtk::SelectionData& data,
1841                                                        guint               info,
1842                                                        guint               time);
1843
1844
1845         void  drop_paths  (const Glib::RefPtr<Gdk::DragContext>& context,
1846                            gint                x,
1847                            gint                y,
1848                            const Gtk::SelectionData& data,
1849                            guint               info,
1850                            guint               time);
1851
1852         void  drop_regions  (const Glib::RefPtr<Gdk::DragContext>& context,
1853                              gint                x,
1854                              gint                y,
1855                              const Gtk::SelectionData& data,
1856                              guint               info,
1857                              guint               time);
1858
1859         /* audio export */
1860
1861         ExportDialog *export_dialog;
1862         ExportDialog *export_range_markers_dialog;
1863         
1864         void export_range (nframes_t start, nframes_t end);
1865         void export_range_markers ();
1866
1867         int  write_region_selection(RegionSelection&);
1868         bool write_region (string path, boost::shared_ptr<ARDOUR::AudioRegion>);
1869         void export_region ();
1870         void bounce_region_selection ();
1871         void bounce_range_selection ();
1872         void external_edit_region ();
1873
1874         int write_audio_selection (TimeSelection&);
1875         bool write_audio_range (ARDOUR::AudioPlaylist&, const ARDOUR::ChanCount& channels, list<ARDOUR::AudioRange>&);
1876
1877         void write_selection ();
1878
1879         /* history */
1880
1881         UndoAction get_memento() const;
1882
1883         XMLNode *before; /* used in *_reversible_command */
1884
1885         void begin_reversible_command (string cmd_name);
1886         void commit_reversible_command ();
1887
1888         /* visual history */
1889
1890         UndoHistory visual_history;
1891         UndoTransaction current_visual_command;
1892
1893
1894         void update_title ();   
1895         void update_title_s (const string & snapshot_name);
1896
1897         struct State {
1898             Selection* selection;
1899             double frames_per_unit;
1900
1901             State (PublicEditor const * e);
1902             ~State ();
1903         };
1904
1905         void store_state (State&) const;
1906         void restore_state (State *);
1907
1908         void instant_save ();
1909
1910         boost::shared_ptr<ARDOUR::AudioRegion> last_audition_region;
1911         
1912         /* freeze operations */
1913
1914         ARDOUR::InterThreadInfo freeze_status;
1915         gint freeze_progress_timeout (void *);
1916         static void* _freeze_thread (void*);
1917         void* freeze_thread ();
1918
1919         void freeze_route ();
1920         void unfreeze_route ();
1921
1922         /* edit-group solo + mute */
1923
1924         void set_edit_group_solo (ARDOUR::Route&, bool);
1925         void set_edit_group_mute (ARDOUR::Route&, bool);
1926
1927         /* duplication */
1928
1929         void duplicate_dialog (bool with_dialog);
1930         
1931         nframes64_t event_frame (GdkEvent*, double* px = 0, double* py = 0) const;
1932
1933         /* returns false if mouse pointer is not in track or marker canvas
1934          */
1935         bool mouse_frame (nframes64_t&, bool& in_track_canvas) const;
1936
1937         void time_fx_motion (ArdourCanvas::Item*, GdkEvent*);
1938         void start_time_fx (ArdourCanvas::Item*, GdkEvent*);
1939         void end_time_fx (ArdourCanvas::Item*, GdkEvent*);
1940
1941         struct TimeFXDialog : public ArdourDialog {
1942             ARDOUR::TimeFXRequest request;
1943             Editor&               editor;
1944             bool                  pitching;
1945             Gtk::Adjustment       pitch_octave_adjustment;
1946             Gtk::Adjustment       pitch_semitone_adjustment;
1947             Gtk::Adjustment       pitch_cent_adjustment;
1948             Gtk::SpinButton       pitch_octave_spinner;
1949             Gtk::SpinButton       pitch_semitone_spinner;
1950             Gtk::SpinButton       pitch_cent_spinner;
1951             RegionSelection       regions;
1952             Gtk::ProgressBar      progress_bar;
1953
1954             /* SoundTouch */
1955             Gtk::ToggleButton     quick_button;
1956             Gtk::ToggleButton     antialias_button;
1957             Gtk::HBox             upper_button_box;
1958
1959             /* RubberBand */
1960             Gtk::ComboBoxText     stretch_opts_selector;
1961             Gtk::Label            stretch_opts_label;
1962             Gtk::ToggleButton     precise_button;
1963             Gtk::HBox             opts_box;
1964
1965             Gtk::Button*          cancel_button;
1966             Gtk::Button*          action_button;
1967             Gtk::VBox             packer;
1968             int                   status;
1969
1970             TimeFXDialog (Editor& e, bool for_pitch);
1971
1972             gint update_progress ();
1973             sigc::connection first_cancel;
1974             sigc::connection first_delete;
1975             void cancel_in_progress ();
1976             gint delete_in_progress (GdkEventAny*);
1977         };
1978
1979         /* "whats mine is yours" */
1980
1981         friend class TimeFXDialog;
1982
1983         TimeFXDialog* current_timefx;
1984
1985         static void* timefx_thread (void *arg);
1986         void do_timefx (TimeFXDialog&);
1987
1988         int time_stretch (RegionSelection&, float fraction);
1989         int pitch_shift (RegionSelection&, float cents);
1990         void pitch_shift_regions ();
1991         int time_fx (RegionSelection&, float val, bool pitching);
1992
1993         /* editor-mixer strip */
1994
1995         MixerStrip *current_mixer_strip;
1996         bool show_editor_mixer_when_tracks_arrive;
1997         Gtk::VBox current_mixer_strip_vbox;
1998         void cms_new (boost::shared_ptr<ARDOUR::Route>);
1999         void cms_deleted ();
2000         void current_mixer_strip_hidden ();
2001         void current_mixer_strip_removed ();
2002
2003         void detach_tearoff (Gtk::Box* b, Gtk::Window* w);
2004         void reattach_tearoff (Gtk::Box* b, Gtk::Window* w, int32_t n);
2005
2006         /* nudging tracks */
2007
2008         void nudge_track (bool use_edit_point, bool forwards);
2009
2010         /* xfades */
2011
2012         bool _xfade_visibility;
2013         
2014 #ifdef WITH_CMT
2015         void handle_new_imageframe_time_axis_view(const string & track_name, void* src) ;
2016         void handle_new_imageframe_marker_time_axis_view(const string & track_name, TimeAxisView* marked_track) ;
2017
2018         void start_imageframe_grab(ArdourCanvas::Item*, GdkEvent*) ;
2019         void start_markerview_grab(ArdourCanvas::Item*, GdkEvent*) ;
2020
2021         void imageframe_drag_motion_callback(ArdourCanvas::Item*, GdkEvent*) ;
2022         void markerview_drag_motion_callback(ArdourCanvas::Item*, GdkEvent*) ;
2023         void timeaxis_item_drag_finished_callback(ArdourCanvas::Item*, GdkEvent*) ;
2024
2025         gint canvas_imageframe_item_view_event(ArdourCanvas::Item* item, GdkEvent* event, ImageFrameView* ifv);
2026         gint canvas_imageframe_view_event(ArdourCanvas::Item* item, GdkEvent* event, ImageFrameTimeAxis* ifta);
2027         gint canvas_imageframe_start_handle_event(ArdourCanvas::Item* item, GdkEvent* event, ImageFrameView* ifv);
2028         gint canvas_imageframe_end_handle_event(ArdourCanvas::Item* item, GdkEvent* event, ImageFrameView* ifv);
2029
2030         gint canvas_marker_time_axis_view_event(ArdourCanvas::Item* item, GdkEvent* event, MarkerTimeAxis* mta);
2031         gint canvas_markerview_item_view_event(ArdourCanvas::Item* item, GdkEvent* event, MarkerView* mv);
2032         gint canvas_markerview_start_handle_event(ArdourCanvas::Item* item, GdkEvent* event, MarkerView* mv);
2033         gint canvas_markerview_end_handle_event(ArdourCanvas::Item* item, GdkEvent* event, MarkerView* mv);
2034
2035         void imageframe_start_handle_op(ArdourCanvas::Item* item, GdkEvent* event) ;
2036         void imageframe_end_handle_op(ArdourCanvas::Item* item, GdkEvent* event) ;
2037         void imageframe_start_handle_trim_motion(ArdourCanvas::Item* item, GdkEvent* event) ;
2038         void imageframe_start_handle_end_trim(ArdourCanvas::Item* item, GdkEvent* event) ;
2039         void imageframe_end_handle_trim_motion(ArdourCanvas::Item* item, GdkEvent* event) ;
2040         void imageframe_end_handle_end_trim(ArdourCanvas::Item* item, GdkEvent* event) ;
2041         
2042         void markerview_item_start_handle_op(ArdourCanvas::Item* item, GdkEvent* event) ;
2043         void markerview_item_end_handle_op(ArdourCanvas::Item* item, GdkEvent* event) ;
2044         void markerview_start_handle_trim_motion(ArdourCanvas::Item* item, GdkEvent* event) ;
2045         void markerview_start_handle_end_trim(ArdourCanvas::Item* item, GdkEvent* event) ;
2046         void markerview_end_handle_trim_motion(ArdourCanvas::Item* item, GdkEvent* event) ;
2047         void markerview_end_handle_end_trim(ArdourCanvas::Item* item, GdkEvent* event) ;
2048
2049         void popup_imageframe_edit_menu(int button, int32_t time, ArdourCanvas::Item* ifv, bool with_frame) ;
2050         void popup_marker_time_axis_edit_menu(int button, int32_t time, ArdourCanvas::Item* ifv, bool with_frame) ;
2051
2052         ImageFrameSocketHandler* image_socket_listener ;
2053 #endif
2054
2055         void toggle_xfade_active (boost::weak_ptr<ARDOUR::Crossfade>);
2056         void toggle_xfade_length (boost::weak_ptr<ARDOUR::Crossfade>);
2057         void edit_xfade (boost::weak_ptr<ARDOUR::Crossfade>);
2058         void xfade_edit_left_region ();
2059         void xfade_edit_right_region ();
2060
2061         static const int32_t default_width = 995;
2062         static const int32_t default_height = 765;
2063
2064         /* nudge */
2065
2066         Gtk::Button      nudge_forward_button;
2067         Gtk::Button      nudge_backward_button;
2068         Gtk::HBox        nudge_hbox;
2069         Gtk::VBox        nudge_vbox;
2070         AudioClock       nudge_clock;
2071
2072         nframes_t get_nudge_distance (nframes_t pos, nframes_t& next);
2073
2074         bool nudge_forward_release (GdkEventButton*);
2075         bool nudge_backward_release (GdkEventButton*);
2076         
2077         /* audio filters */
2078
2079         void apply_filter (ARDOUR::Filter&, string cmd);
2080
2081         /* handling cleanup */
2082
2083         int playlist_deletion_dialog (boost::shared_ptr<ARDOUR::Playlist>);
2084
2085         vector<sigc::connection> session_connections;
2086
2087         /* tracking step changes of track height */
2088
2089         TimeAxisView* current_stepping_trackview;
2090         struct timeval last_track_height_step_timestamp;
2091         gint track_height_step_timeout();
2092         sigc::connection step_timeout;
2093
2094         TimeAxisView* entered_track;
2095         RegionView*   entered_regionview;
2096
2097         class ExclusiveRegionSelection {
2098           public:
2099                 ExclusiveRegionSelection (Editor&, RegionView*);
2100                 ~ExclusiveRegionSelection ();
2101
2102           private:
2103                 Editor& editor;
2104                 RegionView* regionview;
2105                 bool remove;
2106         };
2107
2108         void ensure_entered_region_selected (bool op_acts_on_objects = false);
2109         void ensure_entered_track_selected (bool op_acts_on_objects = false);
2110         bool clear_entered_track;
2111         gint left_track_canvas (GdkEventCrossing*);
2112         void set_entered_track (TimeAxisView*);
2113         void set_entered_regionview (RegionView*);
2114         gint left_automation_track ();
2115
2116         bool _new_regionviews_show_envelope;
2117
2118         void toggle_gain_envelope_visibility ();
2119         void toggle_gain_envelope_active ();
2120         void reset_region_gain_envelopes ();
2121
2122         bool on_key_press_event (GdkEventKey*);
2123         bool on_key_release_event (GdkEventKey*);
2124
2125         void session_state_saved (string);
2126
2127         Glib::RefPtr<Gtk::Action>              undo_action;
2128         Glib::RefPtr<Gtk::Action>              redo_action;
2129
2130         void history_changed ();
2131
2132         Gtk::HBox      status_bar_hpacker;
2133
2134         Editing::EditPoint _edit_point;
2135
2136         Gtk::ComboBoxText edit_point_selector;
2137
2138         void set_edit_point_preference (Editing::EditPoint ep);
2139         void cycle_edit_point (bool with_marker);
2140         void set_edit_point ();
2141         void edit_point_selection_done ();
2142         void edit_point_chosen (Editing::EditPoint);
2143         Glib::RefPtr<Gtk::RadioAction> edit_point_action (Editing::EditPoint);
2144         std::vector<std::string> edit_point_strings;
2145
2146         void selected_marker_moved (ARDOUR::Location*);
2147         sigc::connection edit_point_clock_connection_a;
2148         sigc::connection edit_point_clock_connection_b;
2149
2150         bool get_edit_op_range (nframes64_t& start, nframes64_t& end) const;
2151
2152         RegionSelection get_regions_at (nframes64_t where, const TrackSelection& ts) const;
2153         RegionSelection get_regions_after (nframes64_t where, const TrackSelection& ts) const;
2154         
2155         RegionSelection tmp_regions;
2156         
2157         RegionSelection& get_regions_for_action ();
2158
2159         sigc::connection fast_screen_update_connection;
2160         gint start_updating ();
2161         gint stop_updating ();
2162         void fast_update_strips ();
2163         bool meters_running;
2164
2165         void select_next_route ();
2166         void select_prev_route ();
2167 };
2168
2169 #endif /* __ardour_editor_h__ */