diff src/melodyTriangle.cpp @ 18:9a414ea6880d

Added colour coding of voice status.
author samer
date Tue, 31 Jan 2012 15:49:40 +0000
parents add71da95cb4
children 055d7524bae4
line wrap: on
line diff
--- a/src/melodyTriangle.cpp	Tue Jan 31 12:52:42 2012 +0000
+++ b/src/melodyTriangle.cpp	Tue Jan 31 15:49:40 2012 +0000
@@ -20,19 +20,31 @@
 	//voices=*Voice[numVoices];
 	sender.setup( host,port );
 	receiver.setup( receivePort );
-
+	
+	{
+		ofxOscMessage m;
+		m.setAddress( "/reply_to" );
+		m.addIntArg( receivePort );
+		sender.sendMessage( m );
+		printf("sent /reply_to %i\n",receivePort);
+	}
 }
 
 //--------------------------------------------------------------
 void melodyTriangle::setup(){
-	//voices = new Voice[NUMVOICES];
-	
 	ofSetCircleResolution(100);
 	ofBackground(0,0,0);
 	ofSetWindowTitle("Melody Triangle");
+	// if vertical sync is off, we can go a bit fast... 
+	// this caps the framerate at 40fps.
+	ofSetFrameRate(40); 
+	ofEnableSmoothing();
+
+	// Set up triange coordinates. 
+	// NB. whatever happens here, the triangle must be
+	// isosceles and left-right symmetric around x=x1.
+	// Otherwise the clipping won't work
 	triangleHeight=ofGetHeight()*0.75;
-	ofSetFrameRate(40); // if vertical sync is off, we can go a bit fast... this caps the framerate at 60fps.
-	ofEnableSmoothing();
 	x1=ofGetWidth()/2;
 	y1=(ofGetHeight()-triangleHeight)/2;
 	x2=ofGetWidth()/2-triangleHeight/sqrt(3);
@@ -109,26 +121,41 @@
 		// get the next message
 		ofxOscMessage m;
 		receiver.getNextMessage( &m );
-		string msg_string;
-		msg_string = m.getAddress();
-		msg_string += ": ";
-		for ( int i=0; i<m.getNumArgs(); i++ )
-		{
-			// get the argument type
-			msg_string += m.getArgTypeName( i );
-			msg_string += ":";
-			// display the argument - make sure we get the right type
-			if( m.getArgType( i ) == OFXOSC_TYPE_INT32 )
-				msg_string += ofToString( m.getArgAsInt32( i ) );
-			else if( m.getArgType( i ) == OFXOSC_TYPE_FLOAT )
-				msg_string += ofToString( m.getArgAsFloat( i ) );
-			else if( m.getArgType( i ) == OFXOSC_TYPE_STRING )
-				msg_string += m.getArgAsString( i );
-			else
-				msg_string += "unknown";
+		if (m.getAddress()=="/notify") {
+			int id=m.getArgAsInt32(0)-1;
+			string st=m.getArgAsString(1);
+			
+			if (id>=0 && id<numVoices) {
+				Voice *v=voices[id];
+
+				if (st=="received") v->status=Voice::clear;
+				else if (st=="pending") v->status=Voice::pending;
+				else if (st=="requested") v->status=Voice::waiting;
+				else cout << "** unrecognised voice status: " << st << ".\n";
+			} else {
+				cout << "** voice id "<<id<<" out of range.\n";
+			}
+		} else {
+			string msg_string;
+			msg_string = m.getAddress();
+			msg_string += ": ";
+			for ( int i=0; i<m.getNumArgs(); i++ )
+			{
+				// get the argument type
+				msg_string += m.getArgTypeName( i );
+				msg_string += ":";
+				// display the argument - make sure we get the right type
+				if( m.getArgType( i ) == OFXOSC_TYPE_INT32 )
+					msg_string += ofToString( m.getArgAsInt32( i ) );
+				else if( m.getArgType( i ) == OFXOSC_TYPE_FLOAT )
+					msg_string += ofToString( m.getArgAsFloat( i ) );
+				else if( m.getArgType( i ) == OFXOSC_TYPE_STRING )
+					msg_string += m.getArgAsString( i );
+				else
+					msg_string += "unknown";
+			}
+			cout<< msg_string << "\n";
 		}
-		cout<< msg_string << "\n";
-		
 	}
 }
 
@@ -208,6 +235,7 @@
 						vg->posx=mouseX;
 						vg->posy=mouseY;
 						vg->inTriangle=false;
+						vg->status=Voice::clear;
 					} else {
 						// otherwise, we move to clipped point
 						constrained=true;
@@ -239,6 +267,7 @@
 			
 			if (vg->inTriangle){
 				sendPosition(*vg);
+				vg->status=Voice::moved;
 				if (sendStart && vg->isActive){
 					ofxOscMessage m;
 					///track id x y left right top bottom area