Skip to content

Instantly share code, notes, and snippets.

@jordanorelli
Created June 10, 2012 20:37
Show Gist options
  • Save jordanorelli/2907239 to your computer and use it in GitHub Desktop.
Save jordanorelli/2907239 to your computer and use it in GitHub Desktop.
ChucK -> Processing communication demo
import oscP5.*;
import netP5.*;
PGraphics pg;
OscP5 oscP5;
NetAddress inbound;
float minFreq = 140;
float maxFreq = 1600;
float[] notes;
void setup() {
size(800, 600);
oscP5 = new OscP5(this, 9000);
oscP5.plug(this, "getNote", "/noteOn");
background(0);
pg = createGraphics(width, height, JAVA2D);
}
void draw() {
}
void oscEvent(OscMessage m) {
if(!m.isPlugged()){
println("unknown message received at " + m.addrPattern() + " with type " + m.typetag());
}
}
public void getNote(float freq, float pan) {
float x = map(pan, -1.0, 1.0, 0, width);
float y = map(freq, 140, 1600, 0, height);
pg.beginDraw();
pg.background(0);
pg.stroke(255);
pg.strokeWeight(4);
pg.ellipse(x, y, 20, 20);
pg.endDraw();
image(pg, 0, 0);
}
SinOsc s => ADSR e => Pan2 pan => dac;
OscSend toUI;
toUI.setHost("localhost", 9000);
100::ms => e.attackTime;
100::ms => e.releaseTime;
e.keyOff();
140 => float minFreq;
1600 => float maxFreq;
fun void playNote(float f) {
Std.rand2f(-1, 1) => float p;
p => pan.pan;
f => s.freq;
e.keyOn();
f => toUI.addFloat;
p => toUI.addFloat;
toUI.startMsg("/noteOn", "ff");
100::ms => now;
e.keyOff();
100::ms => now;
}
while (1) {
playNote(Math.rand2f(minFreq, maxFreq));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment