2 #include <sigc++/bind.h>
3 #include <sigc++/bind_return.h>
4 #include <msp/core/hash.h>
5 #include <msp/core/maputils.h>
18 void Hub::attach(Device &dev)
20 unsigned index = devices.size();
21 devices.push_back(&dev);
22 dev.signal_button_press.connect(sigc::bind_return(sigc::bind(sigc::mem_fun(this, &Hub::button_press), index), false));
23 dev.signal_button_release.connect(sigc::bind_return(sigc::bind(sigc::mem_fun(this, &Hub::button_release), index), false));
24 dev.signal_axis_motion.connect(sigc::bind_return(sigc::bind(sigc::mem_fun(this, &Hub::axis_motion), index), false));
27 std::string Hub::get_button_name(unsigned btn) const
29 unsigned dev_index = btn>>8;
30 if(dev_index>=devices.size())
31 throw out_of_range("Hub::get_button_name");
33 const Device &dev = *devices[dev_index];
34 return dev.get_name()+": "+dev.get_button_name(btn&0xFF);
37 std::string Hub::get_axis_name(unsigned axis) const
39 unsigned dev_index = axis>>8;
40 if(dev_index>=devices.size())
41 throw out_of_range("Hub::get_axis_name");
43 const Device &dev = *devices[dev_index];
44 return dev.get_name()+": "+dev.get_axis_name(axis&0xFF);
47 void Hub::button_press(unsigned btn, unsigned index)
50 set_button_state((index<<8) | btn, true, true);
53 void Hub::button_release(unsigned btn, unsigned index)
56 set_button_state((index<<8) | btn, false, true);
59 void Hub::axis_motion(unsigned axis, float value, float, unsigned index)
62 set_axis_value((index<<8) | axis, value, true);