summaryrefslogtreecommitdiff
path: root/src/keyVar.cpp
diff options
context:
space:
mode:
authorTim Redfern <tim@sendak.local>2011-12-19 13:37:11 +0000
committerTim Redfern <tim@sendak.local>2011-12-19 13:37:11 +0000
commitf96ac8a05c915832c0efe5e70264245fca15b33e (patch)
tree366fea81a62199fb5d0521c91fe6e0c9bd2243e0 /src/keyVar.cpp
linux osx project initial
Diffstat (limited to 'src/keyVar.cpp')
-rw-r--r--src/keyVar.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/keyVar.cpp b/src/keyVar.cpp
new file mode 100644
index 0000000..ca64b7f
--- /dev/null
+++ b/src/keyVar.cpp
@@ -0,0 +1,47 @@
+/*
+ * keyvar.cpp
+
+ generalised cushioned keyboard controller
+ */
+
+#include "keyVar.h"
+
+void keyVar::set(char _keyInc,char _keyDec,float _val,float _speed,float _accel,float _accelTime){
+ keyInc=_keyInc;
+ keyDec=_keyDec;
+ val=_val; //initial value
+ speed=_speed;
+ accel=_accel;
+ accelTime=_accelTime;
+ state=0;
+ timePressed=timeCalc=0;
+}
+void keyVar::keyPressed(char _key){
+ //need to deal with key repeat: OSX anyway
+ if (_key==keyInc&&state!=1) {
+ state=1;
+ timePressed=timeCalc=ofGetElapsedTimef();
+ printf("pressed %i\n",_key);
+ }
+ if (_key==keyDec&&state!=-1) {
+ state=-1;
+ timePressed=timeCalc=ofGetElapsedTimef();
+ printf("pressed %i\n",_key);
+ }
+}
+void keyVar::keyReleased(char _key){
+ if (_key==keyInc&&state==1) {
+ state=0;
+ printf("released %i\n",_key);
+ }
+ if (_key==keyDec&&state==-1) {
+ state=0;
+ printf("released %i\n",_key);
+ }
+}
+float keyVar::getVal(){
+ float segment = min(1.0f,(ofGetElapsedTimef()-timePressed)/accelTime);
+ if (state) val+=pow(segment,accel)*(ofGetElapsedTimef()-timeCalc)*speed*state;
+ timeCalc=ofGetElapsedTimef();
+ return val;
+} \ No newline at end of file