annotate 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
rev   line source
hekeus@6 1 #include "ofMain.h"
samer@23 2 #include "ofxOsc.h"
hekeus@6 3 #include "Voice.h"
hekeus@6 4
samer@22 5 #define MAX_VOICES 10
hekeus@6 6
hekeus@6 7 class melodyTriangle : public ofBaseApp{
hekeus@6 8
hekeus@6 9 public:
samer@22 10 ~melodyTriangle();
samer@23 11 melodyTriangle(const char *host, int port, int numVoices,
samer@23 12 bool enableKeys, int voiceIdOffset, int receivePort);
samer@22 13
hekeus@6 14 void setup();
hekeus@6 15 void update();
hekeus@6 16 void draw();
hekeus@6 17
hekeus@6 18 void keyPressed(int key);
hekeus@6 19 void keyReleased(int key);
hekeus@6 20 void mouseMoved(int x, int y );
hekeus@6 21 void mouseDragged(int x, int y, int button);
hekeus@6 22 void mousePressed(int x, int y, int button);
hekeus@6 23 void mouseReleased(int x, int y, int button);
hekeus@6 24 void windowResized(int w, int h);
samer@22 25
samer@22 26 private:
samer@23 27 class bad_voice_id : public std::exception {
samer@23 28 int id;
samer@23 29 public:
samer@23 30 bad_voice_id(int id): id(id) {}
samer@23 31 ~bad_voice_id() throw() {}
samer@23 32 const char *what() const throw();
samer@23 33 };
samer@23 34
samer@22 35 // private methods
samer@23 36 Voice *get_voice(int id) throw(bad_voice_id);
samer@23 37
samer@23 38 void voiceKeypress(Voice *v, int key);
samer@22 39 void sendReplyTo();
samer@12 40 void sendCalibrate();
samer@23 41 void sendDeath(int id);
samer@23 42 void sendPosition(Voice *v);
samer@12 43 void sendPeriod(int id, int num, int den);
samer@12 44 void sendShift(int id, int num, int den);
samer@12 45 void sendOctave(int id, int oct);
samer@13 46 void sendAmplitude(int id, float amp);
samer@22 47 bool clipToTriangle(int *cx, int *cy);
samer@22 48 void fitTriangleIn(int w, int h);
samer@22 49 void handleMessage(ofxOscMessage &m);
samer@23 50 void reset();
samer@22 51
samer@22 52 // Immutable after construction and setup
samer@22 53 ofxOscSender sender;
samer@22 54 ofxOscReceiver receiver;
samer@22 55 int receivePort; // for sending /reply_to message
samer@22 56 int numVoices;
hekeus@6 57
samer@22 58 // somewhat mutable (on window resize)
samer@22 59 int x1,y1,x2,y2,x3,y3; // Triangle Coords
samer@22 60 int DX13, DY13, SQLEN13; // to optimise clipping
hekeus@6 61
samer@22 62 // mutable state
samer@23 63 Voice *voices[MAX_VOICES];
samer@23 64 int voiceGrabbed;
samer@23 65 bool constrained;
samer@23 66 bool enableKeys;
samer@23 67 int display_frames;
samer@23 68 string display_msg;
samer@22 69 ofTrueTypeFont display_font;
hekeus@6 70 };