1 #include <msp/core/except.h>
2 #include <msp/strings/lexicalcast.h>
9 ControlSource::ControlSource():
15 ControlSource::ControlSource(Device &d, ControlSrcType t, unsigned i):
21 std::string ControlSource::str() const
24 return dev->get_button_name(index);
25 else if(type==AXIS_POS)
26 return dev->get_axis_name(index)+" +";
27 else if(type==AXIS_NEG)
28 return dev->get_axis_name(index)+" -";
32 return lexical_cast(index);
40 Control::Control(const ControlSource &s):
45 Control::Control(Device &d, ControlSrcType t, unsigned i):
52 void Control::capture(Device &d)
56 capture_dev->signal_button_press.connect(sigc::mem_fun(this, &Control::button_press));
57 capture_dev->signal_axis_motion.connect(sigc::mem_fun(this, &Control::axis_motion));
60 void Control::cancel_capture()
67 void Control::set_source(Device &d, ControlSrcType t, unsigned i)
69 set_source(ControlSource(d, t, i));
72 void Control::set_source(const ControlSource &s)
79 void Control::connect_signals()
86 src.dev->signal_button_press.connect(sigc::mem_fun(this, &Control::button_press));
87 src.dev->signal_button_release.connect(sigc::mem_fun(this, &Control::button_release));
91 src.dev->signal_axis_motion.connect(sigc::mem_fun(this, &Control::axis_motion));
94 throw Exception("Invalid source in Control");
98 void Control::button_press(unsigned i)
109 signal_capture_complete.emit();
111 else if(src.type==BUTTON && i==src.index)
115 void Control::button_release(unsigned i)
117 if(src.type==BUTTON && i==src.index)
121 void Control::axis_motion(unsigned i, float v, float r)
125 ControlSrcType type=NONE;
140 signal_capture_complete.emit();
143 else if(src.type==AXIS_POS && i==src.index && v>=0)
145 else if(src.type==AXIS_NEG && i==src.index && v<=0)