Hi, I am needing to access variables from different classes in a several tabbed processing program. I do not know how to use the data I am generating in an FFT analysis (inputFFAnalysis) to effect the background variables in main tab that has void setup(). Also, I tried to separate a Knob class (not sure if properly, but does not seem to be throwing errors), which I can also use to effect the base color values for the background. Does anyone know how I can manipulate the code to use the data in separate areas of the program? Thank you!
Below is most of the MAIN tab:
-----------------------------
Tab for Input FFTAnalysis Class:
----------------------
My poor attempt to remove the Knob Class into another tab (though not throwing errors):
-------------------
Below is most of the MAIN tab:
-----------------------------
import krister.Ess.*;
import controlP5.*;
UFDWlib dw;
ControlP5 cp5;
Knob myKnobA;
Knob myKnobB;
Knob myKnobC;
InputFFTAnalysis sound;
Ground myground;
//Tree mytrees[];
int num_of_trees=10;
float camera_angle;
int camera_direction;
int sky_image;
int bg_R;
int bg_G ;
int bg_B ;
void setup () {
dw=new UFDWlib();
//dw.setupComputer(1);
//dw.setup(600,450);
dw.setup(screen.width,screen.height);
PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
GL gl = pgl.gl;
dw.startSetup(gl);
dw.background(0,0,0);
sky_image=dw.loadTexture("sky.png");
//sky_image=dw.loadTexture("Simply_Pastel_Night_Sky_by_Moonchilde_Stock.jpg");
//sky_image=dw.loadTexture("Evening_Sky_Road_by_K_chan009.png");
//sky_image=dw.loadTexture("Moon-580x435.jpg");
camera_angle=0;
camera_direction=1;
smooth();
bg_R = 0;
bg_G = 0;
bg_B = 0;
// start up Ess
Ess.start(this);
sound = new InputFFTAnalysis();
myground=new Ground(dw);
frameRate(25);
//myInput.start();
noStroke();
cp5 = new ControlP5(this);
myKnobA = cp5.addKnob("bg_R")
.setRange(0,255)
.setValue(50)
.setPosition(700,20)
.setRadius(35)
.setViewStyle(Knob.ARC)
.setDragDirection(Knob.VERTICAL)
;
myKnobB = cp5.addKnob("bg_G")
.setRange(0,255)
.setValue(50)
.setPosition(700,115)
.setRadius(35)
.setViewStyle(Knob.ARC)
.setDragDirection(Knob.VERTICAL)
;
myKnobC = cp5.addKnob("bg_B")
.setRange(0,255)
.setValue(50)
.setPosition(700,210)
.setRadius(35)
.setViewStyle(Knob.ARC)
.setDragDirection(Knob.VERTICAL)
;
}
import controlP5.*;
UFDWlib dw;
ControlP5 cp5;
Knob myKnobA;
Knob myKnobB;
Knob myKnobC;
InputFFTAnalysis sound;
Ground myground;
//Tree mytrees[];
int num_of_trees=10;
float camera_angle;
int camera_direction;
int sky_image;
int bg_R;
int bg_G ;
int bg_B ;
void setup () {
dw=new UFDWlib();
//dw.setupComputer(1);
//dw.setup(600,450);
dw.setup(screen.width,screen.height);
PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
GL gl = pgl.gl;
dw.startSetup(gl);
dw.background(0,0,0);
sky_image=dw.loadTexture("sky.png");
//sky_image=dw.loadTexture("Simply_Pastel_Night_Sky_by_Moonchilde_Stock.jpg");
//sky_image=dw.loadTexture("Evening_Sky_Road_by_K_chan009.png");
//sky_image=dw.loadTexture("Moon-580x435.jpg");
camera_angle=0;
camera_direction=1;
smooth();
bg_R = 0;
bg_G = 0;
bg_B = 0;
// start up Ess
Ess.start(this);
sound = new InputFFTAnalysis();
myground=new Ground(dw);
frameRate(25);
//myInput.start();
noStroke();
cp5 = new ControlP5(this);
myKnobA = cp5.addKnob("bg_R")
.setRange(0,255)
.setValue(50)
.setPosition(700,20)
.setRadius(35)
.setViewStyle(Knob.ARC)
.setDragDirection(Knob.VERTICAL)
;
myKnobB = cp5.addKnob("bg_G")
.setRange(0,255)
.setValue(50)
.setPosition(700,115)
.setRadius(35)
.setViewStyle(Knob.ARC)
.setDragDirection(Knob.VERTICAL)
;
myKnobC = cp5.addKnob("bg_B")
.setRange(0,255)
.setValue(50)
.setPosition(700,210)
.setRadius(35)
.setViewStyle(Knob.ARC)
.setDragDirection(Knob.VERTICAL)
;
}
void draw() {
background(bg_R+InputFFTAnalysis.spect_r,bg_G+InputFFTAnalysis.spect_g,bg_B+InputFFTAnalysis.spect_b);
PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
GL gl = pgl.beginGL();
dw.clearFrame(gl);
sound.UpdateData();
//DRAWS THE BACKGROUND
dw.pushMatrix();
dw.resetTransform();
dw.translate(0,-10+camera_angle*70,-200);
dw.image(sky_image,400,400);
dw.popMatrix();
dw.resetDepth();
//DRAWS THE GROUND
myground.draw(sound);
pgl.endGL();
}
void mouseDragged() {
mousePressed();
}
----------------------
background(bg_R+InputFFTAnalysis.spect_r,bg_G+InputFFTAnalysis.spect_g,bg_B+InputFFTAnalysis.spect_b);
PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
GL gl = pgl.beginGL();
dw.clearFrame(gl);
sound.UpdateData();
//DRAWS THE BACKGROUND
dw.pushMatrix();
dw.resetTransform();
dw.translate(0,-10+camera_angle*70,-200);
dw.image(sky_image,400,400);
dw.popMatrix();
dw.resetDepth();
//DRAWS THE GROUND
myground.draw(sound);
pgl.endGL();
}
void mouseDragged() {
mousePressed();
}
Tab for Input FFTAnalysis Class:
----------------------
class InputFFTAnalysis
{
FFT myFFT;
FFT levelFFT;
AudioInput myInput;
int bufferSize;
int steps;
float limitDiff;
int numAverages=32;
float myDamp=.1f;
float maxLimit,minLimit;
int r;
int g;
int b;
float spect_r;
float spect_g;
float spect_b;
float wavesamples[];
float frequency[];
InputFFTAnalysis()
{
// set up our AudioInput
bufferSize=512;
myInput=new AudioInput(bufferSize*4); // 512
// set up our FFT
myFFT=new FFT(bufferSize*2); // 512*2 = 1024
//myFFT=new FFT(bufferSize);
myFFT.equalizer(true);
wavesamples=new float[512];
frequency=new float[512];
levelFFT=new FFT();
// set up our FFT normalization/dampening
minLimit=.005;
maxLimit=.05;
myFFT.limits(minLimit,maxLimit);
myFFT.damp(myDamp); // .1f
myFFT.averages(numAverages); // 32
// get the number of bins per average
steps=bufferSize/numAverages; // 512/32 = 16
// get the distance of travel between minimum and maximum limits
limitDiff=maxLimit-minLimit; // .05 - .005
r = 0;
g = 100;
b = 0;
spect_r = 0;
spect_g = 0;
spect_b = 0;
myInput.start();
}
void UpdateData()
{
// draw the waveform //waveform is how loud the sound is?
stroke(255,0,0); // time it takes for music to start? / length of song? * 512?
int interp=(int)max(0,(((millis()-myInput.bufferStartTime)/(float)myInput.duration)*myInput.size)); // what does this translate to in actuality?
// Does this number change or is it instanitated one time only?
// for example 1 millli sec/ 180 million sec * 512 = .00284
for (int i=0;i<bufferSize;i++) { //for i up to 512
float left=160; // what does the left and right stuff meen?
float right=160;
float wave=0;
if (i+interp+1<myInput.buffer2.length) {
left-=myInput.buffer2[i+interp]*50.0;
right-=myInput.buffer2[i+1+interp]*50.0;
wave-=myInput.buffer2[i+interp]*75.0;
}
wavesamples[i]=wave;
line(10+i,left,11+i,right);
}
myFFT.getSpectrum(myInput); //****HOW do I get this math to equal 1024 instead of 512?****
noStroke();
fill(255,0,0);
// draw the spectrum sound spectrum measures amount of vibration at each individual frequency?
for (int i=0; i<bufferSize; i++) {
frequency[i]=myFFT.spectrum[i]*150;
rect(10+i,10,1,myFFT.spectrum[i]*200);
if(i<171) { // WHY ARE THESE COLORS NOT CHANGING ALONG CONTINUOUSLY W Frequencies??
spect_g = myFFT.spectrum[i]*200;
}
else if(i>171 && i<341) {
spect_r = myFFT.spectrum[i]*200;
}
else {
spect_b = myFFT.spectrum[i]*200;
}
}
// draw our averages WHAT IS THIS FOR?
for(int i=0; i<numAverages; i++) {
fill(255,128);
rect(10+i*steps,10,steps,myFFT.averages[i]*200); // 10+i*16, 10, 16,
fill(255);
rect(10+i*steps,(int)(10+myFFT.maxAverages[i]*200),steps,1);
rect(10+i*steps,10,1,200);
}
// complete the frame around our averages
rect(10+numAverages*steps,10,1,201);
rect(10,10,bufferSize,1);
rect(10,210,bufferSize,1);
// draw the range of normalization
rect(550,10,50,1);
rect(550,210,50,1);
float percent=max(0,(myFFT.max-minLimit)/limitDiff);
fill(255,0,0,128);
rect(550,(int)(11+198*percent),50,1);
rect(550,11,50,(int)(198*percent));
// draw our damper slider
fill(255);
rect(610,10,30,1);
rect(610,210,30,1);
fill(255,128);
rect(610,(int)(11+198*myDamp),30,1);
levelFFT.getLevel(myInput);
//println(myChannel.duration);
//println(bufferSize);
//println(bufferDuration);
//println(myFFT.spectrum);
//println(wavesamples);
//println(myFFT.getLevel(myInput));
}
public void audioInputData(AudioInput theInput) {
myFFT.getSpectrum(myInput);
for (int i=0; i<bufferSize; i++) {
frequency[i]=myFFT.spectrum[i]*150;
}
println("ok");
}
}
-------------------
{
FFT myFFT;
FFT levelFFT;
AudioInput myInput;
int bufferSize;
int steps;
float limitDiff;
int numAverages=32;
float myDamp=.1f;
float maxLimit,minLimit;
int r;
int g;
int b;
float spect_r;
float spect_g;
float spect_b;
float wavesamples[];
float frequency[];
InputFFTAnalysis()
{
// set up our AudioInput
bufferSize=512;
myInput=new AudioInput(bufferSize*4); // 512
// set up our FFT
myFFT=new FFT(bufferSize*2); // 512*2 = 1024
//myFFT=new FFT(bufferSize);
myFFT.equalizer(true);
wavesamples=new float[512];
frequency=new float[512];
levelFFT=new FFT();
// set up our FFT normalization/dampening
minLimit=.005;
maxLimit=.05;
myFFT.limits(minLimit,maxLimit);
myFFT.damp(myDamp); // .1f
myFFT.averages(numAverages); // 32
// get the number of bins per average
steps=bufferSize/numAverages; // 512/32 = 16
// get the distance of travel between minimum and maximum limits
limitDiff=maxLimit-minLimit; // .05 - .005
r = 0;
g = 100;
b = 0;
spect_r = 0;
spect_g = 0;
spect_b = 0;
myInput.start();
}
void UpdateData()
{
// draw the waveform //waveform is how loud the sound is?
stroke(255,0,0); // time it takes for music to start? / length of song? * 512?
int interp=(int)max(0,(((millis()-myInput.bufferStartTime)/(float)myInput.duration)*myInput.size)); // what does this translate to in actuality?
// Does this number change or is it instanitated one time only?
// for example 1 millli sec/ 180 million sec * 512 = .00284
for (int i=0;i<bufferSize;i++) { //for i up to 512
float left=160; // what does the left and right stuff meen?
float right=160;
float wave=0;
if (i+interp+1<myInput.buffer2.length) {
left-=myInput.buffer2[i+interp]*50.0;
right-=myInput.buffer2[i+1+interp]*50.0;
wave-=myInput.buffer2[i+interp]*75.0;
}
wavesamples[i]=wave;
line(10+i,left,11+i,right);
}
myFFT.getSpectrum(myInput); //****HOW do I get this math to equal 1024 instead of 512?****
noStroke();
fill(255,0,0);
// draw the spectrum sound spectrum measures amount of vibration at each individual frequency?
for (int i=0; i<bufferSize; i++) {
frequency[i]=myFFT.spectrum[i]*150;
rect(10+i,10,1,myFFT.spectrum[i]*200);
if(i<171) { // WHY ARE THESE COLORS NOT CHANGING ALONG CONTINUOUSLY W Frequencies??
spect_g = myFFT.spectrum[i]*200;
}
else if(i>171 && i<341) {
spect_r = myFFT.spectrum[i]*200;
}
else {
spect_b = myFFT.spectrum[i]*200;
}
}
// draw our averages WHAT IS THIS FOR?
for(int i=0; i<numAverages; i++) {
fill(255,128);
rect(10+i*steps,10,steps,myFFT.averages[i]*200); // 10+i*16, 10, 16,
fill(255);
rect(10+i*steps,(int)(10+myFFT.maxAverages[i]*200),steps,1);
rect(10+i*steps,10,1,200);
}
// complete the frame around our averages
rect(10+numAverages*steps,10,1,201);
rect(10,10,bufferSize,1);
rect(10,210,bufferSize,1);
// draw the range of normalization
rect(550,10,50,1);
rect(550,210,50,1);
float percent=max(0,(myFFT.max-minLimit)/limitDiff);
fill(255,0,0,128);
rect(550,(int)(11+198*percent),50,1);
rect(550,11,50,(int)(198*percent));
// draw our damper slider
fill(255);
rect(610,10,30,1);
rect(610,210,30,1);
fill(255,128);
rect(610,(int)(11+198*myDamp),30,1);
levelFFT.getLevel(myInput);
//println(myChannel.duration);
//println(bufferSize);
//println(bufferDuration);
//println(myFFT.spectrum);
//println(wavesamples);
//println(myFFT.getLevel(myInput));
}
public void audioInputData(AudioInput theInput) {
myFFT.getSpectrum(myInput);
for (int i=0; i<bufferSize; i++) {
frequency[i]=myFFT.spectrum[i]*150;
}
println("ok");
}
}
-------------------
void knob(int theValue) {
bg_R = color(theValue);
println("bg_R knob event. setting background to "+theValue);
bg_G = color(theValue);
println("bg_G knob event. setting background to "+theValue);
}
bg_R = color(theValue);
println("bg_R knob event. setting background to "+theValue);
bg_G = color(theValue);
println("bg_G knob event. setting background to "+theValue);
}
1