Hi, can anyone provide pointers on how to read rather than play an audio file with Minim (assuming Minim is the most appropriate library - is it?). Specifically I would like to read data points (like using myMP3.left.get(i) or myMP3.left.level(i) functions) at specific time intervals (say every 1000 milliseconds) over the course of the song. For example, a 2 minute long song would result in an array of 120 float "samples" each 1 second apart in time. Ideas?
In the past when using PGraphics I have always used JAVA2D. I am now using Processing 2 and decided to give P2D a try but encountered a problem. I created the following code as a simple test to explain the problem.
If you take the following program and run it:..
PGraphics png;
String outDir="C:/a_PDE_Output/";
String filenam;
float x,y;
int limitF=100;
void setup() {
//size(100,100,P2D);
png = createGraphics(1024, 768, JAVA2D);
png.beginDraw();
png.background(255,210,210);
}
void draw() {
x = random(png.width-1);
y = random(png.height-1);
png.fill(random(255),random(255),random(255));
png.ellipse(x,y,10,10);
if(frameCount >= limitF) drawEnd();
}
void drawEnd() {
bldFname();
png.endDraw();
png.save(filenam);
println("Saved "+filenam);
exit();
}
void bldFname() {
String pr = "testing";
String sx = ".png";
filenam=outDir+pr+sx;
}
It will work as expected. Ellipses are drawn to the PGraphics object and then the output is saved to the file.
Now change JAVA2D to P2D on the createGraphics() statement.
Note that the program will not run as OpenGL needs the size() statement in order to execute.
So uncomment the size() statement and run the program. The program will run BUT...
while the background statement does execute and create the requested background color, none of the ellipses are written to the PGraphics object. Can someone else give this a try and confirm my findings.
stroke(255); // just to prove that an ellipse is actually being drawn
}
void draw() {
if(frameCount==1) {
image(img, 0, 0,width,height); // puts the image on screen - works
loadPixels(); // loads the pixel array - appears to work
}
x = int(random(width-1)); // grab a random x
y = int(random(height-1)); // grab a random y
int i = int(x + (y*width)); // get the pixel array location
clr = pixels[i]; // pixel is supposed to have a color datatype so put it in the color variable clr
r=red(clr); g=green(clr); b=blue(clr); // just for grins, grab the r,g,b components
//println(x+","+y+" --> "+r +","+g+","+b);
//fill(clr);
fill(r,g,b);
ellipse(x,y,70,70);
}
So in the above code, everything works fine using the fill statement on line 24.
BUT - if I comment out the fill on 24 and uncomment the fill on 23, the ellipses drawn become invisible. I confirmed that they were actually drawing by putting the stroke(255) into setup(). Obviously clr has valid color data because the r,g,b variables are correctly populated with the appropriate values.
So what am I missing? Why does fill(clr) result in the creation of invisible ellipses?
Best Regards, Jim
Here is a curiosity I encountered with Processing 2 - did not test this with Processing 1.5. Take the following code and run it:
void setup() {
size(900,600,P3D);
smooth();
noFill();
background(0);
strokeWeight(3);
}
void draw() {
for (int n = 0; n<273; n++ ) {
int r = (int)random(255);
stroke(r);
pushMatrix();
translate(random(300,600),random(200,500));
box(50,40,25);
popMatrix();
}
}
You will find that it works fine. Now change the n<273 to n<274 (or some larger number) and run the program.
On my system I get the following warning/error message:
Stroke path is too long, some bevel triangles won't be added
Clearly something is going on.But the really curious thing is this. If I set the strokeWeight to 1, no matter how long/large the loop becomes, I never see the Stroke path message. It only occurs if the stroke weight is a value larger than 1 .
Hi, if you take a look at the following screen shot: you will note that the spheres rendered at the center of the image are round while the spheres rendered at the edges are distorted.
My question is this: is there a way to get all the spheres to appear perfectly round? The only method that I know of is to change the camera's Z location (moving away from the objects). However this results in the spheres being rendered at a much smaller size and reducing the usable screen area to a fraction of the actual screen size.
I'd like to keep the size but lose the distortion. Any tips as to tricks would be greatly appreciated.
Okay I wrote a sketch that plays music and paints lines. The program starts and stops when the user presses the space bar. Works fine.
It took some doing but I was also able to get the program working in Processing.js mode - with getting the audio to play being the challenge. But I got it working and it works fine in the browsers I tested it in (Firefox 21 and Internet Explorer 9).
It then occurred to me to see if it worked in Chrome but the only place I have Chrome installed is on my Android tablet. And that's when it hit me - there is NO KEYBOARD available.
Given that more and more folks are going to be converting their Processing projects to Processing.js in order to run them on the web, and given that more and more people are using tablets to surf, does this render all web-based Processing sketches that require keyboard input useless?
Note that I am posting this to the Processing.js Google group. If an answer is provided there, I will repost it here.
As soon as my Coursera class on digital media is over (assuming I can actually complete it) I will be dumping Processing 2 and returning to Processing 1. Why?
Well, my laptop is a mere 2 years old. I've updated my NVIDIA drivers to the most recent available for my card (March 2012) and yet many sketches that ran fine under Processing 1.51 crash under Processing 2 with OpenGL errors. In addition, all sketchs that references either P2D or P3D crash 100% of the time! I assume that this is because my system is not brand spanking new. My understanding is that a conscious decision was made to make Processing 2 more dependent on OpenGL - which is highly version and device driver sensitive!
Rather than replace my computer just so that maybe Processing 2's OpenGL errors will disappear, I'll replace Processing 2 with Processing 1 instead - thus returning to a land where OpenGL errors apparently do not exist.
I've tried with 32 bit and 64 bit Processing - in multiple locations, with/without admin authority. The "Add Mode" tool fails 100% of the time on everything: Android, Javascript, Coffeescript.
Manually adding the Android files to the /modes directory (which /modes? - doesn't matter as I've tried adding to both) doesn't work because when Processing is started, it doesn't recognize that the mode was added (Is there something that needs to be manually added to the preferences.txt file?).
So is there someone somewhere who can give me precise directions on how to get Processing/Android installed and working on a Windows 7 PC?
Ok I have not yet migrated to version 2 but for those of us still on an earlier version, I was playing around with the unbinary() function (
http://processing.org/reference/unbinary_.html ) and noticed that - unlike the binary() function, unbinary() only seems to work with positive numbers.
To see what I mean, take the following code and run it. It will die (though the binary() command works just fine if you comment out lines 4 and 5. Make the number in line 1 positive and the program works just fine.
int nnn = -1234;
String bc = binary(nnn);
println(bc);
int newn = unbinary(bc);
println(newn);
It seems that if you want to use unbinary with both positive and negative numbers, you'll first need to test the number to see if it is positive or negative, record the result, convert the number to positive and then perform the binary() operation [ binary(abs(integer)) ] .
FYI,
Please note the existence of a new open group on Linkedin devoted to the Processing programming language.
The group name is Processing Programming Language.
The group URL is
http://www.linkedin.com/groups?home=&gid=4549593
Hi,
I had a rather complex Processing program and thought it would be nice to output to a PDF in addition to the screen. Unfortunately it blows up with a "missing a PopMatrix() error"
So I created the following very simple program that preserves the core characteristics of my real program in order to see what would happen:
import processing.pdf.*;
float offsetX,offsetY;
boolean wipe=true;
void setup(){
size(1200,800);
offsetX=width/2;
offsetY=height/2;
beginRecord(PDF, "testingpdf.pdf");
noLoop();
}
void draw(){
drawit();
noLoop();
}
void drawit() {
float x,y;
rectMode(CENTER);
translate(offsetX,offsetY);
for(int n=0; n < 50; n++) {
fill(random(0,255),random(0,255),random(0,255));
x = random(0,width);
y = random(0,height);
pushMatrix();
translate(x,y);
rotate(radians(random(0,TWO_PI)));
rect(0,0,random(20,100),random(20,100));
popMatrix();
}
}
void mousePressed() {
offsetX=mouseX;
offsetY=mouseY;
if(wipe) background(255);
loop();
}
void keyPressed() {
if(key=='x' || key=='X') {
// output file
endRecord();
println("Quit and Saved ");
exit();
}
}
The program works fine until I add the begin and end record statements for the PDF. When I press 'x' to save, I get this error:
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: missing a popMatrix() to go with that pushMatrix()
Taking another charge at it, I modified the program as follows:
import processing.pdf.*;
float offsetX,offsetY;
boolean wipe=true;
void setup(){
size(1200,800);
offsetX=width/2;
offsetY=height/2;
beginRecord(PDF, "testingpdf.pdf");
}
void draw(){ }
void drawit() {
float x,y;
rectMode(CENTER);
translate(offsetX,offsetY);
for(int n=0; n < 50; n++) {
fill(random(0,255),random(0,255),random(0,255));
x = random(0,width);
y = random(0,height);
pushMatrix();
translate(x,y);
rotate(radians(random(0,TWO_PI)));
rect(0,0,random(20,100),random(20,100));
popMatrix();
}
}
void mousePressed() {
offsetX=mouseX;
offsetY=mouseY;
if(wipe) background(255);
drawit();
}
void keyPressed() {
if(key=='x' || key=='X') {
// output file
endRecord();
println("Quit and Saved ");
exit();
}
}
The popMatrix error message goes away but is replaced with the following message:
isRecording(), or this particular variation of it, is not available with this renderer.
Note that these errors do not occur if I write to the PDF file using
size(w, h, PDF, "filename"); instead of the begin and end record statements.
Unfortunately this method means no screen output and I really do need to be able to see what I'm doing before deciding whether or not to create the PDF.
Hi, I'm experiencing an unusual problem with PImage. That is I am repeatedly using get, set, and copy to copy from a source PImage to a destination PImage. The problem is that after each get/set/copy series of operations the image becomes progressively darker. This happens on 2 different systems running Processing 1.5.1 under Windows 7 64bit so I know it is not machine dependent.
In the image below, the left side is the original image and the right side is what it looks like after 160 copies. :
The code that follows is part of a much larger program in which I discovered the problem. Cutting out all the other code, I was able to isolate the source of the darkening to the code that appears below. Based on my understanding of get/set/copy, I am at a complete loss to explain why successive copy operations should cause the image being processed to darken.
Any suggestions as to how to overcome this will be greatly appreciated. Thanks.
Hi, I just installed the proSVG library found here:
http://sites.google.com/site/kdlprosvg/Home in order to output SVG files.
The date associated with this library is Oct. 2008.
Trying to run either of the two example programs provided I get a null pointer exception. Following is the complete error message:
Exception in thread "Animation Thread" java.lang.NullPointerException
at processing.core.PGraphicsJava2D.loadPixels(Unknown Source)
at prosvg.SVGKdl.save(SVGKdl.java:88)
at processing.core.PApplet.saveFrame(Unknown Source)
at testsvtTEMP.draw(testsvtTEMP.java:46)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:662)
Has anyone else had success using this library with Processing 1.5.1?
FYI earlier this year I added a tutorial to my website for beginners on using Processing to recreate Georg Nees' piece
Schotter, one of the early works of computer art.
1 - I create a Processing sketch and do save as "AAA" Processing creates a subdirectory AAA and inside that creates AAA.pde
2 - I make some changes and save again but then I also create a copy by doing a save as "AAAcopy" thus creating a new subdirectory and new pde(s).
3 - Later I restart processing, I open and edit AAA. I save AAA but no matter what I do, I can not get processing to do a save as to AAAcopy. I think this is probably a bug in Processing because when I do an initial save the directory in which the sketch is placed does not exist and save creates the directory and the pde files. However if that directory does exist, Processing opens the directory when "Save" is clicked instead of saving. Clicking save again results in Processing creating a new sub-subdirectory in which the sketch is saved.
This is really annoying. Is this a known behavior/bug that I am just not aware of? Or is there some way to get Processing to save AAA as AAAcopy when AAAcopy already exists?
FYI, I added the tutorial
Recursion and Algorithmic Art Using Processing to my web site. This is an expansion of a tutorial I wrote for CMD Journal earlier this year. The url for the tutorial is:
www.artsnova.com/Processing_Recursion_Tutorial.html
This is something that crops up once in a great while for me and has always annoyed me.
The problem: you can only do a curly brace array initialization at the point you declare your array - note that this is a Java thing.
So the following code will crash and burn:
float[] xx1;
void setup() {
size(100, 100);
xx1 = { width/2, height/2,1,2,3};
}
There are times when I need a global array but can't initialize it at that moment and the curly braces make for a nice shortcut. My way around the problem is to do the following:
float[] xx1;
void setup() {
size(100, 100);
float [] xx2 = { width/2, height/2, 1,2,3};
xx1=xx2;
}
This way I can use the curly brace shortcut and get the data into my global array.
void setup() { size(1100,800); background(255); // smooth(); noLoop(); } void draw() { for (int x = 0; x < width; x+=4) { for (int y = height; y > 0; y-=6) { line(0,0, x,y); } } }
Uncomment the smooth() statement and the program stops working -- no error message, no drawing. Running the program in static mode (no setup() or draw()) results in no canvas window either.
I don't know if this is peculiar to my system or my environment at the moment (I have had sketches go from failing to working just by rebooting) I do note that the Processing doc does indicate some problems with the smooth statement so perhaps this is a manifestation of another problem.
draw() .... do a bunch of stuff if(alldone) { endRecord(); exit()}
while the PDF is still created, it is missing a lot of the lines that were drawn.
In the above image, the sketch on the right is the PDF that was created by the first code example. The sketch on the left is the PDF created by the second code example.
Note that the nice thing about the beginRecord()/endRecord() method (the 2nd example) is that you can watch the progress of the sketch on your screen.
Note that I'm using Processing 1.2.1 on Windows XP.
Hi, It's been quite some time since I've visited the forum here and boy have things changed.
I have three questions about Minim.
Question 1: Given the following statement
player = minim.loadFile(audioFile, bufferSize);
and assuming that bufferSize is 1024, this means that I have created an "array" of 1024 elements.
Now inside of draw() I have the following, for example:
for(int i = 0; i < player.bufferSize(); i++) { float value = player.left.get(i); // some code to draw something }
So at the end of the for loop I have read through the entire buffer and hit the last line of code in draw() - at which point draw(0 executes again. My question is what is the trigger that causes the
player buffer to be loaded with the next 1024 bytes of audio data? Is the buffer automatically reloaded when the end of the draw() function is encountered correct? If so, what happens if I don't have a draw() function (drawing offline as opposed to drawing to the screen)?
Question 2: How do I find out the number of bytes of data in the audio file (ie how many total "array" elements...)? All the lengths that I've found in the Minim doc relate to time (milliseconds).
Question 3: What is the best way to synchronize the end of the audio file with halting the drawing? I set the player to loop 1 time and then used the following as the last line of draw():
if ( !player.isPlaying() ) savepic();