Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

OscP5 can't draw anything

$
0
0

Hi. I'm using OscP5 to receive data from PureData. I want to draw something on the screen everytime an OSC message is received. What is going to be drawn depends on the message pattern.

On the code bellow i'm trying to draw a random ellipse everytime any message is received, just for illustrating my problem.

The problem is: nothing is drawn. The function i'm calling IS running, as you can see in the console. But nothing is being drawn most of the times. An ellipse is drawn like every 100 times the function is called.

import oscP5.*;
import netP5.*;
float count=1;

OscP5 oscP5;
NetAddress myRemoteLocation;

void setup() {
  size(400,400);
  oscP5 = new OscP5(this,12000);
  myRemoteLocation = new NetAddress("127.0.0.1",12000);
}

void draw() {
}

public void randomEllipse() {
  ellipse(random(0,width),random(0,height),20,20);
  println("randomEllipse() ran "+count+" times");
  count++;
}


public void oscEvent(OscMessage theOscMessage) {
  randomEllipse();
}

// This sends the message to this same Sketch when any key is pressed. Don't forget to click the sketch for focus!
void keyPressed() {
  OscMessage myMessage = new OscMessage("/test");  
  oscP5.send(myMessage, myRemoteLocation);
}

My theory is:

oscEvent works well when setting public variables that will be used as parameters for stuff in draw(). So i'm guessing that for something to be drawn, it must be run at the time a frame is beeing processed. So if you receive a oscMsg but no frame is beeing drawn, the ellipse() inside the function won't be scheduled to the next frame. On the rare case that the oscMsg is receive when a frame is beeing drawn, then the ellipse will appear.

I've thought about using oscEvent to assing somevalue to a array, then reading that array every frame with draw() to know what actions were scheduled.

But this will be a lot of extra work, since i will have lots of different things to drawn depending of lots of osc patters received. So some messages would use strings, others floats, others lists of floats. This way i would have to use an array to everykind of input i receive from the Osc, or save everything as a string, use a second typeTag array and convert everything on the fly.

My question is: There is another way to draw something when an Osc message is being received without having to save stuff on variables? Something like

public void oscEvent(OscMessage theOscMessage) {
  ellipse(random(0,width),random(0,height),20,20);
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles