We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSound,  Music Libraries › Basic minim library values & arraylist
Page Index Toggle Pages: 1
Basic minim library values & arraylist (Read 2124 times)
Basic minim library values & arraylist
May 17th, 2010, 2:36pm
 
Hi I'm a real novice at Processing still, & am trying to learn to use libraries, and have come up against a problem saving values created using one of the minim examples to an arraylist of objects.

The sketch below is a basic equiliser built from an example, where I have tried to create an arraylist to hold 'stills' from the equiliser bars as objects in an arraylist, then draw the whole list to the screen (so the 'past sound levels' are drawn extending off into the distance).
- Basically I'm trying to combine an eq graph with this processing example: http://processing.org/learning/topics/arraylistclass.html

My new objects seem to create & display, but they are all updating to show the current equiliser values instead of the ones set when they were created - am I just sourcing the wrong set of values to draw from in my object display() function Thank you.


Code:
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;

ArrayList rowsArrayList = new ArrayList();
float[] currentRowArray = new float[257];

FFT fftLog1;
Minim minim;
AudioInput groove1;

void setup() {
 size(600,400, P3D);
 frameRate(5);
 minim = new Minim(this);
 groove1 = minim.getLineIn(Minim.MONO, 512);
 fftLog1 = new FFT(groove1.bufferSize(),groove1.sampleRate());
     strokeWeight(1);
}

void draw() {

 background(0);
 fftLog1.forward(groove1.mix); //combine stereo into mono sound.
 
for(int b=0; b<rowsArrayList.size(); b++){//loop through all arraylist..
BarRowObject currentRow = (BarRowObject) rowsArrayList.get(b);

 translate(0, 0, b*-10);
 currentRow.display();

}
 
 if(rowsArrayList.size() >10){//makes sure there arraylist is a limited length..
 rowsArrayList.remove(0);
 }

}//end of draw.



void keyPressed(){
 
 for(int i = 0; i < fftLog1.specSize(); i++) {
   currentRowArray[i] = (fftLog1.getBand(i)*100);
 }
 
rowsArrayList.add(new BarRowObject(currentRowArray));
}





class BarRowObject {
float[] barValues = new float[256];

public BarRowObject ( float[] tempBarValues ){;
barValues = tempBarValues;

}


void display(){
  stroke(255);
   for(int i = 0; i < fftLog1.specSize(); i++) {
   pushMatrix();
   translate(i*10, (height*0.75)-(((fftLog1.getBand(i)*100))/2), 0);
   noFill();
   box(10, (fftLog1.getBand(i)*100), 10);
   popMatrix();
   }
}
 
}


Re: Basic minim library values & arraylist
Reply #1 - May 17th, 2010, 10:11pm
 
I think arraylist stores pointers to objects, therefore if you create a list of objects you want to get, you've created a 'live link' to them.  They will therefore always be up-to-date

Probably what you want to do is, every time you want to sample the eq bars, is create a new float, set it to the current value, and make an array of the floats
something like

Float temp = bar.value(i);
sampledValues[i] = temp;// that way you know you've got a float sitting still.  Sit still, dammit!

I'd code that properly  but I haven't played with the eq yet

hope that helps!
Re: Basic minim library values & arraylist
Reply #2 - May 18th, 2010, 3:04am
 
Thanks, I'm just going to try that now, seems as I grasp one idea (classes) another sidles its way out of my head!
Re: Basic minim library values & arraylist
Reply #3 - May 18th, 2010, 4:17am
 
Sorted it after a bit of shuffling around, many thanks! Smiley

Code:
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;

ArrayList rowsArrayList = new ArrayList();
float[] currentRowArray = new float[257];
float[] sampledRowArray = new float[257];

FFT fftLog1;
Minim minim;
AudioInput groove1;

boolean recorder = true;

void setup() {
size(600,400, P3D);
frameRate(5);
minim = new Minim(this);
groove1 = minim.getLineIn(Minim.MONO, 512);
fftLog1 = new FFT(groove1.bufferSize(),groove1.sampleRate());
strokeWeight(1);
}

void draw() {

background(0);
fftLog1.forward(groove1.mix); //combine stereo into mono sound.

if(recorder){
for(int i = 0; i < fftLog1.specSize(); i++) {

float temp = (fftLog1.getBand(i)*100);
println(i+" "+temp);
sampledRowArray[i] = temp;
}
println(sampledRowArray);
println("");
rowsArrayList.add(new BarRowObject(sampledRowArray));
sampledRowArray = new float[257];
//recorder = false;
}

for(int b=0; b<rowsArrayList.size(); b++){//loop through all arraylist..
BarRowObject currentRow = (BarRowObject) rowsArrayList.get(b);

translate(0, 0, b*-10);
currentRow.display();


}

if(rowsArrayList.size() >10){//makes sure there arraylist is a limited length..
rowsArrayList.remove(0);
}


//if(keyPressed){
// recorder = true;
//}else{
// recorder = false;
//}

}//end of draw.








class BarRowObject {
float[] barValues = new float[256];

public BarRowObject ( float[] tempBarValues ){;
barValues = tempBarValues;

}


void display(){
stroke(255);
for(int i = 0; i < currentRowArray.length; i++) {
pushMatrix();
translate(i*10, (height*0.75)-((barValues[i])/2), 0);
noFill();
box(10, barValues[i], 10);
popMatrix();
}
}

}
Re: Basic minim library values & arraylist
Reply #4 - May 18th, 2010, 5:20am
 
Cool Smiley
Page Index Toggle Pages: 1