annotate src/melodyTriangle.h @ 37:260cc4f4d70a

Now using OSC bundles to make sure cotemporal messages are received in correct order; also added randInit state flag (toggle 'i') to control sending of /randinit on birth.
author samer
date Wed, 22 Feb 2012 00:30:20 +0000
parents 06a2fdb333ca
children 330f2746fedd
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
samer@30 9 public:
samer@30 10 ~melodyTriangle();
samer@30 11 melodyTriangle(const char *host, int port, int numVoices,
samer@30 12 bool enableKeys, int voiceIdOffset, int receivePort);
samer@30 13
samer@30 14 void setup();
samer@30 15 void update();
samer@30 16 void draw();
samer@30 17
samer@30 18 void keyPressed(int key);
samer@30 19 void keyReleased(int key);
samer@30 20 void mouseMoved(int x, int y );
samer@30 21 void mouseDragged(int x, int y, int button);
samer@30 22 void mousePressed(int x, int y, int button);
samer@30 23 void mouseReleased(int x, int y, int button);
samer@30 24 void windowResized(int w, int h);
samer@30 25
samer@30 26 private:
samer@30 27 class bad_voice_id : public std::exception {
samer@30 28 int id;
hekeus@6 29 public:
samer@30 30 bad_voice_id(int id): id(id) {}
samer@30 31 ~bad_voice_id() throw() {}
samer@30 32 const char *what() const throw();
samer@30 33 };
samer@22 34
samer@37 35 // static methods
samer@37 36 ofxOscMessage msgReplyTo();
samer@37 37 ofxOscMessage msgCalibrate();
samer@37 38 static ofxOscMessage msgPosition(Voice *v);
samer@37 39 static ofxOscMessage msgPeriod(int id, int num, int den);
samer@37 40 static ofxOscMessage msgShift(int id, int num, int den);
samer@37 41 static ofxOscMessage msgOctave(int id, int oct);
samer@37 42 static ofxOscMessage msgAmplitude(int id, float amp);
samer@37 43 static ofxOscMessage msg(const char *msg);
samer@37 44 static ofxOscMessage msg(const char *msg, int a);
samer@37 45 static ofxOscMessage msg(const char *msg, int a, int b);
samer@37 46 static ofxOscMessage msg(const char *msg, int a, int b, int c);
samer@37 47
samer@30 48 // private methods
samer@37 49 void handleMessage(ofxOscMessage &m);
samer@30 50 Voice *get_voice(int id) throw(bad_voice_id);
samer@30 51 void voiceKeypress(Voice *v, int key);
samer@37 52 void setKeyboardEnable(bool en);
samer@30 53 bool clipToTriangle(int *cx, int *cy);
samer@30 54 void fitTriangleIn(int w, int h);
samer@30 55 void reset();
samer@30 56
samer@30 57 // Immutable after construction and setup
samer@30 58 ofxOscSender sender;
samer@30 59 ofxOscReceiver receiver;
samer@30 60 int receivePort; // for sending /reply_to message
samer@30 61 int numVoices;
hekeus@6 62
samer@30 63 // somewhat mutable (on window resize)
samer@30 64 int x1,y1,x2,y2,x3,y3; // Triangle Coords
samer@30 65 int DX13, DY13, SQLEN13; // to optimise clipping
samer@30 66
samer@30 67 // mutable state
samer@30 68 Voice *voices[MAX_VOICES];
samer@30 69 Voice *voiceGrabbed;
samer@30 70 bool constrained;
samer@30 71 bool enableKeys;
samer@30 72 bool allowExit;
samer@31 73 bool snapTruePos;
samer@37 74 bool randInit;
samer@30 75 int display_frames;
samer@30 76 int ratio;
samer@30 77 int tempoIndex;
samer@30 78 string display_msg;
samer@30 79 ofTrueTypeFont display_font;
hekeus@6 80 };