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