changeset 13:9e31c0507e65

Added amplitude control (keys '*' and '/').
author samer
date Mon, 30 Jan 2012 13:29:53 +0000
parents 317637282293
children 578c1acf1cc4
files src/Voice.cpp src/Voice.h src/melodyTriangle.cpp src/melodyTriangle.h
diffstat 4 files changed, 25 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- 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 (x<y) ? x : y; }
+
 Voice::Voice(int id, int x, int y){
 	this->id=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; }
 
-}
-
--- 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;
 };
--- 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);
 						}
 					}
 				}
--- 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);