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);
47 Control::Control(const ControlSource &s):
56 Control::Control(Device &d, ControlSrcType t, unsigned i):
70 void Control::capture(Device &d)
74 capture_dev->signal_button_press.connect(sigc::bind_return(sigc::mem_fun(this, &Control::button_press), false));
75 capture_dev->signal_axis_motion.connect(sigc::bind_return(sigc::mem_fun(this, &Control::axis_motion), false));
78 void Control::cancel_capture()
85 void Control::set_source(Device &d, ControlSrcType t, unsigned i)
87 set_source(ControlSource(d, t, i));
90 void Control::set_source(const ControlSource &s)
97 void Control::set_activator(BinaryControl *ctrl)
104 void Control::reset_edges()
107 falling_edge = false;
110 void Control::connect_signals()
117 src.dev->signal_button_press.connect(sigc::bind_return(sigc::mem_fun(this, &Control::button_press), false));
118 src.dev->signal_button_release.connect(sigc::bind_return(sigc::mem_fun(this, &Control::button_release), false));
122 src.dev->signal_axis_motion.connect(sigc::bind_return(sigc::mem_fun(this, &Control::axis_motion), false));
127 activator->signal_release.connect(sigc::mem_fun(this, &Control::deactivate));
130 void Control::button_press(unsigned i)
134 src.dev = capture_dev;
141 signal_capture_complete.emit();
143 else if(src.type==BUTTON && i==src.index && (!activator || activator->get_state()))
147 void Control::button_release(unsigned i)
149 if(src.type==BUTTON && i==src.index && (!activator || activator->get_state()))
153 void Control::axis_motion(unsigned i, float v, float r)
157 ControlSrcType type = NONE;
165 src.dev = capture_dev;
172 signal_capture_complete.emit();
175 else if(activator && !activator->get_state() && i==src.index)
177 else if(src.type==AXIS_POS && i==src.index && v>=origin)
178 on_motion(v-origin, r);
179 else if(src.type==AXIS_NEG && i==src.index && v<=origin)
180 on_motion(origin-v, -r);
183 void Control::deactivate()
187 else if(src.type==AXIS_POS || src.type==AXIS_NEG)
189 float v = src.dev->get_axis_value(src.index);
190 on_motion(0, (src.type==AXIS_POS ? origin-v : v-origin));