Rev 13 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
* fader.cc
* DIN Is Noise is copyright (c) 2006-2017 Jagannathan Sampath
* For more information, please visit http://dinisnoise.org/
*/
#include "fader.h"
#include "console.h"
#include "chrono.h"
#include "log.h"
fader::fader (float vs, float ve) {
set (vs, ve, 0);
}
void fader::set (float vs, float ve, int _on, float dt) {
start = vs;
end = ve;
delta = end - start;
if (delta < 0) flip = 1; else flip = 0;
alpha = 0;
amount = start;
delta_time = dt;
on = _on;
reached = !on;
start_time = ui_clk();
}
int fader::eval () {
if (on) {
double dt = ui_clk() - start_time;
if (dt >= delta_time) {
if (reached) {
on = 0;
if (post != "") {
cons (post);
post = "";
}
} else {
reached = 1;
alpha = 1;
}
} else alpha = dt * 1.0f / delta_time;
if (flip) amount = 1 - alpha; else amount = alpha;
}
return on;
}
void fader::restart () {
on = 1;
reached = 0;
alpha = 0;
start_time = ui_clk();
}
void fader::set_post (const std::string& pst) {
post = pst;
}
float fader::value () {
return (start + alpha * delta);
}