Search code examples
actionscript-3flashprocessingosc

About Processing


I was wondering about OSC could you tell me more about it.


Solution

  • I've used TUIO-AS3's UDPConnector for some minimal OSC interaction with as3 for a few projects and didn't have any problems. Here a minimal snippet to illustrate what I've done:

    package
    {
        import flash.display.Sprite;
        import flash.utils.getDefinitionByName;
    
        import org.tuio.connectors.UDPConnector;
        import org.tuio.osc.*;
    
        public class BasicOSC extends Sprite implements IOSCConnectorListener
        {
            private var oscSocket:UDPConnector;
            private const OSCSERVER:String = "127.0.0.1";
            private const PORT:int = 8082;
    
            public function BasicOSC()
            {
                try{    
                    oscSocket = new UDPConnector(OSCSERVER,PORT);
                    oscSocket.addListener(this);
                    trace(this,"OSC ready");
                }catch(e:Error){    trace(e.getStackTrace());   }   
            }
            public function acceptOSCPacket(oscPacket:OSCPacket):void{
                //handle OSC here
                var message:OSCMessage = oscPacket as OSCMessage;
                trace("message from :",message.address,"at",new Date());
                for(var i:int = 0; i < message.arguments.length; i++)
                    trace("\targs["+i+"]",message.arguments[i]);
            }
        }
    }
    

    Update: Notice that I'm casting the OSCPacket as an OSCMessage which behind the scenes deals with the parsing and easily makes the address and arguments available, which is what you're after.

    For reference here's the minimal Processing sketch I've used to simulate your setup:

    import oscP5.*;
    import netP5.*;
    
    OscP5 osc;
    NetAddress where;
    
    void setup() {
      frameRate(25);text("click to send\nOSC",5,50);
    
      osc = new OscP5(this,12000);
      where = new NetAddress("127.0.0.1",8082);
    }
    void draw() {}
    void mousePressed() {
      OscMessage what = new OscMessage("/straps");
      what.add(193.4509887695313);
      osc.send(what, where); 
    }
    

    HTH

    PreventFires

    City Monitor