Quantcast
Channel: Processing Forum
Viewing all 1768 articles
Browse latest View live

Re : updatePixels method for Capture object

$
0
0
It appears that the Caputure class extends the PImage class so all the methods available to PImage are also available to the Capture class. This means that the documetation for PImage methods also apply to the Capture class.


Re : array of audio files - failed

$
0
0
Hello d.dora_92!

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

$
0
0
Both ways finally work! :)

I changed my capital letters and also the word "trigger" to "play", and it worked quite well, but your way, GoToLoop, works much better and faster! Well, I am really new in such experience, as you understand, but the more I try, the more I get excited... :) I will study more, also to understand exactly what you did, so that my next questions will be more advanced. :P 

Thank you both very much!!!!!! :)

Re : array of audio files - failed

$
0
0
So glad you liked my tweaked version!

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();
    }
    
It is the enhanced for each loop format.

Cya another time!

Re : rendering to video file

$
0
0
saveFrame() works, creates .tif's

ffmpeg command line did a good job with this: 
ffmpeg -f image2 -i screen-%04d.tif -r 12 -s 640x360 CubicGridImmediate.avi

Windows Movie Maker seemed to have a limitation of shortest picture duration of 1/8 sec and transition of 1/4 sec so not really usable.

Thanks!

Send Vertex Array to PShape

$
0
0
Hello,

The new PShape features are awesome. Especially the adding of Vertices or loading OBJs. But what I am missing in comparison to the old GLModel class is the opportunity to send an array of vertices to it. Like the model.updateVertices(vertexarray)

Because I think sending the vertices one by one makes it too many calls. Especially when doing it dynamically in the draw loop. Did anyone has experience with it?

Thanks in advance.

function interrupt draw

$
0
0
I have create an application which read a video and where the speed can be modified by event "keyPressed".
This works well but when I press several times the key, the method draw seems stop and my movie in pause until the event endding.
How to solve this problem of interrupt ? How I can reduce the time of the interrupt fonction ?

This is my sketch :

  1. import processing.video.*;
  2. Movie mov;
  3. float speed;

  4. void setup() {
  5.   size(480, 390);
  6.   frameRate(50);
  7.   mov = new Movie(this, "myvideo.mov");
  8.   mov.play();
  9.   speed=0.5;
  10. }

  11. void draw() {
  12.  background(255);
  13.  fill(255);   
  14.  mov.speed(speed);
  15.  image(mov, 90, 90, 390, 390);
  16.   fill(0);
  17.   text( "speed : " + speed, 10, 30);
  18.   if((mov.duration())-(mov.time())<0.1 && speed>0){
  19.     println("fin video "+mov.time()+"mov.duration : "+(mov.duration()));
  20.     mov.jump(0);
  21.   }
  22.   if(speed<0 && (mov.time()-0)<0.1){
  23.      println("fin video "+mov.time());
  24.      mov.speed(abs(speed));
  25.     mov.jump(mov.duration());
  26.   }
  27. }

  28. // Called every time a new frame is available to read
  29. void movieEvent(Movie m) {
  30.   m.read();
  31. }

  32. void keyPressed() {
  33.   if (key == CODED) {
  34.     if (keyCode == LEFT) {
  35.         speed = speed -0.1;
  36.     } else if (keyCode == RIGHT) {
  37.         speed = speed+0.1;
  38.    }
  39.   } 
  40. }
  41.   

Re : function interrupt draw

$
0
0
You haven't coded a way to check & restrict minimum & maximum values for variable speed.
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

$
0
0
Hi there,

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

$
0
0
I am using processing 2.0 beta 7 on a Mac. It has a new gstream API to play videos.I can use the processing.movie.Movie to play local video files without any problems, but how can I play 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

$
0
0
Hi there,
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

$
0
0
Thanks, that's what I was looking for. Should get me started, have some learning to do now

OpenGL glReadPixels and PBOs

$
0
0
In the past I have used the version of glReadPixels(...) that takes a Buffer to fill as input in an attempt to capture image sequences from Processing sketches in real-time without slowing down the interaction. I had also read about the other version of glReadPixels(...) that takes an offset instead of a buffer and is supposed to transfer pixels to a PBO (pixel buffer object) in video memory. It is apparently supposed to return immediately after starting the memory transfer.

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)

$
0
0
Hi Jonsku,

I'm trying to get your code to work and understand some reasoning behind it.  I'm using the current git processing code.

Why do you call 
  1. PGL pgl = ((PGraphicsOpenGL) g).beginPGL();
  2. gl = pgl.gl.getGL().getGL2();
every draw?  And why are you setting the viewport every draw?
Also I really don't understand this idea of pushing and popping framebuffers.  This may be more of a processing specific implementation thing, but do you have any insight?

I am trying to use your code to follow a workflow as follows.  I renamed your class to FBOGraphics for my test:
  1. 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);

    }


And it does nothing (which is the same I was seeing with your full code).  Any ideas?

Thanks


Sound Response (beginner needing serious help!)

$
0
0
Hello all! I am extremely new to processing and this forum, so your help and patience would be greatly appreciated!

My professor wants us to create a sound responsive work - in a zip folder, he included 

1.) SoundRespond.pde :
  1. class SoundRespond { // Define a class with custom name

  2.   import ddf.minim.*; // Variables and library imports
  3.   private Minim minim;
  4.   private AudioInput input;

  5.   SoundRespond(PApplet myApplet) { //A constructor, necessary part of a class

  6.     minim = new Minim (myApplet);
  7.     input = minim.getLineIn (Minim.STEREO, 512);
  8.   }

  9.   float adding( float _upperRange) { // Function for sound response
  10.     ////////////sound stuff///////
  11.     float volumeValue = input.mix.level () * 250;
  12.     volumeValue = constrain(volumeValue, 0, 100);

  13.     volumeValue = map(volumeValue, 0, 100, 0, _upperRange);
  14.     //println(volumeValue);// uncomment to debug only, else leave comment
  15.     ////////sound stuff end////////
  16.     return volumeValue;
  17.   }


  18. }
2.) His example sketch:
  1. //  1) +++++ To make a sketch sound responsive the first step is to put the SoundRespond.pde file in the same folder
  2. //with the sketch you are working on.
  3. //++++++++++++++++++++++++++++++++

  4. //  2) +++++ The second step is to copy the line below into your sketch above void setup() +++++
  5. SoundRespond mySoundRespond;
  6. //+++++++++++++++++++++++++++++++

  7. float diam =60;   //diameter of the circle
  8. float xPos = 0;   //the position of the circle left to right on x axis
  9. float yPos = 200; //the position of the circle to to bottom on y axis
  10. float speed = 3;  // how many pixels the circle will move with each frame
  11. float sndChng;

  12. void setup() {
  13.   size(500,500);
  14.   //  3) +++++ The third step is to copy the line below into your sketch below size(width,height);  +++++
  15.   // between the curly brackets of of setup()
  16.   mySoundRespond = new SoundRespond(this);
  17.   //++++++++++++++++++++++++++++++++++
  18.   smooth();
  19. }

  20. void draw() {
  21.   background(255);  // redraw the background each frame to erase the previous circle

  22.   // Use values to draw an ellipse
  23.   noStroke();
  24.   fill(#831919);
  25.   ellipse(xPos,yPos,diam,diam);
  26.   
  27.     //  4) +++++ The forth step is to choose a variable of something you want to change with sound  +++++
  28.   // this has to be between the curly brackets of of draw().
  29.   // Copy and paste "mySoundRespond.adding(value);" and put a number in the place of the word ""value".

  30.   sndChng = mySoundRespond.adding(5);

  31.   //The number determines the amount of the sound response effect. 
  32.   //For speed changes try 2.0-5.0 to start, size changes can be much larger numbers.
  33.   //++++++++++++++++++++++++++++++++++

  34. //must multiply speed by sndChng! adding does not work!!
  35. //uncomment constrain() below to keep circle moving
  36. //sndChng = constrain(sndChng,1,10);
  37.   xPos = xPos + (speed*sndChng);


  38.   println("xPos " + xPos);
  39.    println("speed " + speed);
  40.   if ((xPos > width) || (xPos < 0)) {
  41.    speed = speed * -1;
  42.   }
  43.  
  44.  
  45. }
I followed his first few instructions, copying the folder into my new sketch folder. In creating my own sketch, as well as trying to run this example, I received a "Found one too many { characters without a } to match it." message with the 
  1.   import ddf.minim.*; // Variables and library imports
line highlighted in the SoundRespond file. I've been scanning this over and over - I cannot find a source for this error! Any suggestions on what I might be reading wrong?

Re : Sound Response (beginner needing serious help!)

$
0
0
Hello!

You have one { too much.

You can auto format with ctrl-t

Then check please : the last } in draw() e.g. must be very left side of editor without any indent.

Now search a } that has an indent where shouldn't be any. The { must be before this.

Anyway maybe just go to the very last line and insert } could work or be very wrong

Or post your code here


Re : Sound Response (beginner needing serious help!)

$
0
0
Hmmm. The keyword import loads extra libraries to be used by your sketches.
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?

Re : Sound Response (beginner needing serious help!)

$
0
0
Thank you both! GoToLoop, you were right - I just erased the import ddf.minim.*; line from the SoundRespond class and pasted it below SoundRespond mySoundRespond; in my main sketch. Excellent! Maybe if I can come up with something moderately decent looking I'll post my code :) Thank you!

Re : Sound Response (beginner needing serious help!)

Viewing all 1768 articles
Browse latest View live