1 #include "smoothcontrol.h"
9 SmoothControl::SmoothControl():
16 SmoothControl::SmoothControl(const ControlSource &s):
24 SmoothControl::SmoothControl(Device &d, ControlSrcType t, unsigned i):
32 SmoothControl::~SmoothControl()
37 void SmoothControl::set_dead_zone(float d)
39 if(d<0 || (threshold>0 && d>=threshold))
40 throw invalid_argument("SmoothControl::set_dead_zone");
44 void SmoothControl::set_threshold(float t)
46 if(t>=0 && t<=dead_zone)
47 throw invalid_argument("SmoothControl::set_threshold");
51 void SmoothControl::set_range(float d, float t)
53 if(d<0 || (t>=0 && d>=t))
54 throw invalid_argument("SmoothControl::set_range");
59 void SmoothControl::pair(SmoothControl *ctrl)
66 SmoothControl *old_pair = paired_ctrl;
74 paired_ctrl->pair(this);
77 void SmoothControl::on_press()
79 on_motion(1, 1-value);
82 void SmoothControl::on_release()
88 void SmoothControl::on_motion(float v, float r)
90 float old_value = value;
105 value /= threshold-dead_zone;
108 if(value && !old_value)
110 else if(!value && old_value)
113 signal_motion.emit(value);
115 if(paired_ctrl && (v>0 || (v==0 && paired_ctrl->value!=0)))
116 paired_ctrl->on_motion(-v, -r);