view src/melodyTriangle.h @ 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
#include "ofMain.h"
#include "ofxOsc.h"
#include "Voice.h"

#define MAX_VOICES 10

class melodyTriangle : public ofBaseApp{
	
	public:
		~melodyTriangle();
		melodyTriangle(const char *host, int port, int numVoices, 
					   bool enableKeys, int voiceIdOffset, int receivePort);
	
		void setup();
		void update();
		void draw();
		
		void keyPressed(int key);
		void keyReleased(int key);
		void mouseMoved(int x, int y );
		void mouseDragged(int x, int y, int button);
		void mousePressed(int x, int y, int button);
		void mouseReleased(int x, int y, int button);
		void windowResized(int w, int h);

	private:
		class bad_voice_id : public std::exception {
			int	id;
		public:
			bad_voice_id(int id): id(id) {}
			~bad_voice_id() throw() {}
			const char *what() const throw();
		};
		
		// private methods
		Voice *get_voice(int id) throw(bad_voice_id);
	
		void voiceKeypress(Voice *v, int key);
		void sendReplyTo();
		void sendCalibrate();
		void sendDeath(int id);
		void sendPosition(Voice *v);
		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 clipToTriangle(int *cx, int *cy);
		void fitTriangleIn(int w, int h);
		void handleMessage(ofxOscMessage &m);
		void reset();
	
		// Immutable after construction and setup
		ofxOscSender	sender;
		ofxOscReceiver	receiver;
		int  receivePort;         // for sending /reply_to message
		int	 numVoices;
		
		// somewhat mutable (on window resize)
		int  x1,y1,x2,y2,x3,y3;   // Triangle Coords
		int  DX13, DY13, SQLEN13; // to optimise clipping
	
		// mutable state
		Voice  *voices[MAX_VOICES];
		int    voiceGrabbed;
		bool   constrained;
		bool   enableKeys;
		int    display_frames;
		string display_msg;
		ofTrueTypeFont display_font;
};