Remove use of invalidated iterator (#4826).
[ardour.git] / gtk2_ardour / editor.h
index 83d8b394c30364f06cd5f5e6f78bcb53345e973a..d5b2cb9172454483479fa48683378e72d2c35235 100644 (file)
@@ -42,6 +42,7 @@
 #include "gtkmm2ext/click_box.h"
 #include "gtkmm2ext/dndtreeview.h"
 #include "gtkmm2ext/stateful_button.h"
+#include "gtkmm2ext/bindings.h"
 
 #include "pbd/stateful.h"
 #include "pbd/signals.h"
 #include "ardour/import_status.h"
 #include "ardour/tempo.h"
 #include "ardour/location.h"
-#include "ardour/audioregion.h"
-#include "ardour/track.h"
 #include "ardour/types.h"
-#include "ardour/route_group.h"
 
-#include "audio_clock.h"
 #include "gtk-custom-ruler.h"
+#include "ardour_button.h"
 #include "ardour_dialog.h"
 #include "public_editor.h"
 #include "editing.h"
@@ -71,13 +69,14 @@ namespace Gnome { namespace Canvas {
 
 namespace Gtkmm2ext {
        class TearOff;
-        class Bindings;
+       class Bindings;
 }
 
 namespace ARDOUR {
        class RouteGroup;
        class Playlist;
        class AudioPlaylist;
+       class AudioRegion;
        class Region;
        class Location;
        class TempoSection;
@@ -87,6 +86,7 @@ namespace ARDOUR {
        class Crossfade;
        class ChanCount;
        class MidiOperator;
+       class Track;
        class MidiTrack;
        class AudioTrack;
 }
@@ -96,6 +96,7 @@ namespace LADSPA {
 }
 
 class AnalysisWindow;
+class AudioClock;
 class AudioRegionView;
 class AudioStreamView;
 class AudioTimeAxisView;
@@ -103,10 +104,12 @@ class AutomationLine;
 class AutomationSelection;
 class AutomationTimeAxisView;
 class BundleManager;
+class ButtonJoiner;
 class ControlPoint;
 class CrossfadeView;
 class DragManager;
 class GroupedButtons;
+class GUIObjectState;
 class Marker;
 class MidiRegionView;
 class MixerStrip;
@@ -166,7 +169,12 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        }
 
        void cycle_snap_mode ();
-       void cycle_snap_choice ();
+       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 set_snap_mode (Editing::SnapMode);
        void set_snap_threshold (double pixel_distance) {snap_threshold = pixel_distance;}
@@ -188,6 +196,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        bool internal_editing() const { return _internal_editing ; }
        void set_internal_edit (bool yn);
+       bool toggle_internal_editing_from_double_click (GdkEvent*);
 
 #ifdef WITH_CMT
        void add_imageframe_time_axis(const std::string & track_name, void*) ;
@@ -200,7 +209,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 (PBD::ID& id) const;
+       RouteTimeAxisView* get_route_view_by_route_id (const PBD::ID& id) const;
 
        void consider_auditioning (boost::shared_ptr<ARDOUR::Region>);
        void hide_a_region (boost::shared_ptr<ARDOUR::Region>);
@@ -268,6 +277,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        Selection& get_selection() const { return *selection; }
        Selection& get_cut_buffer() const { return *cut_buffer; }
+       void track_mixer_selection ();
 
        bool extend_selection_to_track (TimeAxisView&);
 
@@ -277,6 +287,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void invert_selection_in_track ();
        void invert_selection ();
        void deselect_all ();
+       long select_range (framepos_t, framepos_t);
 
        void set_selected_regionview_from_region_list (boost::shared_ptr<ARDOUR::Region> region, Selection::Operation op = Selection::Set);
 
@@ -343,10 +354,10 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        /* playhead/screen stuff */
 
-        void set_stationary_playhead (bool yn);
-        void toggle_stationary_playhead ();
-        bool stationary_playhead() const { return _stationary_playhead; }
-        
+       void set_stationary_playhead (bool yn);
+       void toggle_stationary_playhead ();
+       bool stationary_playhead() const { return _stationary_playhead; }
+
        void set_follow_playhead (bool yn, bool catch_up = true);
        void toggle_follow_playhead ();
        bool follow_playhead() const { return _follow_playhead; }
@@ -375,6 +386,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        void show_window ();
 
+       void ensure_time_axis_view_is_visible (const TimeAxisView& tav);
        void scroll_tracks_down_line ();
        void scroll_tracks_up_line ();
 
@@ -390,7 +402,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void reset_zoom (double);
        void reposition_and_zoom (framepos_t, double);
 
-       framepos_t get_preferred_edit_position (bool ignore_playhead = false);
+       framepos_t get_preferred_edit_position (bool ignore_playhead = false, bool use_context_click = false);
 
        bool update_mouse_speed ();
        bool decelerate_mouse_speed ();
@@ -435,12 +447,12 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
                return _drags;
        }
 
-       void maybe_autoscroll (bool, bool);
-       
-        Gdk::Cursor* get_canvas_cursor () const { return current_canvas_cursor; }
-        void set_canvas_cursor (Gdk::Cursor*, bool save=false);
-        void set_current_trimmable (boost::shared_ptr<ARDOUR::Trimmable>);
-        void set_current_movable (boost::shared_ptr<ARDOUR::Movable>);
+       void maybe_autoscroll (bool, bool, bool, bool);
+
+       Gdk::Cursor* get_canvas_cursor () const { return current_canvas_cursor; }
+       void set_canvas_cursor (Gdk::Cursor*, bool save=false);
+       void set_current_trimmable (boost::shared_ptr<ARDOUR::Trimmable>);
+       void set_current_movable (boost::shared_ptr<ARDOUR::Movable>);
 
        MouseCursors const * cursors () const {
                return _cursors;
@@ -472,11 +484,13 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        typedef std::pair<TimeAxisView*,XMLNode*> TAVState;
 
        struct VisualState {
+           VisualState (bool with_tracks);
+           ~VisualState ();
            double              y_position;
            double              frames_per_unit;
-           framepos_t         leftmost_frame;
+           framepos_t          leftmost_frame;
            Editing::ZoomFocus  zoom_focus;
-           std::list<TAVState> track_states;
+           GUIObjectState*     gui_state;
        };
 
        std::list<VisualState*> undo_visual_stack;
@@ -489,10 +503,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void swap_visual_state ();
 
        std::vector<VisualState*> visual_states;
-       sigc::connection visual_state_op_connection;
        void start_visual_state_op (uint32_t n);
        void cancel_visual_state_op (uint32_t n);
-       bool end_visual_state_op (uint32_t n);
 
        framepos_t leftmost_frame;
        double      frames_per_unit;
@@ -503,6 +515,10 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        Editing::MouseMode mouse_mode;
        Editing::MouseMode pre_internal_mouse_mode;
+       Editing::SnapType  pre_internal_snap_type;
+       Editing::SnapMode  pre_internal_snap_mode;
+       Editing::SnapType  internal_snap_type;
+       Editing::SnapMode  internal_snap_mode;
        bool _internal_editing;
        Editing::MouseMode effective_mouse_mode () const;
 
@@ -518,21 +534,15 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        void update_join_object_range_location (double, double);
 
-       int  post_maximal_editor_width;
-       int  post_maximal_editor_height;
-       int  post_maximal_horizontal_pane_position;
-       int  post_maximal_vertical_pane_position;
-       int  pre_maximal_horizontal_pane_position;
-       int  pre_maximal_vertical_pane_position;
-       int  pre_maximal_editor_width;
-       int  pre_maximal_editor_height;
+       boost::optional<int>  pre_notebook_shrink_pane_width;
+
        void pane_allocation_handler (Gtk::Allocation&, Gtk::Paned*);
 
        Gtk::Notebook _the_notebook;
        bool _notebook_shrunk;
        void add_notebook_page (std::string const &, Gtk::Widget &);
        bool notebook_tab_clicked (GdkEventButton *, Gtk::Widget *);
-       
+
        Gtk::HPaned   edit_pane;
        Gtk::VPaned   editor_summary_pane;
 
@@ -565,11 +575,11 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
                Marker* start;
                Marker* end;
                bool    valid;
-               
+
                LocationMarkers () : start(0), end(0), valid (true) {}
-               
+
                ~LocationMarkers ();
-               
+
                void hide ();
                void show ();
 
@@ -577,7 +587,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
                void set_selected (bool);
                void canvas_height_set (double);
                void setup_lines ();
-               
+
                void set_name (const std::string&);
                void set_position (framepos_t start, framepos_t end = 0);
                void set_color_rgba (uint32_t);
@@ -585,6 +595,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        LocationMarkers  *find_location_markers (ARDOUR::Location *) const;
        ARDOUR::Location* find_location_from_marker (Marker *, bool& is_start) const;
+       Marker* find_marker_from_location_id (PBD::ID const &, bool) const;
        Marker* entered_marker;
        bool _show_marker_lines;
 
@@ -623,21 +634,25 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        CrossfadeView*     clicked_crossfadeview;
        ControlPoint*      clicked_control_point;
 
-       void sort_track_selection (TrackViewList* sel = 0);
+       void sort_track_selection (TrackViewList&);
 
        void get_equivalent_regions (RegionView* rv, std::vector<RegionView*> &, PBD::PropertyID) const;
        RegionSelection get_equivalent_regions (RegionSelection &, PBD::PropertyID) const;
+       std::vector<boost::shared_ptr<ARDOUR::Crossfade> > get_equivalent_crossfades (
+               RouteTimeAxisView&, boost::shared_ptr<ARDOUR::Crossfade>, PBD::PropertyID
+               ) 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;
 
        /* functions to be passed to mapover_tracks(), possibly with sigc::bind()-supplied arguments */
-
        void mapped_get_equivalent_regions (RouteTimeAxisView&, uint32_t, RegionView *, std::vector<RegionView*>*) const;
        void mapped_use_new_playlist (RouteTimeAxisView&, uint32_t, std::vector<boost::shared_ptr<ARDOUR::Playlist> > const &);
        void mapped_use_copy_playlist (RouteTimeAxisView&, uint32_t, std::vector<boost::shared_ptr<ARDOUR::Playlist> > const &);
        void mapped_clear_playlist (RouteTimeAxisView&, uint32_t);
-
-       /* end */
-
+       void mapped_get_equivalent_crossfades (
+               RouteTimeAxisView&, uint32_t, boost::shared_ptr<ARDOUR::Crossfade>, std::vector<boost::shared_ptr<ARDOUR::Crossfade> >*
+               ) const;
+       
        void button_selection (ArdourCanvas::Item* item, GdkEvent* event, ItemType item_type);
        bool button_release_can_deselect;
 
@@ -645,19 +660,17 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        void set_selected_track (TimeAxisView&, Selection::Operation op = Selection::Set, bool no_remove=false);
        void select_all_tracks ();
-        void select_all_internal_edit (Selection::Operation);
+       void select_all_internal_edit (Selection::Operation);
 
        bool set_selected_control_point_from_click (Selection::Operation op = Selection::Set, bool no_remove=false);
        void set_selected_track_from_click (bool press, Selection::Operation op = Selection::Set, bool no_remove=false);
-       void set_selected_track_as_side_effect (Selection::Operation op, bool force = false);
-       bool set_selected_regionview_from_click (bool press, Selection::Operation op = Selection::Set, bool no_track_remove=false);
+       void set_selected_track_as_side_effect (Selection::Operation op);
+       bool set_selected_regionview_from_click (bool press, Selection::Operation op = Selection::Set);
 
        bool set_selected_regionview_from_map_event (GdkEventAny*, StreamView*, boost::weak_ptr<ARDOUR::Region>);
        void collect_new_region_view (RegionView *);
        void collect_and_select_new_region_view (RegionView *);
 
-       long select_range_around_region (RegionView *);
-
        Gtk::Menu track_context_menu;
        Gtk::Menu track_region_context_menu;
        Gtk::Menu track_selection_context_menu;
@@ -669,6 +682,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        Gtk::Menu * track_edit_playlist_submenu;
        Gtk::Menu * track_selection_edit_playlist_submenu;
 
+       GdkEvent context_click_event;
+
        void popup_track_context_menu (int, int, ItemType, bool);
        Gtk::Menu* build_track_context_menu ();
        Gtk::Menu* build_track_bus_context_menu ();
@@ -682,6 +697,9 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void add_selection_context_items (Gtk::Menu_Helpers::MenuList&);
        Gtk::MenuItem* _popup_region_menu_item;
 
+       void popup_control_point_context_menu (ArdourCanvas::Item *, GdkEvent *);
+       Gtk::Menu _control_point_context_menu;
+
        void handle_new_route (ARDOUR::RouteList&);
        void timeaxisview_deleted (TimeAxisView *);
 
@@ -694,6 +712,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void set_canvas_cursor ();
 
        ArdourCanvas::Canvas* track_canvas;
+       bool within_track_canvas;
 
        friend class VerboseCursor;
        VerboseCursor* _verbose_cursor;
@@ -843,7 +862,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        BBTRulerScale bbt_ruler_scale;
 
-        uint32_t bbt_bars;
+       uint32_t bbt_bars;
        gint bbt_nmarks;
        uint32_t bbt_bar_helper_on;
        uint32_t bbt_accent_modulo;
@@ -923,7 +942,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        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&);
+       ARDOUR::framepos_t find_next_region_boundary (ARDOUR::framepos_t, int32_t dir, const TrackViewList&);
 
        std::vector<ARDOUR::framepos_t> region_boundary_cache;
        void build_region_boundary_cache ();
@@ -934,11 +953,11 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        Gtk::Table          edit_packer;
 
        Gtk::Adjustment     vertical_adjustment;
-        
+
        Gtk::Layout         controls_layout;
        bool control_layout_scroll (GdkEventScroll* ev);
-        void reset_controls_layout_width ();
-        void reset_controls_layout_height (int32_t height);
+       void reset_controls_layout_width ();
+       void reset_controls_layout_height (int32_t height);
 
        enum Direction {
                LEFT,
@@ -946,7 +965,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
                UP,
                DOWN
        };
-               
+
        bool scroll_press (Direction);
        void scroll_release ();
        sigc::connection _scroll_connection;
@@ -969,6 +988,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        Gtk::HBox           edit_controls_hbox;
 
        void control_scroll (float);
+       void control_select (uint32_t rid);
        void access_action (std::string,std::string);
        bool deferred_control_scroll (framepos_t);
        sigc::connection control_scroll_connection;
@@ -1016,7 +1036,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        /* track views */
        TrackViewList track_views;
-       std::pair<TimeAxisView*, ARDOUR::layer_t> trackview_by_y_position (double);
+       std::pair<TimeAxisView*, double> trackview_by_y_position (double);
        TimeAxisView* axis_view_from_route (boost::shared_ptr<ARDOUR::Route>) const;
 
        TrackViewList get_tracks_for_range_action () const;
@@ -1032,29 +1052,35 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        framepos_t cut_buffer_start;
        framecnt_t cut_buffer_length;
 
-        Gdk::Cursor* pre_press_cursor;
-        boost::weak_ptr<ARDOUR::Trimmable> _trimmable;
-        boost::weak_ptr<ARDOUR::Movable> _movable;
+       Gdk::Cursor* pre_press_cursor;
+       boost::weak_ptr<ARDOUR::Trimmable> _trimmable;
+       boost::weak_ptr<ARDOUR::Movable> _movable;
 
        bool typed_event (ArdourCanvas::Item*, GdkEvent*, ItemType);
        bool button_press_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
        bool button_press_handler_1 (ArdourCanvas::Item *, GdkEvent *, ItemType);
        bool button_press_handler_2 (ArdourCanvas::Item *, GdkEvent *, ItemType);
        bool button_release_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
-        bool button_press_dispatch (GdkEventButton*);
-        bool button_release_dispatch (GdkEventButton*);
+       bool button_press_dispatch (GdkEventButton*);
+       bool button_release_dispatch (GdkEventButton*);
        bool motion_handler (ArdourCanvas::Item*, GdkEvent*, bool from_autoscroll = false);
        bool enter_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
        bool leave_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
+       bool key_press_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
+       bool key_release_handler (ArdourCanvas::Item*, GdkEvent*, ItemType);
 
-        Gtkmm2ext::Bindings* button_bindings;
-        XMLNode* button_settings () const;
+       Gtkmm2ext::Bindings* button_bindings;
+       XMLNode* button_settings () const;
 
        /* KEYMAP HANDLING */
 
        void register_actions ();
        void register_region_actions ();
 
+        void load_bindings ();
+        Gtkmm2ext::ActionMap editor_action_map;
+        Gtkmm2ext::Bindings  key_bindings;
+
        int ensure_cursor (framepos_t* pos);
 
        void cut_copy (Editing::CutCopyOp);
@@ -1073,10 +1099,22 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void toggle_region_lock ();
        void toggle_opaque_region ();
        void toggle_record_enable ();
+       void toggle_solo ();
+       void toggle_solo_isolate ();
+       void toggle_mute ();
        void toggle_region_lock_style ();
+
+       enum LayerOperation {
+               Raise,
+               RaiseToTop,
+               Lower,
+               LowerToBottom
+       };
+
+       void do_layer_operation (LayerOperation);
        void raise_region ();
        void raise_region_to_top ();
-        void change_region_layering_order ();
+       void change_region_layering_order (bool from_context_menu);
        void lower_region ();
        void lower_region_to_bottom ();
        void split_regions_at (framepos_t, RegionSelection&);
@@ -1099,7 +1137,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void duplicate_some_regions (RegionSelection&, float times);
        void duplicate_selection (float times);
        void region_fill_selection ();
-       void join_regions ();
+       void combine_regions ();
+       void uncombine_regions ();
 
        void region_fill_track ();
        void audition_playlist_region_standalone (boost::shared_ptr<ARDOUR::Region>);
@@ -1111,11 +1150,11 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void reset_region_scale_amplitude ();
        void adjust_region_gain (bool up);
        void quantize_region ();
-       void insert_patch_change ();
+       void insert_patch_change (bool from_context);
        void fork_region ();
 
        void do_insert_time ();
-       void insert_time (framepos_t, framecnt_t, Editing::InsertTimeOption, bool, bool, bool, bool, bool);
+       void insert_time (framepos_t, framecnt_t, Editing::InsertTimeOption, bool, bool, bool, bool, bool, bool);
 
        void tab_to_transient (bool forward);
 
@@ -1134,10 +1173,11 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        void split_region ();
 
+       void delete_ ();
        void cut ();
        void copy ();
-       void paste (float times);
-       
+       void paste (float times, bool from_context_menu = false);
+
        void place_transient ();
        void remove_transient (ArdourCanvas::Item* item);
        void snap_regions_to_grid ();
@@ -1161,7 +1201,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void zoom_to_region (bool both_axes);
        void temporal_zoom_session ();
        void temporal_zoom (gdouble scale);
-       void temporal_zoom_by_frame (framepos_t start, framepos_t end, const std::string & op);
+       void temporal_zoom_by_frame (framepos_t start, framepos_t end);
        void temporal_zoom_to_frame (bool coarser, framepos_t frame);
 
        void insert_region_list_drag (boost::shared_ptr<ARDOUR::Region>, int x, int y);
@@ -1327,8 +1367,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        void region_view_item_click (AudioRegionView&, GdkEventButton*);
 
-       void remove_gain_control_point (ArdourCanvas::Item*, GdkEvent*);
-       void remove_control_point (ArdourCanvas::Item*, GdkEvent*);
+       bool can_remove_control_point (ArdourCanvas::Item *);
+       void remove_control_point (ArdourCanvas::Item *);
 
        void mouse_brush_insert_region (RegionView*, framepos_t pos);
 
@@ -1372,16 +1412,15 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        bool canvas_markerview_item_view_event(GdkEvent* event, ArdourCanvas::Item*,MarkerView*);
        bool canvas_markerview_start_handle_event(GdkEvent* event, ArdourCanvas::Item*,MarkerView*);
        bool canvas_markerview_end_handle_event(GdkEvent* event, ArdourCanvas::Item*,MarkerView*);
-       
+
        PBD::Signal0<void> EditorFreeze;
        PBD::Signal0<void> EditorThaw;
 
   private:
-        friend class DragManager;
-        friend class EditorRouteGroups;
-        friend class EditorRegions;
+       friend class DragManager;
+       friend class EditorRouteGroups;
+       friend class EditorRegions;
 
-       ArdourCanvas::Item *last_item_entered;
        /** true if the mouse is over a place where region trim can happen */
        bool _over_region_trim_target;
 
@@ -1413,10 +1452,13 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        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
-        bool _stationary_playhead;
+       /// true if we scroll the tracks rather than the playhead
+       bool _stationary_playhead;
+       /// true if we are in fullscreen mode
+       bool _maximised;
 
-       ARDOUR::TempoMap::BBTPointList *current_bbt_points;
+       ARDOUR::TempoMap::BBTPointList::const_iterator current_bbt_points_begin;
+       ARDOUR::TempoMap::BBTPointList::const_iterator current_bbt_points_end;
 
        TempoLines* tempo_lines;
 
@@ -1459,16 +1501,16 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void marker_menu_set_from_playhead ();
        void marker_menu_set_from_selection ();
        void marker_menu_range_to_next ();
+       void marker_menu_zoom_to_range ();
        void new_transport_marker_menu_set_loop ();
        void new_transport_marker_menu_set_punch ();
        void update_loop_range_view (bool visibility=false);
        void update_punch_range_view (bool visibility=false);
-        void new_transport_marker_menu_popdown ();
+       void new_transport_marker_menu_popdown ();
        void marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
        void tempo_or_meter_marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
-       void transport_marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
        void new_transport_marker_context_menu (GdkEventButton*, ArdourCanvas::Item*);
-       void build_range_marker_menu (bool);
+       void build_range_marker_menu (bool, bool);
        void build_marker_menu (ARDOUR::Location *);
        void build_tempo_or_meter_marker_menu (bool);
        void build_new_transport_marker_menu ();
@@ -1501,11 +1543,10 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void editor_mixer_button_toggled ();
        void editor_list_button_toggled ();
 
-       AudioClock               zoom_range_clock;
-       Gtk::Button              zoom_in_button;
-       Gtk::Button              zoom_out_button;
-       Gtk::Button              zoom_out_full_button;
-       Gtk::Button              zoom_onetoone_button;
+       AudioClock*               zoom_range_clock;
+       ArdourButton              zoom_in_button;
+       ArdourButton              zoom_out_button;
+       ArdourButton              zoom_out_full_button;
 
        Gtk::Button              tav_expand_button;
        Gtk::Button              tav_shrink_button;
@@ -1516,30 +1557,32 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        Gtk::Label               toolbar_selection_cursor_label;
 
        Gtkmm2ext::TearOff*      _mouse_mode_tearoff;
-       Gtkmm2ext::StatefulToggleButton mouse_select_button;
-       Gtkmm2ext::StatefulToggleButton mouse_move_button;
-       Gtkmm2ext::StatefulToggleButton mouse_gain_button;
-       Gtkmm2ext::StatefulToggleButton mouse_zoom_button;
-       Gtkmm2ext::StatefulToggleButton mouse_timefx_button;
-       Gtkmm2ext::StatefulToggleButton mouse_audition_button;
-       Gtkmm2ext::StatefulToggleButton join_object_range_button;
+       ArdourButton mouse_select_button;
+       ArdourButton mouse_draw_button;
+       ArdourButton mouse_move_button;
+       ArdourButton mouse_gain_button;
+       ArdourButton mouse_zoom_button;
+       ArdourButton mouse_timefx_button;
+       ArdourButton mouse_audition_button;
+
+       ButtonJoiner* smart_mode_joiner;
+       Glib::RefPtr<Gtk::ToggleAction> smart_mode_action;
 
        void                     mouse_mode_toggled (Editing::MouseMode m);
        void                     mouse_mode_object_range_toggled () {}
        bool                     ignore_mouse_mode_toggle;
 
-       Gtkmm2ext::StatefulToggleButton internal_edit_button;
-       void                     toggle_internal_editing ();
+       ArdourButton internal_edit_button;
+       void         toggle_internal_editing ();
 
        bool                     mouse_select_button_release (GdkEventButton*);
 
        Gtk::VBox                automation_box;
        Gtk::Button              automation_mode_button;
-       Gtk::ToggleButton        global_automation_button;
 
        Gtk::ComboBoxText edit_mode_selector;
        Gtk::VBox         edit_mode_box;
-        std::vector<std::string> edit_mode_strings;
+       std::vector<std::string> edit_mode_strings;
 
        void set_edit_mode (ARDOUR::EditMode);
        void cycle_edit_mode ();
@@ -1583,14 +1626,10 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        Gtk::EventBox            toolbar_base;
        Gtk::Frame               toolbar_frame;
        Gtk::Viewport           _toolbar_viewport;
-       
+
        /* midi toolbar */
 
        Gtk::HBox                panic_box;
-       Gtk::Button              midi_panic_button;
-       Gtk::ToggleButton        midi_sound_notes;
-       void                     midi_panic ();
-       bool                     sound_notes () const { return midi_sound_notes.get_active(); }
 
        void setup_midi_toolbar ();
 
@@ -1682,6 +1721,9 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        framecnt_t autoscroll_x_distance;
        double autoscroll_y_distance;
 
+       bool _autoscroll_fudging;
+       int autoscroll_fudge_threshold () const;
+
        static gint _autoscroll_canvas (void *);
        bool autoscroll_canvas ();
        void start_canvas_autoscroll (int x, int y);
@@ -1714,7 +1756,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
                 const Gtk::SelectionData&             data,
                 guint                                 info,
                 guint                                 time);
-        
+
        void track_canvas_drag_data_received (
                 const Glib::RefPtr<Gdk::DragContext>& context,
                 gint                                  x,
@@ -1722,7 +1764,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
                 const Gtk::SelectionData&             data,
                 guint                                 info,
                 guint                                 time);
-        
+
        void drop_paths (
                 const Glib::RefPtr<Gdk::DragContext>& context,
                 gint                                  x,
@@ -1730,7 +1772,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
                 const Gtk::SelectionData&             data,
                 guint                                 info,
                 guint                                 time);
-        
+
        void drop_regions (
                 const Glib::RefPtr<Gdk::DragContext>& context,
                 gint                                  x,
@@ -1738,7 +1780,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
                 const Gtk::SelectionData&             data,
                 guint                                 info,
                 guint                                 time);
-        
+
        void drop_routes (
                 const Glib::RefPtr<Gdk::DragContext>& context,
                 gint                x,
@@ -1746,12 +1788,12 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
                 const Gtk::SelectionData& data,
                 guint               info,
                 guint               time);
-        
+
        /* audio export */
 
        int  write_region_selection(RegionSelection&);
        bool write_region (std::string path, boost::shared_ptr<ARDOUR::AudioRegion>);
-       void bounce_region_selection ();
+       void bounce_region_selection (bool with_processing);
        void bounce_range_selection (bool replace, bool enable_processing);
        void external_edit_region ();
 
@@ -1765,14 +1807,6 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void update_title ();
        void update_title_s (const std::string & snapshot_name);
 
-       struct State {
-           Selection* selection;
-           double frames_per_unit;
-
-           State (PublicEditor const * e);
-           ~State ();
-       };
-
        void instant_save ();
 
        boost::shared_ptr<ARDOUR::AudioRegion> last_audition_region;
@@ -1796,17 +1830,13 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
         */
        bool mouse_frame (framepos_t&, bool& in_track_canvas) const;
 
-       /* "whats mine is yours" */
-
        TimeFXDialog* current_timefx;
-
        static void* timefx_thread (void *arg);
-       void do_timefx (TimeFXDialog&);
+       void do_timefx ();
 
        int time_stretch (RegionSelection&, float fraction);
        int pitch_shift (RegionSelection&, float cents);
        void pitch_shift_region ();
-       int time_fx (RegionSelection&, float val, bool pitching);
 
        void transpose_region ();
 
@@ -1872,8 +1902,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        ImageFrameSocketHandler* image_socket_listener ;
 #endif
 
-       void toggle_xfade_active (boost::weak_ptr<ARDOUR::Crossfade>);
-       void toggle_xfade_length (boost::weak_ptr<ARDOUR::Crossfade>);
+       void toggle_xfade_active (RouteTimeAxisView *, boost::weak_ptr<ARDOUR::Crossfade>);
+       void toggle_xfade_length (RouteTimeAxisView *, boost::weak_ptr<ARDOUR::Crossfade>);
        void edit_xfade (boost::weak_ptr<ARDOUR::Crossfade>);
        void xfade_edit_left_region ();
        void xfade_edit_right_region ();
@@ -1887,7 +1917,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        Gtk::Button      nudge_backward_button;
        Gtk::HBox        nudge_hbox;
        Gtk::VBox        nudge_vbox;
-       AudioClock       nudge_clock;
+       AudioClock*       nudge_clock;
 
        bool nudge_forward_release (GdkEventButton*);
        bool nudge_backward_release (GdkEventButton*);
@@ -1929,7 +1959,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        gint left_automation_track ();
 
        void reset_canvas_action_sensitivity (bool);
-       void toggle_gain_envelope_visibility ();
+       void set_gain_envelope_visibility (bool);
+       void set_region_gain_visibility (RegionView*, bool);
        void toggle_gain_envelope_active ();
        void reset_region_gain_envelopes ();
 
@@ -1967,7 +1998,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        RegionSelection get_regions_from_selection ();
        RegionSelection get_regions_from_selection_and_edit_point ();
        RegionSelection get_regions_from_selection_and_entered ();
-       
+
        void start_updating_meters ();
        void stop_updating_meters ();
        bool meters_running;
@@ -1979,7 +2010,6 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void timecode_snap_to_internal (framepos_t& first, int32_t direction = 0, bool for_mark = false);
 
        RhythmFerret* rhythm_ferret;
-       BundleManager* _bundle_manager;
 
        void fit_tracks (TrackViewList &);
        void fit_selected_tracks ();
@@ -1998,10 +2028,10 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void visible_order_range (int*, int*) const;
 
        void located ();
-       
+
        /** true if we've made a locate request that hasn't yet been processed */
        bool _pending_locate_request;
-       
+
        /** if true, there is a pending Session locate which is the initial one when loading a session;
            we need to know this so that we don't (necessarily) set the viewport to show the playhead
            initially.
@@ -2019,7 +2049,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        EditorGroupTabs* _group_tabs;
        void fit_route_group (ARDOUR::RouteGroup *);
 
-        void step_edit_status_change (bool);
+       void step_edit_status_change (bool);
        void start_step_editing ();
        void stop_step_editing ();
        bool check_step_edit ();
@@ -2027,8 +2057,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        double _last_motion_y;
 
-        RegionLayeringOrderEditor* layering_order_editor;
-        void update_region_layering_order_editor ();
+       RegionLayeringOrderEditor* layering_order_editor;
+       void update_region_layering_order_editor ();
 
        /** Track that was the source for the last cut/copy operation.  Used as a place
            to paste things iff there is no selected track.
@@ -2047,12 +2077,27 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        Gtk::MenuItem& action_menu_item (std::string const &);
        void action_pre_activated (Glib::RefPtr<Gtk::Action> const &);
 
-        void set_canvas_cursor_for_region_view (double, RegionView *);
+       void set_canvas_cursor_for_region_view (double, RegionView *);
 
        MouseCursors* _cursors;
 
-        void resize_text_widgets ();
+       void follow_mixer_selection ();
+       bool _following_mixer_selection;
+
+       int time_fx (ARDOUR::RegionList&, float val, bool pitching);
+
+       bool doing_range_stuff() const {
+               return (mouse_mode == Editing::MouseRange && (_join_object_range_state == JOIN_OBJECT_RANGE_NONE)) ||
+                       _join_object_range_state == JOIN_OBJECT_RANGE_RANGE;
+       }
        
+       bool doing_object_stuff() const {
+               return (mouse_mode == Editing::MouseObject && (_join_object_range_state == JOIN_OBJECT_RANGE_NONE)) ||
+                       _join_object_range_state == JOIN_OBJECT_RANGE_OBJECT;
+       }
+
+       void toggle_sound_midi_notes ();
+
        friend class Drag;
        friend class RegionDrag;
        friend class RegionMoveDrag;
@@ -2068,8 +2113,9 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        friend class ControlPointDrag;
        friend class LineDrag;
        friend class RubberbandSelectDrag;
-        friend class TimeFXDrag;
-        friend class ScrubDrag;
+       friend class EditorRubberbandSelectDrag;
+       friend class TimeFXDrag;
+       friend class ScrubDrag;
        friend class SelectionDrag;
        friend class RangeMarkerBarDrag;
        friend class MouseZoomDrag;