I’m working on a SuperCollider, Processing 3 interaction. 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. I would really appreciate any help. I have been working on this for a while. I have watched some tutorials on this, so my code is inspired by the tutorials. Here is what I have so far:
SuperCollider Code:
~bus1 = Bus.control(s);
~proc = NetAddr("127.0.0.1", 12321);
(
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(kbs, sig.dup);
Out.ar(0, sig.dup);
}).add;
)
OSCdef(\getfreq, {
~proc.sendMsg("/freq1", ~bus1.getSynchronous.asFloat);
}, "/getfreq");
(
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]*2, inf),
\dur, Pseq([1/8], inf),
\stretch, 1.5,
\kbs, ~bus1,
\out, 0,
).play;
)
Processing 3 Code:
import netP5.*;
import oscP5.*;
OscP5 osc;
NetAddress sc;
float color1 = 0.0;
float color2 = 0.0;
float color3 = 0.0;
float color4 = 0.0;
float color5 = 0.0;
void setup(){
size(640, 480, P2D);
background(0);
osc = new OscP5(this, 12321);
sc = new NetAddress("127.0.0.1", 57120);
osc.plug(this, "newfreq", "/freq1");
}
void draw(){
OscMessage msg = new OscMessage("/getfreq");
osc.send(msg, sc);
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);
}
void newfreq (float rms){
color1 = map(rms, 220, 220.1, 0.0, 255);
color2 = map(rms, 261.63, 261.64, 0.0, 255);
color3 = map(rms, 392, 393, 0.0, 255);
color4 = map(rms, 164.81, 164.82, 0.0, 255);
color5 = map(rms, 196, 197, 0.0, 255);
}