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