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