Re : updatePixels method for Capture object
Re : array of audio files - failed
Since quarks already spotted the error,
let me give ya some tweaks for your code instead!
A warning though:
Since I don't have your files, I couldn't test if it really works!
So tell us later whether this version works for ya.
import ddf.minim.*; final static String[] fileNames = { "dog", "horse", "frog", "rooster", "cat", "duck", "ear" }; final static int numImgs = fileNames.length; final static PImage[] imgs = new PImage[numImgs]; final static int numSongs = fileNames.length - 1; final static AudioPlayer[] songs = new AudioPlayer[numSongs]; final Minim minim = new Minim(this); PImage bg; void setup() { size(1000, 600); background(170, 245, 120); frameRate(30); noLoop(); for ( byte idx = 0; idx != numImgs; imgs[idx] = loadImage( fileNames[idx++] + ".jpg") ); for ( byte idx = 0; idx != numSongs; songs[idx] = minim.loadFile( fileNames[idx++] + ".wav") ); for (short idx = 0, rows = 100; rows <= 350; rows += 200) for (short cols = 100; cols <= 700; cols += 300) image(imgs[idx++], cols, rows); image(imgs[numImgs-1], 475, 25); bg = get(); } void draw() { background(bg); } void mousePressed() { if (mouseX > 475 && mouseX < 525 && mouseY > 25 && mouseY < 75) songs[ (int) random(numSongs) ].play(); redraw(); } void stop() { for ( byte idx = 0; idx != numSongs; songs[idx++].close() ); minim.stop(); super.stop(); }
Re : array of audio files - failed
Re : array of audio files - failed
Secret is to identify any redundant patterns,
and make them become arrays & loops and so on!
Well, just for another Java fun,
the last loop within function stop() could also be written this way:
void stop() { for ( AudioPlayer ap: songs ) ap.close(); minim.stop(); super.stop(); }
Cya another time!
Re : rendering to video file
Send Vertex Array to PShape
function interrupt draw
- import processing.video.*;
- Movie mov;
- float speed;
- void setup() {
- size(480, 390);
- frameRate(50);
- mov = new Movie(this, "myvideo.mov");
- mov.play();
- speed=0.5;
- }
- void draw() {
- background(255);
- fill(255);
- mov.speed(speed);
- image(mov, 90, 90, 390, 390);
- fill(0);
- text( "speed : " + speed, 10, 30);
- if((mov.duration())-(mov.time())<0.1 && speed>0){
- println("fin video "+mov.time()+"mov.duration : "+(mov.duration()));
- mov.jump(0);
- }
- if(speed<0 && (mov.time()-0)<0.1){
- println("fin video "+mov.time());
- mov.speed(abs(speed));
- mov.jump(mov.duration());
- }
- }
- // Called every time a new frame is available to read
- void movieEvent(Movie m) {
- m.read();
- }
- void keyPressed() {
- if (key == CODED) {
- if (keyCode == LEFT) {
- speed = speed -0.1;
- } else if (keyCode == RIGHT) {
- speed = speed+0.1;
- }
- }
- }
Re : function interrupt draw
So a user of your app has free rein to bug it in a matter of key presses!
Here's your function keyPressed() w/ additional check for speed:
final static float minSpd = .1, maxSpd = 10; final static float incSpd = .1; void keyPressed() { if (keyCode == LEFT) speed -= incSpd; else if (keyCode == RIGHT) speed += incSpd; if (speed < minSpd) speed = minSpd; else if (speed > maxSpd) speed = maxSpd; }
processing.net Sockets
how can I check which ports are available using the processing.net library?
Or what UDP Socket communication would you recommend?
I start a Server per job, and each job can have a variable number of nodes they send some info's
to the server.
When I start another job, I have to find out, which port isn't in use.
Thanks for help
Tom
stream video from the internet
public void setup()
{
size(WIDTH, HEIGHT);
myMovie = new Movie(this, "abc.mp4");
myMovie.play();
}
public void draw()
{
//(WIDTH-myMovie.width)/2
image(myMovie, 0, 0);
}
// Called every time a new frame is available to read
public void movieEvent(Movie m)
{
m.read();
}
I tried to change the filename to a url link which ends with .mp4, but it did not work. Anyone has an idea?
Processing a controller USB
i've been programming arduino for a short time and now am working on controlling my devices with one of my controller ( xbox 360 especially ), and i discovered processing in order to use some of these libraries.
i started downloading "procontroll" too, but i simply cannot get any serial signal for example, this code does not display anything:
import processing.serial.*;
Serial newSerial ;
void setup()
{
size(200, 200);
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}
void draw()
{ println ( newSerial.list () ) ;
}
i'm trying to do this because every time i get errors like array size does not fit ( for serial.list () )
and deleting [] gets me " cannot convert string[] to string " .
Any advices??
i think the fact i do not get any serial.list is that my drivers aren't working ( tho i have downloaded the very last ones, and the controller is recognised by the computer as " Xbox 360 Controller for windows", but i cannot acces it in any other serial devices ( terminal etc.. )
I need help because i'm not totaly sure if this is due to this
thanks
Re : audio file as input
OpenGL glReadPixels and PBOs
Now I'm trying to implement a system to read back pixels using two PBOs which should have very little impact on the running sketch. (The buffer version takes about 10ms for 1280x720 which slows down a sketch that pushes 60fps to 45.) There is a nice article outlining what I am trying to do here under asynchronous read-back: http://www.songho.ca/opengl/gl_pbo.html
I'm using gl.glBufferData(pboIds[0], width*height*4, null, GL.GL_STREAM_READ); to allocate memory for the PBO. This line produces an invalid enumerant error (on GL.GL_STREAM_READ I guess). I've also tried this line with an empty buffer instead of null with the same results. When I try to map the read-back buffer I get this GLExcpetion: "Error: buffer size returned by glGetBufferParameterivARB was zero;"
Here is all the GL stuff that I'm having trouble with now:
void setup() {
...
pboIds = new int[2];
gl.glGenBuffers(2, pboIds, 0);
gl.glBindBuffer(GL.GL_PIXEL_PACK_BUFFER, pboIds[0]);
gl.glBufferData(
pboIds[0], width*height*4, null, GL.GL_STREAM_READ);
// gl.glGetError();
gl.glBindBuffer(GL.GL_PIXEL_PACK_BUFFER, pboIds[1]);
gl.glBufferData(
pboIds[1], width*height*4, null, GL.GL_STREAM_READ);
// gl.glGetError();
gl.glBindBuffer(GL.GL_PIXEL_PACK_BUFFER, 0);
}
void draw() {
...
int vpboInd = frameCount%2;
int cpboInd = (frameCount+1)%2;
gl.glReadBuffer(GL.GL_FRONT);
gl.glBindBuffer(GL.GL_PIXEL_PACK_BUFFER, pboIds[vpboInd]);
gl.glReadPixels(
0,0,width,height,GL.GL_BGRA,GL.GL_UNSIGNED_BYTE,0L);
gl.glBindBuffer(GL.GL_PIXEL_PACK_BUFFER, pboIds[cpboInd]);
try {
gl.glMapBuffer(GL.GL_PIXEL_PACK_BUFFER, GL.GL_READ_ONLY);
} catch(Throwable ex) {ex.printStackTrace();}
gl.glUnmapBuffer(GL.GL_PIXEL_PACK_BUFFER);
gl.glBindBuffer(GL.GL_PIXEL_PACK_BUFFER, 0);
}
Has anyone worked with PBOs, tried this before, or see any problems with this code?
Re : Processing 2 and OpenGL Frame Buffer Objects (FBO)
Re : Processing 2 and OpenGL Frame Buffer Objects (FBO)
- PGL pgl = ((PGraphicsOpenGL) g).beginPGL();
- gl = pgl.gl.getGL().getGL2();
public void setup() {
[setup gl context, create fbo]
((FBOGraphics) g).pushFramebuffer();
gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, myFBO); // Bind our frame buffer
fill(255, 255, 255);
rect(100, 100, 200, 500);
((FBOGraphics) g).popFramebuffer();
}
public void draw() {
background(0);
// why the repeat? If I don't use we crash
PGL pgl = ((PGraphicsOpenGL) g).beginPGL();
gl = pgl.gl.getGL().getGL2();
gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0);
((PGraphicsOpenGL) g).drawTexture(GL.GL_TEXTURE_2D, fboTexture, width, height, 0, 0, width, height);
}
Sound Response (beginner needing serious help!)
- class SoundRespond { // Define a class with custom name
- import ddf.minim.*; // Variables and library imports
- private Minim minim;
- private AudioInput input;
- SoundRespond(PApplet myApplet) { //A constructor, necessary part of a class
- minim = new Minim (myApplet);
- input = minim.getLineIn (Minim.STEREO, 512);
- }
- float adding( float _upperRange) { // Function for sound response
- ////////////sound stuff///////
- float volumeValue = input.mix.level () * 250;
- volumeValue = constrain(volumeValue, 0, 100);
- volumeValue = map(volumeValue, 0, 100, 0, _upperRange);
- //println(volumeValue);// uncomment to debug only, else leave comment
- ////////sound stuff end////////
- return volumeValue;
- }
- }
- // 1) +++++ To make a sketch sound responsive the first step is to put the SoundRespond.pde file in the same folder
- //with the sketch you are working on.
- //++++++++++++++++++++++++++++++++
- // 2) +++++ The second step is to copy the line below into your sketch above void setup() +++++
- SoundRespond mySoundRespond;
- //+++++++++++++++++++++++++++++++
- float diam =60; //diameter of the circle
- float xPos = 0; //the position of the circle left to right on x axis
- float yPos = 200; //the position of the circle to to bottom on y axis
- float speed = 3; // how many pixels the circle will move with each frame
- float sndChng;
- void setup() {
- size(500,500);
- // 3) +++++ The third step is to copy the line below into your sketch below size(width,height); +++++
- // between the curly brackets of of setup()
- mySoundRespond = new SoundRespond(this);
- //++++++++++++++++++++++++++++++++++
- smooth();
- }
- void draw() {
- background(255); // redraw the background each frame to erase the previous circle
- // Use values to draw an ellipse
- noStroke();
- fill(#831919);
- ellipse(xPos,yPos,diam,diam);
- // 4) +++++ The forth step is to choose a variable of something you want to change with sound +++++
- // this has to be between the curly brackets of of draw().
- // Copy and paste "mySoundRespond.adding(value);" and put a number in the place of the word ""value".
- sndChng = mySoundRespond.adding(5);
- //The number determines the amount of the sound response effect.
- //For speed changes try 2.0-5.0 to start, size changes can be much larger numbers.
- //++++++++++++++++++++++++++++++++++
- //must multiply speed by sndChng! adding does not work!!
- //uncomment constrain() below to keep circle moving
- //sndChng = constrain(sndChng,1,10);
- xPos = xPos + (speed*sndChng);
- println("xPos " + xPos);
- println("speed " + speed);
- if ((xPos > width) || (xPos < 0)) {
- speed = speed * -1;
- }
- }
- import ddf.minim.*; // Variables and library imports
Re : Sound Response (beginner needing serious help!)
Re : Sound Response (beginner needing serious help!)
And I see that import ddf.minim.*; in inside class SoundRespond.
Since it's inside that class, dunno whether the rest of your program can make use of it.
I've always put them at the very top of my main sketch and never had any problems.
Perhaps you may try doing that too?