This offers a way to reliably tell if a control was actuated for
applications which don't want to use the signal interface.
if(!state)
{
state = true;
if(!state)
{
state = true;
if(state)
{
state = false;
if(state)
{
state = false;
signal_release.emit();
}
}
signal_release.emit();
}
}
void set_threshold(float);
bool get_state() const { return state; }
void set_threshold(float);
bool get_state() const { return state; }
+ bool was_pressed() const { return rising_edge; }
+ bool was_released() const { return falling_edge; }
private:
virtual void on_press();
private:
virtual void on_press();
Control::Control():
capture_dev(0),
activator(0),
Control::Control():
capture_dev(0),
activator(0),
+ origin(0),
+ rising_edge(false),
+ falling_edge(false)
{ }
Control::Control(const ControlSource &s):
src(s),
capture_dev(0),
activator(0),
{ }
Control::Control(const ControlSource &s):
src(s),
capture_dev(0),
activator(0),
+ origin(0),
+ rising_edge(false),
+ falling_edge(false)
{ }
Control::Control(Device &d, ControlSrcType t, unsigned i):
src(d, t, i),
capture_dev(0),
activator(0),
{ }
Control::Control(Device &d, ControlSrcType t, unsigned i):
src(d, t, i),
capture_dev(0),
activator(0),
+ origin(0),
+ rising_edge(false),
+ falling_edge(false)
+void Control::reset_edges()
+{
+ rising_edge = false;
+ falling_edge = false;
+}
+
void Control::connect_signals()
{
switch(src.type)
void Control::connect_signals()
{
switch(src.type)
Device *capture_dev;
BinaryControl *activator;
float origin;
Device *capture_dev;
BinaryControl *activator;
float origin;
+ bool rising_edge;
+ bool falling_edge;
Control();
Control(const ControlSource &);
Control();
Control(const ControlSource &);
const ControlSource &get_source() const { return src; }
void set_activator(BinaryControl *);
BinaryControl *get_activator() const { return activator; }
const ControlSource &get_source() const { return src; }
void set_activator(BinaryControl *);
BinaryControl *get_activator() const { return activator; }
+ bool has_rising_edge() const { return rising_edge; }
+ bool has_falling_edge() const { return falling_edge; }
+ void reset_edges();
protected:
virtual void on_press() = 0;
virtual void on_release() = 0;
protected:
virtual void on_press() = 0;
virtual void on_release() = 0;
void SmoothControl::on_motion(float v, float r)
{
void SmoothControl::on_motion(float v, float r)
{
+ float old_value = value;
if(v<-dead_zone)
value = v+dead_zone;
else if(v>dead_zone)
if(v<-dead_zone)
value = v+dead_zone;
else if(v>dead_zone)
value /= threshold-dead_zone;
}
value /= threshold-dead_zone;
}
+ if(value && !old_value)
+ rising_edge = true;
+ else if(!value && old_value)
+ falling_edge = true;
+
signal_motion.emit(value);
if(paired_ctrl && (v>0 || (v==0 && paired_ctrl->value!=0)))
signal_motion.emit(value);
if(paired_ctrl && (v>0 || (v==0 && paired_ctrl->value!=0)))