Mercurial > hg > screen-ui
changeset 18:9a414ea6880d
Added colour coding of voice status.
author | samer |
---|---|
date | Tue, 31 Jan 2012 15:49:40 +0000 |
parents | 21eb7b7a5dc0 |
children | 055d7524bae4 |
files | release/MelodyTriangle.app.tar.gz src/Voice.cpp src/Voice.h src/melodyTriangle.cpp |
diffstat | 4 files changed, 83 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Voice.cpp Tue Jan 31 12:52:42 2012 +0000 +++ b/src/Voice.cpp Tue Jan 31 15:49:40 2012 +0000 @@ -21,20 +21,35 @@ octave=0; highlight=false; amplitude=0.6; + status=clear; } void Voice::draw(){ - ofSetColor(200,0,0); + int r,g,b; + switch (status) { + case clear: r=1; g=0; b=0; break; + default: r=1; g=1; b=0; break; +// case pending: r=1; g=1; b=0; break; +// case waiting: r=1; g=0; b=0; break; +// case moved: r=1; g=0; b=1; break; +// default: r=0; g=1; b=0; + } - if (isActive){ - ofFill(); + if (isActive) { r=2*r; g=2*g; b=2*b; } + ofSetColor(100*r,40*g,60*b); + ofFill(); + ofCircle(posx, posy, radius); + //ofNoFill(); + //ofCircle(posx, posy, radius); + + if (highlight) { + ofSetColor(230, 230, 230); + ofNoFill(); + ofCircle(posx, posy, radius); } else { ofNoFill(); + ofCircle(posx, posy, radius); } - ofCircle(posx, posy, radius); - if (highlight) ofSetColor(255, 192, 192); - ofNoFill(); - ofCircle(posx, posy, radius); } double Voice::louder() { return amplitude=min(1,amplitude*1.125); }
--- a/src/Voice.h Tue Jan 31 12:52:42 2012 +0000 +++ b/src/Voice.h Tue Jan 31 15:49:40 2012 +0000 @@ -12,6 +12,13 @@ Voice(int id, int x, int y); Voice() {}; + enum status { + clear, + pending, + waiting, + moved + }; + bool isInVoice(int x, int y) { return (ofDist(x, y, posx, posy)<=radius); }; double louder(); double quieter(); @@ -25,4 +32,5 @@ int octave; bool highlight; double amplitude; + enum status status; };
--- 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