Processing / Super Colider library
So I'm working on an interesting project in the super collider to processing library.
However, I've run into a snag. I'm using the Synth.get feature to watch the amplitude of a Synth, and all I get back is a default value
SynthDef(\voice, { |outbus = 0, amp = 10, freq = 440, pan = 0|
var data;
amp = SinOsc.kr(20,1,20); // Amplitude.kr( SoundIn.ar(0)) * 10 ;
freq = Lag.kr(freq, 0.1);
data = SinOsc.ar(freq, 0, amp);
Out.ar(outbus, Pan2.ar(data, pan));
}).store;
here's the synth def.
and here's the processing code (prepare! - the relevant bit is at the very bottom ):
import supercollider.*;
import oscP5.*;
import netP5.*;
Synth synth;
Synth voice;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Timer
class Timer {
int timedelt = 1;
int time = 0;
int timeit(){
this.time += this.timedelt ;
return time;
};
void reset(){time = 0;};
void printme(){print(time);};
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Makes the circle
class Circle {
float radius, delta;
float xdelt;
float ydelt;
float x, y;
float randomgrowth;
Circle ( int radius, int delta ) {
this.radius = radius;
this.delta = delta;
this.x = random(1000);
this.y = random(1000);
this.xdelt = random(40)- 20;
this.ydelt = random(40) - 20;
this.randomgrowth = random(400);
}
void draw() {
fill(25,25,25,25);
ellipse(this.x, this.y, this.radius, this.radius);
fill(127,255,0,25);
ellipse(this.x , this.y , this.radius / 2, this.radius / 2 + 10);
synth.set("amp", this.radius / 500);
synth.set("freq", 80 + this.y / 10);
synth.set("lfofreq", this.x / 10);
}
void update(){
if(radius >= randomgrowth){
// this.delta *= -1;
this.radius = randomgrowth;
}
/* else if ( radius < 0 ) {
this.delta *= -1;
this.radius = 0;
}
*/
if (this.x >= 1200 ) {
this.x *= -1;
}
if (this.y >= 1200 ) {
this.y *= -1;
}
this.radius += this.delta;
this.x += this.xdelt;
this.y += this.ydelt;
}
void kill(){ ///// Kills the Circle
this.radius = 0;
this.delta = 0;
// synth.free();
}
}
Circle circle;
Circle[] circlearray;
Timer timeguy;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////SQUARE
class Square {
float size, delta;
float xdelt;
float ydelt;
float x, y;
Square ( int size ) {
this.size = size;
this.delta = delta;
voice.get("amp", this, "deltamod");
this.x = random(500);
this.y = random(500);
this.xdelt = random(40)- 20;
this.ydelt = random(40) - 20;
}
void draw(){
fill(25,25,25,25);
rect(this.x , this.y, this.size ,this.size );
}
void update(){
this.size += this.delta;
if (this.size == 500){
square.kill();
for(int i = 0; i < 50; i++){
circlearray[i].kill();
}
}
}
void kill(){ ///// Kills the Square
this.size = 0;
this.delta = 0;
// synth.free();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////// SETUP
}
Square square;
void setup(){
// uses default sc server at 127.0.0.1:57110
// does NOT create synth!
synth = new Synth("sine");
voice = new Synth("voice");
// set initial arguments
synth.set("amp", 0.5);
synth.set("freq", 80);
// voice.set("amp", 10);
voice.set("freq", 0);
// create synth
synth.create();
voice.create();
size(1200,800);
timeguy = new Timer();
circle = new Circle(40,2);
square = new Square(40);
int[] foo = new int[10];
circlearray = new Circle[100];
for( int i = 0; i < 100; i++){
circlearray[i] = new Circle(40,2);
}
}
//////////////////////////////////////////////////////////////////////////////IMPLEMENT
void draw(){
timeguy.timeit();
timeguy.printme();
circle.update();
square.update();
background(255,0,0);
circle.draw();
square.draw();
voice.get("amp", this, "show");
for( int i = 0; i < 100; i++){
circlearray[i].update();
circlearray[i].draw();
}
if(timeguy.time == 1200){
for( int i = 0; i < 100; i++){
circlearray[i].kill();
}
};
}
/////
void mousePressed ()
{
voice.get("amp", this, "show");
}
void show (int nodeID, String arg, float value)
{
println("amp " + value);
square.delta = value;
if (square.size > 100){
square.kill();}
}
One idea I have entertained is that the Synthdef only spits out default values until you tell it to do something. I'm not sure how I'll make it do something "fake" so that I can simply read amplitudes from the microphone into processing.
Does anyone have any ideas?
The super collider guys have insinuated to me that I simply can't use a Synthdef in this way. Has anyone here found another way to get live amplitude values into processing? this is kind of maddening since I've been touting processing's superiority to Jitter/GEM lately.