if(!state)
{
state = true;
+ rising_edge = true;
signal_press.emit();
}
}
if(state)
{
state = false;
+ falling_edge = true;
signal_release.emit();
}
}
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();
Control::Control():
capture_dev(0),
activator(0),
- origin(0)
+ origin(0),
+ rising_edge(false),
+ falling_edge(false)
{ }
Control::Control(const ControlSource &s):
src(s),
capture_dev(0),
activator(0),
- origin(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),
- origin(0)
+ origin(0),
+ rising_edge(false),
+ falling_edge(false)
{
connect_signals();
}
connect_signals();
}
+void Control::reset_edges()
+{
+ rising_edge = false;
+ falling_edge = false;
+}
+
void Control::connect_signals()
{
switch(src.type)
Device *capture_dev;
BinaryControl *activator;
float origin;
+ bool rising_edge;
+ bool falling_edge;
Control();
Control(const ControlSource &);
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;
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)
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)))