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