]> git.tdb.fi Git - libs/gui.git/blob - source/input/binarycontrol.cpp
70a816570fb2d33bcc697ec52fe1fe770cd19147
[libs/gui.git] / source / input / binarycontrol.cpp
1 #include "binarycontrol.h"
2 #include "device.h"
3
4 namespace Msp {
5 namespace Input {
6
7 BinaryControl::BinaryControl():
8         state(false),
9         threshold(0.5)
10 { }
11
12 BinaryControl::BinaryControl(const ControlSource &s):
13         Control(s),
14         state(false),
15         threshold(0.5)
16 { }
17
18 BinaryControl::BinaryControl(Device &d, ControlSrcType t, unsigned i):
19         Control(d, t, i),
20         state(false),
21         threshold(0.5)
22 { }
23
24 void BinaryControl::set_threshold(float t)
25 {
26         threshold=t;
27 }
28
29 void BinaryControl::on_press()
30 {
31         if(!state)
32         {
33                 state=true;
34                 signal_press.emit();
35         }
36 }
37
38 void BinaryControl::on_release()
39 {
40         if(state)
41         {
42                 state=false;
43                 signal_release.emit();
44         }
45 }
46
47 void BinaryControl::on_motion(float value, float)
48 {
49         if(value>threshold)
50                 on_press();
51         else
52                 on_release();
53 }
54
55 } // namespace Input
56 } // namespace Msp