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