3 #include <sigc++/bind.h>
4 #include <sigc++/bind_return.h>
5 #include <msp/core/hash.h>
6 #include <msp/core/maputils.h>
19 void Hub::attach(Device &dev)
21 unsigned index = devices.size();
22 devices.push_back(&dev);
23 dev.signal_button_press.connect(sigc::bind_return(sigc::bind(sigc::mem_fun(this, &Hub::button_press), index), false));
24 dev.signal_button_release.connect(sigc::bind_return(sigc::bind(sigc::mem_fun(this, &Hub::button_release), index), false));
25 dev.signal_axis_motion.connect(sigc::bind_return(sigc::bind(sigc::mem_fun(this, &Hub::axis_motion), index), false));
28 Device *Hub::find_subdevice(DeviceType t, unsigned n)
30 for(Device *d: devices)
31 if(Device *dev = d->find_subdevice(t, 0))
40 Device *Hub::find_subdevice(const string &n)
44 for(Device *d: devices)
45 if(Device *dev = d->find_subdevice(n))
50 string Hub::get_button_name(unsigned btn) const
52 unsigned dev_index = btn>>8;
53 if(dev_index>=devices.size())
54 throw out_of_range("Hub::get_button_name");
56 const Device &dev = *devices[dev_index];
57 return dev.get_name()+": "+dev.get_button_name(btn&0xFF);
60 string Hub::get_axis_name(unsigned axis) const
62 unsigned dev_index = axis>>8;
63 if(dev_index>=devices.size())
64 throw out_of_range("Hub::get_axis_name");
66 const Device &dev = *devices[dev_index];
67 return dev.get_name()+": "+dev.get_axis_name(axis&0xFF);
70 void Hub::button_press(unsigned btn, unsigned index)
73 set_button_state((index<<8) | btn, true, true);
76 void Hub::button_release(unsigned btn, unsigned index)
79 set_button_state((index<<8) | btn, false, true);
82 void Hub::axis_motion(unsigned axis, float value, float, unsigned index)
85 set_axis_value((index<<8) | axis, value, true);