Make ContourdesignControlProtocol::_button_actions private again ...
authorJohannes Mueller <github@johannes-mueller.org>
Sat, 25 May 2019 19:25:16 +0000 (21:25 +0200)
committerJohannes Mueller <github@johannes-mueller.org>
Thu, 30 May 2019 15:09:33 +0000 (17:09 +0200)
... and add proper bounds checks.

libs/surfaces/contourdesign/contourdesign.cc
libs/surfaces/contourdesign/contourdesign.h
libs/surfaces/contourdesign/contourdesign_gui.cc

index 1b03e9869fa3b8e97cc46224f4f4a4cae06681b2..c42a0d740f826ea22a68e97fa45bd17d908b2a17 100644 (file)
@@ -498,6 +498,25 @@ ContourDesignControlProtocol::setup_default_button_actions ()
        _button_actions.push_back (make_button_action ("Transport/GotoEnd"));
 }
 
+const boost::shared_ptr<ButtonBase>
+ContourDesignControlProtocol::get_button_action (unsigned int index) const
+{
+       if (index >= _button_actions.size()) {
+               return boost::shared_ptr<ButtonBase>();
+       }
+       return _button_actions[index];
+}
+
+void
+ContourDesignControlProtocol::set_button_action (unsigned int index, const boost::shared_ptr<ButtonBase> btn_act)
+{
+       if (index >= _button_actions.size()) {
+               return;
+       }
+       _button_actions[index] = btn_act;
+}
+
+
 void
 ContourDesignControlProtocol::handle_button_press (unsigned short btn)
 {
index 58244f3a6a1220b0f20ead8ca84440e5596cc282..b9e6037c6fe3e174be81ff64a241c5a9b69b847a 100644 (file)
@@ -107,6 +107,10 @@ public:
        bool test_mode () const { return _test_mode; }
        void set_test_mode (bool tm) { _test_mode = tm; }
 
+       int get_button_count() const { return _button_actions.size(); }
+       const boost::shared_ptr<ButtonBase> get_button_action (unsigned int index) const;
+       void set_button_action (unsigned int index, const boost::shared_ptr<ButtonBase> btn_act);
+
        JumpDistance jog_distance () const { return _jog_distance; }
        void set_jog_distance (JumpDistance jd) { _jog_distance = jd; }
 
@@ -118,8 +122,6 @@ public:
        PBD::Signal1<void, unsigned short> ButtonPress;
        PBD::Signal1<void, unsigned short> ButtonRelease;
 
-       std::vector<boost::shared_ptr<ButtonBase> > _button_actions; // XXX TODO: use accessor/setter methods
-
 private:
        void do_request (ContourDesignControlUIRequest*);
        void start ();
@@ -170,6 +172,8 @@ private:
        std::vector<double> _shuttle_speeds;
        JumpDistance _jog_distance;
 
+       std::vector<boost::shared_ptr<ButtonBase> > _button_actions;
+
        mutable ContourDesignGUI* _gui;
        void build_gui ();
 
index 67dad3088ced4134f80d89e789a76e7305fe676f..c58b4e03dd5279727230728432acd00980fb2e19 100644 (file)
@@ -164,9 +164,7 @@ ContourDesignGUI::ContourDesignGUI (ContourDesignControlProtocol& ccp)
        table->set_row_spacings (6);
        table->set_col_spacings (6);;
 
-       vector<boost::shared_ptr<ButtonBase> >::const_iterator it;
-       unsigned int btn_idx = 0;
-       for (it = _ccp._button_actions.begin(); it != _ccp._button_actions.end(); ++it) {
+       for (int btn_idx=0; btn_idx < _ccp.get_button_count(); ++btn_idx) {
                boost::shared_ptr<ArdourButton> b (new ArdourButton (string_compose (_("Setting for button %1"), btn_idx+1),
                                                                     ArdourButton::Element(ArdourButton::Indicator|ArdourButton::Text|ArdourButton::Inactive)));
                table->attach (*b, 0, 2, btn_idx, btn_idx+1);
@@ -174,7 +172,10 @@ ContourDesignGUI::ContourDesignGUI (ContourDesignControlProtocol& ccp)
 
                ButtonConfigWidget* bcw = manage (new ButtonConfigWidget);
 
-               bcw->set_current_config (*it);
+               boost::shared_ptr<ButtonBase> btn_act = _ccp.get_button_action (btn_idx);
+               assert (btn_act);
+               bcw->set_current_config (btn_act);
+
                bcw->Changed.connect (sigc::bind (sigc::mem_fun (*this, &ContourDesignGUI::update_action), btn_idx, bcw));
                table->attach (*bcw, 3, 5, btn_idx, btn_idx+1);
 
@@ -185,7 +186,6 @@ ContourDesignGUI::ContourDesignGUI (ContourDesignControlProtocol& ccp)
                        this->ProButtonsSensitive.connect (sigc::mem_fun (*b, &ArdourButton::set_sensitive));
                        this->ProButtonsSensitive.connect (sigc::mem_fun (*bcw, &ButtonConfigWidget::set_sensitive));
                }
-               ++btn_idx;
        }
 
        set_spacing (6);
@@ -226,12 +226,7 @@ ContourDesignGUI::update_jog_distance ()
 void
 ContourDesignGUI::update_action (unsigned int index, ButtonConfigWidget* sender)
 {
-       if (index >= _ccp._button_actions.size()) {
-               DEBUG_TRACE (DEBUG::ContourDesignControl, string_compose ("ContourDesignGUI::update_action() index out of bounds %1 / %2\n", index, _ccp._button_actions.size()));
-               return;
-       }
-       _ccp._button_actions[index] = sender->get_current_config (_ccp);
-       DEBUG_TRACE (DEBUG::ContourDesignControl, string_compose ("update_action () %1\n", index));
+       _ccp.set_button_action (index, sender->get_current_config (_ccp));
 }
 
 void