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