Browse Source

proper brick and gui scaling, minbpm/maxbpm

master
Victor Giers 2 years ago
parent
commit
768dc4df83
3 changed files with 57 additions and 16 deletions
  1. 1
    1
      data/saves.sav
  2. 6
    1
      oscillator.pde
  3. 50
    14
      secondapplet.pde

+ 1
- 1
data/saves.sav View File

//globals //globals
uptime = 116628228
uptime = 116631667

+ 6
- 1
oscillator.pde View File

float value; // is returned, constrained between "low" and "high" float value; // is returned, constrained between "low" and "high"
float low = -1.0; float low = -1.0;
float high = 1.0; float high = 1.0;
float minBPM, maxBPM;
boolean playing, pause, valInvert; boolean playing, pause, valInvert;


Oscillator(float bpm_, int[] osciModes_) { Oscillator(float bpm_, int[] osciModes_) {
minBPM = 5;
maxBPM = 15;
bpm(bpm_); bpm(bpm_);
possibleModes = osciModes_; possibleModes = osciModes_;
mode = possibleModes[int(random(possibleModes.length))]; mode = possibleModes[int(random(possibleModes.length))];
play(); play();
} }


void amplitude(float low_, float high_) { void amplitude(float low_, float high_) {
beatCount++; beatCount++;
if (random(1) > .5) { if (random(1) > .5) {
mode = possibleModes[int(random(possibleModes.length))]; mode = possibleModes[int(random(possibleModes.length))];
bpm(int(random(2, 20)));
bpm(random(minBPM, maxBPM));
} }
} }



+ 50
- 14
secondapplet.pde View File

ArrayList<Slider> slider = new ArrayList<Slider>(); //brick ArrayList<Slider> slider = new ArrayList<Slider>(); //brick


public void settings() { public void settings() {
size(275, 500);
size(275, 120);
} }


public void setup() { public void setup() {
.setType(ControlP5.LIST); .setType(ControlP5.LIST);
cp5.addToggle("rec") cp5.addToggle("rec")
.setPosition(100, height-50) .setPosition(100, height-50)
.setSize(20,20)
.setSize(20, 20)
.plugTo(this, "CP5_recordAction"); .plugTo(this, "CP5_recordAction");
} }
void CP5_recordAction(){
void CP5_recordAction() {
recording = !recording; recording = !recording;
} }


int totalBrickHeight;
public void draw() { public void draw() {
background(68, 68, 68); background(68, 68, 68);
image(bin, width-55, height-85, 40, 40); image(bin, width-55, height-85, 40, 40);
stroke(255); stroke(255);
strokeWeight(1); strokeWeight(1);
line(0, height-120, width, height-120); line(0, height-120, width, height-120);
totalBrickHeight = 0;
for (int i = 0; i < shaderList.size(); i++) { for (int i = 0; i < shaderList.size(); i++) {
bricks.get(i).update(); bricks.get(i).update();
bricks.get(i).display(); bricks.get(i).display();
totalBrickHeight+= bricks.get(i).h;
} }
} }


void refreshSurface() {
surface.setSize(width, height+bricks.get(shaderList.size()-1).h);
cp5.setPosition(0, height-120);
}

class shaderManager { class shaderManager {
void addShader(Shader shader) { void addShader(Shader shader) {
shaderList.add(shader); shaderList.add(shader);
shader.pos = shaderList.size()-1; shader.pos = shaderList.size()-1;
bricks.add(new Brick(shaderList.size()-1, shaderList.get(shaderList.size()-1).params));
bricks.add(new Brick(shaderList.size()-1, shaderList.get(shaderList.size()-1).params, shader.name));
refreshSurface();
println("Added " + shader + " to fxList at spot. List length: " + shaderList.size()); println("Added " + shader + " to fxList at spot. List length: " + shaderList.size());
} }
void swapShader(int pos1, int pos2) { void swapShader(int pos1, int pos2) {
bricks.get(i).pos = i; bricks.get(i).pos = i;
shaderList.get(i).pos = i; shaderList.get(i).pos = i;
} }
refreshSurface();
} }
} }
void applyShader() { void applyShader() {
class Brick { class Brick {
ArrayList<Slider> slider = new ArrayList<Slider>(); ArrayList<Slider> slider = new ArrayList<Slider>();
ArrayList<Param> params = new ArrayList<Param>(); ArrayList<Param> params = new ArrayList<Param>();
boolean dragHovered;
color brickBGcol;
int pos; int pos;
int h;
String name;


Brick(int pos_, ArrayList params_) {
Brick(int pos_, ArrayList params_, String name_) {
name = name_;
pos = pos_; pos = pos_;
params = params_; params = params_;

h = 20 + params.size() * 20;
for (int i = 0; i < params.size(); i++) { for (int i = 0; i < params.size(); i++) {
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, params.get(i).osciModes)); //add possible waves to slider
slider.add(new Slider(10, 20+(20*i)+totalBrickHeight, 230, 12, params.get(i).minValue, params.get(i).maxValue, params.get(i).name, params.get(i).type, params.get(i).osciModes)); //add possible waves to slider
} }
println(totalBrickHeight + " " + h);
} }


void exchangeSlider(int sliderNo, Param param) { void exchangeSlider(int sliderNo, Param param) {
slider.get(i).update(); slider.get(i).update();
params.get(i).value = slider.get(i).value; params.get(i).value = slider.get(i).value;
} }
brickBGcol = color(85, 85, 85);
} }


void display() { void display() {
noStroke();
fill(brickBGcol);
rect(0, totalBrickHeight, width, h);

fill(255);
text(name, 10, 10+totalBrickHeight, 10);

for (int i = 0; i < slider.size(); i++) { for (int i = 0; i < slider.size(); i++) {
slider.get(i).display(); slider.get(i).display();
} }

stroke(150);
strokeWeight(1+int(dragHovered)*2);
line(0, totalBrickHeight+h-1, width, totalBrickHeight+h-1);
} }
} }


int pressedSlider = -1; int pressedSlider = -1;


//class Slider extends Brick{
class Slider { class Slider {
int x, y, w, h, mode; int x, y, w, h, mode;
int[] osciModes; int[] osciModes;
float minVal, maxVal, value; //should be private but doesnt work lol float minVal, maxVal, value; //should be private but doesnt work lol
boolean hovering, hovering_anim_btn, animated, randomized;
boolean hovering, hovering_anim_btn, animated;
String label; String label;
Oscillator osci; Oscillator osci;


mode = mode_; mode = mode_;
label = label_ + (mode == INTVAL ? " (INT)" : " (FLOAT)"); label = label_ + (mode == INTVAL ? " (INT)" : " (FLOAT)");
osciModes = osciModes_; osciModes = osciModes_;
osci = new Oscillator(int(random(2, 20)), osciModes);
osci = new Oscillator(int(random(5, 15)), osciModes);
osci.amplitude(minVal, maxVal); osci.amplitude(minVal, maxVal);


animated = true; animated = true;
randomized = true;


slider.add(this); slider.add(this);
} }
} }


void update() { void update() {



osci.update(); osci.update();


if (animated) { if (animated) {
} }


void display() { void display() {

stroke(255);
fill(100+(40*int(hovering))); fill(100+(40*int(hovering)));
rect(x, y, w, h); rect(x, y, w, h);
fill(185+(40*int(hovering))); fill(185+(40*int(hovering)));
rect(x, y, map(value, minVal, maxVal, 0, w), h); rect(x, y, map(value, minVal, maxVal, 0, w), h);
fill(255); fill(255);
text(label, x+5, y+10, 10);
text(label, x+5, y+7);


if (animated) { if (animated) {
fill(185+(40*int(hovering_anim_btn))); fill(185+(40*int(hovering_anim_btn)));
} else { } else {
fill(100+(40*int(hovering_anim_btn))); fill(100+(40*int(hovering_anim_btn)));
} }
rect(x+w+5, y, 15, 15);
rect(x+w+5, y, h, h);
} }
} }



Loading…
Cancel
Save