comparison src/Voice.cpp @ 23:460c05dd74d0

Various enhancements and code refactorings: * added some compiler warnings. * text display is centred and with settable TrueType font * removed highlight member from Voice state - value is derived from other data and passed to Voice::draw() * Changed voice radius from member to defined constant * default number of voices is now 4 * adjusted some colours and buffer zone width * new keyboard commands: reset, quit. * when keyboard disabled, keys are now passed to server via OSC * added handlers for various new OSC messages: - fullscreen, reset, quit, keyboard enable - notify (voice state) : several sub-messages * call reset and calibrate on window resize (fits triangle to window)
author samer
date Sat, 04 Feb 2012 23:14:38 +0000
parents 4dcc4312b5fa
children f4ebb87adec1
comparison
equal deleted inserted replaced
22:4dcc4312b5fa 23:460c05dd74d0
10 #include "Voice.h" 10 #include "Voice.h"
11 11
12 inline static double min(double x,double y) { return (x<y) ? x : y; } 12 inline static double min(double x,double y) { return (x<y) ? x : y; }
13 13
14 Voice::Voice(int id): 14 Voice::Voice(int id):
15 radius(12), isActive(true), 15 isActive(true), inTriangle(false), status(pending),
16 inTriangle(false), octave(0), highlight(false), 16 octave(0), amplitude(0.6), id(id), posx(0), posy(0) {}
17 amplitude(0.6), status(clear), id(id), posx(0), posy(0) {}
18 17
19 void Voice::draw(){ 18 void Voice::draw(bool highlight){
20 int r,g,b; 19 // if (inTriangle) {
21 switch (status) { 20 int r,g,b;
22 case clear: r=1; g=0; b=0; break; 21 switch (status) {
23 default: r=1; g=1; b=0; break; 22 case clear: r=1; g=1; b=0; break;
24 // case pending: r=1; g=1; b=0; break; 23 default: r=1; g=0; b=0; break;
25 // case waiting: r=1; g=0; b=0; break; 24 // case pending: r=1; g=1; b=0; break;
26 // case moved: r=1; g=0; b=1; break; 25 // case waiting: r=1; g=0; b=0; break;
27 // default: r=0; g=1; b=0; 26 // case moved: r=1; g=0; b=1; break;
28 } 27 // default: r=0; g=1; b=0;
28 }
29 if (isActive) { r=2*r; g=2*g; b=2*b; }
30 ofSetColor(100*r,60*g,60*b);
31 // } else {
32 // if (isActive) ofSetColor(128,128,128);
33 // else ofSetColor(64,64,64);
34 // }
29 35
30 if (isActive) { r=2*r; g=2*g; b=2*b; }
31 ofSetColor(100*r,60*g,60*b);
32 ofFill(); 36 ofFill();
33 ofCircle(posx, posy, radius); 37 ofCircle(posx, posy, RADIUS);
34 //ofNoFill(); 38 //ofNoFill();
35 //ofCircle(posx, posy, radius); 39 //ofCircle(posx, posy, RADIUS);
36 40
37 if (highlight) { 41 if (highlight) {
38 ofSetColor(230, 230, 230); 42 ofSetColor(230, 230, 230);
39 ofNoFill(); 43 ofNoFill();
40 ofCircle(posx, posy, radius); 44 ofCircle(posx, posy, RADIUS);
41 } else { 45 } else {
42 ofNoFill(); 46 ofNoFill();
43 ofCircle(posx, posy, radius); 47 ofCircle(posx, posy, RADIUS);
44 } 48 }
45 } 49 }
46 50
47 double Voice::louder() { return amplitude=min(1,amplitude*1.0625); } 51 double Voice::louder() { return amplitude=min(1,amplitude*1.0625); }
48 double Voice::quieter() { return amplitude/=1.0625; } 52 double Voice::quieter() { return amplitude/=1.0625; }
49 53
54 enum Voice::status Voice::stringToStatus(string s) throw(bad_status) {
55 if (s=="received") return clear;
56 else if (s=="pending") return pending;
57 else if (s=="requested") return waiting;
58 else throw bad_status(s);
59 }
60
61 const char *Voice::bad_status::what() const throw() {
62 return ("Unrecognised voice status: "+str+".").c_str();
63 }
64