/*
Processing/OSC/Max/SC Task 1
*/

/*
* code adapted by Richard Hoadley, 2011
* rhoadley.net
* v0.2
* todo:
* add mouse pressed action
* add modulation? function to other mouse coordinate...
* add colour?
*/
 
import oscP5.*;
import netP5.*;
 
OscP5 oscP5;

/* a NetAddress contains the ip address and port number of a remote location in the network. */
NetAddress myBroadcastLocation; 


void setup() {
size(480, 120);
smooth();
stroke(0, 102);

/* create a new instance of oscP5. 
* 12000 is the port number you are listening for incoming osc messages.
*/
oscP5 = new OscP5(this,12000);
 
/* create a new NetAddress. a NetAddress is used when sending osc messages
* with the oscP5.send method.
*/
 
/* the address of the osc broadcast server */
myBroadcastLocation = new NetAddress("127.0.0.1",57120);
}


void draw() {
float weight = dist(mouseX, mouseY, pmouseX, pmouseY);
strokeWeight(weight);
line(mouseX, mouseY, pmouseX, pmouseY);

 /* create a new OscMessage with an address pattern, in this case /test. */
 // OscMessage myOscMessage = new OscMessage("/test");
OscMessage myOscMessage;
myOscMessage = new OscMessage("/test");

/* add a value (an integer) to the OscMessage */
myOscMessage.add(mouseX); 
myOscMessage.add(mouseY); 
myOscMessage.add(weight); 
println( myOscMessage); 
// println(myBroadcastLocation);
/* send the OscMessage to a remote location specified in myNetAddress */
oscP5.send(myOscMessage, myBroadcastLocation);

}


/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage theOscMessage) {
  /* get and print the address pattern and the typetag of the received OscMessage */
  println("### received an osc message with addrpattern "+theOscMessage.addrPattern()+" and typetag "+theOscMessage.typetag());
  theOscMessage.print();
}