1 #include "smoothcontrol.h"
9 SmoothControl::SmoothControl(const ControlSource &s):
13 SmoothControl::SmoothControl(Device &d, ControlSrcType t, unsigned i):
17 SmoothControl::~SmoothControl()
22 void SmoothControl::set_dead_zone(float d)
24 if(d<0 || (threshold>0 && d>=threshold))
25 throw invalid_argument("SmoothControl::set_dead_zone");
29 void SmoothControl::set_threshold(float t)
31 if(t>=0 && t<=dead_zone)
32 throw invalid_argument("SmoothControl::set_threshold");
36 void SmoothControl::set_range(float d, float t)
38 if(d<0 || (t>=0 && d>=t))
39 throw invalid_argument("SmoothControl::set_range");
44 void SmoothControl::pair(SmoothControl *ctrl)
51 SmoothControl *old_pair = paired_ctrl;
52 paired_ctrl = nullptr;
53 old_pair->pair(nullptr);
59 paired_ctrl->pair(this);
62 void SmoothControl::on_press()
64 on_motion(1, 1-value);
67 void SmoothControl::on_release()
73 void SmoothControl::on_motion(float v, float r)
75 float old_value = value;
90 value /= threshold-dead_zone;
93 if(value && !old_value)
95 else if(!value && old_value)
98 signal_motion.emit(value);
100 if(paired_ctrl && (v>0 || (v==0 && paired_ctrl->value!=0)))
101 paired_ctrl->on_motion(-v, -r);