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