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