+#include <stdexcept>
#include "smoothcontrol.h"
+using namespace std;
+
namespace Msp {
namespace Input {
void SmoothControl::set_dead_zone(float d)
{
+ if(d<0 || (threshold>0 && d>=threshold))
+ throw invalid_argument("SmoothControl::set_dead_zone");
dead_zone = d;
}
void SmoothControl::set_threshold(float t)
{
+ if(t>=0 && t<=dead_zone)
+ throw invalid_argument("SmoothControl::set_threshold");
+ threshold = t;
+}
+
+void SmoothControl::set_range(float d, float t)
+{
+ if(d<0 || (t>=0 && d>=t))
+ throw invalid_argument("SmoothControl::set_range");
+ dead_zone = d;
threshold = t;
}
void SmoothControl::on_motion(float v, float r)
{
- if(v<-threshold)
- value = -1;
- else if(v>threshold)
- value = 1;
- else if(v<-dead_zone)
- value = (v+dead_zone)/(threshold-dead_zone);
+ if(v<-dead_zone)
+ value = v+dead_zone;
else if(v>dead_zone)
- value = (v-dead_zone)/(threshold-dead_zone);
+ value = v-dead_zone;
else
value = 0;
+ if(threshold>=0)
+ {
+ if(v<-threshold)
+ value = -1;
+ else if(v>threshold)
+ value = 1;
+ else
+ value /= threshold-dead_zone;
+ }
+
signal_motion.emit(value);
if(paired_ctrl && (v>0 || (v==0 && paired_ctrl->value!=0)))