fixed random oscillator mode
This commit is contained in:
@@ -3,6 +3,7 @@ class Oscillator {
|
||||
int spawnMillis;
|
||||
int pauseMillis;
|
||||
int beatCount = 0;
|
||||
int[] possibleModes;
|
||||
int mode;
|
||||
|
||||
//int function; //function to be called by bang-oscillators
|
||||
@@ -12,8 +13,10 @@ class Oscillator {
|
||||
float high = 1.0;
|
||||
boolean playing, pause, valInvert;
|
||||
|
||||
Oscillator(float bpm_) {
|
||||
Oscillator(float bpm_, int[] osciModes_) {
|
||||
bpm(bpm_);
|
||||
possibleModes = osciModes_;
|
||||
mode = possibleModes[int(random(possibleModes.length))];
|
||||
play();
|
||||
}
|
||||
|
||||
@@ -51,15 +54,20 @@ class Oscillator {
|
||||
value = 0;
|
||||
}
|
||||
|
||||
|
||||
boolean beat = false;
|
||||
void update() {
|
||||
if (playing) {
|
||||
while (millis() - spawnMillis > speed*beatCount) {
|
||||
beat = true;
|
||||
beatCount++;
|
||||
if (random(1) > .5) {
|
||||
mode = possibleModes[int(random(possibleModes.length))];
|
||||
bpm(int(random(2, 20)));
|
||||
}
|
||||
}
|
||||
|
||||
float millisToBeat = millis() - spawnMillis - (speed*beatCount);
|
||||
position = map(-millisToBeat, speed, 0, 0, TWO_PI);
|
||||
position = map(-millisToBeat, speed, 0, 0, TWO_PI); //position in time between last beat and next beat
|
||||
|
||||
switch(mode) {
|
||||
case(SINE):
|
||||
@@ -105,16 +113,19 @@ class Oscillator {
|
||||
else if (sin(position) >= 1.6666666666) value = 1.6666666666;
|
||||
value *= 1.5;
|
||||
break;
|
||||
case(RANDOM):
|
||||
//value = random(-1,1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
value = constrain(value, -1.0, 1.0);
|
||||
|
||||
value = map(value, -1.0, 1.0, low, high);
|
||||
//value = valInvert? map(value, 1.0, -1.0, low, high) : map(value, -1.0, 1.0, low, high);
|
||||
if (mode != RANDOM) {
|
||||
value = constrain(value, -1.0, 1.0);
|
||||
value = map(value, -1.0, 1.0, low, high);
|
||||
} else if (beat && mode == RANDOM) {
|
||||
beat = false;
|
||||
value = random(low, high);
|
||||
}
|
||||
}
|
||||
|
||||
//fill(0);
|
||||
//ellipse(inc, height/2+value*height/4, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user