Remove use of invalidated iterator (#4826).
[ardour.git] / gtk2_ardour / editor.h
index e9960b3938c3b9394fd9bbb1643d4e4ed72116ee..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"
@@ -52,6 +53,7 @@
 #include "ardour/types.h"
 
 #include "gtk-custom-ruler.h"
+#include "ardour_button.h"
 #include "ardour_dialog.h"
 #include "public_editor.h"
 #include "editing.h"
@@ -102,6 +104,7 @@ class AutomationLine;
 class AutomationSelection;
 class AutomationTimeAxisView;
 class BundleManager;
+class ButtonJoiner;
 class ControlPoint;
 class CrossfadeView;
 class DragManager;
@@ -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);
 
@@ -391,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 ();
@@ -436,7 +447,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
                return _drags;
        }
 
-       void maybe_autoscroll (bool, bool);
+       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);
@@ -473,7 +484,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        typedef std::pair<TimeAxisView*,XMLNode*> TAVState;
 
        struct VisualState {
-           VisualState();
+           VisualState (bool with_tracks);
            ~VisualState ();
            double              y_position;
            double              frames_per_unit;
@@ -492,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;
@@ -506,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;
 
@@ -521,14 +534,8 @@ 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;
@@ -539,8 +546,6 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        Gtk::HPaned   edit_pane;
        Gtk::VPaned   editor_summary_pane;
 
-       bool idle_reset_vertical_pane_position (int);
-
        Gtk::EventBox meter_base;
        Gtk::HBox     meter_box;
        Gtk::EventBox marker_base;
@@ -590,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;
 
@@ -628,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;
 
@@ -654,15 +664,13 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        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;
@@ -674,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 ();
@@ -702,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;
@@ -1025,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;
@@ -1055,6 +1066,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        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;
@@ -1064,6 +1077,10 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        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);
@@ -1086,9 +1103,18 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        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&);
@@ -1124,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);
 
@@ -1150,7 +1176,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        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);
@@ -1175,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);
@@ -1395,7 +1421,6 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        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;
 
@@ -1429,8 +1454,11 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        bool _follow_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;
 
@@ -1473,6 +1501,7 @@ 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);
@@ -1480,9 +1509,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        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 ();
@@ -1516,10 +1544,9 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        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;
+       ArdourButton              zoom_in_button;
+       ArdourButton              zoom_out_button;
+       ArdourButton              zoom_out_full_button;
 
        Gtk::Button              tav_expand_button;
        Gtk::Button              tav_shrink_button;
@@ -1530,26 +1557,28 @@ 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;
@@ -1601,10 +1630,6 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        /* 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 ();
 
@@ -1696,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);
@@ -1779,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;
@@ -1810,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 ();
 
@@ -1886,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 ();
@@ -1943,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 ();
 
@@ -2064,7 +2081,22 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 
        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;
@@ -2081,6 +2113,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        friend class ControlPointDrag;
        friend class LineDrag;
        friend class RubberbandSelectDrag;
+       friend class EditorRubberbandSelectDrag;
        friend class TimeFXDrag;
        friend class ScrubDrag;
        friend class SelectionDrag;