view src/melodyTriangle.h @ 22:4dcc4312b5fa

Bit of a tidy up, adding text display, added full screen toggle and window resize handler.
author samer
date Thu, 02 Feb 2012 18:17:24 +0000
parents 9d7e139cd0a3
children 460c05dd74d0
line wrap: on
line source


#include "ofMain.h"
#include "Voice.h"

#include "ofxOsc.h"

#define MAX_VOICES 10


class melodyTriangle : public ofBaseApp{
	
	public:
		melodyTriangle(const char *host, int port, int numVoices, bool enableKeys, int voiceIdOffset, int receivePort);
		~melodyTriangle();
	
		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:
		// private methods
		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);
		bool clipToTriangle(int *cx, int *cy);
		void fitTriangleIn(int w, int h);
		void handleMessage(ofxOscMessage &m);
	
		// Immutable after construction and setup
		ofxOscSender	sender;
		ofxOscReceiver	receiver;
		int  receivePort;         // for sending /reply_to message
		int	 numVoices;
		bool enableKeys;
		
		// 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;
		ofTrueTypeFont display_font;
		string display_msg;
		int    display_frames;
		bool   constrained;
};