#include "testApp.h"
#include "ofOsc.h"
#include <iostream>

#include "ofMain.h"
#include "ofGraphics.h"


#define HOST "localhost"
#define PORT 12345

//--------------------------------------------------------------
void testApp::setup(){
	// open an outgoing connection to HOST:PORT
	sender.setup( HOST, PORT );
}

//--------------------------------------------------------------
void testApp::update(){
	
}


//--------------------------------------------------------------
void testApp::draw(){
	// display instructions
	char buf[256];
	sprintf( buf, "sending osc messages to %s:%d", HOST, PORT );
	ofDrawBitmapString( buf, 10, 20 );
	ofDrawBitmapString( "move the mouse to send osc message [/mouse/position <x> <y>]", 10, 50 );
	ofDrawBitmapString( "click to send osc message [/mouse/button <button> <\"up\"|\"down\">]", 10, 65 );
	ofDrawBitmapString( "press A to send osc message [/test 1 3.5 hello <time>]", 10, 80 );
}


//--------------------------------------------------------------
void testApp::keyPressed  (int key){ 
	if ( key =='a' || key == 'A' )
	{
		ofOscMessage m;
		m.setAddress( "/test" );
		m.addIntArg( 1 );
		m.addFloatArg( 3.5f );
		m.addStringArg( "hello" );
		m.addFloatArg( ofGetElapsedTimef() );
		sender.sendMessage( m );
	}
}

//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
	ofOscMessage m;
	m.setAddress( "/mouse/position" );
	m.addIntArg( x );
	m.addIntArg( y );
	sender.sendMessage( m );
}

//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
	
}

//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
	ofOscMessage m;
	m.setAddress( "/mouse/button" );
	m.addStringArg( "down" );
	sender.sendMessage( m );
}

//--------------------------------------------------------------
void testApp::mouseReleased(){
	ofOscMessage m;
	m.setAddress( "/mouse/button" );
	m.addStringArg( "up" );
	sender.sendMessage( m );	
}
