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