Repository navigation
Expand file tree
/
Copy pathofApp.cpp
More file actions
225 lines (174 loc) · 7.72 KB
/
Copy pathofApp.cpp
File metadata and controls
225 lines (174 loc) · 7.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#include "ofApp.h"
void ofApp::setup(){
ofBackground(22);
ofSetFrameRate(60);
ofSetVerticalSync(true);
ofSetCircleResolution(circleResolution);
ofEnableAlphaBlending();
//set some default values for your params (optional)
drawOutlines = false;
currentSentence = "unInited";
x = y = 66;
numCircles = 30;
menu = MENU_OPTION_1;
unloadTest = "inited from source";
// START THE SERVER ///////////////////////////////////////////
RUI_SETUP(); //specify a port if you want a specific one
//if you dont specify, the server will choose a random one
//the first time you launch it, and will use it forever
// SETUP A CALLBACK ///////////////////////////////////////////
ofAddListener(RUI_GET_OF_EVENT(), this, &ofApp::clientDidSomething);
//extra verbose!
ofSetLogLevel("ofxRemoteUIServer", OF_LOG_VERBOSE);
ofSetLogLevel("ofxRemoteUI", OF_LOG_VERBOSE);
RUI_GET_INSTANCE()->setVerbose(true);
// SET PARAM GROUPS / COLORS //////////////////////////////////
RUI_NEW_GROUP("POSITION"); //make a new group (optional)
//All items inside a group show the same background hue on the client
// SHARE A FLOAT PARAM ////////////////////////////////////////
RUI_SHARE_PARAM(x, 0, ofGetWidth() ); //add an "x" float param to the current group ("position")
RUI_SET_LAST_PARAM_DESC("move your particles left and right"); //add a description to the paramater u just shared
RUI_SHARE_PARAM(y, 0, ofGetHeight()); //provide a variable, a rangeMin and a rangeMax
RUI_SET_LAST_PARAM_DESC("move your particles up and down"); //add a description to the paramater u just shared
//note the param is shared with a name different than the variable name here (WCN : With Custom Name)
RUI_SHARE_PARAM_WCN("Z: what", z, 0, ofGetWidth() ); //add an "x" float param to the current group ("position")
RUI_NEW_GROUP("STYLE"); //make a new group (optional)
// SHARE A BOOL PARAM ////////////////////////////////////////
RUI_SHARE_PARAM(drawOutlines);
RUI_NEW_COLOR(); //slighly change the bg color within the group
RUI_SHARE_PARAM(numCircles, 0, 30); //variable, rangeMin, rangeMax
RUI_NEW_COLOR(); //slighly change the bg color within the group
RUI_SHARE_PARAM(circleSize, 1, 30); //variable, rangeMin, rangeMax
RUI_NEW_GROUP("GETTERS AND SETTERS");
// Store a multiplier and display it as a percentage.
RUI_SHARE_PARAM("Animation speed (%)",
[this] { return animationSpeed * 100.0f; },
[this](float percent) { animationSpeed = ofClamp(percent, 0.0f, 200.0f) / 100.0f; },
0.0f, 200.0f);
// Apply changes to the renderer as well as updating the stored value.
RUI_SHARE_PARAM_DESC("Circle resolution", "Number of segments used to draw each circle.",
[this] { return circleResolution; },
[this](int resolution) {
circleResolution = ofClamp(resolution, 3, 128);
ofSetCircleResolution(circleResolution);
},
3, 128);
RUI_SHARE_PARAM_WCN("Animate circles",
[this] { return animateCircles; },
[this](bool enabled) { animateCircles = enabled; });
RUI_NEW_GROUP("OTHER"); //make a new group
// SHARE A STRING PARAM ////////////////////////////////
RUI_SHARE_PARAM(currentSentence, ofColor(255,0,0,64)); // you can also set a color on a per-param basis
// SHARE A FLOAT //////////////////////////////////////
RUI_SHARE_PARAM(currentMouseX, 0, ofGetWidth());
// SHARE AN ENUM PARAM ////////////////////////////////
//build a string list for the UI to show
string menuItems[] = {"MENU_OPTION_0", "MENU_OPTION_1", "MENU_OPTION_2", "MENU_OPTION_3"};
//privide the enum param, loweset enum, highest enum, and the Enum string list
RUI_SHARE_ENUM_PARAM(menu, MENU_OPTION_0, MENU_OPTION_3, menuItems);
// SHARE A COLOR PARAM ////////////////////////////////
RUI_SHARE_COLOR_PARAM(color);
// SHARE A string PARAM to unload it later;
//this is useful in cases where a variable used to be shared,
//but its value is now on the xml and you still want it loaded
//but you dont want it to show on the client interface
//to do so, you first share the param, then load from XML, then remove the param
RUI_SHARE_PARAM(unloadTest);
//this efectively removes all remoteUI references to this param
//but bc it's been loaded from xml in the previous step before,
//the end result is that you get to load its value from XML
//but it doesnt show in the client.
//This is meant to be a way to reduce clutter in the client,
//allowing you to phase out params that have settled down and dont
//need further editing, but still allowing you to load its value from the xml.
RUI_REMOVE_PARAM(unloadTest);
cout << "unloadTest: '" << unloadTest << "'" << endl;
RUI_WATCH_PARAM(currentMouseX); //this will print the supplied param all the time on screen,
//useful for debugging
//RUI_START_THREADED(); //if you want all the osc communication to happen on a different
//thread, call this. This has implications though.
//your params can be changed at anytime by the client,
//potentially leading to problems. String params are
//especially very likely to cause crashes!
//so don't use this unless you know you need it!
}
void ofApp::update(){
if(animateCircles) animationFrame += animationSpeed;
currentMouseX = ofGetMouseX();
}
void ofApp::draw(){
if (drawOutlines == 1) ofNoFill();
else ofFill();
ofTranslate(x, y);
for(int i = 0; i < numCircles; i++){
unsigned char r = i * 34;
unsigned char g = i * 93;
unsigned char b = i * 17;
ofSetColor(r,g,b);
ofCircle(
-ofGetWidth() * 0.5 + ofGetWidth() * ofNoise((animationFrame + 20 * i) * 0.004 + i),
-ofGetHeight() * 0.5 + ofGetHeight() * ofNoise((animationFrame + 10 * i) * 0.004 + 4 * i),
circleSize
);
}
ofSetupScreen();
ofDrawBitmapStringHighlight(
string("SERVER\n") +
"x: " + ofToString(x) + "\n" +
"y: " + ofToString(y) + "\n" +
"drawOutlines: " + ofToString(drawOutlines) + "\n" +
"currentSentence: " + currentSentence + "\n" +
"menu item: " + ofToString(menu) ,
20, 20,
ofColor::black, color
);
}
void ofApp::keyPressed( int key ){
if(key == '1'){
ofLogNotice() << "b4 adding test, test is " << test;
RUI_SHARE_PARAM(test, 0, 100);
ofLogNotice() << "after adding test, test is " << test;
}
if(key == '2'){
ofLogNotice() << "b4 remving test, test is " << test;
RUI_GET_INSTANCE()->removeParamFromDB("test", true);
ofLogNotice() << "after remving test, test is " << test;
test = 66;
ofLogNotice() << "setting test to 66 " << test;
}
if(key == '3'){
RUI_GET_INSTANCE()->removeParamFromDB("x");
}
if(key == '4'){
RUI_SHARE_PARAM(test2, 0, 100);
}
if(key == '5'){
RUI_GET_INSTANCE()->removeParamFromDB("test2", true);
}
if(key == '9'){
//force an update in the client side (same as pressing sync button on osx client)
RUI_PUSH_TO_CLIENT();
}
if(key == '0'){
//and also send a text log line to the client
RUI_LOG("key pressed at %f", ofGetElapsedTimef());
}
}
//define a callback method to get notifications of client actions
void ofApp::clientDidSomething(RemoteUIServerCallBackArg &arg){
switch (arg.action) {
case CLIENT_CONNECTED: cout << "CLIENT_CONNECTED" << endl; break;
case CLIENT_DISCONNECTED: cout << "CLIENT_DISCONNECTED" << endl; break;
case CLIENT_UPDATED_PARAM: cout << "CLIENT_UPDATED_PARAM: "<< arg.paramName << " - ";
arg.param.print();
break;
case CLIENT_DID_SET_PRESET: cout << "CLIENT_DID_SET_PRESET" << endl; break;
case CLIENT_SAVED_PRESET: cout << "CLIENT_SAVED_PRESET" << endl; break;
case CLIENT_DELETED_PRESET: cout << "CLIENT_DELETED_PRESET" << endl; break;
case CLIENT_SAVED_STATE: cout << "CLIENT_SAVED_STATE" << endl; break;
case CLIENT_DID_RESET_TO_XML: cout << "CLIENT_DID_RESET_TO_XML" << endl; break;
case CLIENT_DID_RESET_TO_DEFAULTS: cout << "CLIENT_DID_RESET_TO_DEFAULTS" << endl; break;
default:
break;
}
}