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