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