cleaned up, added record button

This commit is contained in:
2022-06-23 00:26:10 +02:00
parent fa596c9f18
commit e2b94e116d
8 changed files with 234 additions and 276 deletions

View File

@@ -1,51 +1,52 @@
//contains the GUI (ie CP5) in the secondapplet. also contains 3 classes: shaderManager, Brick and Slider
PImage bin;
final static int INTVAL = 100;
final static int FLOATVAL = 101;
public class SecondApplet extends PApplet {
ControlP5 cp5;
final static int SINE = 0; //add 0.25 to phase to get cos
final static int SAWTOOTH = 1;
final static int SAWTOOTHINVERSE = 2;
final static int SQUARE = 3; //switches between -1 and 1, that's all
final static int TRIANGLE = 4;
final static int TAN = 5;
final static int TANINVERSE = 6;
final static int RAMP = 7; //line for half the sequence up to 1, then stay at 1 for the other half
final static int RAMPINVERSE = 8; //line for half the sequence up to 1, then stay at 1 for the other half
final static int RAMPUPDOWN = 9; //line up, stay, line down, stay
final static int RANDOM = 10;
final static int RANDOMIZE_ALL = 777; //not for wave-generation. meant for low frequency oscillator that calls a function after every beat
String availableFx[] = {
"fxASDFPixelSort",
"fxDistorter",
"fxWahWah",
"fxAuEcho",
"fxPhaser",
"fxWZIP",
"fxDarker",
"fxBrighter",
"fxMove",
"fxScale",
"fxEpilepsy",
"fxPosterize",
"fxCopyZoom",
"fxDual",
"fxScanker",
"fxPixelSort",
"fxHSB",
"fxEcho",
"fxSubtleSort",
"fxBlackWhite",
"fxDrawGenerative",
"fxDrawStrokes",
"fxFM",
"fxGrauzone",
"fxSlitScan"
};
shaderManager shaderManager = new shaderManager();
ArrayList<Shader> shaderList = new ArrayList<Shader>();
ArrayList<Brick> bricks = new ArrayList<Brick>();
ArrayList<Slider> slider = new ArrayList<Slider>(); //brick
public void settings() {
size(275, 500);
}
public void setup() {
surface.setLocation(285, 240);
List l = Arrays.asList(availableFx);
cp5 = new ControlP5(this);
cp5.addScrollableList("")
.setPosition(10, height-110)
.setSize(80, 100)
.setBarHeight(0)
.setItemHeight(20)
.plugTo(this, "CP5_listActions")
.addItems(l)
.setType(ControlP5.LIST);
cp5.addToggle("rec")
.setPosition(100, height-50)
.setSize(20,20)
.plugTo(this, "CP5_recordAction");
}
void CP5_recordAction(){
recording = !recording;
}
public void draw() {
background(68, 68, 68);
image(bin, width-55, height-85, 40, 40);
stroke(255);
strokeWeight(1);
line(0, height-120, width, height-120);
for (int i = 0; i < shaderList.size(); i++) {
bricks.get(i).update();
bricks.get(i).display();
}
}
class shaderManager {
void addShader(Shader shader) {
shaderList.add(shader);
@@ -59,8 +60,8 @@ public class SecondApplet extends PApplet {
Collections.swap(bricks, pos1, pos2);
shaderList.get(pos1).pos = pos1;
shaderList.get(pos2).pos = pos2;
bricks.get(pos1).setPosition(pos1);
bricks.get(pos2).setPosition(pos2);
bricks.get(pos1).pos = pos1;
bricks.get(pos2).pos = pos2;
}
}
void removeShader(int pos) {
@@ -68,7 +69,7 @@ public class SecondApplet extends PApplet {
shaderList.remove(pos);
bricks.remove(pos);
for (int i = shaderList.size()-1; i > -1; i--) {
bricks.get(i).setPosition(i);
bricks.get(i).pos = i;
shaderList.get(i).pos = i;
}
}
@@ -82,19 +83,16 @@ public class SecondApplet extends PApplet {
}
}
ArrayList<Shader> shaderList = new ArrayList<Shader>();
ArrayList<Brick> bricks = new ArrayList<Brick>();
class Brick {
ArrayList<Slider> slider = new ArrayList<Slider>();
ArrayList<Param> params = new ArrayList<Param>();
int position;
int pos;
Brick(int position_, ArrayList params_) {
position = position_;
Brick(int pos_, ArrayList params_) {
pos = pos_;
params = params_;
for (int i = 0; i < params.size(); i++) {
slider.add(new Slider(10, 10+20*i+position*75, 230, 12, params.get(i).minValue, params.get(i).maxValue, params.get(i).name, params.get(i).type)); //add possible waves to slider
slider.add(new Slider(10, 10+20*i+pos*75, 230, 12, params.get(i).minValue, params.get(i).maxValue, params.get(i).name, params.get(i).type)); //add possible waves to slider
}
}
@@ -119,8 +117,6 @@ public class SecondApplet extends PApplet {
}
}
ArrayList<Slider> slider;
int pressedSlider = -1;
class Slider {
@@ -221,64 +217,8 @@ public class SecondApplet extends PApplet {
}
}
public void settings() {
size(275, 500);
}
public void setup() {
slider = new ArrayList<Slider>(); //brick
cp5 = new ControlP5(this);
List l = Arrays.asList(availableFx);
cp5.addScrollableList("")
.setPosition(10, height-110)
.setSize(80, 100)
.setBarHeight(0)
.setItemHeight(20)
.plugTo(this, "liste")
.addItems(l)
.setType(ControlP5.LIST);
surface.setLocation(285, 240);
//surface.setSize(1000,100);
//testslider = new Slider(10, 10, 230, 15, 0, 5, "testslider", INTVAL);
randomizer = new Oscillator(5); //every 12 seconds;
randomizer.mode = RANDOMIZE_ALL;
}
public void draw() {
background(68, 68, 68);
image(bin, width-55, height-85, 40, 40);
stroke(255);
strokeWeight(1);
line(0, height-120, width, height-120);
randomizer.update();
//this goes to bricks
for (int i = 0; i < shaderList.size(); i++) {
bricks.get(i).update();
bricks.get(i).display();
//for (int j = 0; j < fxList.get(i).shader.params.size(); j++) {
//Slider s = fxList.get(i).shader.params.get(i);
//}
}
}
//CP5
void liste(int n) {
void CP5_listActions(int n) {
if (shaderList.size() < maxFx) {
switch(n) {
case(0):
@@ -364,143 +304,6 @@ public class SecondApplet extends PApplet {
}
}
class Oscillator {
float speed; //in milliseconds
int spawnMillis;
int pauseMillis;
int beatCount = 0;
int mode;
//int function; //function to be called by bang-oscillators
float position; // between 0 and TWO_PI
float value; // is returned, constrained between "low" and "high"
float low = -1.0;
float high = 1.0;
boolean playing, pause, valInvert;
Oscillator(float bpm_) {
bpm(bpm_);
play();
}
void amplitude(float low_, float high_) {
low = low_;
high = high_;
}
void frequency(float hertz_) {
speed = 1000/hertz_;
}
void bpm(float bpm_) {
speed = int(60 / bpm_ * 1000);
}
void play() {
if (pause) {
float pauseTime = millis() - pauseMillis;
spawnMillis += pauseTime;
pause = false;
} else if (!playing) {
spawnMillis = millis();
}
playing = true;
}
void pause() {
if (playing) {
pauseMillis = millis();
pause = true;
playing = false;
}
}
void stop() {
beatCount = 0;
playing = false;
value = 0;
}
void update() {
if (playing) {
while (millis() - spawnMillis > speed*beatCount) {
beatCount++;
if (mode == RANDOMIZE_ALL) randomize_all();
}
float millisToBeat = millis() - spawnMillis - (speed*beatCount);
position = map(-millisToBeat, speed, 0, 0, TWO_PI);
switch(mode) {
case(SINE):
value = sin(position);
break;
case(SAWTOOTH):
value = ((position % TWO_PI)-PI)/PI;
break;
case(SAWTOOTHINVERSE):
value = (((position % TWO_PI)-PI)/PI)*-1;
break;
case(SQUARE):
value = sin(position > PI ? 1 : -1);
break;
case(TRIANGLE):
value = position-PI < 0 ? ((position % TWO_PI)-PI)/PI : (((position % TWO_PI)-PI)/PI)*-1;
value+=0.5;
value*=2;
if (value == 3.0) value = -1;
break;
case(TAN):
value = tan(position);
break;
case(TANINVERSE):
value = tan(position)*-1;
break;
case(RAMP):
value = sin(position) > 0 ? ((position % TWO_PI)-PI)/PI : 0;
value+=0.5;
value*=2;
if (value == 3.0) value = -1;
break;
case(RAMPINVERSE):
value = sin(position) > 0 ? ((position % TWO_PI)-PI)/PI : 0;
value+=0.5;
value*=2;
if (value == 3.0) value = -1;
value = value*-1;
break;
case(RAMPUPDOWN):
if (sin(position) <= -1.6666666666) value = -1.6666666666;
else if (sin(position) < 1.6666666666 && sin(position) > -1.6666666666) value = sin(position);
else if (sin(position) >= 1.6666666666) value = 1.6666666666;
value *= 1.5;
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);
}
//fill(0);
//ellipse(inc, height/2+value*height/4, 1, 1);
}
}
void randomize_all() {
for (int i = slider.size()-1; i >= 0; i--) {
Slider s = slider.get(i);
if (random(1) > .5) s.osci.mode = int(round(random(9)));
if (random(1) > .5) s.osci.play();
else pause();
if (random(1) > .5) s.osci.bpm(random(2, 10));
}
}
void mousePressed() {
for (int i = slider.size()-1; i >= 0; i--) {
Slider s = slider.get(i);