(root)/wip/src/beat2value.cc - Rev 648
Rev 315 |
Rev 821 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
* beat2value.cc
* DIN Is Noise is copyright (c) 2006-2018 Jagannathan Sampath
* For more information, please visit http://dinisnoise.org/
*/
#include "beat2value.h"
#include "console.h"
#include "utils.h"
#include "log.h"
#include <string>
using namespace std;
beat2value::beat2value (const string& n, const string& c) : name (n), crvname (c), crv (c) { setup (); }
void beat2value::setup () {
dlog << "*** setting up beat2value: " << name;
now = 0;
delta = 0;
min_bpm = 0;
bpm = 45;
set_bpm (bpm);
style = "loop";
xmin = &_loopmin;
xmax = &_loopmax;
sol (&crv);
dlog << ", complete +++" << endl;
}
beat2value::~beat2value () {
crv.save (crvname);
dlog << "--- destroyed beat2value: " << name << " ---" << endl;
}
int beat2value::gen_and_mix (float* soln, float* mixb, float* mixa, int n) {
sol (now, delta, n, soln, *xmin, *xmax);
if (mixer.active) {
mixer.gen_mix (mixb, n, *xmin, *xmax);
mixer.do_mix (soln, mixb, mixa, n);
}
return mixer.active;
}
int beat2value::modulate_and_mix (float* in, float* mixb, float* mixa, int n, float depth) {
sol (now, delta, n, in, *xmin, *xmax);
multiply (in, n, depth);
if (mixer.active) {
mixer.gen_mix (mixb, n, *xmin, *xmax);
multiply (mixb, n, depth);
mixer.do_mix (in, mixb, mixa, n);
}
return mixer.active;
}
int beat2value::modulate_and_mix (float* in, float* mixb, float* mixa, int n, float* depth) {
sol (now, delta, n, in, *xmin, *xmax);
multiply (in, depth, n);
if (mixer.active) {
mixer.gen_mix (mixb, n, *xmin, *xmax);
multiply (mixb, depth, n);
mixer.do_mix (in, mixb, mixa, n);
}
return mixer.active;
}
float beat2value::set_bpm (float n) { // check and set bpm and return bpm
if (n < min_bpm) n = min_bpm;
bpm = n;
float bps = bpm / 60.0f; // beats per sec
// calculate delta for use in solvers
int sgn = 1; if (delta < 0) sgn = -1;
extern int SAMPLE_RATE;
delta = sgn * bps * 1.0f / SAMPLE_RATE;
return bpm;
}
float beat2value::get_bpm () {
return bpm;
}
void beat2value::set_mix (multi_curve& crv) {
mixer.setup (crv, now, delta);
}