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