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