Hi, im trying to use OSC to have processing and super collider communicate with each other. I have them communicating so far as when something happens within processing a sound is generated in super collider. This im ok with, the problem im having is that I want a sound to be generated only when the line comes in contact with an ellipse within the first section, so the first 100 pixels on the y axis. Below is my code from both processing and super collider.
Any help would be greatly appreciated
cheers
Code:ArrayList balls;
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
int numBalls = 100;
int currentBall = 0;
int ballWidth = 25;
float linex = 0.0;
boolean ball = false;
boolean start = false;
PFont font;
int ballX = 0;
int ballY = 0;
void setup(){
size(500,550);
smooth();
oscP5 = new OscP5(this,12000);
myRemoteLocation = new NetAddress("127.0.0.1",57120);
balls = new ArrayList();
font = createFont("GillSans-48.vlw",42);
textFont(font);
}
void draw(){
background(0);
stroke(247,15,15,200);
strokeWeight(8);
if(start == true){
linex = linex + 2.0;
line(linex,0.0,linex,500);
if(linex>=500){
linex=0;
}
}
stroke(255);
strokeWeight(4);
line(0,100,500,100);
line(0,200,500,200);
line(0,300,500,300);
line(0,400,500,400);
fill(250,25,25);
noStroke();
rect(0,500,500,500);
if((keyPressed == true) && (key == 's')){
start = true;
}
fill(255);
text("Press 's' to start",10,545);
for(int i = balls.size()-1; i>=0;i--){
Ball ball = (Ball) balls.get(i);
ball.display();
}
}
void mousePressed(){
ball =true;
ballX = mouseX;
ballY = mouseY;
balls.add(new Ball(ballX, ballY,ballWidth));
}
BALL CLASS CODE:
Code: class Ball{
float x,y,w;
Ball(float tempX, float tempY, float tempW){
x = tempX;
y = tempY;
w = tempW;
}
void display(){
fill(255);
noStroke();
if(dist(x,0,linex,0)<=ballWidth/2)fill(255,0,0);
if(dist(x,0,linex,0)>=ballWidth/2)fill(255);
ellipse(x,y,w,w);
if(dist(x,0,linex,0)<=ballWidth/2){
OscMessage myMessage = new OscMessage("/synth");
oscP5.send(myMessage,myRemoteLocation);
}
}
}
SUPERCOLLIDER CODE:
Code:(
SynthDef("synth",{ arg freq = 440, note = 50, amp = 0.3, dur = 1;
var sig;
sig = SinOsc.ar(freq, 0, amp)
* EnvGen.kr(Env.perc(0.01,dur),doneAction:2);
Out.ar(0, sig ! 2);
}).send(s);
)
(
var node;
o = OSCresponder(nil, '/synth', {arg time, responder, msg, addr;
Synth(\synth,
[\freq, 440, \dur, 1 ]);
}).add;
)
o = remove;