1 #include <sigc++/bind_return.h>
2 #include <msp/strings/lexicalcast.h>
3 #include "binarycontrol.h"
12 ControlSource::ControlSource():
18 ControlSource::ControlSource(Device &d, ControlSrcType t, unsigned i):
24 std::string ControlSource::str() const
27 return dev->get_button_name(index);
28 else if(type==AXIS_POS)
29 return dev->get_axis_name(index)+" +";
30 else if(type==AXIS_NEG)
31 return dev->get_axis_name(index)+" -";
35 return lexical_cast<string>(index);
45 Control::Control(const ControlSource &s):
52 Control::Control(Device &d, ControlSrcType t, unsigned i):
64 void Control::capture(Device &d)
68 capture_dev->signal_button_press.connect(sigc::bind_return(sigc::mem_fun(this, &Control::button_press), false));
69 capture_dev->signal_axis_motion.connect(sigc::bind_return(sigc::mem_fun(this, &Control::axis_motion), false));
72 void Control::cancel_capture()
79 void Control::set_source(Device &d, ControlSrcType t, unsigned i)
81 set_source(ControlSource(d, t, i));
84 void Control::set_source(const ControlSource &s)
91 void Control::set_activator(BinaryControl *ctrl)
98 void Control::connect_signals()
105 src.dev->signal_button_press.connect(sigc::bind_return(sigc::mem_fun(this, &Control::button_press), false));
106 src.dev->signal_button_release.connect(sigc::bind_return(sigc::mem_fun(this, &Control::button_release), false));
110 src.dev->signal_axis_motion.connect(sigc::bind_return(sigc::mem_fun(this, &Control::axis_motion), false));
115 activator->signal_release.connect(sigc::mem_fun(this, &Control::deactivate));
118 void Control::button_press(unsigned i)
122 src.dev = capture_dev;
129 signal_capture_complete.emit();
131 else if(src.type==BUTTON && i==src.index && (!activator || activator->get_state()))
135 void Control::button_release(unsigned i)
137 if(src.type==BUTTON && i==src.index && (!activator || activator->get_state()))
141 void Control::axis_motion(unsigned i, float v, float r)
145 ControlSrcType type = NONE;
153 src.dev = capture_dev;
160 signal_capture_complete.emit();
163 else if(activator && !activator->get_state() && i==src.index)
165 else if(src.type==AXIS_POS && i==src.index && v>=origin)
166 on_motion(v-origin, r);
167 else if(src.type==AXIS_NEG && i==src.index && v<=origin)
168 on_motion(origin-v, -r);
171 void Control::deactivate()
175 else if(src.type==AXIS_POS || src.type==AXIS_NEG)
177 float v = src.dev->get_axis_value(src.index);
178 on_motion(0, (src.type==AXIS_POS ? origin-v : v-origin));