import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;

public float firstValue = 0;

void setup() {
  size(400,400);
  frameRate(25);
  /* start oscP5, listening for incoming messages at port 12000 */
  oscP5 = new OscP5(this,7400);
  
  /* 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("127.0.0.1",10000);
}

void draw() {
  background(0);  
}


void oscEvent(OscMessage theOscMessage) {
  /* check if theOscMessage has the address pattern we are looking for. */
  
  if(theOscMessage.checkAddrPattern("/EXP/Blink")==true) {
    /* check if the typetag is the right one. */
//   if(theOscMessage.checkTypetag("float")) {
      /* parse theOscMessage and extract the values from the osc message arguments. */
      float firstValue = theOscMessage.get(0).floatValue();
      print("### received an osc message /EXP/Blink with typetag float.");
      println(" value: "+firstValue+"");
     
      return;
  //  }  
  } 
  OscMessage myMessage = new OscMessage("/EXP/Blink");
  
 myMessage.add(firstValue); /* add a float to the osc message */
 /* send the message */
  oscP5.send(myMessage, myRemoteLocation); 
  
 println("### sent an osc message. with address pattern "+theOscMessage.addrPattern());
}


