OSC Reciever Issue

edited January 2017 in Library Questions

Hello processing world! (this is my first post here)

I have a problem with the OSC reciever of oscP5 library. I can see the messges I'm receiving from SuperCollider. I can set variables in processig. Also I can send back the recieved messages. But unfortunetly I can not draw anything with that messages. I tried 4 different methods and still nothing. Please some help!

Thanks a lot..!

    import oscP5.*;
    import netP5.*;

    OscP5 oscP5;
    NetAddress myRemoteLocation;
    NetAddress superCollider;

    void setup() {
      size(700, 500);
      background(0);

      oscP5 = new OscP5(this, 12000);
      myRemoteLocation = new NetAddress("127.0.0.2", 12000);
      superCollider = new NetAddress("192.168.1.4", 57120);

      oscP5.plug(this, "test3", "/test3");
    }

    void draw() {
    }

    void mousePressed() {

      fill(250);
      rect(random(0, width), random(0, height), random(50, 200), random(50, 200));
    }

    void oscEvent(OscMessage theOscMessage) {
      /* check if theOscMessage has the address pattern we are looking for. */
      if (theOscMessage.checkAddrPattern("/test")==true) {
        /* check if the typetag is the right one. */
        if (theOscMessage.checkTypetag("ii")) {

          /* parse theOscMessage and extract the values from the osc message arguments. */
          int val01 = theOscMessage.get(0).intValue();  // get the first osc argument
          int val02 = theOscMessage.get(1).intValue(); // get the second osc argument


          fill(250);
          rect(random(0, width), random(0, height), random(50, 200), random(50, 200));

          OscMessage myMessage = new OscMessage("/testBack");
          myMessage.add(val01); /* add an int to the osc message */
          myMessage.add(val02);
          oscP5.send(myMessage, superCollider);
        }
      }

      /* check if theOscMessage has the address pattern we are looking for. */
      String addr = theOscMessage.addrPattern();
      int val0 = theOscMessage.get(0).intValue(); 
      if (addr.equals("/test2")) {
        fill(250);
        rect(random(0, width), random(0, height), random(50, 200), random(50, 200));
      }
      if (theOscMessage.checkAddrPattern("/test4")==true) {
        /* parse theOscMessage and extract the values from the osc message arguments. */
        int val01 = theOscMessage.get(0).intValue();  // get the first osc argument
        int val02 = theOscMessage.get(1).intValue(); // get the second osc argument
        fill(150);
        ellipse(20, 20, 50, 50);


        OscMessage myMessage = new OscMessage("/testBack4");
        myMessage.add(val01); /* add an int to the osc message */
        myMessage.add(val02);
        oscP5.send(myMessage, superCollider);
      }
    }

    public void test3(int theA, int theB) {
      println("### plug event method. received a message /test3.");
      println(" 2 ints received: " +theA+ ", " +theB);  

      fill(250);
      rect(random(0, width), random(0, height), random(50, 200), random(50, 200));
    }

Answers

  • Format your code. Edit your post, select your code and hit ctrl+o. Ensure there is an empty line above and below your code.

    Kf

  • Sorry, first try. Thanks

  • Answer ✓

    Do not issue drawing commands outside the "Animation Thread"! [-X
    Place them in draw() or some other function called from draw(). :-B

  • @GoToLoop okay. can you tell me please if I have to place all the reciever in draw() or only the the rect() for example and trigger it in some way from the recieved message?

  • Answer ✓

    Here is an example of how to use data from an OSC event. just click and move the mouse around.

    Kf

    /**
     * oscP5sendreceive by andreas schlegel
     * example shows how to send and receive osc messages.
     * oscP5 website at http://www.sojamo.de/oscP5
     */
    
    import oscP5.*;
    import netP5.*;
    
    OscP5 oscP5;
    NetAddress myRemoteLocation;
    boolean drawFlag=false;
    
    void setup() {
      size(400, 400);
      frameRate(25);
      /* start oscP5, listening for incoming messages at port 12000 */
      oscP5 = new OscP5(this, 12000);
    
      /* myRemoteLocation is a NetAddress. a NetAddress takes 2 parameters,
       * an ip address and a port number. myRemoteLocation is used as parameter in
       * oscP5.send() when sending osc packets to another computer, device, 
       * application. usage see below. for testing purposes the listening port
       * and the port of the remote location address are the same, hence you will
       * send messages back to this sketch.
       */
      myRemoteLocation = new NetAddress("192.168.0.13", 12000); //("127.0.0.1",12000);
      fill(255);
      strokeWeight(3);
      stroke(250, 250, 20);
    }
    
    
    void draw() {
      background(0);  
      if (drawFlag==true)
        ellipse(width/2, height/2, mouseX, mouseX);
    }
    
    void mousePressed() {
      /* in the following different ways of creating osc messages are shown by example */
      OscMessage myMessage = new OscMessage("/test");
      int[] mm={1, 2, 5, mouseX};
      myMessage.add(mm); /* add an int to the osc message */
    
      /* send the message */
      oscP5.send(myMessage, myRemoteLocation);
    }
    
    
    
    /* incoming osc message are forwarded to the oscEvent method. */
    void oscEvent(OscMessage theOscMessage) {
      /* print the address pattern and the typetag of the received OscMessage */
      print("### received an osc message.");
      print(" addrpattern: "+theOscMessage.addrPattern());
      println(" typetag: "+theOscMessage.typetag());
    
      drawFlag=!drawFlag;
    }
    
  • @kfrajer Hey.. thank you very much!

Sign In or Register to comment.