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@30
|
35 // private methods
|
samer@30
|
36 Voice *get_voice(int id) throw(bad_voice_id);
|
samer@30
|
37 void voiceKeypress(Voice *v, int key);
|
samer@22
|
38
|
samer@30
|
39 void sendReplyTo();
|
samer@30
|
40 void sendCalibrate();
|
samer@30
|
41 void sendPosition(Voice *v);
|
samer@30
|
42 void sendPeriod(int id, int num, int den);
|
samer@30
|
43 void sendShift(int id, int num, int den);
|
samer@30
|
44 void sendOctave(int id, int oct);
|
samer@30
|
45 void sendAmplitude(int id, float amp);
|
samer@30
|
46 void send(const char *msg);
|
samer@30
|
47 void send(const char *msg, int a);
|
samer@30
|
48 void handleMessage(ofxOscMessage &m);
|
samer@23
|
49
|
samer@30
|
50 bool clipToTriangle(int *cx, int *cy);
|
samer@30
|
51 void fitTriangleIn(int w, int h);
|
samer@30
|
52 void reset();
|
samer@30
|
53
|
samer@30
|
54 void setKeyboardEnable(bool en);
|
samer@22
|
55
|
samer@30
|
56 // Immutable after construction and setup
|
samer@30
|
57 ofxOscSender sender;
|
samer@30
|
58 ofxOscReceiver receiver;
|
samer@30
|
59 int receivePort; // for sending /reply_to message
|
samer@30
|
60 int numVoices;
|
hekeus@6
|
61
|
samer@30
|
62 // somewhat mutable (on window resize)
|
samer@30
|
63 int x1,y1,x2,y2,x3,y3; // Triangle Coords
|
samer@30
|
64 int DX13, DY13, SQLEN13; // to optimise clipping
|
samer@30
|
65
|
samer@30
|
66 // mutable state
|
samer@30
|
67 Voice *voices[MAX_VOICES];
|
samer@30
|
68 Voice *voiceGrabbed;
|
samer@30
|
69 bool constrained;
|
samer@30
|
70 bool enableKeys;
|
samer@30
|
71 bool allowExit;
|
samer@31
|
72 bool snapTruePos;
|
samer@30
|
73 int display_frames;
|
samer@30
|
74 int ratio;
|
samer@30
|
75 int tempoIndex;
|
samer@30
|
76 string display_msg;
|
samer@30
|
77 ofTrueTypeFont display_font;
|
hekeus@6
|
78 };
|