comparison src/melodyTriangle.cpp @ 32:06a2fdb333ca

Added visibilty control for tokens; removed token highlight when keyboard disabled.
author samer
date Wed, 15 Feb 2012 10:14:04 +0000
parents 417deb31dd4e
children 260cc4f4d70a
comparison
equal deleted inserted replaced
31:417deb31dd4e 32:06a2fdb333ca
1 #include "melodyTriangle.h" 1 #include "melodyTriangle.h"
2 #include <GLUT/GLUT.h> 2 #include <GLUT/GLUT.h>
3 3
4 #define BUFFER_ZONE 64 // have to drag this far to snap out of triange. 4 #define BUFFER_ZONE 64 // have to drag this far to snap out of triange.
5 5 #define NUM_TEMPI 9
6 static int tempi[]={20,30,45,60,90,120,150,180}; 6
7 static int tempi[]={20,30,45,60,90,120,150,180,240};
8
7 9
8 melodyTriangle::melodyTriangle(const char *host, int port, int numVoices, 10 melodyTriangle::melodyTriangle(const char *host, int port, int numVoices,
9 bool enableKeys,int voiceIdOffset,int receivePort): 11 bool enableKeys,int voiceIdOffset,int receivePort):
10 numVoices(numVoices), receivePort(receivePort), snapTruePos(enableKeys), 12 numVoices(numVoices), receivePort(receivePort), snapTruePos(enableKeys),
11 enableKeys(enableKeys), allowExit(true), ratio(2), tempoIndex(4), 13 enableKeys(enableKeys), allowExit(true), ratio(2), tempoIndex(4),
119 if (constrained) ofSetColor(255,96,96); 121 if (constrained) ofSetColor(255,96,96);
120 ofNoFill(); 122 ofNoFill();
121 ofTriangle(x1, y1, x2, y2, x3, y3); 123 ofTriangle(x1, y1, x2, y2, x3, y3);
122 124
123 for (int i=numVoices-1; i>=0; i--){ 125 for (int i=numVoices-1; i>=0; i--){
124 voices[i]->draw(voices[i]->isInVoice(mouseX,mouseY)); 126 voices[i]->draw(enableKeys && voices[i]->isInVoice(mouseX,mouseY));
125 } 127 }
126 128
127 // display message if any 129 // display message if any
128 if (display_frames!=0) { 130 if (display_frames!=0) {
129 ofRectangle bbox=display_font.getStringBoundingBox(display_msg,0,0); 131 ofRectangle bbox=display_font.getStringBoundingBox(display_msg,0,0);
193 case '{': 195 case '{':
194 if (tempoIndex>0) tempoIndex--; 196 if (tempoIndex>0) tempoIndex--;
195 send("/tempo",tempi[tempoIndex]); 197 send("/tempo",tempi[tempoIndex]);
196 break; 198 break;
197 case '}': 199 case '}':
198 if (tempoIndex<7) tempoIndex++; 200 if (tempoIndex<NUM_TEMPI-1) tempoIndex++;
199 send("/tempo",tempi[tempoIndex]); 201 send("/tempo",tempi[tempoIndex]);
200 break; 202 break;
201 203
202 case ' ': send("/marker"); break; 204 case ' ': send("/marker"); break;
203 case 'S': send("/save"); break; 205 case 'S': send("/save"); break;
221 } 223 }
222 224
223 void melodyTriangle::voiceKeypress(Voice *v, int key) { 225 void melodyTriangle::voiceKeypress(Voice *v, int key) {
224 switch (key) { 226 switch (key) {
225 case 'a': 227 case 'a':
226 send(v->isActive ? "/stop" : "/start", v->id); 228 if (v->inTriangle) {
229 send(v->isActive ? "/stop" : "/start", v->id);
230 }
227 v->isActive=!v->isActive; 231 v->isActive=!v->isActive;
228 break; 232 break;
229 case OF_KEY_LEFT: sendShift(v->id,-1,ratio); break; 233 case OF_KEY_LEFT: sendShift(v->id,-1,ratio); break;
230 case OF_KEY_RIGHT: sendShift(v->id,1,ratio); break; 234 case OF_KEY_RIGHT: sendShift(v->id,1,ratio); break;
231 case OF_KEY_UP: sendPeriod(v->id,1,ratio); break; 235 case OF_KEY_UP: sendPeriod(v->id,1,ratio); break;
303 try { 307 try {
304 if (msg_path.compare(0,8,"/notify/")==0) { 308 if (msg_path.compare(0,8,"/notify/")==0) {
305 string msg=msg_path.substr(8); 309 string msg=msg_path.substr(8);
306 Voice *v=get_voice(m.getArgAsInt32(0)); 310 Voice *v=get_voice(m.getArgAsInt32(0));
307 311
312 cout << "Received " << msg_path << "\n";
308 if (msg=="requested") v->status=Voice::waiting; 313 if (msg=="requested") v->status=Voice::waiting;
309 else if (msg=="pending") v->status=Voice::pending; 314 else if (msg=="pending") v->status=Voice::pending;
310 else if (msg=="received") { 315 else if (msg=="received") {
311 float x=m.getArgAsFloat(1); 316 float x=m.getArgAsFloat(1);
312 float y=m.getArgAsFloat(2); 317 float y=m.getArgAsFloat(2);
333 } else if (msg=="running") { 338 } else if (msg=="running") {
334 v->isActive = m.getArgAsInt32(1) ? true : false; 339 v->isActive = m.getArgAsInt32(1) ? true : false;
335 } else if (msg=="params") { 340 } else if (msg=="params") {
336 v->octave = m.getArgAsInt32(1); 341 v->octave = m.getArgAsInt32(1);
337 v->amplitude = m.getArgAsFloat(2); 342 v->amplitude = m.getArgAsFloat(2);
343 } else if (msg=="visible") {
344 v->isVisible = m.getArgAsInt32(1);
345 if (voiceGrabbed==v && !v->isVisible)
346 voiceGrabbed=NULL;
338 } 347 }
339 } else if (msg_path=="/display") { 348 } else if (msg_path=="/display") {
340 display_msg=m.getArgAsString(0); 349 display_msg=m.getArgAsString(0);
341 display_frames=m.getArgAsInt32(1); 350 display_frames=m.getArgAsInt32(1);
342 } else if (msg_path=="/font") { 351 } else if (msg_path=="/font") {
403 m.addIntArg( receivePort ); 412 m.addIntArg( receivePort );
404 sender.sendMessage( m ); 413 sender.sendMessage( m );
405 printf("sent /reply_to %i\n",receivePort); 414 printf("sent /reply_to %i\n",receivePort);
406 } 415 }
407 416
408 void melodyTriangle::sendPeriod(int id, int num, int den){ 417 void melodyTriangle::sendPeriod(int id, int num, int den){ send("/period",id,num,den); }
409 ofxOscMessage m; 418 void melodyTriangle::sendShift(int id, int num, int den) { send("/shift",id,num,den); }
410 m.setAddress("/period"); 419 void melodyTriangle::sendOctave(int id, int oct){ send("/octave",id,oct); }
411 m.addIntArg(id);
412 m.addIntArg(num);
413 m.addIntArg(den);
414 sender.sendMessage(m);
415 printf("sent /period %i %i %i\n",id,num,den);
416 }
417
418 void melodyTriangle::sendShift(int id, int num, int den){
419 ofxOscMessage m;
420 m.setAddress("/shift");
421 m.addIntArg(id);
422 m.addIntArg(num);
423 m.addIntArg(den);
424 sender.sendMessage(m);
425 printf("sent /shift %i %i %i\n",id,num,den);
426 }
427
428 void melodyTriangle::sendOctave(int id, int oct){
429 ofxOscMessage m;
430 m.setAddress("/octave");
431 m.addIntArg(id);
432 m.addIntArg(oct);
433 sender.sendMessage(m);
434 printf("sent /octave %i %i\n",id,oct);
435 }
436 420
437 void melodyTriangle::sendAmplitude(int id, float amp){ 421 void melodyTriangle::sendAmplitude(int id, float amp){
438 ofxOscMessage m; 422 ofxOscMessage m;
439 m.setAddress("/amplitude"); 423 m.setAddress("/amplitude");
440 m.addIntArg(id); 424 m.addIntArg(id);
441 m.addFloatArg(amp); 425 m.addFloatArg(amp);
442 sender.sendMessage(m); 426 sender.sendMessage(m);
443 printf("sent /amplitude %i %1.3f\n",id,amp); 427 printf("sent /amplitude %i %1.3f\n",id,amp);
444 } 428 }
445 429
430 void melodyTriangle::send(const char *addr, int a, int b, int c) {
431 ofxOscMessage m;
432 m.setAddress(addr);
433 m.addIntArg(a);
434 m.addIntArg(b);
435 m.addIntArg(c);
436 sender.sendMessage(m);
437 printf("sent %s %i\n",addr,a);
438 }
439
440
441 void melodyTriangle::send(const char *addr, int a, int b) {
442 ofxOscMessage m;
443 m.setAddress(addr);
444 m.addIntArg(a);
445 m.addIntArg(b);
446 sender.sendMessage(m);
447 printf("sent %s %i\n",addr,a);
448 }
449
450
446 void melodyTriangle::send(const char *addr, int a) { 451 void melodyTriangle::send(const char *addr, int a) {
447 ofxOscMessage m; 452 ofxOscMessage m;
448 m.setAddress(addr); 453 m.setAddress(addr);
449 m.addIntArg(a); 454 m.addIntArg(a);
450 sender.sendMessage(m); 455 sender.sendMessage(m);