annotate src/melodyTriangle.h @ 25:f4ebb87adec1

Added code to keep track of true position of voices in information space; Two voice drawing methods display both true position target position while dragging; string to Voice::status code no longer required; refactored OSC message sending code; added keys to control subdivision ratio for period and shift controls.
author samer
date Sun, 05 Feb 2012 18:13:30 +0000
parents 460c05dd74d0
children 9e8c19c90986
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@25 37 void voiceKeypress(Voice *v, int key);
samer@23 38
samer@22 39 void sendReplyTo();
samer@12 40 void sendCalibrate();
samer@23 41 void sendPosition(Voice *v);
samer@12 42 void sendPeriod(int id, int num, int den);
samer@12 43 void sendShift(int id, int num, int den);
samer@12 44 void sendOctave(int id, int oct);
samer@13 45 void sendAmplitude(int id, float amp);
samer@25 46 void send(const char *msg);
samer@25 47 void send(const char *msg, int a);
samer@25 48 void handleMessage(ofxOscMessage &m);
samer@25 49
samer@22 50 bool clipToTriangle(int *cx, int *cy);
samer@22 51 void fitTriangleIn(int w, int h);
samer@23 52 void reset();
samer@22 53
samer@22 54 // Immutable after construction and setup
samer@22 55 ofxOscSender sender;
samer@22 56 ofxOscReceiver receiver;
samer@22 57 int receivePort; // for sending /reply_to message
samer@22 58 int numVoices;
hekeus@6 59
samer@22 60 // somewhat mutable (on window resize)
samer@22 61 int x1,y1,x2,y2,x3,y3; // Triangle Coords
samer@22 62 int DX13, DY13, SQLEN13; // to optimise clipping
hekeus@6 63
samer@22 64 // mutable state
samer@23 65 Voice *voices[MAX_VOICES];
samer@25 66 Voice *voiceGrabbed;
samer@23 67 bool constrained;
samer@23 68 bool enableKeys;
samer@23 69 int display_frames;
samer@25 70 int ratio;
samer@25 71 int tempoIndex;
samer@23 72 string display_msg;
samer@22 73 ofTrueTypeFont display_font;
hekeus@6 74 };