view src/melodyTriangle.h @ 36:f973f0cc743b

Merge.
author samer
date Wed, 15 Feb 2012 12:26:10 +0000
parents 06a2fdb333ca
children 260cc4f4d70a
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 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);
	void send(const char *msg);
	void send(const char *msg, int a);
	void send(const char *msg, int a, int b);
	void send(const char *msg, int a, int b, int c);
	void handleMessage(ofxOscMessage &m);
	
	bool clipToTriangle(int *cx, int *cy);
	void fitTriangleIn(int w, int h);
	void reset();

	void setKeyboardEnable(bool en);
	
	// 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];
	Voice  *voiceGrabbed;
	bool   constrained;
	bool   enableKeys;
	bool   allowExit;
	bool   snapTruePos;
	int    display_frames;
	int    ratio;
	int	   tempoIndex;
	string display_msg;
	ofTrueTypeFont display_font;
};