3 This file is part of libmspgbase
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/core/except.h>
9 #include <msp/strings/lexicalcast.h>
16 ControlSource::ControlSource():
22 ControlSource::ControlSource(Device &d, ControlSrcType t, unsigned i):
28 std::string ControlSource::str() const
31 return dev->get_button_name(index);
32 else if(type==AXIS_POS)
33 return dev->get_axis_name(index)+" +";
34 else if(type==AXIS_NEG)
35 return dev->get_axis_name(index)+" -";
39 return lexical_cast(index);
47 Control::Control(const ControlSource &s):
52 Control::Control(Device &d, ControlSrcType t, unsigned i):
59 void Control::capture(Device &d)
63 capture_dev->signal_button_press.connect(sigc::mem_fun(this, &Control::button_press));
64 capture_dev->signal_axis_motion.connect(sigc::mem_fun(this, &Control::axis_motion));
67 void Control::cancel_capture()
74 void Control::set_source(Device &d, ControlSrcType t, unsigned i)
76 set_source(ControlSource(d, t, i));
79 void Control::set_source(const ControlSource &s)
86 void Control::connect_signals()
93 src.dev->signal_button_press.connect(sigc::mem_fun(this, &Control::button_press));
94 src.dev->signal_button_release.connect(sigc::mem_fun(this, &Control::button_release));
98 src.dev->signal_axis_motion.connect(sigc::mem_fun(this, &Control::axis_motion));
101 throw Exception("Invalid source in Control");
105 void Control::button_press(unsigned i)
116 signal_capture_complete.emit();
118 else if(src.type==BUTTON && i==src.index)
122 void Control::button_release(unsigned i)
124 if(src.type==BUTTON && i==src.index)
128 void Control::axis_motion(unsigned i, float v, float r)
132 ControlSrcType type=NONE;
147 signal_capture_complete.emit();
150 else if(src.type==AXIS_POS && i==src.index && v>=0)
152 else if(src.type==AXIS_NEG && i==src.index && v<=0)