view 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
line wrap: on
line source
/*
 *  Voice.cpp
 *  MelodyTriangle
 *
 *  Created by Henrik Ekeus on 12/01/2012.
 *  Copyright 2012 Queen Mary University of London. All rights reserved.
 *
 */

#include "Voice.h"

inline static double min(double x,double y) { return (x<y) ? x : y; }

Voice::Voice(int id): 
	isActive(true), inTriangle(false), status(pending),
	octave(0), amplitude(0.6), id(id), posx(0), posy(0) {}

void Voice::draw(bool highlight){
//	if (inTriangle) {
		int r,g,b;
		switch (status) {
			case clear:   r=1; g=1; b=0; break;
			default:      r=1; g=0; 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) { r=2*r; g=2*g; b=2*b; }
		ofSetColor(100*r,60*g,60*b);
//	} else {
//		if (isActive) ofSetColor(128,128,128);
//		else ofSetColor(64,64,64);
//	}
	
	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);
	}
}

double Voice::louder()  { return amplitude=min(1,amplitude*1.0625); }
double Voice::quieter() { return amplitude/=1.0625; }

enum Voice::status Voice::stringToStatus(string s) throw(bad_status) {
	if      (s=="received")  return clear;
	else if (s=="pending")   return pending;
	else if (s=="requested") return waiting;
	else throw bad_status(s);
}

const char *Voice::bad_status::what() const throw() { 
	return ("Unrecognised voice status: "+str+".").c_str(); 
}