hekeus@6: #include "ofMain.h" samer@23: #include "ofxOsc.h" hekeus@6: #include "Voice.h" hekeus@6: samer@22: #define MAX_VOICES 10 hekeus@6: hekeus@6: class melodyTriangle : public ofBaseApp{ hekeus@6: samer@30: public: samer@30: ~melodyTriangle(); samer@30: melodyTriangle(const char *host, int port, int numVoices, samer@30: bool enableKeys, int voiceIdOffset, int receivePort); samer@30: samer@30: void setup(); samer@30: void update(); samer@30: void draw(); samer@30: samer@30: void keyPressed(int key); samer@30: void keyReleased(int key); samer@30: void mouseMoved(int x, int y ); samer@30: void mouseDragged(int x, int y, int button); samer@30: void mousePressed(int x, int y, int button); samer@30: void mouseReleased(int x, int y, int button); samer@30: void windowResized(int w, int h); samer@30: samer@30: private: samer@30: class bad_voice_id : public std::exception { samer@30: int id; hekeus@6: public: samer@30: bad_voice_id(int id): id(id) {} samer@30: ~bad_voice_id() throw() {} samer@30: const char *what() const throw(); samer@30: }; samer@22: samer@37: // static methods samer@37: ofxOscMessage msgReplyTo(); samer@37: ofxOscMessage msgCalibrate(); samer@37: static ofxOscMessage msgPosition(Voice *v); samer@37: static ofxOscMessage msgPeriod(int id, int num, int den); samer@37: static ofxOscMessage msgShift(int id, int num, int den); samer@37: static ofxOscMessage msgOctave(int id, int oct); samer@37: static ofxOscMessage msgAmplitude(int id, float amp); samer@37: static ofxOscMessage msg(const char *msg); samer@37: static ofxOscMessage msg(const char *msg, int a); samer@37: static ofxOscMessage msg(const char *msg, int a, int b); samer@37: static ofxOscMessage msg(const char *msg, int a, int b, int c); samer@37: samer@30: // private methods samer@37: void handleMessage(ofxOscMessage &m); samer@30: Voice *get_voice(int id) throw(bad_voice_id); samer@30: void voiceKeypress(Voice *v, int key); samer@37: void setKeyboardEnable(bool en); samer@30: bool clipToTriangle(int *cx, int *cy); samer@30: void fitTriangleIn(int w, int h); samer@30: void reset(); samer@38: string help_string(bool global); samer@30: samer@30: // Immutable after construction and setup samer@30: ofxOscSender sender; samer@30: ofxOscReceiver receiver; samer@30: int receivePort; // for sending /reply_to message samer@30: int numVoices; hekeus@6: samer@30: // somewhat mutable (on window resize) samer@30: int x1,y1,x2,y2,x3,y3; // Triangle Coords samer@30: int DX13, DY13, SQLEN13; // to optimise clipping samer@30: samer@30: // mutable state samer@30: Voice *voices[MAX_VOICES]; samer@30: Voice *voiceGrabbed; samer@30: bool constrained; samer@30: bool enableKeys; samer@30: bool allowExit; samer@31: bool snapTruePos; samer@37: bool randInit; samer@30: int ratio; samer@30: int tempoIndex; samer@38: int display_frames; samer@30: string display_msg; samer@38: ofTrueTypeFont *display_font; samer@38: ofTrueTypeFont help_font; samer@38: ofTrueTypeFont main_font; hekeus@6: };