osc app using openframeworks

Nikolaus Gradwohl2009-03-06T04:21:00+01:00

I have written a little demo app in openframeworks that shows how to react to osc events. Openframeworks uses ofxOsc as OSC library, which comes preinstalled in the FAT distribution.

the programm shows a square on a black background. the gray level of the square can be adjusted by sending osc messages to port 1234.

the following little ruby program sets the color to #808080

require 'osc'
msg = OSC::Message.new("/color", "i", 128 )
c = OSC::UDPSocket.new
c.send( msg, 0, "localhost", 1234 )

in the 'setup' method a osc receiver is initalized, and in the 'update' method, the messages are fetched from a queue and parsed.

I didn't generate any real complex osc messages for now, but as far as i can tell it is a very nice osc framework.


#include "testApp.h"

void testApp::setup(){
    gray = 255;
    receiver.setup( 1234 );

void testApp::update(){

    while( receiver.hasWaitingMessages() ) {
        ofxOscMessage m;
        receiver.getNextMessage( &m );
        if ( strcmp( m.getAddress(), "/color" ) == 0 ) {
            gray = m.getArgAsInt32( 0 );

void testApp::draw(){
    ofBackground( 0,0,0 );
    ofSetColor( gray, gray, gray );
    ofRect(  ofGetWidth()/2-100, ofGetHeight()/2-100, 200, 200 );

void testApp::keyPressed  (int key){}
void testApp::keyReleased  (int key){}
void testApp::mouseMoved(int x, int y ){}
void testApp::mouseDragged(int x, int y, int button){}
void testApp::mousePressed(int x, int y, int button){}
void testApp::mouseReleased(){}


    #ifndef _TEST_APP
    #define _TEST_APP

    #include "ofMain.h"
    #include "ofAddons.h"

    class testApp : public ofSimpleApp{


            void setup();
            void update();
            void draw();

            void keyPressed(int key);
            void keyReleased(int key);
            void mouseMoved(int x, int y );
            void mouseDragged(int x, int y, int button);
            void mousePressed(int x, int y, int button);
            void mouseReleased();

            int gray;
            ofxOscReceiver  receiver;




#include "ofMain.h"
#include "testApp.h"

int main( ){

    // can be OF_WINDOW or OF_FULLSCREEN
    // pass in width and height too:
    ofSetupOpenGL(400,400, OF_WINDOW);

    // this kicks off the running of my app
    ofRunApp(new testApp);
Tweet This! submit to reddit Digg!   Tags: | no comments | no trackbacks

See also:

feeling watched in openframeworks
rotating box in openframeworks
OpenFrameworks Demo
running openframeworks on a RaspberryPI
Android Monome-Clone in Processing



Leave a response

Leave a comment