Shuttle Surface: Fix C++ style: use accessor/setter methods
authorRobin Gareus <robin@gareus.org>
Sat, 25 May 2019 14:45:53 +0000 (16:45 +0200)
committerRobin Gareus <robin@gareus.org>
Sat, 25 May 2019 14:49:15 +0000 (16:49 +0200)
This also fixes C++ compat: no forward declaration of friend classes
(OSX compilation) and C++98 compat (enums are not classes e.g. ActiveState)

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

index b0976f0ddf55725147f3274cff74326db7d9e5d2..7694592e5681a2f18ba0e5047fd3019de1c2fd2a 100644 (file)
@@ -570,6 +570,15 @@ void ContourDesignControlProtocol::jump_backward (JumpDistance dist)
        jump_forward(bw);
 }
 
+void
+ContourDesignControlProtocol::set_shuttle_speed (int index, double speed)
+{
+       /* called from GUI thread */
+       // XXX this may race with ContourDesignControlProtocol::shuttle_event()
+       // TODO: add bounds check
+       _shuttle_speeds[index] = speed;
+}
+
 void
 ContourDesignControlProtocol::shuttle_event(int position)
 {
index 730e89ddafbb91fa479d00aa77db211600885abe..6c81c0a099be74bfa580cdd8ce440b35631bbc8e 100644 (file)
@@ -65,7 +65,6 @@ class ContourDesignControlProtocol
        : public ARDOUR::ControlProtocol
        , public AbstractUI<ContourDesignControlUIRequest>
 {
-       friend ContourDesignGUI;
 public:
        ContourDesignControlProtocol (ARDOUR::Session &);
        virtual ~ContourDesignControlProtocol ();
@@ -99,6 +98,27 @@ public:
 
        boost::shared_ptr<ButtonBase> make_button_action (std::string action_string);
 
+       int usb_errorcode () const { return _error; }
+
+       bool keep_rolling () const { return _keep_rolling; }
+       void set_keep_rolling (bool kr) { _keep_rolling = kr; }
+
+       bool test_mode () const { return _test_mode; }
+       void set_test_mode (bool tm) { _test_mode = tm; }
+
+       JumpDistance jog_distance () const { return _jog_distance; }
+       void set_jog_distance (JumpDistance jd) { _jog_distance = jd; }
+
+       void set_shuttle_speed (int index, double speed);
+       double shuttle_speed (int index) const {
+               return _shuttle_speeds[index];
+       }
+
+       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 ();
@@ -113,6 +133,7 @@ private:
        int acquire_device ();
        void release_device ();
 
+       void setup_default_button_actions ();
        void handle_button_press (unsigned short btn);
        void handle_button_release (unsigned short btn);
 
@@ -141,8 +162,6 @@ private:
        State _state;
 
        bool _test_mode;
-       PBD::Signal1<void, unsigned short> ButtonPress;
-       PBD::Signal1<void, unsigned short> ButtonRelease;
 
        // Config stuff
 
@@ -150,9 +169,6 @@ private:
        std::vector<double> _shuttle_speeds;
        JumpDistance _jog_distance;
 
-       std::vector<boost::shared_ptr<ButtonBase> > _button_actions;
-       void setup_default_button_actions ();
-
        mutable ContourDesignGUI* _gui;
        void build_gui ();
 
index 88c05234dfcf33c6181055c8ab699eefe4737dcc..67dad3088ced4134f80d89e789a76e7305fe676f 100644 (file)
@@ -100,7 +100,7 @@ ContourDesignGUI::ContourDesignGUI (ContourDesignControlProtocol& ccp)
        : _ccp (ccp)
        , _test_button (_("Button Test"), ArdourButton::led_default_elements)
        , _keep_rolling (_("Keep rolling after jumps"))
-       , _jog_distance (ccp._jog_distance)
+       , _jog_distance (ccp.jog_distance ())
        , _device_state_lbl ()
 {
        Frame* dg_sample = manage (new Frame (_("Device")));
@@ -123,7 +123,7 @@ ContourDesignGUI::ContourDesignGUI (ContourDesignControlProtocol& ccp)
 
        HBox* speed_box = manage (new HBox);
        for (int i=0; i != ContourDesignControlProtocol::num_shuttle_speeds; ++i) {
-               double speed = ccp._shuttle_speeds[i];
+               double speed = ccp.shuttle_speed (i);
                boost::shared_ptr<Gtk::Adjustment> adj (new Gtk::Adjustment (speed, 0.0, 100.0, 0.25));
                _shuttle_speed_adjustments.push_back (adj);
                SpinButton* sb = manage (new SpinButton (*adj, 0.25, 2));
@@ -140,7 +140,7 @@ ContourDesignGUI::ContourDesignGUI (ContourDesignControlProtocol& ccp)
 
        _keep_rolling.set_tooltip_text (_("If checked Ardour keeps rolling after jog or shuttle events. If unchecked it stops."));
        _keep_rolling.signal_toggled().connect (sigc::mem_fun (*this, &ContourDesignGUI::toggle_keep_rolling));
-       _keep_rolling.set_active (_ccp._keep_rolling);
+       _keep_rolling.set_active (_ccp.keep_rolling ());
 
        sj_table->attach (_keep_rolling, 0,1, 2,3);
 
@@ -207,20 +207,20 @@ ContourDesignGUI::ContourDesignGUI (ContourDesignControlProtocol& ccp)
 void
 ContourDesignGUI::toggle_keep_rolling ()
 {
-       _ccp._keep_rolling = _keep_rolling.get_active();
+       _ccp.set_keep_rolling (_keep_rolling.get_active ());
 }
 
 void
 ContourDesignGUI::set_shuttle_speed (int index)
 {
        double speed = _shuttle_speed_adjustments[index]->get_value ();
-       _ccp._shuttle_speeds[index] = speed;
+       _ccp.set_shuttle_speed (index, speed);
 }
 
 void
 ContourDesignGUI::update_jog_distance ()
 {
-       _ccp._jog_distance = _jog_distance.get_distance ();
+       _ccp.set_jog_distance (_jog_distance.get_distance ());
 }
 
 void
@@ -237,9 +237,10 @@ ContourDesignGUI::update_action (unsigned int index, ButtonConfigWidget* sender)
 void
 ContourDesignGUI::toggle_test_mode ()
 {
-       _ccp._test_mode = !_ccp._test_mode;
-       if (_ccp._test_mode) {
-               _test_button.set_active_state (ActiveState::ExplicitActive);
+       bool testmode = ! _ccp.test_mode(); // toggle
+       _ccp.set_test_mode (testmode);
+       if (testmode) {
+               _test_button.set_active_state (Gtkmm2ext::ExplicitActive);
        } else {
                reset_test_state ();
        }
@@ -257,11 +258,11 @@ ContourDesignGUI::init_on_show ()
 bool
 ContourDesignGUI::reset_test_state (GdkEventAny*)
 {
-       _ccp._test_mode = false;
-       _test_button.set_active (ActiveState::Off);
+       _ccp.set_test_mode (false);
+       _test_button.set_active (Gtkmm2ext::Off);
        vector<boost::shared_ptr<ArdourButton> >::const_iterator it;
        for (it = _btn_leds.begin(); it != _btn_leds.end(); ++it) {
-               (*it)->set_active_state (ActiveState::Off);
+               (*it)->set_active_state (Gtkmm2ext::Off);
        }
 
        return false;
@@ -270,13 +271,13 @@ ContourDesignGUI::reset_test_state (GdkEventAny*)
 void
 ContourDesignGUI::test_button_press (unsigned short btn)
 {
-       _btn_leds[btn]->set_active_state (ActiveState::ExplicitActive);
+       _btn_leds[btn]->set_active_state (Gtkmm2ext::ExplicitActive);
 }
 
 void
 ContourDesignGUI::test_button_release (unsigned short btn)
 {
-       _btn_leds[btn]->set_active_state (ActiveState::Off);
+       _btn_leds[btn]->set_active_state (Gtkmm2ext::Off);
 }
 
 bool
@@ -297,7 +298,7 @@ ContourDesignGUI::update_device_state ()
                XpressButtonsSensitive (false);
                ProButtonsSensitive (false);
                _device_state_lbl.set_markup (string_compose ("<span weight=\"bold\" foreground=\"red\">Device not working:</span> %1",
-                                                             libusb_strerror ((libusb_error)_ccp._error)));
+                                             libusb_strerror ((libusb_error)_ccp.usb_errorcode ())));
        }
 
        return false;