comparison src/Voice.cpp @ 25:f4ebb87adec1

Added code to keep track of true position of voices in information space; Two voice drawing methods display both true position target position while dragging; string to Voice::status code no longer required; refactored OSC message sending code; added keys to control subdivision ratio for period and shift controls.
author samer
date Sun, 05 Feb 2012 18:13:30 +0000
parents 460c05dd74d0
children 417deb31dd4e
comparison
equal deleted inserted replaced
24:328822cd308c 25:f4ebb87adec1
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 isActive(true), inTriangle(false), status(pending), 15 isActive(true), inTriangle(false), octave(0), amplitude(0.6),
16 octave(0), amplitude(0.6), id(id), posx(0), posy(0) {} 16 status(pending), id(id), posx(0), posy(0), truex(-1), truey(-1) {}
17 17
18 void Voice::draw(bool highlight){ 18 void Voice::draw(bool highlight){
19 // if (inTriangle) { 19 int r,g,b;
20 int r,g,b; 20 switch (status) {
21 switch (status) { 21 case clear: r=1; g=1; b=0; break;
22 case clear: r=1; g=1; b=0; break; 22 default: r=1; g=0; b=0; break;
23 default: r=1; g=0; b=0; break; 23 }
24 // case pending: r=1; g=1; b=0; break; 24 if (isActive) { r=2*r; g=2*g; b=2*b; }
25 // case waiting: r=1; g=0; b=0; break; 25
26 // case moved: r=1; g=0; b=1; break; 26 if (inTriangle && truex>=0) {
27 // default: r=0; g=1; b=0; 27 ofSetColor(230,230,230);
28 } 28 ofLine(posx,posy,truex,truey);
29 if (isActive) { r=2*r; g=2*g; b=2*b; } 29 // ofNoFill(); ofCircle(truex, truey, RADIUS/2-1);
30 ofSetColor(100*r,60*g,60*b); 30 }
31 // } else { 31 ofSetColor(100*r,60*g,60*b);
32 // if (isActive) ofSetColor(128,128,128);
33 // else ofSetColor(64,64,64);
34 // }
35
36 ofFill(); 32 ofFill();
37 ofCircle(posx, posy, RADIUS); 33 ofCircle(posx, posy, RADIUS);
38 //ofNoFill(); 34 ofNoFill();
39 //ofCircle(posx, posy, RADIUS); 35 if (highlight) ofSetColor(230, 230, 230);
40 36 ofCircle(posx, posy, RADIUS);
41 if (highlight) { 37
42 ofSetColor(230, 230, 230); 38 }
39
40 void Voice::draw_alt(bool highlight){
41 int r,g,b;
42 switch (status) {
43 case clear: r=1; g=1; b=0; break;
44 default: r=1; g=0; b=0; break;
45 }
46 if (isActive) { r=2*r; g=2*g; b=2*b; }
47
48 if (inTriangle && truex>=0) {
49 ofSetColor(230,230,230);
50 ofLine(posx,posy,truex,truey);
51 ofSetColor(100*r,60*g,60*b);
52 ofFill();
53 ofCircle(truex, truey, RADIUS);
43 ofNoFill(); 54 ofNoFill();
55 if (highlight) ofSetColor(230, 230, 230);
56 ofCircle(truex, truey, RADIUS);
57 } else {
58 ofSetColor(100*r,60*g,60*b);
59 ofFill();
44 ofCircle(posx, posy, RADIUS); 60 ofCircle(posx, posy, RADIUS);
45 } else {
46 ofNoFill(); 61 ofNoFill();
62 if (highlight) ofSetColor(230, 230, 230);
47 ofCircle(posx, posy, RADIUS); 63 ofCircle(posx, posy, RADIUS);
48 } 64 }
49 } 65 }
50 66
67
51 double Voice::louder() { return amplitude=min(1,amplitude*1.0625); } 68 double Voice::louder() { return amplitude=min(1,amplitude*1.0625); }
52 double Voice::quieter() { return amplitude/=1.0625; } 69 double Voice::quieter() { return amplitude/=1.0625; }
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