Processing OSC

Nikolaus Gradwohl2008-07-04T06:23:00+02:00

I have recently posted about my chuck-script that generates osc events from my m-audio iControl. Now i have written a Processing-sketch, that visualizes the events. The OSC-Events are parsed using the oscP5.

import oscP5.*;
import netP5.*;

OscP5 oscP5;
int buttons[] = {0,0,0,0,0,0,0,0};
float knobs[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};

void setup() {
size(500,500);
frameRate(25);
background( 0 );
oscP5 = new OscP5( this, "239.0.0.1", 3334 );
}

void draw() {
drawControl();
}

void drawControl() {
smooth();
ellipseMode( CORNER );
for (int i = 0; i < 8; i++ ) {
    fill( 255 * buttons[i] );
    stroke( 255 );
    ellipse( 10, 20 + i * 20, 15, 15 );

    fill( 0 );
    rect( 40, 20 + i * 20, 100, 15 );  
    noStroke();
    fill( 0, 0, 128 );
    rect( 41, 21 + i * 20, 99 * knobs[i], 14 );  

}
}

void oscEvent( OscMessage m ) {
print( " pattern " + m.addrPattern());
println( " type " + m.typetag());
if (m.addrPattern().equals( "/icontrol/button" )) {
    int chan = m.get(0).intValue();
    int val = m.get(1).intValue();
    buttons[chan] = val;
} else if ( m.addrPattern().equals( "/icontrol/knob")) {
    int chan = m.get(0).intValue();
    float val = m.get(1).floatValue();
    knobs[chan] = val;
}
}
read more ...