/*
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; 
int myFreqVal = 127;
float myLengthVal = 0.1;
float hPos=0.0;

void setup() {
size(828, 128);
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() {

}


/* 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 */
  
  // uncomment this for messages
//println("### received an osc message with addrpattern "+theOscMessage.addrPattern()+" and typetag "+theOscMessage.typetag());
//theOscMessage.print();
  
  // uncomment this for pitches:
  myFreqVal = theOscMessage.get(0).intValue();
  print(myFreqVal);
  print(", ");
  myLengthVal = theOscMessage.get(1).floatValue();
  println(myLengthVal);
  line(hPos, myFreqVal, hPos + (myLengthVal*40), myFreqVal);
  hPos = hPos + (myLengthVal*40);
}