2 #include <sigc++/bind_return.h>
3 #include <msp/strings/lexicalcast.h>
4 #include "binarycontrol.h"
12 ControlSource::ControlSource(Device &d, ControlSrcType t, unsigned i):
18 std::string ControlSource::str() const
21 return dev->get_button_name(index);
22 else if(type==AXIS_POS)
23 return dev->get_axis_name(index)+" +";
24 else if(type==AXIS_NEG)
25 return dev->get_axis_name(index)+" -";
26 else if(type==NO_SOURCE)
29 return lexical_cast<string>(index);
33 Control::Control(const ControlSource &s):
37 Control::Control(Device &d, ControlSrcType t, unsigned i):
46 void Control::capture(Device &d)
50 capture_dev->signal_button_press.connect(sigc::bind_return(sigc::mem_fun(this, &Control::button_press), false));
51 capture_dev->signal_axis_motion.connect(sigc::bind_return(sigc::mem_fun(this, &Control::axis_motion), false));
54 void Control::cancel_capture()
61 void Control::set_source(Device &d, ControlSrcType t, unsigned i)
63 set_source(ControlSource(d, t, i));
66 void Control::set_source(const ControlSource &s)
73 void Control::set_activator(BinaryControl *ctrl)
80 void Control::reset_edges()
86 void Control::connect_signals()
93 src.dev->signal_button_press.connect(sigc::bind_return(sigc::mem_fun(this, &Control::button_press), false));
94 src.dev->signal_button_release.connect(sigc::bind_return(sigc::mem_fun(this, &Control::button_release), false));
98 src.dev->signal_axis_motion.connect(sigc::bind_return(sigc::mem_fun(this, &Control::axis_motion), false));
103 activator->signal_release.connect(sigc::mem_fun(this, &Control::deactivate));
106 void Control::button_press(unsigned i)
110 src.dev = capture_dev;
117 signal_capture_complete.emit();
119 else if(src.type==BUTTON && i==src.index && (!activator || activator->get_state()))
123 void Control::button_release(unsigned i)
125 if(src.type==BUTTON && i==src.index && (!activator || activator->get_state()))
129 void Control::axis_motion(unsigned i, float v, float r)
133 ControlSrcType type = NO_SOURCE;
141 src.dev = capture_dev;
148 signal_capture_complete.emit();
151 else if(activator && !activator->get_state() && i==src.index)
153 else if(src.type==AXIS_POS && i==src.index && v>=origin)
154 on_motion(v-origin, r);
155 else if(src.type==AXIS_NEG && i==src.index && v<=origin)
156 on_motion(origin-v, -r);
159 void Control::deactivate()
163 else if(src.type==AXIS_POS || src.type==AXIS_NEG)
165 float v = src.dev->get_axis_value(src.index);
166 on_motion(0, (src.type==AXIS_POS ? origin-v : v-origin));