# HG changeset patch # User samer # Date 1327930193 0 # Node ID 9e31c0507e652ea041a41f47836c56050f270b81 # Parent 3176372822936e372aae8328dad2051157a263a6 Added amplitude control (keys '*' and '/'). diff -r 317637282293 -r 9e31c0507e65 src/Voice.cpp --- a/src/Voice.cpp Mon Jan 30 00:00:15 2012 +0000 +++ b/src/Voice.cpp Mon Jan 30 13:29:53 2012 +0000 @@ -9,6 +9,8 @@ #include "Voice.h" +inline static double min(double x,double y) { return (xid=id; posx=x; @@ -18,10 +20,9 @@ inTriangle=false; octave=0; highlight=false; + amplitude=0.6; } -Voice::Voice(){} - void Voice::draw(){ ofSetColor(200,0,0); @@ -36,12 +37,6 @@ ofCircle(posx, posy, radius); } -bool Voice::isInVoice(int x, int y){ - if (ofDist(x, y, posx, posy)<=radius){ - return true; - }else { - return false; - } +double Voice::louder() { return amplitude=min(1,amplitude*1.125); } +double Voice::quieter() { return amplitude/=1.125; } -} - diff -r 317637282293 -r 9e31c0507e65 src/Voice.h --- a/src/Voice.h Mon Jan 30 00:00:15 2012 +0000 +++ b/src/Voice.h Mon Jan 30 13:29:53 2012 +0000 @@ -9,11 +9,13 @@ #include "ofMain.h" class Voice { public: + Voice(int id, int x, int y); + Voice() {}; - void draw(); - Voice(int id, int x, int y); - Voice(); - bool isInVoice(int x, int y); + bool isInVoice(int x, int y) { return (ofDist(x, y, posx, posy)<=radius); }; + double louder(); + double quieter(); + void draw(); int id; int posx,posy; @@ -22,6 +24,5 @@ int radius; int octave; bool highlight; - - + double amplitude; }; diff -r 317637282293 -r 9e31c0507e65 src/melodyTriangle.cpp --- a/src/melodyTriangle.cpp Mon Jan 30 00:00:15 2012 +0000 +++ b/src/melodyTriangle.cpp Mon Jan 30 13:29:53 2012 +0000 @@ -89,6 +89,15 @@ printf("sent /octave %i %i\n",id,oct); } +void melodyTriangle::sendAmplitude(int id, float amp){ + ofxOscMessage m; + m.setAddress("/amplitude"); + m.addIntArg(id); + m.addFloatArg(amp); + sender.sendMessage(m); + printf("sent /amplitude %i %1.3f\n",id,amp); +} + //-------------------------------------------------------------- void melodyTriangle::update(){ while( receiver.hasWaitingMessages() ) @@ -298,6 +307,9 @@ case ',': sendPeriod(v->id,3,1); break; case '+': sendOctave(v->id, ++v->octave); break; case '-': sendOctave(v->id, --v->octave); break; + case '*': sendAmplitude(v->id, v->louder()); break; + case '/': sendAmplitude(v->id, v->quieter()); break; + default: printf("unrecognised key: %d.\n",key); } } } diff -r 317637282293 -r 9e31c0507e65 src/melodyTriangle.h --- a/src/melodyTriangle.h Mon Jan 30 00:00:15 2012 +0000 +++ b/src/melodyTriangle.h Mon Jan 30 13:29:53 2012 +0000 @@ -41,6 +41,7 @@ void sendPeriod(int id, int num, int den); void sendShift(int id, int num, int den); void sendOctave(int id, int oct); + void sendAmplitude(int id, float amp); bool isInTriangle(int x, int y);