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