comparison 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
comparison
equal deleted inserted replaced
17:21eb7b7a5dc0 18:9a414ea6880d
18 this->enableKeys=enableKeys; 18 this->enableKeys=enableKeys;
19 this->voiceIdOffset=voiceIdOffset; 19 this->voiceIdOffset=voiceIdOffset;
20 //voices=*Voice[numVoices]; 20 //voices=*Voice[numVoices];
21 sender.setup( host,port ); 21 sender.setup( host,port );
22 receiver.setup( receivePort ); 22 receiver.setup( receivePort );
23 23
24 {
25 ofxOscMessage m;
26 m.setAddress( "/reply_to" );
27 m.addIntArg( receivePort );
28 sender.sendMessage( m );
29 printf("sent /reply_to %i\n",receivePort);
30 }
24 } 31 }
25 32
26 //-------------------------------------------------------------- 33 //--------------------------------------------------------------
27 void melodyTriangle::setup(){ 34 void melodyTriangle::setup(){
28 //voices = new Voice[NUMVOICES];
29
30 ofSetCircleResolution(100); 35 ofSetCircleResolution(100);
31 ofBackground(0,0,0); 36 ofBackground(0,0,0);
32 ofSetWindowTitle("Melody Triangle"); 37 ofSetWindowTitle("Melody Triangle");
38 // if vertical sync is off, we can go a bit fast...
39 // this caps the framerate at 40fps.
40 ofSetFrameRate(40);
41 ofEnableSmoothing();
42
43 // Set up triange coordinates.
44 // NB. whatever happens here, the triangle must be
45 // isosceles and left-right symmetric around x=x1.
46 // Otherwise the clipping won't work
33 triangleHeight=ofGetHeight()*0.75; 47 triangleHeight=ofGetHeight()*0.75;
34 ofSetFrameRate(40); // if vertical sync is off, we can go a bit fast... this caps the framerate at 60fps.
35 ofEnableSmoothing();
36 x1=ofGetWidth()/2; 48 x1=ofGetWidth()/2;
37 y1=(ofGetHeight()-triangleHeight)/2; 49 y1=(ofGetHeight()-triangleHeight)/2;
38 x2=ofGetWidth()/2-triangleHeight/sqrt(3); 50 x2=ofGetWidth()/2-triangleHeight/sqrt(3);
39 y2=ofGetHeight()-(ofGetHeight()-triangleHeight)/2; 51 y2=ofGetHeight()-(ofGetHeight()-triangleHeight)/2;
40 x3=ofGetWidth()/2+triangleHeight/sqrt(3); 52 x3=ofGetWidth()/2+triangleHeight/sqrt(3);
107 while( receiver.hasWaitingMessages() ) 119 while( receiver.hasWaitingMessages() )
108 { 120 {
109 // get the next message 121 // get the next message
110 ofxOscMessage m; 122 ofxOscMessage m;
111 receiver.getNextMessage( &m ); 123 receiver.getNextMessage( &m );
112 string msg_string; 124 if (m.getAddress()=="/notify") {
113 msg_string = m.getAddress(); 125 int id=m.getArgAsInt32(0)-1;
114 msg_string += ": "; 126 string st=m.getArgAsString(1);
115 for ( int i=0; i<m.getNumArgs(); i++ ) 127
116 { 128 if (id>=0 && id<numVoices) {
117 // get the argument type 129 Voice *v=voices[id];
118 msg_string += m.getArgTypeName( i ); 130
119 msg_string += ":"; 131 if (st=="received") v->status=Voice::clear;
120 // display the argument - make sure we get the right type 132 else if (st=="pending") v->status=Voice::pending;
121 if( m.getArgType( i ) == OFXOSC_TYPE_INT32 ) 133 else if (st=="requested") v->status=Voice::waiting;
122 msg_string += ofToString( m.getArgAsInt32( i ) ); 134 else cout << "** unrecognised voice status: " << st << ".\n";
123 else if( m.getArgType( i ) == OFXOSC_TYPE_FLOAT ) 135 } else {
124 msg_string += ofToString( m.getArgAsFloat( i ) ); 136 cout << "** voice id "<<id<<" out of range.\n";
125 else if( m.getArgType( i ) == OFXOSC_TYPE_STRING ) 137 }
126 msg_string += m.getArgAsString( i ); 138 } else {
127 else 139 string msg_string;
128 msg_string += "unknown"; 140 msg_string = m.getAddress();
129 } 141 msg_string += ": ";
130 cout<< msg_string << "\n"; 142 for ( int i=0; i<m.getNumArgs(); i++ )
131 143 {
144 // get the argument type
145 msg_string += m.getArgTypeName( i );
146 msg_string += ":";
147 // display the argument - make sure we get the right type
148 if( m.getArgType( i ) == OFXOSC_TYPE_INT32 )
149 msg_string += ofToString( m.getArgAsInt32( i ) );
150 else if( m.getArgType( i ) == OFXOSC_TYPE_FLOAT )
151 msg_string += ofToString( m.getArgAsFloat( i ) );
152 else if( m.getArgType( i ) == OFXOSC_TYPE_STRING )
153 msg_string += m.getArgAsString( i );
154 else
155 msg_string += "unknown";
156 }
157 cout<< msg_string << "\n";
158 }
132 } 159 }
133 } 160 }
134 161
135 bool melodyTriangle::clipToTriangle(int *x, int *y) { 162 bool melodyTriangle::clipToTriangle(int *x, int *y) {
136 bool clipped; 163 bool clipped;
206 233
207 printf("sent /death %i \n",vg->id); 234 printf("sent /death %i \n",vg->id);
208 vg->posx=mouseX; 235 vg->posx=mouseX;
209 vg->posy=mouseY; 236 vg->posy=mouseY;
210 vg->inTriangle=false; 237 vg->inTriangle=false;
238 vg->status=Voice::clear;
211 } else { 239 } else {
212 // otherwise, we move to clipped point 240 // otherwise, we move to clipped point
213 constrained=true; 241 constrained=true;
214 vg->posx=clipx; 242 vg->posx=clipx;
215 vg->posy=clipy; 243 vg->posy=clipy;
237 } 265 }
238 } 266 }
239 267
240 if (vg->inTriangle){ 268 if (vg->inTriangle){
241 sendPosition(*vg); 269 sendPosition(*vg);
270 vg->status=Voice::moved;
242 if (sendStart && vg->isActive){ 271 if (sendStart && vg->isActive){
243 ofxOscMessage m; 272 ofxOscMessage m;
244 ///track id x y left right top bottom area 273 ///track id x y left right top bottom area
245 m.setAddress( "/start" ); 274 m.setAddress( "/start" );
246 m.addIntArg( vg->id ); 275 m.addIntArg( vg->id );