Trouble running oscp5 library and P3D renderer together in processing 3.x

153 Views Asked by At

I attempted to map data from external devices to draw patterns. But the oscP5 library and P3D renderer could not work together in processing both 3.3.7 and 3.4 while they can work separately. They can work in processing 2.2.1 but 2.2.1 doesn't support the sound library. Any one knows how to solve it?

import oscP5.*;
OscP5 oscP5;

float value;

void setup(){
size(400, 400, P3D);
rectMode(CENTER);
oscP5 = new OscP5(this, 60000);
}

void oscEvent(OscMessage theOscMessage){
  if (theOscMessage.checkAddrPattern("/ATT")){
    value = theOscMessage.get(0).floatValue();
  }
}

void draw(){
  background(0);
  noStroke();
  fill(255);
  float r = second()/10;
  rotateZ(r);
  rect(width/2, height/2, value, value);
}

The error when oscP5 and P3D work together

1

There are 1 best solutions below

0
On

I solved the problem. In my original code there is a frameRate initialisation in setup() (minimal example showed below), I didn't realise that it's it that caused the problem (cause the frameRate initialisation causes no error when it works with oscP5 or P3D respectively) so I didn't write it in my question. Now I deleted the frameRate initialisation line (frameRate(30)) then oscP5 and P3D can finnaly work together (even I'm still confused but it doesn't affect my current work).

import oscP5.*;
OscP5 oscP5;

float value;

void setup(){
size(400, 400, P3D);
// the following line causes the error when oscP5 and P3D attempt to work together,
// but the code works when there is either oscP5 and P3D, oscP5 and frameRate or P3D and frameRate.
frameRate(30);
rectMode(CENTER);
oscP5 = new OscP5(this, 60000);
}

void oscEvent(OscMessage theOscMessage){
  if (theOscMessage.checkAddrPattern("/ATT")){
  value = theOscMessage.get(0).floatValue();
  }
}

void draw(){
  background(0);
  noStroke();
  fill(255);
  float r = second()/10;
  rotateZ(r);
  rect(width/2, height/2, value, value);
}

Hope that I explained clearly. :)