Processing with SuperCollider (using oscP5 library)

I’m trying to get SuperCollider to control animations in Processing through OSC. Whenever a certain frequency is played from a synth, a shape appears in the Processing window, but when the frequency is not being played, the shape does not appear on the screen. The frequency would be controlling the color value of the shapes. For example, if a frequency of 220 is played, the color value will be 255. I’m wondering if I could send the frequencies from my Pbind as floating point number OSC messages to Processing to control the animations? I’d really appreciate any help.

It seems I’m almost there. I see shapes appear in the Processing window but they don’t go away. And it seems the incoming messages don’t correspond to the color number.

I’ve tried making another pattern in SC where I’m just sending a bunch of zeroes so the shapes do go away momentarily, however I hear a bass-y clicking sound that is unpleasant, so I think I’d like to figure out how to make the shapes go away in Processing.

SuperCollider:

n = NetAddr("127.0.0.1", 47120);  // open 47120 on localhost server


(
SynthDef.new(\synth, {
	arg freq, kbs;
	var env, sig;
	env = EnvGen.kr(Env([0,1,0], [0.01, 0.5]), doneAction:2);
	sig = Saw.ar(freq, 0.25)*env;
	Out.ar(0, sig.dup);
}).add;
)


(
    Pbind(
	\instrument, \synth,
    \freq, Pseq([220.00, 329.63, 523.25, 329.63, 523.25, 329.63, 146.83, 220.00, 349.23, 220.00, 349.23, 220.00, 174.71, 261.63, 440.00, 261.63, 440.00, 261.63].asFloat, inf),
    \bla, Pfunc { |e| n.sendMsg("/sc3p5" , e[\freq] ) },
	\dur, Pseq([1/8], inf),
	\stretch, 10.5,
	\out, 0,
).play;
)

Processing:

import oscP5.*;
import netP5.*;
OscP5 oscP5;

float color1 = 0.0;
float color2 = 0.0;
float color3 = 0.0;
float color4 = 0.0;
float color5 = 0.0;

void setup() {
  size(400, 300);
  frameRate(24);
  background(0);
  smooth();

  OscProperties properties = new OscProperties();
  properties.setListeningPort(47120); // osc receive port (from sc)
  oscP5 = new OscP5(this, properties);
}

void oscEvent(OscMessage msg) {
  if (msg.checkAddrPattern("/sc3p5")) {
    color1 = msg.get(0).floatValue(); // receive floats from sc
  }
    if (msg.checkAddrPattern("/sc3p5")) {
    color2 = msg.get(0).floatValue(); // receive floats from sc
  }
    if (msg.checkAddrPattern("/sc3p5")) {
    color3 = msg.get(0).floatValue(); // receive floats from sc
  }
    if (msg.checkAddrPattern("/sc3p5")) {
    color4 = msg.get(0).floatValue(); // receive floats from sc
  }
    if (msg.checkAddrPattern("/sc3p5")) {
    color5 = msg.get(0).floatValue(); // receive floats from sc
  }
}

void draw() {
    stroke(0, 255, 0);
    fill(color1);
    triangle(0, 0, 0, 50, 50,0); 
    stroke(0, 255, 0); 
    fill(color2); 
    triangle(0, 50, 50, 0, 50, 50); 
    stroke(0, 255, 0);
    fill(color3); 
    triangle(50, 0, 50, 50, 100, 0); 
    stroke(0, 255, 0); 
    fill(color4); 
    triangle(50, 50, 100, 0, 100, 50);
    stroke(0, 255, 0);
    fill(color5);
    triangle(100, 50, 100, 0, 150, 0); 
}