Created
October 17, 2013 09:23
-
-
Save loveandsheep/7021830 to your computer and use it in GitHub Desktop.
simple time measure class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "littleTimeSequencer.h" | |
void littleTimeSequencer::setup(float duration, bool bLoop) | |
{ | |
targDuration = duration; | |
isPlaying = false; | |
isPause = false; | |
isLoop = bLoop; | |
} | |
void littleTimeSequencer::start() | |
{ | |
bangTime = ofGetElapsedTimef(); | |
passTime = 0.0; | |
isPlaying = true; | |
isPause = false; | |
} | |
void littleTimeSequencer::setPause(bool bPause) | |
{ | |
isPause = bPause; | |
} | |
void littleTimeSequencer::reset() | |
{ | |
passTime = 0.0; | |
isPlaying = false; | |
isPause = true; | |
} | |
float littleTimeSequencer::getPctCubic(bool flip) | |
{ | |
if (flip) | |
{ | |
return pow(getPctLinear(false),1.0f/2.0f); | |
}else{ | |
return pow(getPctLinear(false),2.0f); | |
} | |
} | |
float littleTimeSequencer::getPctQuart(bool flip) | |
{ | |
if (flip) | |
{ | |
return pow(getPctLinear(false),1.0f/4.0f); | |
} | |
else | |
{ | |
return pow(getPctLinear(false),4.0f); | |
} | |
} | |
float littleTimeSequencer::getPctQuint(bool flip) | |
{ | |
if (flip) | |
{ | |
return pow(getPctLinear(false),1.0f/5.0f); | |
} | |
else | |
{ | |
return pow(getPctLinear(false),5.0f); | |
} | |
} | |
float littleTimeSequencer::getPctSigmoid() | |
{ | |
float x = (getPctLinear(false)-0.5)*20; | |
return 1 / (1 + pow(2.71828182846f,-x)); | |
} | |
float littleTimeSequencer::getPctLinear(bool flip) | |
{ | |
update(); | |
if (flip) | |
{ | |
return 1.0 - passTime / targDuration; | |
} | |
else | |
{ | |
return passTime / targDuration; | |
} | |
} | |
float littleTimeSequencer::getCurrentTime(){ | |
update(); | |
return passTime; | |
} | |
void littleTimeSequencer::update() | |
{ | |
if (isPause) | |
{ | |
bangTime = ofGetElapsedTimef() - passTime; | |
isPlaying = true; | |
} | |
else | |
{ | |
passTime = ofGetElapsedTimef() - bangTime; | |
isPlaying = true; | |
} | |
if (isLoop) | |
{ | |
passTime = passTime - (int)(passTime/targDuration)*targDuration; | |
isPlaying = true; | |
} | |
else | |
{ | |
if (passTime > targDuration) | |
{ | |
passTime = targDuration; | |
isPlaying = false; | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofMain.h" | |
class littleTimeSequencer{ | |
public: | |
void setup(float duration,bool bLoop); | |
void update(); | |
void start(); | |
void setPause(bool bPause); | |
void reset(); | |
float getPctLinear(bool flip); | |
float getPctCubic(bool flip); | |
float getPctQuart(bool flip); | |
float getPctQuint(bool flip); | |
float getPctSigmoid(); | |
float getCurrentTime(); | |
protected: | |
float currentTime; | |
float bangTime; | |
float passTime; | |
float targDuration; | |
bool isPlaying; | |
bool isPause; | |
bool isLoop; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment