replace ::cast_dynamic() with relevant ActionManager::get_*_action() calls
[ardour.git] / gtk2_ardour / editor.h
index 7c224a1d0c1b7548ae92ece57fec5056790f1b76..04c32b7128acdab450b058504d2c8e180dfc5e08 100644 (file)
 #include <gtkmm/layout.h>
 
 #include "gtkmm2ext/bindings.h"
-#include "gtkmm2ext/click_box.h"
 #include "gtkmm2ext/dndtreeview.h"
-#include "gtkmm2ext/pane.h"
-#include "gtkmm2ext/selector.h"
-#include "gtkmm2ext/stateful_button.h"
 
 #include "pbd/stateful.h"
 #include "pbd/signals.h"
 #include "canvas/fwd.h"
 #include "canvas/ruler.h"
 
-#include "ardour_button.h"
+#include "widgets/ardour_button.h"
+#include "widgets/ardour_dropdown.h"
+#include "widgets/pane.h"
+
 #include "ardour_dialog.h"
-#include "ardour_dropdown.h"
 #include "public_editor.h"
 #include "editing.h"
 #include "enums.h"
 #include "selection_memento.h"
 #include "tempo_curve.h"
 
+#include "ptformat/ptfformat.h"
+
 namespace Gtkmm2ext {
        class Bindings;
 }
 
+namespace Evoral {
+       class SMF;
+}
+
 namespace ARDOUR {
        class AudioPlaylist;
        class AudioRegion;
@@ -98,7 +102,6 @@ class AutomationLine;
 class AutomationSelection;
 class AutomationTimeAxisView;
 class BundleManager;
-class ButtonJoiner;
 class ControlPoint;
 class CursorContext;
 class DragManager;
@@ -111,7 +114,6 @@ class EditorRoutes;
 class EditorRouteGroups;
 class EditorSnapshots;
 class EditorSummary;
-class GroupedButtons;
 class GUIObjectState;
 class ArdourMarker;
 class MidiRegionView;
@@ -128,31 +130,32 @@ class RulerDialog;
 class Selection;
 class SoundFileOmega;
 class StreamView;
+class GridLines;
 class TempoLines;
 class TimeAxisView;
+class TimeInfoBox;
 class TimeFXDialog;
 class TimeSelection;
 class RegionLayeringOrderEditor;
 class VerboseCursor;
 
-class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARDOUR::SessionHandlePtr
+class Editor : public PublicEditor, public PBD::ScopedConnectionList
 {
- public:
+public:
        Editor ();
        ~Editor ();
 
        void             set_session (ARDOUR::Session *);
-       ARDOUR::Session* session() const { return _session; }
 
        Gtk::Window* use_own_window (bool and_fill_it);
 
        void             first_idle ();
        virtual bool     have_idled () const { return _have_idled; }
 
-       framepos_t leftmost_sample() const { return leftmost_frame; }
+       samplepos_t leftmost_sample() const { return _leftmost_sample; }
 
-       framecnt_t current_page_samples() const {
-               return (framecnt_t) _visible_canvas_width * samples_per_pixel;
+       samplecnt_t current_page_samples() const {
+               return (samplecnt_t) _visible_canvas_width * samples_per_pixel;
        }
 
        double visible_canvas_height () const {
@@ -161,19 +164,15 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        double trackviews_height () const;
 
        void cycle_snap_mode ();
-       void next_snap_choice ();
-       void next_snap_choice_music_only ();
-       void next_snap_choice_music_and_time ();
-       void prev_snap_choice ();
-       void prev_snap_choice_music_only ();
-       void prev_snap_choice_music_and_time ();
-       void set_snap_to (Editing::SnapType);
+       void next_grid_choice ();
+       void prev_grid_choice ();
+       void set_grid_to (Editing::GridType);
        void set_snap_mode (Editing::SnapMode);
-       void set_snap_threshold (double pixel_distance) {snap_threshold = pixel_distance;}
 
        Editing::SnapMode  snap_mode () const;
-       Editing::SnapType  snap_type () const;
-       bool  snap_musical () const;
+       Editing::GridType  grid_type () const;
+       bool  grid_musical () const;
+       bool  grid_nonmusical () const;
 
        void undo (uint32_t n = 1);
        void redo (uint32_t n = 1);
@@ -181,7 +180,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        XMLNode& get_state ();
        int set_state (const XMLNode&, int version);
 
-       void set_mouse_mode (Editing::MouseMode, bool force=true);
+       void set_mouse_mode (Editing::MouseMode, bool force = false);
        void step_mouse_mode (bool next);
        Editing::MouseMode current_mouse_mode () const { return mouse_mode; }
        Editing::MidiEditMode current_midi_edit_mode () const;
@@ -192,7 +191,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void foreach_time_axis_view (sigc::slot<void,TimeAxisView&>);
        void add_to_idle_resize (TimeAxisView*, int32_t);
 
-       RouteTimeAxisView* get_route_view_by_route_id (const PBD::ID& id) const;
+       StripableTimeAxisView* get_stripable_time_axis_by_id (const PBD::ID& id) const;
 
        void consider_auditioning (boost::shared_ptr<ARDOUR::Region>);
        void hide_a_region (boost::shared_ptr<ARDOUR::Region>);
@@ -219,7 +218,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
           account any scrolling offsets.
        */
 
-       framepos_t pixel_to_sample_from_event (double pixel) const {
+       samplepos_t pixel_to_sample_from_event (double pixel) const {
 
                /* pixel can be less than zero when motion events
                   are processed. since we've already run the world->canvas
@@ -234,37 +233,39 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
                }
        }
 
-       framepos_t pixel_to_sample (double pixel) const {
+       samplepos_t pixel_to_sample (double pixel) const {
                return pixel * samples_per_pixel;
        }
 
-        double sample_to_pixel (framepos_t sample) const {
-               return round (sample / (double) samples_per_pixel);
+       double sample_to_pixel (samplepos_t sample) const {
+               return round (sample / (double) samples_per_pixel);
        }
 
-       double sample_to_pixel_unrounded (framepos_t sample) const {
+       double sample_to_pixel_unrounded (samplepos_t sample) const {
                return sample / (double) samples_per_pixel;
        }
 
        /* selection */
 
        Selection& get_selection() const { return *selection; }
-       bool get_selection_extents (framepos_t &start, framepos_t &end) const;  // the time extents of the current selection, whether Range, Region(s), Control Points, or Notes
+       bool get_selection_extents (samplepos_t &start, samplepos_t &end) const;  // the time extents of the current selection, whether Range, Region(s), Control Points, or Notes
        Selection& get_cut_buffer() const { return *cut_buffer; }
-       void track_mixer_selection ();
+
+       void set_selection (std::list<Selectable*>, Selection::Operation);
 
        bool extend_selection_to_track (TimeAxisView&);
 
        void play_selection ();
-       framepos_t get_preroll ();
-       void maybe_locate_with_edit_preroll (framepos_t);
+       void maybe_locate_with_edit_preroll (samplepos_t);
        void play_with_preroll ();
+       void rec_with_preroll ();
+       void rec_with_count_in ();
        void select_all_in_track (Selection::Operation op);
        void select_all_objects (Selection::Operation op);
        void invert_selection_in_track ();
        void invert_selection ();
        void deselect_all ();
-       long select_range (framepos_t, framepos_t);
+       long select_range (samplepos_t, samplepos_t);
 
        void set_selected_regionview_from_region_list (boost::shared_ptr<ARDOUR::Region> region, Selection::Operation op = Selection::Set);
 
@@ -272,8 +273,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        /* tempo */
 
-       void set_show_measures (bool yn);
-       bool show_measures () const { return _show_measures; }
+       void update_grid ();
 
        /* analysis window */
 
@@ -295,10 +295,12 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        void               set_zoom_focus (Editing::ZoomFocus);
        Editing::ZoomFocus get_zoom_focus () const { return zoom_focus; }
-       framecnt_t         get_current_zoom () const { return samples_per_pixel; }
+       samplecnt_t         get_current_zoom () const { return samples_per_pixel; }
        void               cycle_zoom_focus ();
-       void temporal_zoom_step (bool coarser);
-       void temporal_zoom_step_mouse_focus (bool coarser);
+       void temporal_zoom_step (bool zoom_out);
+       void temporal_zoom_step_scale (bool zoom_out, double scale);
+       void temporal_zoom_step_mouse_focus (bool zoom_out);
+       void temporal_zoom_step_mouse_focus_scale (bool zoom_out, double scale);
        void ensure_time_axis_view_is_visible (TimeAxisView const & tav, bool at_top);
        void tav_zoom_step (bool coarser);
        void tav_zoom_smooth (bool coarser, bool force_all);
@@ -322,15 +324,17 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void set_selected_mixer_strip (TimeAxisView&);
        void mixer_strip_width_changed ();
        void hide_track_in_display (TimeAxisView* tv, bool apply_to_selection = false);
+       void show_track_in_display (TimeAxisView* tv, bool move_into_view = false);
+       void tempo_curve_selected (ARDOUR::TempoSection* ts, bool yn);
 
        /* nudge is initiated by transport controls owned by ARDOUR_UI */
 
-       framecnt_t get_nudge_distance (framepos_t pos, framecnt_t& next);
-       framecnt_t get_paste_offset (framepos_t pos, unsigned paste_count, framecnt_t duration);
-       unsigned get_grid_beat_divisions(framepos_t position);
-       Evoral::Beats get_grid_type_as_beats (bool& success, framepos_t position);
+       samplecnt_t get_nudge_distance (samplepos_t pos, samplecnt_t& next);
+       samplecnt_t get_paste_offset (samplepos_t pos, unsigned paste_count, samplecnt_t duration);
+       unsigned get_grid_beat_divisions(samplepos_t position);
+       Temporal::Beats get_grid_type_as_beats (bool& success, samplepos_t position);
 
-       unsigned get_grid_music_divisions (uint32_t event_state);
+       int32_t get_grid_music_divisions (uint32_t event_state);
 
        void nudge_forward (bool next, bool force_playhead);
        void nudge_backward (bool next, bool force_playhead);
@@ -356,12 +360,14 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void toggle_zero_line_visibility ();
        void set_summary ();
        void set_group_tabs ();
-       void toggle_measure_visibility ();
+
+       /* returns the left-most and right-most time that the gui should allow the user to scroll to */
+       std::pair <samplepos_t,samplepos_t> session_gui_extents (bool use_extra = true) const;
 
        /* fades */
 
-       void toggle_region_fades (int dir);
-       void update_region_fade_visibility ();
+       void toggle_region_fades (int dir);
+       void update_region_fade_visibility ();
 
        /* redirect shared ops menu. caller must free returned menu */
 
@@ -383,6 +389,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void scroll_left_half_page ();
        void scroll_right_half_page ();
 
+       void select_topmost_track ();
+
        void prepare_for_cleanup ();
        void finish_cleanup ();
 
@@ -390,13 +398,13 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void restore_editing_space();
 
        double get_y_origin () const;
-       void reset_x_origin (framepos_t);
+       void reset_x_origin (samplepos_t);
        void reset_x_origin_to_follow_playhead ();
        void reset_y_origin (double);
-       void reset_zoom (framecnt_t);
-       void reposition_and_zoom (framepos_t, double);
+       void reset_zoom (samplecnt_t);
+       void reposition_and_zoom (samplepos_t, double);
 
-       framepos_t get_preferred_edit_position (Editing::EditIgnoreOption = Editing::EDIT_IGNORE_NONE,
+       samplepos_t get_preferred_edit_position (Editing::EditIgnoreOption = Editing::EDIT_IGNORE_NONE,
                                                bool use_context_click = false,
                                                bool from_outside_canvas = false);
 
@@ -414,7 +422,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void start_resize_line_ops ();
        void end_resize_line_ops ();
 
-       TrackViewList const & get_track_views () {
+       TrackViewList const & get_track_views () const {
                return track_views;
        }
 
@@ -426,38 +434,37 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
                        Editing::ImportDisposition            disposition,
                        Editing::ImportMode                   mode,
                        ARDOUR::SrcQuality                    quality,
-                       framepos_t&                           pos,
+                       ARDOUR::MidiTrackNameSource           mts,
+                       ARDOUR::MidiTempoMapDisposition       mtd,
+                       samplepos_t&                           pos,
                        boost::shared_ptr<ARDOUR::PluginInfo> instrument = boost::shared_ptr<ARDOUR::PluginInfo>());
 
        void do_embed (std::vector<std::string>              paths,
                       Editing::ImportDisposition            disposition,
                       Editing::ImportMode                   mode,
-                      framepos_t&                           pos,
+                      samplepos_t&                           pos,
                       boost::shared_ptr<ARDOUR::PluginInfo> instrument = boost::shared_ptr<ARDOUR::PluginInfo>());
 
        void get_regions_corresponding_to (boost::shared_ptr<ARDOUR::Region> region, std::vector<RegionView*>& regions, bool src_comparison);
 
        void get_regionviews_by_id (PBD::ID const id, RegionSelection & regions) const;
-       void get_per_region_note_selection (std::list<std::pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Evoral::Beats> > > > >&) const;
+       void get_per_region_note_selection (std::list<std::pair<PBD::ID, std::set<boost::shared_ptr<Evoral::Note<Temporal::Beats> > > > >&) const;
 
-       void center_screen (framepos_t);
+       void center_screen (samplepos_t);
 
        TrackViewList axis_views_from_routes (boost::shared_ptr<ARDOUR::RouteList>) const;
 
-       void snap_to (framepos_t&       first,
-                     ARDOUR::RoundMode direction = ARDOUR::RoundNearest,
-                     bool              for_mark  = false,
-                     bool              ensure_snap = false);
+       void snap_to (ARDOUR::MusicSample& first,
+                     ARDOUR::RoundMode   direction = ARDOUR::RoundNearest,
+                     ARDOUR::SnapPref    pref = ARDOUR::SnapToAny_Visual,
+                     bool                ensure_snap = false);
 
-       void snap_to_with_modifier (framepos_t&       first,
-                                   GdkEvent const *  ev,
-                                   ARDOUR::RoundMode direction = ARDOUR::RoundNearest,
-                                   bool              for_mark  = false);
+       void snap_to_with_modifier (ARDOUR::MusicSample& first,
+                                   GdkEvent const *    ev,
+                                   ARDOUR::RoundMode   direction = ARDOUR::RoundNearest,
+                                   ARDOUR::SnapPref    pref = ARDOUR::SnapToAny_Visual);
 
-       void snap_to (framepos_t&       first,
-                     framepos_t&       last,
-                     ARDOUR::RoundMode direction = ARDOUR::RoundNearest,
-                     bool              for_mark  = false);
+       void set_snapped_cursor_position (samplepos_t pos);
 
        void begin_selection_op_history ();
        void begin_reversible_selection_op (std::string cmd_name);
@@ -520,6 +527,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        ArdourCanvas::ScrollGroup* get_hscroll_group () const { return h_scroll_group; }
        ArdourCanvas::ScrollGroup* get_hvscroll_group () const { return hv_scroll_group; }
        ArdourCanvas::ScrollGroup* get_cursor_scroll_group () const { return cursor_scroll_group; }
+       ArdourCanvas::Container* get_drag_motion_group () const { return _drag_motion_group; }
 
        ArdourCanvas::GtkCanvasViewport* get_track_canvas () const;
 
@@ -533,46 +541,49 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void metric_get_minsec (std::vector<ArdourCanvas::Ruler::Mark>&, gdouble, gdouble, gint);
 
        /* editing operations that need to be public */
-       void mouse_add_new_marker (framepos_t where, bool is_cd=false);
-       void split_regions_at (framepos_t, RegionSelection&, const int32_t& sub_num);
+       void mouse_add_new_marker (samplepos_t where, bool is_cd=false);
+       void split_regions_at (ARDOUR::MusicSample, RegionSelection&);
        void split_region_at_points (boost::shared_ptr<ARDOUR::Region>, ARDOUR::AnalysisFeatureList&, bool can_ferret, bool select_new = false);
-       RegionSelection get_regions_from_selection_and_mouse (framepos_t);
+       RegionSelection get_regions_from_selection_and_mouse (samplepos_t);
 
-       void mouse_add_new_tempo_event (framepos_t where);
-       void mouse_add_new_meter_event (framepos_t where);
+       void mouse_add_new_tempo_event (samplepos_t where);
+       void mouse_add_new_meter_event (samplepos_t where);
        void edit_tempo_section (ARDOUR::TempoSection*);
        void edit_meter_section (ARDOUR::MeterSection*);
 
-  protected:
+protected:
        void map_transport_state ();
-       void map_position_change (framepos_t);
+       void map_position_change (samplepos_t);
+       void transport_looped ();
 
        void on_realize();
 
        void suspend_route_redisplay ();
        void resume_route_redisplay ();
 
-  private:
+private:
 
        void color_handler ();
 
        bool                 constructed;
 
        // to keep track of the playhead position for control_scroll
-       boost::optional<framepos_t> _control_scroll_target;
+       boost::optional<samplepos_t> _control_scroll_target;
 
        PlaylistSelector* _playlist_selector;
 
+       TimeInfoBox*      _time_info_box;
+
        typedef std::pair<TimeAxisView*,XMLNode*> TAVState;
 
        struct VisualState {
-           VisualState (bool with_tracks);
-           ~VisualState ();
-           double              y_position;
-           framecnt_t          samples_per_pixel;
-           framepos_t          leftmost_frame;
-           Editing::ZoomFocus  zoom_focus;
-           GUIObjectState*     gui_state;
+               VisualState (bool with_tracks);
+               ~VisualState ();
+               double              y_position;
+               samplecnt_t          samples_per_pixel;
+               samplepos_t          _leftmost_sample;
+               Editing::ZoomFocus  zoom_focus;
+               GUIObjectState*     gui_state;
        };
 
        std::list<VisualState*> undo_visual_stack;
@@ -588,16 +599,17 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void start_visual_state_op (uint32_t n);
        void cancel_visual_state_op (uint32_t n);
 
-       framepos_t         leftmost_frame;
-       framecnt_t         samples_per_pixel;
+       samplepos_t         _leftmost_sample;
+       samplecnt_t         samples_per_pixel;
        Editing::ZoomFocus zoom_focus;
 
-       void set_samples_per_pixel (framecnt_t);
+       void set_samples_per_pixel (samplecnt_t);
+       void on_samples_per_pixel_changed ();
 
        Editing::MouseMode mouse_mode;
-       Editing::SnapType  pre_internal_snap_type;
+       Editing::GridType  pre_internal_grid_type;
        Editing::SnapMode  pre_internal_snap_mode;
-       Editing::SnapType  internal_snap_type;
+       Editing::GridType  internal_grid_type;
        Editing::SnapMode  internal_snap_mode;
        Editing::MouseMode effective_mouse_mode () const;
 
@@ -615,16 +627,16 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        boost::optional<float>  pre_notebook_shrink_pane_width;
 
+       Gtk::VBox _editor_list_vbox;
        Gtk::Notebook _the_notebook;
        bool _notebook_shrunk;
        void add_notebook_page (std::string const &, Gtk::Widget &);
        bool notebook_tab_clicked (GdkEventButton *, Gtk::Widget *);
 
-       Gtkmm2ext::HPane   edit_pane;
-       Gtkmm2ext::VPane   editor_summary_pane;
+       ArdourWidgets::HPane edit_pane;
+       ArdourWidgets::VPane editor_summary_pane;
 
        Gtk::EventBox meter_base;
-       Gtk::HBox     meter_box;
        Gtk::EventBox marker_base;
        Gtk::HBox     marker_box;
        Gtk::VBox     scrollers_rulers_markers_box;
@@ -640,9 +652,13 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        gint really_remove_marker (ARDOUR::Location* loc);
        void goto_nth_marker (int nth);
        void trigger_script (int nth);
+       void trigger_script_by_name (const std::string script_name);
        void toggle_marker_lines ();
        void set_marker_line_visibility (bool);
 
+       void jump_forward_to_mark ();
+       void jump_backward_to_mark ();
+
        uint32_t location_marker_color;
        uint32_t location_range_color;
        uint32_t location_loop_color;
@@ -667,7 +683,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
                void setup_lines ();
 
                void set_name (const std::string&);
-               void set_position (framepos_t start, framepos_t end = 0);
+               void set_position (samplepos_t start, samplepos_t end = 0);
                void set_color_rgba (uint32_t);
        };
 
@@ -695,9 +711,9 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        void hide_marker (ArdourCanvas::Item*, GdkEvent*);
        void clear_marker_display ();
-       void mouse_add_new_range (framepos_t);
-       void mouse_add_new_loop (framepos_t);
-       void mouse_add_new_punch (framepos_t);
+       void mouse_add_new_range (samplepos_t);
+       void mouse_add_new_loop (samplepos_t);
+       void mouse_add_new_punch (samplepos_t);
        bool choose_new_marker_name(std::string &name);
        void update_cd_marker_display ();
        void ensure_cd_marker_updated (LocationMarkers * lam, ARDOUR::Location * location);
@@ -717,6 +733,9 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        void get_equivalent_regions (RegionView* rv, std::vector<RegionView*> &, PBD::PropertyID) const;
        RegionSelection get_equivalent_regions (RegionSelection &, PBD::PropertyID) const;
+       RegionView* regionview_from_region (boost::shared_ptr<ARDOUR::Region>) const;
+       RouteTimeAxisView* rtav_from_route (boost::shared_ptr<ARDOUR::Route>) const;
+
        void mapover_tracks (sigc::slot<void,RouteTimeAxisView&,uint32_t> sl, TimeAxisView*, PBD::PropertyID) const;
        void mapover_tracks_with_unique_playlists (sigc::slot<void,RouteTimeAxisView&,uint32_t> sl, TimeAxisView*, PBD::PropertyID) const;
 
@@ -789,7 +808,6 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        size_t push_canvas_cursor (Gdk::Cursor*);
        void pop_canvas_cursor ();
 
-       Gdk::Cursor* which_grabber_cursor () const;
        Gdk::Cursor* which_track_cursor () const;
        Gdk::Cursor* which_mode_cursor () const;
        Gdk::Cursor* which_trim_cursor (bool left_side) const;
@@ -890,8 +908,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void update_just_timecode ();
        void compute_fixed_ruler_scale (); //calculates the RulerScale of the fixed rulers
        void update_fixed_rulers ();
-       void update_tempo_based_rulers (std::vector<ARDOUR::TempoMap::BBTPoint>& grid);
-       void popup_ruler_menu (framepos_t where = 0, ItemType type = RegionItem);
+       void update_tempo_based_rulers ();
+       void popup_ruler_menu (samplepos_t where = 0, ItemType type = RegionItem);
        void update_ruler_visibility ();
        void set_ruler_visible (RulerType, bool);
        void toggle_ruler_visibility (RulerType rt);
@@ -899,10 +917,9 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        bool ruler_label_button_release (GdkEventButton*);
        void store_ruler_visibility ();
        void restore_ruler_visibility ();
+       void show_rulers_for_grid ();
 
-
-
-               enum MinsecRulerScale {
+       enum MinsecRulerScale {
                minsec_show_msecs,
                minsec_show_seconds,
                minsec_show_minutes,
@@ -912,14 +929,14 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        MinsecRulerScale minsec_ruler_scale;
 
-       framecnt_t minsec_mark_interval;
+       samplecnt_t minsec_mark_interval;
        gint minsec_mark_modulo;
        gint minsec_nmarks;
-       void set_minsec_ruler_scale (framepos_t, framepos_t);
+       void set_minsec_ruler_scale (samplepos_t, samplepos_t);
 
        enum TimecodeRulerScale {
                timecode_show_bits,
-               timecode_show_frames,
+               timecode_show_samples,
                timecode_show_seconds,
                timecode_show_minutes,
                timecode_show_hours,
@@ -930,10 +947,10 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        gint timecode_mark_modulo;
        gint timecode_nmarks;
-       void set_timecode_ruler_scale (framepos_t, framepos_t);
+       void set_timecode_ruler_scale (samplepos_t, samplepos_t);
 
-       framecnt_t _samples_ruler_interval;
-       void set_samples_ruler_scale (framepos_t, framepos_t);
+       samplecnt_t _samples_ruler_interval;
+       void set_samples_ruler_scale (samplepos_t, samplepos_t);
 
        enum BBTRulerScale {
                bbt_show_many,
@@ -941,10 +958,10 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
                bbt_show_16,
                bbt_show_4,
                bbt_show_1,
-               bbt_show_beats,
-               bbt_show_ticks,
-               bbt_show_ticks_detail,
-               bbt_show_ticks_super_detail
+               bbt_show_quarters,
+               bbt_show_eighths,
+               bbt_show_sixteenths,
+               bbt_show_thirtyseconds
        };
 
        BBTRulerScale bbt_ruler_scale;
@@ -953,7 +970,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        gint bbt_nmarks;
        uint32_t bbt_bar_helper_on;
        uint32_t bbt_accent_modulo;
-       void compute_bbt_ruler_scale (std::vector<ARDOUR::TempoMap::BBTPoint>& grid, framepos_t lower, framepos_t upper);
+       void compute_bbt_ruler_scale (samplepos_t lower, samplepos_t upper);
 
        ArdourCanvas::Ruler* timecode_ruler;
        ArdourCanvas::Ruler* bbt_ruler;
@@ -989,7 +1006,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        Glib::RefPtr<Gtk::ToggleAction> xjadeo_proc_action;
        Glib::RefPtr<Gtk::ToggleAction> xjadeo_ontop_action;
        Glib::RefPtr<Gtk::ToggleAction> xjadeo_timecode_action;
-       Glib::RefPtr<Gtk::ToggleAction> xjadeo_frame_action;
+       Glib::RefPtr<Gtk::ToggleAction> xjadeo_sample_action;
        Glib::RefPtr<Gtk::ToggleAction> xjadeo_osdbg_action;
        Glib::RefPtr<Gtk::ToggleAction> xjadeo_fullscreen_action;
        Glib::RefPtr<Gtk::ToggleAction> xjadeo_letterbox_action;
@@ -1007,9 +1024,12 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        friend class EditorCursor;
 
-       EditorCursor*        playhead_cursor;
+       EditorCursor* snapped_cursor;
+
+       EditorCursor* playhead_cursor;
+       samplepos_t playhead_cursor_sample () const;
 
-       framepos_t get_region_boundary (framepos_t pos, int32_t dir, bool with_selection, bool only_onscreen);
+       samplepos_t get_region_boundary (samplepos_t pos, int32_t dir, bool with_selection, bool only_onscreen);
 
        void    cursor_to_region_boundary (bool with_selection, int32_t dir);
        void    cursor_to_next_region_boundary (bool with_selection);
@@ -1034,15 +1054,16 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void    select_all_selectables_between (bool within);
        void    select_range_between ();
 
-       boost::shared_ptr<ARDOUR::Region> find_next_region (ARDOUR::framepos_t, ARDOUR::RegionPoint, int32_t dir, TrackViewList&, TimeAxisView ** = 0);
-       ARDOUR::framepos_t find_next_region_boundary (ARDOUR::framepos_t, int32_t dir, const TrackViewList&);
+       boost::shared_ptr<ARDOUR::Region> find_next_region (ARDOUR::samplepos_t, ARDOUR::RegionPoint, int32_t dir, TrackViewList&, TimeAxisView ** = 0);
+       ARDOUR::samplepos_t find_next_region_boundary (ARDOUR::samplepos_t, int32_t dir, const TrackViewList&);
 
-       std::vector<ARDOUR::framepos_t> region_boundary_cache;
+       std::vector<ARDOUR::samplepos_t> region_boundary_cache;
+       void mark_region_boundary_cache_dirty () { _region_boundary_cache_dirty = true; }
        void build_region_boundary_cache ();
+       bool    _region_boundary_cache_dirty;
 
        Gtk::HBox           toplevel_hpacker;
 
-       Gtk::HBox           top_hbox;
        Gtk::HBox           bottom_hbox;
 
        Gtk::Table          edit_packer;
@@ -1093,8 +1114,9 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void control_scroll (float);
        void control_select (boost::shared_ptr<ARDOUR::Stripable>, Selection::Operation);
        void control_unselect ();
-       void access_action (std::string,std::string);
-       bool deferred_control_scroll (framepos_t);
+       void access_action (const std::string&, const std::string&);
+       void set_toggleaction (const std::string&, const std::string&, bool);
+       bool deferred_control_scroll (samplepos_t);
        sigc::connection control_scroll_connection;
 
        void tie_vertical_scrolling ();
@@ -1105,12 +1127,13 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
                enum Type {
                        TimeOrigin = 0x1,
                        ZoomLevel = 0x2,
-                       YOrigin = 0x4
+                       YOrigin = 0x4,
+                       VideoTimeline = 0x8
                };
 
                Type       pending;
-               framepos_t time_origin;
-               framecnt_t samples_per_pixel;
+               samplepos_t time_origin;
+               samplecnt_t samples_per_pixel;
                double     y_origin;
 
                int idle_handler_id;
@@ -1124,6 +1147,9 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        };
 
        VisualChange pending_visual_change;
+       bool visual_change_queued;
+
+       void pre_render ();
 
        static int _idle_visual_changer (void *arg);
        int idle_visual_changer ();
@@ -1133,20 +1159,28 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        /* track views */
        TrackViewList track_views;
        std::pair<TimeAxisView*, double> trackview_by_y_position (double, bool trackview_relative_offset = true) const;
-       TimeAxisView* axis_view_from_stripable (boost::shared_ptr<ARDOUR::Stripable>) const;
+
+       AxisView* axis_view_by_stripable (boost::shared_ptr<ARDOUR::Stripable>) const;
+       AxisView* axis_view_by_control (boost::shared_ptr<ARDOUR::AutomationControl>) const;
+
+       TimeAxisView* time_axis_view_from_stripable (boost::shared_ptr<ARDOUR::Stripable> s) const {
+               return dynamic_cast<TimeAxisView*> (axis_view_by_stripable (s));
+       }
 
        TrackViewList get_tracks_for_range_action () const;
 
        sigc::connection super_rapid_screen_update_connection;
-       framepos_t last_update_frame;
-       void center_screen_internal (framepos_t, float);
+       void center_screen_internal (samplepos_t, float);
 
        void super_rapid_screen_update ();
 
+       int64_t _last_update_time;
+       double _err_screen_engine;
+
        void session_going_away ();
 
-       framepos_t cut_buffer_start;
-       framecnt_t cut_buffer_length;
+       samplepos_t cut_buffer_start;
+       samplecnt_t cut_buffer_length;
 
        boost::shared_ptr<CursorContext> _press_cursor_ctx;  ///< Button press cursor context
 
@@ -1179,18 +1213,18 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        /* CUT/COPY/PASTE */
 
-       framepos_t last_paste_pos;
+       samplepos_t last_paste_pos;
        unsigned   paste_count;
 
        void cut_copy (Editing::CutCopyOp);
        bool can_cut_copy () const;
-       void cut_copy_points (Editing::CutCopyOp, Evoral::Beats earliest=Evoral::Beats(), bool midi=false);
+       void cut_copy_points (Editing::CutCopyOp, Temporal::Beats earliest=Temporal::Beats(), bool midi=false);
        void cut_copy_regions (Editing::CutCopyOp, RegionSelection&);
        void cut_copy_ranges (Editing::CutCopyOp);
        void cut_copy_midi (Editing::CutCopyOp);
 
        void mouse_paste ();
-       void paste_internal (framepos_t position, float times, const int32_t& sub_num);
+       void paste_internal (samplepos_t position, float times, const int32_t sub_num);
 
        /* EDITING OPERATIONS */
 
@@ -1203,6 +1237,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void toggle_mute ();
        void toggle_region_lock_style ();
 
+       void play_solo_selection (bool restart);
+
        enum LayerOperation {
                Raise,
                RaiseToTop,
@@ -1218,14 +1254,14 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void lower_region_to_bottom ();
        void split_region_at_transients ();
        void crop_region_to_selection ();
-       void crop_region_to (framepos_t start, framepos_t end);
-       void set_sync_point (framepos_t, const RegionSelection&);
+       void crop_region_to (samplepos_t start, samplepos_t end);
+       void set_sync_point (samplepos_t, const RegionSelection&);
        void set_region_sync_position ();
        void remove_region_sync();
        void align_regions (ARDOUR::RegionPoint);
        void align_regions_relative (ARDOUR::RegionPoint point);
-       void align_region (boost::shared_ptr<ARDOUR::Region>, ARDOUR::RegionPoint point, framepos_t position);
-       void align_region_internal (boost::shared_ptr<ARDOUR::Region>, ARDOUR::RegionPoint point, framepos_t position);
+       void align_region (boost::shared_ptr<ARDOUR::Region>, ARDOUR::RegionPoint point, samplepos_t position);
+       void align_region_internal (boost::shared_ptr<ARDOUR::Region>, ARDOUR::RegionPoint point, samplepos_t position);
        void remove_selected_regions ();
        void remove_clicked_region ();
        void show_region_properties ();
@@ -1245,6 +1281,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void normalize_region ();
        void reset_region_scale_amplitude ();
        void adjust_region_gain (bool up);
+       void reset_region_gain ();
        void quantize_region ();
        void quantize_regions (const RegionSelection& rs);
        void legatize_region (bool shrink_only);
@@ -1257,10 +1294,10 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void fork_region ();
 
        void do_insert_time ();
-       void insert_time (framepos_t, framecnt_t, Editing::InsertTimeOption, bool, bool, bool, bool, bool, bool);
+       void insert_time (samplepos_t, samplecnt_t, Editing::InsertTimeOption, bool, bool, bool, bool, bool, bool);
 
        void do_remove_time ();
-       void remove_time (framepos_t pos, framecnt_t distance, Editing::InsertTimeOption opt, bool ignore_music_glue, bool markers_too,
+       void remove_time (samplepos_t pos, samplecnt_t distance, Editing::InsertTimeOption opt, bool ignore_music_glue, bool markers_too,
                        bool glued_markers_too, bool locked_markers_too, bool tempo_too);
 
        void tab_to_transient (bool forward);
@@ -1268,7 +1305,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void set_tempo_from_region ();
        void use_range_as_bar ();
 
-       void define_one_bar (framepos_t start, framepos_t end);
+       void define_one_bar (samplepos_t start, samplepos_t end);
 
        void audition_region_from_region_list ();
        void hide_region_from_region_list ();
@@ -1276,8 +1313,6 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        void naturalize_region ();
 
-       void reset_focus (Gtk::Widget*);
-
        void split_region ();
 
        void delete_ ();
@@ -1303,49 +1338,35 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void play_location (ARDOUR::Location&);
        void loop_location (ARDOUR::Location&);
 
-       void calc_extra_zoom_edges(framepos_t &start, framepos_t &end);
-       void temporal_zoom_selection (bool both_axes = false);
-       void temporal_zoom_region (bool both_axes);
+       void calc_extra_zoom_edges(samplepos_t &start, samplepos_t &end);
+       void temporal_zoom_selection (Editing::ZoomAxis);
        void temporal_zoom_session ();
-       void temporal_zoom (framecnt_t samples_per_pixel);
-       void temporal_zoom_by_frame (framepos_t start, framepos_t end);
-       void temporal_zoom_to_frame (bool coarser, framepos_t frame);
+       void temporal_zoom_extents ();
+       void temporal_zoom (samplecnt_t samples_per_pixel);
+       void temporal_zoom_by_sample (samplepos_t start, samplepos_t end);
+       void temporal_zoom_to_sample (bool coarser, samplepos_t sample);
 
        void insert_region_list_selection (float times);
 
-       /* PT import */
-       void external_pt_dialog ();
-       typedef struct ptflookup {
-               uint16_t index1;
-               uint16_t index2;
-               PBD::ID  id;
-
-               bool operator ==(const struct ptflookup& other) {
-                       return (this->index1 == other.index1);
-               }
-       } ptflookup_t;
-
        /* import & embed */
 
        void add_external_audio_action (Editing::ImportMode);
-       void external_audio_dialog ();
-       void session_import_dialog ();
 
        int  check_whether_and_how_to_import(std::string, bool all_or_nothing = true);
        bool check_multichannel_status (const std::vector<std::string>& paths);
 
        SoundFileOmega* sfbrowser;
 
-       void bring_in_external_audio (Editing::ImportMode mode,  framepos_t& pos);
+       void bring_in_external_audio (Editing::ImportMode mode,  samplepos_t& pos);
 
-       bool  idle_drop_paths  (std::vector<std::string> paths, framepos_t frame, double ypos, bool copy);
-       void  drop_paths_part_two  (const std::vector<std::string>& paths, framepos_t frame, double ypos, bool copy);
+       bool  idle_drop_paths  (std::vector<std::string> paths, samplepos_t sample, double ypos, bool copy);
+       void  drop_paths_part_two  (const std::vector<std::string>& paths, samplepos_t sample, double ypos, bool copy);
 
        int import_sndfiles (std::vector<std::string>              paths,
                             Editing::ImportDisposition            disposition,
                             Editing::ImportMode                   mode,
                             ARDOUR::SrcQuality                    quality,
-                            framepos_t&                           pos,
+                            samplepos_t&                           pos,
                             int                                   target_regions,
                             int                                   target_tracks,
                             boost::shared_ptr<ARDOUR::Track>&     track,
@@ -1357,7 +1378,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
                            bool&                                 check_sample_rate,
                            Editing::ImportDisposition            disposition,
                            Editing::ImportMode                   mode,
-                           framepos_t&                           pos,
+                           samplepos_t&                           pos,
                            int                                   target_regions,
                            int                                   target_tracks,
                            boost::shared_ptr<ARDOUR::Track>&     track,
@@ -1365,7 +1386,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        int add_sources (std::vector<std::string>              paths,
                         ARDOUR::SourceList&                   sources,
-                        framepos_t&                           pos,
+                        samplepos_t&                           pos,
                         Editing::ImportDisposition            disposition,
                         Editing::ImportMode                   mode,
                         int                                   target_regions,
@@ -1377,7 +1398,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        int finish_bringing_in_material (boost::shared_ptr<ARDOUR::Region>     region,
                                         uint32_t                              in_chans,
                                         uint32_t                              out_chans,
-                                        framepos_t&                           pos,
+                                        samplepos_t&                           pos,
                                         Editing::ImportMode                   mode,
                                         boost::shared_ptr<ARDOUR::Track>&     existing_track,
                                         const std::string&                    new_track_name,
@@ -1392,11 +1413,22 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        AnalysisWindow* analysis_window;
 
+       /* import & embed */
+       void external_audio_dialog ();
+       void session_import_dialog ();
+
+       /* PT import specific */
+       void external_pt_dialog ();
+       ARDOUR::ImportStatus import_pt_status;
+       static void *_import_pt_thread (void *);
+       void* import_pt_thread ();
+       PTFFormat import_ptf;
+
        /* import specific info */
 
        struct EditorImportStatus : public ARDOUR::ImportStatus {
            Editing::ImportMode mode;
-           framepos_t pos;
+           samplepos_t pos;
            int target_tracks;
            int target_regions;
            boost::shared_ptr<ARDOUR::Track> track;
@@ -1412,7 +1444,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        void import_audio (bool as_tracks);
        void do_import (std::vector<std::string> paths, bool split, bool as_tracks);
-
+       void import_smf_tempo_map (Evoral::SMF const &, samplepos_t pos);
        void move_to_start ();
        void move_to_end ();
        void center_playhead ();
@@ -1430,8 +1462,6 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void clear_locations ();
        void unhide_markers ();
        void unhide_ranges ();
-       void jump_forward_to_mark ();
-       void jump_backward_to_mark ();
        void cursor_align (bool playhead_to_edit);
        void toggle_skip_playback ();
 
@@ -1444,13 +1474,14 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void set_selection_from_loop ();
        void set_selection_from_region ();
 
-       void add_location_mark (framepos_t where);
+       void add_location_mark (samplepos_t where);
        void add_location_from_region ();
        void add_locations_from_region ();
        void add_location_from_selection ();
        void set_loop_from_selection (bool play);
        void set_punch_from_selection ();
        void set_punch_from_region ();
+       void set_auto_punch_range();
 
        void set_session_start_from_playhead ();
        void set_session_end_from_playhead ();
@@ -1458,10 +1489,12 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        void set_loop_from_region (bool play);
 
-       void set_loop_range (framepos_t start, framepos_t end, std::string cmd);
-       void set_punch_range (framepos_t start, framepos_t end, std::string cmd);
+       void set_loop_range (samplepos_t start, samplepos_t end, std::string cmd);
+       void set_punch_range (samplepos_t start, samplepos_t end, std::string cmd);
 
+       void toggle_location_at_playhead_cursor ();
        void add_location_from_playhead_cursor ();
+       bool do_remove_location_at_playhead_cursor ();
        void remove_location_at_playhead_cursor ();
        bool select_new_marker;
 
@@ -1472,26 +1505,23 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        int scrubbing_direction;
        int scrub_reversals;
        int scrub_reverse_distance;
-       void scrub (framepos_t, double);
+       void scrub (samplepos_t, double);
 
        void set_punch_start_from_edit_point ();
        void set_punch_end_from_edit_point ();
        void set_loop_start_from_edit_point ();
        void set_loop_end_from_edit_point ();
 
-       void keyboard_selection_begin ( Editing::EditIgnoreOption = Editing::EDIT_IGNORE_NONE );
+       void keyboard_selection_begin (Editing::EditIgnoreOption = Editing::EDIT_IGNORE_NONE);
        void keyboard_selection_finish (bool add, Editing::EditIgnoreOption = Editing::EDIT_IGNORE_NONE);
        bool have_pending_keyboard_selection;
-       framepos_t pending_keyboard_selection_start;
+       samplepos_t pending_keyboard_selection_start;
 
        void move_range_selection_start_or_end_to_region_boundary (bool, bool);
 
-       Editing::SnapType _snap_type;
+       Editing::GridType _grid_type;
        Editing::SnapMode _snap_mode;
 
-       /// Snap threshold in pixels
-       double snap_threshold;
-
        bool ignore_gui_changes;
 
        DragManager* _drags;
@@ -1544,7 +1574,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        bool can_remove_control_point (ArdourCanvas::Item *);
        void remove_control_point (ArdourCanvas::Item *);
 
-       void mouse_brush_insert_region (RegionView*, framepos_t pos);
+       void mouse_brush_insert_region (RegionView*, samplepos_t pos);
 
        /* Canvas event handlers */
 
@@ -1562,7 +1592,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        bool canvas_fade_out_handle_event (GdkEvent* event,ArdourCanvas::Item*, AudioRegionView*, bool trim = false);
        bool canvas_region_view_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
        bool canvas_wave_view_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
-       bool canvas_frame_handle_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
+       bool canvas_sample_handle_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
        bool canvas_region_view_name_highlight_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
        bool canvas_region_view_name_event (GdkEvent* event,ArdourCanvas::Item*, RegionView*);
        bool canvas_feature_line_event (GdkEvent* event, ArdourCanvas::Item*, RegionView*);
@@ -1589,12 +1619,16 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void toggle_video_timeline_locked ();
        void set_video_timeline_locked (const bool);
        void queue_visual_videotimeline_update ();
-       void embed_audio_from_video (std::string, framepos_t n = 0, bool lock_position_to_video = true);
+       void embed_audio_from_video (std::string, samplepos_t n = 0, bool lock_position_to_video = true);
+
+       bool track_selection_change_without_scroll () const {
+               return _track_selection_change_without_scroll;
+       }
 
        PBD::Signal0<void> EditorFreeze;
        PBD::Signal0<void> EditorThaw;
 
-  private:
+private:
        friend class DragManager;
        friend class EditorRouteGroups;
        friend class EditorRegions;
@@ -1621,11 +1655,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        void initialize_canvas ();
 
-       void set_script_action_name (int i, const std::string&);
-
        /* display control */
 
-       bool _show_measures;
        /// true if the editor should follow the playhead, otherwise false
        bool _follow_playhead;
        /// true if we scroll the tracks rather than the playhead
@@ -1633,17 +1664,17 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        /// true if we are in fullscreen mode
        bool _maximised;
 
-       TempoLines* tempo_lines;
+       std::vector<ArdourCanvas::Ruler::Mark> grid_marks;
+       GridLines* grid_lines;
 
        ArdourCanvas::Container* global_rect_group;
        ArdourCanvas::Container* time_line_group;
 
-       void hide_measures ();
-       void draw_measures (std::vector<ARDOUR::TempoMap::BBTPoint>&);
+       void hide_grid_lines ();
+       void maybe_draw_grid_lines ();
 
        void new_tempo_section ();
 
-
        void remove_tempo_marker (ArdourCanvas::Item*);
        void remove_meter_marker (ArdourCanvas::Item*);
        gint real_remove_tempo_marker (ARDOUR::TempoSection*);
@@ -1653,16 +1684,23 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void edit_meter_marker (MeterMarker&);
        void edit_control_point (ArdourCanvas::Item*);
        void edit_notes (MidiRegionView*);
+       void edit_region (RegionView*);
+
+       void edit_current_meter ();
+       void edit_current_tempo ();
 
        void marker_menu_edit ();
        void marker_menu_remove ();
        void marker_menu_rename ();
        void rename_marker (ArdourMarker *marker);
        void toggle_marker_lock_style ();
+       void toggle_tempo_clamped ();
        void toggle_tempo_type ();
+       void ramp_to_next_tempo ();
        void toggle_marker_menu_lock ();
        void toggle_marker_menu_glue ();
        void marker_menu_hide ();
+       void marker_menu_set_origin ();
        void marker_menu_loop_range ();
        void marker_menu_select_all_selectables_using_range ();
        void marker_menu_select_using_range ();
@@ -1682,7 +1720,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
        void tempo_or_meter_marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
        void new_transport_marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
-       void build_range_marker_menu (bool, bool);
+       void build_range_marker_menu (ARDOUR::Location *, bool, bool);
        void build_marker_menu (ARDOUR::Location *);
        void build_tempo_marker_menu (TempoMarker *, bool);
        void build_meter_marker_menu (MeterMarker *, bool);
@@ -1707,11 +1745,12 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void remove_metric_marks ();
        void draw_metric_marks (const ARDOUR::Metrics& metrics);
 
-       void compute_current_bbt_points (std::vector<ARDOUR::TempoMap::BBTPoint>& grid, framepos_t left, framepos_t right);
+       void compute_current_bbt_points (std::vector<ARDOUR::TempoMap::BBTPoint>& grid, samplepos_t left, samplepos_t right);
 
        void tempo_map_changed (const PBD::PropertyChange&);
-       void marker_position_changed ();
-       void redisplay_tempo (bool immediate_redraw);
+       void tempometric_position_changed (const PBD::PropertyChange&);
+
+       void redisplay_grid (bool immediate_redraw);
 
        uint32_t bbt_beat_subdivision;
 
@@ -1722,14 +1761,14 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void editor_mixer_button_toggled ();
        void editor_list_button_toggled ();
 
-       ArdourButton              zoom_in_button;
-       ArdourButton              zoom_out_button;
-       ArdourButton              zoom_out_full_button;
+       ArdourWidgets::ArdourButton   zoom_in_button;
+       ArdourWidgets::ArdourButton   zoom_out_button;
+       ArdourWidgets::ArdourButton   zoom_out_full_button;
 
-       ArdourButton              tav_expand_button;
-       ArdourButton              tav_shrink_button;
-       ArdourDropdown            visible_tracks_selector;
-       ArdourDropdown            zoom_preset_selector;
+       ArdourWidgets::ArdourButton   tav_expand_button;
+       ArdourWidgets::ArdourButton   tav_shrink_button;
+       ArdourWidgets::ArdourDropdown visible_tracks_selector;
+       ArdourWidgets::ArdourDropdown zoom_preset_selector;
 
        int32_t                   _visible_track_count;
        void build_track_count_menu ();
@@ -1742,15 +1781,15 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        Gtk::Table               toolbar_selection_clock_table;
        Gtk::Label               toolbar_selection_cursor_label;
 
-       ArdourButton mouse_select_button;
-       ArdourButton mouse_draw_button;
-       ArdourButton mouse_move_button;
-       ArdourButton mouse_timefx_button;
-       ArdourButton mouse_content_button;
-       ArdourButton mouse_audition_button;
-       ArdourButton mouse_cut_button;
+       ArdourWidgets::ArdourButton mouse_select_button;
+       ArdourWidgets::ArdourButton mouse_draw_button;
+       ArdourWidgets::ArdourButton mouse_move_button;
+       ArdourWidgets::ArdourButton mouse_timefx_button;
+       ArdourWidgets::ArdourButton mouse_content_button;
+       ArdourWidgets::ArdourButton mouse_audition_button;
+       ArdourWidgets::ArdourButton mouse_cut_button;
 
-       ArdourButton smart_mode_button;
+       ArdourWidgets::ArdourButton smart_mode_button;
        Glib::RefPtr<Gtk::ToggleAction> smart_mode_action;
 
        void                     mouse_mode_toggled (Editing::MouseMode m);
@@ -1759,39 +1798,47 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        bool                     mouse_select_button_release (GdkEventButton*);
 
+       Glib::RefPtr<Gtk::Action> get_mouse_mode_action (Editing::MouseMode m) const;
+
        Gtk::VBox                automation_box;
        Gtk::Button              automation_mode_button;
 
        //edit mode menu stuff
-       ArdourDropdown  edit_mode_selector;
-       void edit_mode_selection_done ( ARDOUR::EditMode m );
+       ArdourWidgets::ArdourDropdown   edit_mode_selector;
+       void edit_mode_selection_done (ARDOUR::EditMode);
        void build_edit_mode_menu ();
-       Gtk::VBox         edit_mode_box;
+       Gtk::VBox edit_mode_box;
 
        void set_edit_mode (ARDOUR::EditMode);
        void cycle_edit_mode ();
 
-       ArdourDropdown snap_type_selector;
-       void build_snap_type_menu ();
+       ArdourWidgets::ArdourDropdown grid_type_selector;
+       void build_grid_type_menu ();
+
+       ArdourWidgets::ArdourButton snap_mode_button;
+       bool snap_mode_button_clicked (GdkEventButton *);
+
+       Gtk::HBox snap_box;
+
+       Gtk::HBox ebox_hpacker;
+       Gtk::VBox ebox_vpacker;
 
-       ArdourDropdown snap_mode_selector;
-       void build_snap_mode_menu ();
-       Gtk::HBox         snap_box;
+       Gtk::HBox _box;
 
-       std::vector<std::string> snap_type_strings;
+       std::vector<std::string> grid_type_strings;
        std::vector<std::string> snap_mode_strings;
 
-       void snap_type_selection_done (Editing::SnapType);
+       void grid_type_selection_done (Editing::GridType);
        void snap_mode_selection_done (Editing::SnapMode);
        void snap_mode_chosen (Editing::SnapMode);
-       void snap_type_chosen (Editing::SnapType);
+       void grid_type_chosen (Editing::GridType);
 
-       Glib::RefPtr<Gtk::RadioAction> snap_type_action (Editing::SnapType);
+       Glib::RefPtr<Gtk::RadioAction> grid_type_action (Editing::GridType);
        Glib::RefPtr<Gtk::RadioAction> snap_mode_action (Editing::SnapMode);
 
        //zoom focus meu stuff
-       ArdourDropdown  zoom_focus_selector;
-       void zoom_focus_selection_done ( Editing::ZoomFocus f );
+       ArdourWidgets::ArdourDropdown   zoom_focus_selector;
+       void zoom_focus_selection_done (Editing::ZoomFocus);
        void build_zoom_focus_menu ();
        std::vector<std::string> zoom_focus_strings;
 
@@ -1799,17 +1846,16 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        Glib::RefPtr<Gtk::RadioAction> zoom_focus_action (Editing::ZoomFocus);
 
-       Gtk::HBox           _zoom_box;
-       void                zoom_adjustment_changed();
+       Gtk::HBox _track_box;
+
+       Gtk::HBox _zoom_box;
+       void zoom_adjustment_changed();
 
        void setup_toolbar ();
 
        void setup_tooltips ();
 
-       Gtk::HBox                toolbar_hbox;
-       Gtk::EventBox            toolbar_base;
-       Gtk::Frame               toolbar_frame;
-       Gtk::Viewport           _toolbar_viewport;
+       Gtk::HBox toolbar_hbox;
 
        void setup_midi_toolbar ();
 
@@ -1820,12 +1866,13 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        SelectionMemento* _selection_memento;
 
        void time_selection_changed ();
-       void update_time_selection_display ();
        void track_selection_changed ();
+       void update_time_selection_display ();
+       void presentation_info_changed (PBD::PropertyChange const &);
        void region_selection_changed ();
        sigc::connection editor_regions_selection_changed_connection;
        void sensitize_all_region_actions (bool);
-       void sensitize_the_right_region_actions ();
+       void sensitize_the_right_region_actions (bool because_canvas_crossing);
        bool _all_region_actions_sensitized;
        /** Flag to block region action handlers from doing what they normally do;
         *  I tried Gtk::Action::block_activate() but this doesn't work (ie it doesn't
@@ -1836,46 +1883,47 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void point_selection_changed ();
        void marker_selection_changed ();
 
-       bool _ignore_follow_edits;
+       bool _track_selection_change_without_scroll;
+       bool _editor_track_selection_change_without_scroll;
 
        void cancel_selection ();
        void cancel_time_selection ();
 
        bool get_smart_mode() const;
 
-       bool audio_region_selection_covers (framepos_t where);
+       bool audio_region_selection_covers (samplepos_t where);
 
        /* transport range select process */
 
-       ArdourCanvas::Rectangle*  cd_marker_bar_drag_rect;
-       ArdourCanvas::Rectangle*  range_bar_drag_rect;
-       ArdourCanvas::Rectangle*  transport_bar_drag_rect;
-       ArdourCanvas::Rectangle     *transport_bar_range_rect;
-       ArdourCanvas::Rectangle     *transport_bar_preroll_rect;
-       ArdourCanvas::Rectangle     *transport_bar_postroll_rect;
-       ArdourCanvas::Rectangle     *transport_loop_range_rect;
-       ArdourCanvas::Rectangle     *transport_punch_range_rect;
-       ArdourCanvas::Line     *transport_punchin_line;
-       ArdourCanvas::Line     *transport_punchout_line;
-       ArdourCanvas::Rectangle     *transport_preroll_rect;
-       ArdourCanvas::Rectangle     *transport_postroll_rect;
+       ArdourCanvas::Rectangle* cd_marker_bar_drag_rect;
+       ArdourCanvas::Rectangle* range_bar_drag_rect;
+       ArdourCanvas::Rectangle* transport_bar_drag_rect;
+       ArdourCanvas::Rectangletransport_bar_range_rect;
+       ArdourCanvas::Rectangletransport_bar_preroll_rect;
+       ArdourCanvas::Rectangletransport_bar_postroll_rect;
+       ArdourCanvas::Rectangletransport_loop_range_rect;
+       ArdourCanvas::Rectangletransport_punch_range_rect;
+       ArdourCanvas::Line*      transport_punchin_line;
+       ArdourCanvas::Line*      transport_punchout_line;
+       ArdourCanvas::Rectangletransport_preroll_rect;
+       ArdourCanvas::Rectangletransport_postroll_rect;
 
-       ARDOUR::Location*  transport_loop_location();
-       ARDOUR::Location*  transport_punch_location();
+       ARDOUR::Location* transport_loop_location();
+       ARDOUR::Location* transport_punch_location();
 
-       ARDOUR::Location   *temp_location;
+       ARDOUR::Locationtemp_location;
 
        /* object rubberband select process */
 
-       void select_all_within (framepos_t, framepos_t, double, double, TrackViewList const &, Selection::Operation, bool);
+       void select_all_within (samplepos_t, samplepos_t, double, double, TrackViewList const &, Selection::Operation, bool);
 
-       ArdourCanvas::Rectangle   *rubberband_rect;
+       ArdourCanvas::Rectanglerubberband_rect;
 
        EditorRouteGroups* _route_groups;
-       EditorRoutes* _routes;
-       EditorRegions* _regions;
-       EditorSnapshots* _snapshots;
-       EditorLocations* _locations;
+       EditorRoutes*      _routes;
+       EditorRegions*     _regions;
+       EditorSnapshots*   _snapshots;
+       EditorLocations*   _locations;
 
        /* diskstream/route display management */
        Glib::RefPtr<Gdk::Pixbuf> rec_enabled_icon;
@@ -1885,7 +1933,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        bool sync_track_view_list_and_routes ();
 
-       Gtk::VBox           list_vpacker;
+       Gtk::VBox list_vpacker;
 
        /* autoscrolling */
 
@@ -1901,7 +1949,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void stop_canvas_autoscroll ();
 
        /* trimming */
-       void point_trim (GdkEvent *, framepos_t);
+       void point_trim (GdkEvent *, samplepos_t);
 
        void trim_region_front();
        void trim_region_back();
@@ -1999,20 +2047,21 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        /* duplication */
 
        void duplicate_range (bool with_dialog);
+       void duplicate_regions (float times);
 
-       /** computes the timeline frame (sample) of an event whose coordinates
+       /** computes the timeline sample (sample) of an event whose coordinates
         * are in canvas units (pixels, scroll offset included).
         */
-       framepos_t canvas_event_sample (GdkEvent const *, double* px = 0, double* py = 0) const;
+       samplepos_t canvas_event_sample (GdkEvent const *, double* px = 0, double* py = 0) const;
 
-       /** computes the timeline frame (sample) of an event whose coordinates
+       /** computes the timeline sample (sample) of an event whose coordinates
         * are in window units (pixels, no scroll offset).
         */
-       framepos_t window_event_sample (GdkEvent const *, double* px = 0, double* py = 0) const;
+       samplepos_t window_event_sample (GdkEvent const *, double* px = 0, double* py = 0) const;
 
        /* returns false if mouse pointer is not in track or marker canvas
         */
-       bool mouse_frame (framepos_t&, bool& in_track_canvas) const;
+       bool mouse_sample (samplepos_t&, bool& in_track_canvas) const;
 
        TimeFXDialog* current_timefx;
        static void* timefx_thread (void *arg);
@@ -2042,8 +2091,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        /* nudge */
 
-       ArdourButton      nudge_forward_button;
-       ArdourButton      nudge_backward_button;
+       ArdourWidgets::ArdourButton      nudge_forward_button;
+       ArdourWidgets::ArdourButton      nudge_backward_button;
        Gtk::HBox        nudge_hbox;
        Gtk::VBox        nudge_vbox;
        AudioClock*       nudge_clock;
@@ -2105,7 +2154,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        Editing::EditPoint _edit_point;
 
-       ArdourDropdown edit_point_selector;
+       ArdourWidgets::ArdourDropdown edit_point_selector;
        void build_edit_point_menu();
 
        void set_edit_point_preference (Editing::EditPoint ep, bool force = false);
@@ -2119,29 +2168,50 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        void selected_marker_moved (ARDOUR::Location*);
 
-       bool get_edit_op_range (framepos_t& start, framepos_t& end) const;
+       bool get_edit_op_range (samplepos_t& start, samplepos_t& end) const;
 
-       void get_regions_at (RegionSelection&, framepos_t where, const TrackViewList& ts) const;
-       void get_regions_after (RegionSelection&, framepos_t where, const TrackViewList& ts) const;
+       void get_regions_at (RegionSelection&, samplepos_t where, const TrackViewList& ts) const;
+       void get_regions_after (RegionSelection&, samplepos_t where, const TrackViewList& ts) const;
 
-       RegionSelection get_regions_from_selection_and_edit_point ();
+       RegionSelection get_regions_from_selection_and_edit_point (Editing::EditIgnoreOption = Editing::EDIT_IGNORE_NONE,
+                                                                  bool use_context_click = false,
+                                                                  bool from_outside_canvas = false);
        RegionSelection get_regions_from_selection_and_entered () const;
 
        void start_updating_meters ();
        void stop_updating_meters ();
        bool meters_running;
 
-       void select_next_route ();
-       void select_prev_route ();
+       void select_next_stripable (bool routes_only = true);
+       void select_prev_stripable (bool routes_only = true);
 
-       void snap_to_internal (framepos_t&       first,
-                              ARDOUR::RoundMode direction = ARDOUR::RoundNearest,
-                              bool              for_mark  = false,
-                              bool              ensure_snap = false);
+       ARDOUR::MusicSample snap_to_minsec (ARDOUR::MusicSample start,
+                                           ARDOUR::RoundMode   direction,
+                                           ARDOUR::SnapPref    gpref);
 
-       void timecode_snap_to_internal (framepos_t&       first,
-                                       ARDOUR::RoundMode direction = ARDOUR::RoundNearest,
-                                       bool              for_mark  = false);
+       ARDOUR::MusicSample snap_to_cd_frames (ARDOUR::MusicSample start,
+                                              ARDOUR::RoundMode   direction,
+                                              ARDOUR::SnapPref    gpref);
+
+       ARDOUR::MusicSample snap_to_bbt (ARDOUR::MusicSample start,
+                                        ARDOUR::RoundMode   direction,
+                                        ARDOUR::SnapPref    gpref);
+
+       ARDOUR::MusicSample snap_to_timecode (ARDOUR::MusicSample start,
+                                             ARDOUR::RoundMode   direction,
+                                             ARDOUR::SnapPref    gpref);
+
+       ARDOUR::MusicSample snap_to_grid (ARDOUR::MusicSample start,
+                                         ARDOUR::RoundMode   direction,
+                                         ARDOUR::SnapPref    gpref);
+
+       void snap_to_internal (ARDOUR::MusicSample& first,
+                              ARDOUR::RoundMode   direction = ARDOUR::RoundNearest,
+                              ARDOUR::SnapPref    gpref = ARDOUR::SnapToAny_Visual,
+                              bool                ensure_snap = false);
+
+       samplepos_t snap_to_marker (samplepos_t        presnap,
+                                   ARDOUR::RoundMode   direction = ARDOUR::RoundNearest);
 
        RhythmFerret* rhythm_ferret;
 
@@ -2204,8 +2274,6 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        bool _region_selection_change_updates_region_list;
 
        void setup_fade_images ();
-       std::map<ARDOUR::FadeShape, Gtk::Image*> _fade_in_images;
-       std::map<ARDOUR::FadeShape, Gtk::Image*> _fade_out_images;
        std::map<ARDOUR::FadeShape, Gtk::Image*> _xfade_in_images;
        std::map<ARDOUR::FadeShape, Gtk::Image*> _xfade_out_images;
 
@@ -2243,15 +2311,17 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        QuantizeDialog* quantize_dialog;
        MainMenuDisabler* _main_menu_disabler;
 
-       /* private helper functions to help with registering axis */
+       /* private helper functions to help with registering region actions */
+
+       Glib::RefPtr<Gtk::Action> register_region_action (Glib::RefPtr<Gtk::ActionGroup> group, Editing::RegionActionTarget, char const * name, char const * label, sigc::slot<void> slot);
+       void register_toggle_region_action (Glib::RefPtr<Gtk::ActionGroup> group, Editing::RegionActionTarget, char const * name, char const * label, sigc::slot<void> slot);
 
        Glib::RefPtr<Gtk::Action> reg_sens (Glib::RefPtr<Gtk::ActionGroup> group, char const * name, char const * label, sigc::slot<void> slot);
        void toggle_reg_sens (Glib::RefPtr<Gtk::ActionGroup> group, char const * name, char const * label, sigc::slot<void> slot);
        void radio_reg_sens (Glib::RefPtr<Gtk::ActionGroup> action_group, Gtk::RadioAction::Group& radio_group, char const * name, char const * label, sigc::slot<void> slot);
 
-       Gtkmm2ext::ActionMap myactions;
-
        friend class Drag;
+       friend class RegionCutDrag;
        friend class RegionDrag;
        friend class RegionMoveDrag;
        friend class RegionSpliceDrag;