rt300@0
|
1 #include "testApp.h"
|
rt300@2
|
2
|
rt300@0
|
3
|
rt300@0
|
4 extern Grid theGridView;
|
rt300@0
|
5 extern PresetManager presetManager;
|
rt300@1
|
6 extern EventLogger eventLogger;
|
rt300@3
|
7 extern Frequencer frequencer;
|
rt300@9
|
8
|
rt300@7
|
9 //DeviceID3523537000
|
rt300@0
|
10 //--------------------------------------------------------------
|
rt300@0
|
11 void testApp::setup(){
|
rt300@16
|
12 paused = true;
|
rt300@16
|
13
|
rt300@16
|
14 ofBackground( 0, 0, 0 );
|
rt300@0
|
15 ofEnableAlphaBlending();
|
rt300@21
|
16 //ofEnableSmoothing();
|
rt300@0
|
17
|
rt300@0
|
18 // open an outgoing connection to HOST:PORT
|
rt300@0
|
19 sender.setup( HOST, PORT );
|
rt300@3
|
20 ofSetFrameRate(30);
|
rt300@0
|
21 // reciever
|
rt300@6
|
22 lastMoveTime = ofGetSystemTimeMicros();
|
rt300@0
|
23 prevTouchX = 0;
|
rt300@0
|
24 prevTouchY = 0;
|
rt300@0
|
25
|
rt300@0
|
26 xLocked = false;
|
rt300@0
|
27 yLocked = false;
|
rt300@0
|
28
|
rt300@0
|
29 numActiveTouches = 0;
|
rt300@3
|
30 touch0.setCoord(17./7., 2./3.);
|
rt300@0
|
31 touch1.setCoord(10,20);
|
rt300@3
|
32
|
rt300@0
|
33 prevTouch0.setCoord(1,2);
|
rt300@0
|
34 prevTouch1.setCoord(10,20);
|
rt300@0
|
35 prevDist = 10;
|
rt300@16
|
36 slowFactor = 0.98;
|
rt300@16
|
37
|
rt300@16
|
38
|
rt300@16
|
39 // the 5 harmonics for the frequencer
|
rt300@16
|
40 freqIndexes.push_back(0);
|
rt300@16
|
41 freqIndexes.push_back(4);
|
rt300@16
|
42 freqIndexes.push_back(6);
|
rt300@16
|
43 freqIndexes.push_back(7);
|
rt300@16
|
44 freqIndexes.push_back(8);
|
rt300@16
|
45
|
rt300@16
|
46
|
rt300@16
|
47 ofxiPhoneSetOrientation( OFXIPHONE_ORIENTATION_PORTRAIT ); // do this before setting up all the other objects
|
rt300@0
|
48
|
rt300@0
|
49 theGridView.init();
|
rt300@0
|
50
|
rt300@0
|
51 setupStandardGui();
|
rt300@0
|
52 standardGUIShowing = false;
|
rt300@0
|
53 standardGUI->setVisible(standardGUIShowing);
|
rt300@0
|
54
|
rt300@0
|
55 setupZoomGui();
|
rt300@0
|
56 zoomGUI->setVisible(!standardGUIShowing);
|
rt300@0
|
57
|
rt300@0
|
58 // initial slider vals
|
rt300@0
|
59 for(int i=0; i<10;i++){
|
rt300@0
|
60 sliderVals.push_back(64);
|
rt300@0
|
61 }
|
rt300@8
|
62
|
rt300@2
|
63 int ticksPerBuffer = 8; // 8 * 64 = buffer len of 512
|
rt300@2
|
64
|
rt300@2
|
65 // setup the app core
|
rt300@2
|
66 core.setup(2, 1, 44100, ticksPerBuffer);
|
rt300@2
|
67
|
rt300@2
|
68 // setup OF sound stream
|
rt300@2
|
69 ofSoundStreamSetup(2, 1, this, 44100, ofxPd::blockSize()*ticksPerBuffer, 3);
|
rt300@1
|
70
|
rt300@5
|
71 presetManager.startupLoadAll();
|
rt300@7
|
72 eventLogger.init();
|
rt300@16
|
73
|
rt300@16
|
74 paused = false;
|
rt300@16
|
75
|
rt300@5
|
76
|
rt300@0
|
77 }
|
rt300@3
|
78 #pragma mark GUI
|
rt300@16
|
79 //--
|
rt300@16
|
80 float testApp::getWidth(){
|
rt300@16
|
81 // depends on orientation
|
rt300@16
|
82 return ofGetWidth();
|
rt300@16
|
83
|
rt300@16
|
84 }
|
rt300@16
|
85 float testApp::getHeight(){
|
rt300@16
|
86 // depends on orientation
|
rt300@16
|
87 return ofGetHeight();
|
rt300@16
|
88
|
rt300@16
|
89 }
|
rt300@0
|
90 //--------------------------------------------------------------
|
rt300@0
|
91 void testApp::setupZoomGui(){
|
rt300@16
|
92 // width = height
|
rt300@16
|
93 zoomGUI = new ofxUICanvas(getWidth()-200,0,190,300);
|
rt300@1
|
94 zoomGUI->setTheme(OFX_UI_THEME_HACKER );
|
rt300@0
|
95
|
rt300@3
|
96 zoomGUI->addLabelToggle("SWITCH VIEW", false);
|
rt300@0
|
97
|
rt300@0
|
98 zoomGUI->addLabelButton("SAVE PRESET", false);
|
rt300@7
|
99
|
rt300@0
|
100
|
rt300@3
|
101 zoomGUI->addLabelButton("ZOOM MIN", false);
|
rt300@3
|
102 zoomGUI->addLabelButton("ZOOM MAX", false);
|
rt300@16
|
103 zoomGUI->addLabelButton("QUESTIONS", false);
|
rt300@3
|
104
|
rt300@0
|
105 ofAddListener(zoomGUI->newGUIEvent, this, &testApp::zoomGUIEvent);
|
rt300@0
|
106 }
|
rt300@0
|
107 //--------------------------------------------------------------
|
rt300@0
|
108 void testApp::zoomGUIEvent(ofxUIEventArgs &e){
|
rt300@0
|
109
|
rt300@0
|
110 if(e.widget->getName() == "SWITCH VIEW")
|
rt300@0
|
111 {
|
rt300@16
|
112 // is toggle
|
rt300@0
|
113 cout << "change VIEW\n";
|
rt300@16
|
114 cout << "of width " << ofGetWidth() <<'\n';
|
rt300@16
|
115 cout << "of height " << ofGetHeight() <<'\n';
|
rt300@0
|
116 standardGUI->setVisible(!standardGUIShowing);
|
rt300@0
|
117 standardGUIShowing = !standardGUIShowing;
|
rt300@0
|
118 if(standardGUIShowing){
|
rt300@0
|
119 // set the slider values to stuff got from zoomer
|
rt300@0
|
120 sliderVals = theGridView.getParams();
|
rt300@3
|
121 setAllGUISliders(sliderVals);
|
rt300@0
|
122 }
|
rt300@0
|
123
|
rt300@0
|
124 }else if(e.widget->getName() == "SAVE PRESET")
|
rt300@0
|
125 {
|
rt300@0
|
126
|
rt300@16
|
127 if(((ofxUIButton *)e.widget)->getValue()==0){ // touchup
|
rt300@3
|
128 cout << "SAVE PRESET\n";
|
rt300@9
|
129 presetManager.showNameDialog();
|
rt300@8
|
130
|
rt300@3
|
131 }
|
rt300@3
|
132
|
rt300@3
|
133 }else if(e.widget->getName() == "ZOOM MIN")
|
rt300@3
|
134 {
|
rt300@16
|
135 if(((ofxUIButton *)e.widget)->getValue()==0){ // touchup
|
rt300@3
|
136 cout << "ZOOM MIN\n";
|
rt300@5
|
137 theGridView.setMinZoom();
|
rt300@5
|
138 eventLogger.logEvent(SET_MIN_ZOOM);
|
rt300@3
|
139 }
|
rt300@3
|
140 }else if(e.widget->getName() == "ZOOM MAX")
|
rt300@3
|
141 {
|
rt300@16
|
142 if(((ofxUIButton *)e.widget)->getValue()==0){ // touchup
|
rt300@8
|
143 cout << "ZOOM MAX\n";
|
rt300@5
|
144 theGridView.setMaxZoom();
|
rt300@5
|
145 eventLogger.logEvent(SET_MAX_ZOOM);
|
rt300@8
|
146
|
rt300@3
|
147 }
|
rt300@16
|
148 }else if(e.widget->getName() == "QUESTIONS")
|
rt300@16
|
149 {
|
rt300@16
|
150 if(((ofxUIButton *)e.widget)->getValue()==0){ // touchup
|
rt300@16
|
151 showQuestionnaire();
|
rt300@16
|
152 }
|
rt300@0
|
153 }else{
|
rt300@0
|
154 cout << "GUI error : unknown event recieved\n";
|
rt300@0
|
155 }
|
rt300@0
|
156
|
rt300@0
|
157 }
|
rt300@0
|
158 //--------------------------------------------------------------
|
rt300@16
|
159 void testApp::showQuestionnaire(){
|
rt300@16
|
160 // stop updating / drawing
|
rt300@16
|
161
|
rt300@22
|
162 // if(eventLogger.questionnaireCompleted) return;
|
rt300@22
|
163
|
rt300@16
|
164 paused = true;
|
rt300@16
|
165
|
rt300@16
|
166 questionnaireViewController = [[QuestionnaireViewController alloc] initWithNibName:@"QuestionnaireViewController" bundle:nil];
|
rt300@16
|
167 [ofxiPhoneGetGLParentView() addSubview:questionnaireViewController.view];
|
rt300@16
|
168
|
rt300@16
|
169 [questionnaireViewController setAppRef:(id)this];
|
rt300@16
|
170 [questionnaireViewController show:(id)this];
|
rt300@16
|
171
|
rt300@16
|
172 //IF THE VIEW IS HIDDEN LETS BRING IT BACK!
|
rt300@16
|
173 //if( questionnaireViewController.view.hidden ){
|
rt300@16
|
174 // questionnaireViewController.view.hidden = NO;
|
rt300@16
|
175 //}
|
rt300@16
|
176
|
rt300@16
|
177 }
|
rt300@16
|
178 //--------------------------------------------------------------
|
rt300@22
|
179 void testApp::questionnaireHidden(vector<int> answers){
|
rt300@16
|
180 // send answers to server as json
|
rt300@22
|
181 eventLogger.questionnaireAnswersObtained(answers);
|
rt300@16
|
182
|
rt300@16
|
183 // set "we've done questionnaire" to true in event logger
|
rt300@16
|
184 paused = false;
|
rt300@16
|
185 }
|
rt300@16
|
186 //--------------------------------------------------------------
|
rt300@0
|
187 void testApp::setupStandardGui(){
|
rt300@0
|
188 float xInit = OFX_UI_GLOBAL_WIDGET_SPACING;
|
rt300@0
|
189 float length = 256-xInit*2;
|
rt300@0
|
190
|
rt300@0
|
191
|
rt300@0
|
192 float dim = 42;
|
rt300@0
|
193
|
rt300@0
|
194 // LEFT GUI
|
rt300@16
|
195 standardGUI = new ofxUICanvas(0,0,length+90,getHeight());
|
rt300@0
|
196
|
rt300@0
|
197
|
rt300@7
|
198 ofxUILabelToggle * butt = standardGUI->addLabelToggle("LOCK SEQUENCE (X)", false);
|
rt300@7
|
199 butt->setColorFill(ofColor(0,0,255));
|
rt300@7
|
200 butt->setColorFillHighlight(ofColor(0,0,255));
|
rt300@0
|
201
|
rt300@0
|
202 // Uh.. loop this
|
rt300@0
|
203 for(int i = 1; i<=10;i++){
|
rt300@0
|
204 stringstream ss;
|
rt300@0
|
205 ss << "P" << i;
|
rt300@0
|
206 ofxUISlider *slider;
|
rt300@0
|
207 slider = (ofxUISlider *)standardGUI->addWidgetDown(new ofxUISlider(length,dim,0.0,127,64,ss.str()));
|
rt300@0
|
208 slider->setDrawPadding(true);
|
rt300@1
|
209 if(i <= 5){
|
rt300@1
|
210 slider->setColorFill(ofColor(0,0,255));
|
rt300@1
|
211 slider->setColorFillHighlight(ofColor(0,0,255));
|
rt300@1
|
212 }else{
|
rt300@1
|
213 slider->setColorFill(ofColor(255,0,0));
|
rt300@1
|
214 slider->setColorFillHighlight(ofColor(255,0,0));
|
rt300@1
|
215 }
|
rt300@1
|
216
|
rt300@0
|
217 sliders.push_back(slider);
|
rt300@0
|
218 }
|
rt300@0
|
219
|
rt300@7
|
220 ofxUILabelToggle * butt2 = standardGUI->addLabelToggle("LOCK SYNTH (Y)", false);
|
rt300@7
|
221 butt2->setColorFill(ofColor(255,0,0));
|
rt300@7
|
222 butt2->setColorFillHighlight(ofColor(255,0,0));
|
rt300@7
|
223
|
rt300@0
|
224 ofAddListener(standardGUI->newGUIEvent, this, &testApp::standardGUIEvent);
|
rt300@0
|
225 standardGUI->loadSettings(ofxiPhoneGetDocumentsDirectory() + "guiSettings.xml");
|
rt300@0
|
226
|
rt300@0
|
227 }
|
rt300@0
|
228 //--------------------------------------------------------------
|
rt300@0
|
229 void testApp::standardGUIEvent(ofxUIEventArgs &e){
|
rt300@0
|
230 if(!standardGUIShowing){
|
rt300@0
|
231 cout << "GUI ERROR";
|
rt300@0
|
232 return;
|
rt300@0
|
233 }
|
rt300@7
|
234
|
rt300@7
|
235 if(e.widget->getName() == "LOCK SEQUENCE (X)")
|
rt300@7
|
236 {
|
rt300@20
|
237
|
rt300@20
|
238 cout << "LOCK SEQUENCE (X)\n";
|
rt300@20
|
239 // lock
|
rt300@20
|
240 theGridView.shiftCentreToSnapped();
|
rt300@20
|
241 xLocked = !xLocked;
|
rt300@20
|
242
|
rt300@7
|
243 }else if(e.widget->getName() == "LOCK SYNTH (Y)")
|
rt300@7
|
244 {
|
rt300@7
|
245
|
rt300@7
|
246 cout << "LOCK SYNTH (Y)\n";
|
rt300@7
|
247 // lock
|
rt300@20
|
248 theGridView.shiftCentreToSnapped();
|
rt300@7
|
249 if(((ofxUIButton *)e.widget)->getValue()){
|
rt300@7
|
250 yLocked = true;
|
rt300@7
|
251 }else{
|
rt300@7
|
252 yLocked = false;
|
rt300@7
|
253
|
rt300@7
|
254 }
|
rt300@7
|
255 }
|
rt300@7
|
256
|
rt300@0
|
257 // "normal" parameter changes
|
rt300@0
|
258 for(int i = 1; i<=10;i++){
|
rt300@0
|
259 stringstream ss;
|
rt300@0
|
260 ss << "P" << i;
|
rt300@0
|
261 string p = ss.str();
|
rt300@0
|
262
|
rt300@0
|
263 if(e.widget->getName() == p)
|
rt300@0
|
264 {
|
rt300@0
|
265 //cout << "param change: " << p;
|
rt300@0
|
266 ofxUISlider *slider = (ofxUISlider *) e.widget;
|
rt300@3
|
267 sliderMoved(i-1,slider->getScaledValue()); // internal array 0 indexed
|
rt300@0
|
268
|
rt300@5
|
269
|
rt300@5
|
270
|
rt300@0
|
271 }
|
rt300@0
|
272 }
|
rt300@0
|
273
|
rt300@0
|
274 // TODO reflect these changes in zoomer view? Or only when switching?
|
rt300@0
|
275
|
rt300@0
|
276 }
|
rt300@0
|
277 //--------------------------------------------------------------
|
rt300@3
|
278 void testApp::sliderMoved(int which, float value){
|
rt300@3
|
279 // an update caused by slider view being touched
|
rt300@0
|
280 sliderVals[which] = (int)value;
|
rt300@0
|
281 theGridView.setParams(sliderVals);
|
rt300@3
|
282
|
rt300@3
|
283 // TODO if <5 do frequencer stuff and send list to PD
|
rt300@3
|
284 // if > 5 send control value to PD
|
rt300@3
|
285 sendParametersToPD();
|
rt300@5
|
286
|
rt300@9
|
287 eventLogger.logEvent(CHANGE_SLIDER, TwoVector(),0.0,which , value);
|
rt300@5
|
288
|
rt300@0
|
289 }
|
rt300@0
|
290 //--------------------------------------------------------------
|
rt300@3
|
291 void testApp::setAllGUISliders(vector<int> vals){
|
rt300@3
|
292 // an update caused by zoomer view being moved
|
rt300@0
|
293 for(int i = 0; i<10;i++){
|
rt300@0
|
294 sliders[i]->setValue(vals[i]);
|
rt300@1
|
295 sliderVals[i] = vals[i];
|
rt300@0
|
296 }
|
rt300@3
|
297
|
rt300@0
|
298 }
|
rt300@0
|
299 //--------------------------------------------------------------
|
rt300@3
|
300 void testApp::sendParametersToPD(){
|
rt300@3
|
301 // frequencer stuff to get 16 steps
|
rt300@3
|
302 vector<double> vals;
|
rt300@3
|
303
|
rt300@3
|
304
|
rt300@3
|
305 vals.push_back((sliderVals[0]+32)*8.); // DC offset
|
rt300@3
|
306 for(int i=1; i<5;i++){
|
rt300@3
|
307 vals.push_back((sliderVals[i] - 64)*2.);
|
rt300@3
|
308 }
|
rt300@3
|
309
|
rt300@3
|
310 vector<double> steps = frequencer.freqMagEdit(freqIndexes, vals);
|
rt300@3
|
311 // send a list using the List object
|
rt300@3
|
312 List seqSteps;
|
rt300@3
|
313
|
rt300@3
|
314 seqSteps.addSymbol("seqSteps");
|
rt300@3
|
315 for(int i=0; i < 16; i++){
|
rt300@3
|
316 seqSteps.addFloat(round(steps[i])); // rounding here??
|
rt300@3
|
317 }
|
rt300@3
|
318
|
rt300@3
|
319 core.pd.sendList("fromOF", seqSteps);
|
rt300@8
|
320
|
rt300@3
|
321 sendOscShape(sliderVals[5]);
|
rt300@3
|
322 sendFiltType(sliderVals[6]);
|
rt300@3
|
323 sendFiltFreq(sliderVals[7]);
|
rt300@3
|
324 sendEnvShape(sliderVals[8]);
|
rt300@3
|
325 sendModFreq(sliderVals[9]);
|
rt300@3
|
326
|
rt300@3
|
327 }
|
rt300@8
|
328 //--------------------------------------------------------------
|
rt300@3
|
329 #pragma mark STANDARD OF FUNCTIONS
|
rt300@3
|
330 //--------------------------------------------------------------
|
rt300@0
|
331 void testApp::update(){
|
rt300@0
|
332 //we do a heartbeat on iOS as the phone will shut down the network connection to save power
|
rt300@0
|
333 //this keeps the network alive as it thinks it is being used.
|
rt300@16
|
334 if(paused) return;
|
rt300@16
|
335
|
rt300@0
|
336 if( ofGetFrameNum() % 120 == 0 ){
|
rt300@0
|
337 ofxOscMessage m;
|
rt300@0
|
338 m.setAddress( "/misc/heartbeat" );
|
rt300@0
|
339 m.addIntArg( ofGetFrameNum() );
|
rt300@0
|
340 sender.sendMessage( m );
|
rt300@0
|
341 }
|
rt300@0
|
342
|
rt300@5
|
343 // continiue to move at velocity, unless snapped
|
rt300@3
|
344
|
rt300@3
|
345 if (numActiveTouches == 0){ // no touches, use momentum
|
rt300@3
|
346 // TODO set velocity to 0 when hits walls
|
rt300@3
|
347
|
rt300@22
|
348 if(moveVel.norm() > 0.3){
|
rt300@22
|
349 if(theGridView.snapped){
|
rt300@22
|
350 // stop it, send snap event
|
rt300@22
|
351 moveVel.setCoord(0.0,0.0);
|
rt300@22
|
352 }else{
|
rt300@22
|
353 theGridView.move(moveVel);
|
rt300@22
|
354 moveVel = moveVel*slowFactor;
|
rt300@22
|
355 }
|
rt300@3
|
356 // and get new parameter values
|
rt300@5
|
357 setAllGUISliders(theGridView.getParams());
|
rt300@3
|
358 sendParametersToPD();
|
rt300@22
|
359 }else if(moveVel.norm() > 0.01){ // and less than 0.3
|
rt300@3
|
360 // stop it
|
rt300@3
|
361 moveVel.setCoord(0.0,0.0);
|
rt300@5
|
362 setAllGUISliders(theGridView.getParams());
|
rt300@3
|
363 sendParametersToPD();
|
rt300@5
|
364 eventLogger.logEvent(SCROLL_STOPPED, theGridView.getCoord() );
|
rt300@22
|
365
|
rt300@3
|
366 }else{
|
rt300@3
|
367 // stopped - do nothing
|
rt300@3
|
368 }
|
rt300@3
|
369
|
rt300@0
|
370 }
|
rt300@0
|
371 // continiue to zoom at velocity
|
rt300@0
|
372 if (numActiveTouches < 2 && abs(zoomVel)>0.001){
|
rt300@0
|
373 theGridView.zoom(zoomVel + 1.0); // +1 because zoomVel factor is + or - , wheras zoom is a multiplier near 1
|
rt300@0
|
374 zoomVel = zoomVel*slowFactor;
|
rt300@0
|
375 }
|
rt300@6
|
376
|
rt300@0
|
377 }
|
rt300@0
|
378 //--------------------------------------------------------------
|
rt300@0
|
379 void testApp::sendOSCParams(){
|
rt300@0
|
380
|
rt300@0
|
381 vector<int> params = theGridView.getParams(); // FILTER HERE? NEED FLOATS...
|
rt300@0
|
382 vector<int>::iterator iter = params.begin();
|
rt300@0
|
383
|
rt300@0
|
384 ofxOscMessage m;
|
rt300@0
|
385 m.setAddress( "p" );
|
rt300@0
|
386
|
rt300@0
|
387 for(;iter < params.end();iter++){
|
rt300@0
|
388
|
rt300@0
|
389 m.addFloatArg( *iter );
|
rt300@0
|
390
|
rt300@0
|
391 }
|
rt300@0
|
392 sender.sendMessage( m );
|
rt300@0
|
393 }
|
rt300@0
|
394 //--------------------------------------------------------------
|
rt300@0
|
395 void testApp::draw(){
|
rt300@16
|
396 if(paused) return;
|
rt300@16
|
397 if (standardGUIShowing){// ?
|
rt300@0
|
398 ofSetColor(57, 57, 57,200);
|
rt300@16
|
399 ofRect(0,0,getWidth(),getHeight());
|
rt300@0
|
400 }
|
rt300@0
|
401 theGridView.draw();
|
rt300@16
|
402
|
rt300@0
|
403 }
|
rt300@0
|
404
|
rt300@0
|
405 //--------------------------------------------------------------
|
rt300@0
|
406 void testApp::exit(){
|
rt300@4
|
407
|
rt300@4
|
408 presetManager.exitAndSaveAll();
|
rt300@7
|
409 eventLogger.exitAndSave();
|
rt300@2
|
410 core.exit();
|
rt300@4
|
411
|
rt300@0
|
412 delete standardGUI;
|
rt300@0
|
413 delete zoomGUI;
|
rt300@4
|
414 cout << "exit done \n";
|
rt300@0
|
415 }
|
rt300@0
|
416
|
rt300@0
|
417 //--------------------------------------------------------------
|
rt300@0
|
418 void testApp::touchDown(ofTouchEventArgs &touch){
|
rt300@0
|
419 if(standardGUIShowing){
|
rt300@0
|
420 // check if in GUI area
|
rt300@0
|
421 if(touch.x < 256) return;
|
rt300@0
|
422 }
|
rt300@0
|
423
|
rt300@0
|
424 numActiveTouches++;
|
rt300@0
|
425 // absolute position doesn't matter
|
rt300@0
|
426 // which one?
|
rt300@0
|
427 if(touch.id == 0){
|
rt300@0
|
428 touch0.setCoord(touch.x,touch.y);
|
rt300@0
|
429 prevTouch0 = touch0;
|
rt300@0
|
430 }else if(touch.id == 1){
|
rt300@0
|
431
|
rt300@0
|
432 touch1.setCoord(touch.x,touch.y);
|
rt300@0
|
433 prevTouch1 = touch1;
|
rt300@0
|
434
|
rt300@0
|
435 }
|
rt300@0
|
436 if(numActiveTouches == 1){
|
rt300@0
|
437 moveVel.setCoord(0.0, 0.0);
|
rt300@0
|
438 prevMove.setCoord(0.0, 0.0);
|
rt300@0
|
439 prevMove2.setCoord(0.0, 0.0);
|
rt300@0
|
440 }else if(numActiveTouches == 2){
|
rt300@0
|
441 zoomVel = 0.0;
|
rt300@0
|
442 prevZoom = 0.0;
|
rt300@0
|
443 prevZoom2 = 0.0;
|
rt300@0
|
444 double dist = touch1.distanceTo(touch0);
|
rt300@0
|
445 prevDist = dist;
|
rt300@0
|
446 }
|
rt300@0
|
447
|
rt300@0
|
448 }
|
rt300@0
|
449
|
rt300@0
|
450 //--------------------------------------------------------------
|
rt300@0
|
451 void testApp::touchMoved(ofTouchEventArgs &touch){
|
rt300@1
|
452
|
rt300@1
|
453 //cout << "touch id " << touch.id << "\n";
|
rt300@1
|
454 //cout << "active touches " << numActiveTouches << "\n";
|
rt300@1
|
455
|
rt300@1
|
456
|
rt300@0
|
457 if(standardGUIShowing){
|
rt300@3
|
458 // TODO check if in GUI area
|
rt300@0
|
459 if(touch.x < 256) return;
|
rt300@0
|
460 }
|
rt300@7
|
461 // check if in other gui area
|
rt300@16
|
462 if(touch.x > getWidth()-200 && touch.y < 300){
|
rt300@7
|
463 return;
|
rt300@7
|
464 }
|
rt300@0
|
465
|
rt300@1
|
466 // which one? keep track of each touch point
|
rt300@0
|
467 if(touch.id == 0){
|
rt300@0
|
468 touch0.setCoord(touch.x,touch.y);
|
rt300@0
|
469
|
rt300@0
|
470 }else if(touch.id == 1){
|
rt300@0
|
471
|
rt300@0
|
472 touch1.setCoord(touch.x,touch.y);
|
rt300@0
|
473 }
|
rt300@0
|
474
|
rt300@1
|
475 if(numActiveTouches == 1){
|
rt300@0
|
476
|
rt300@1
|
477 handleScroll();
|
rt300@0
|
478 }else if(numActiveTouches == 2){
|
rt300@1
|
479 handleZoom();
|
rt300@0
|
480
|
rt300@0
|
481 }
|
rt300@0
|
482 prevTouch0 = touch0;
|
rt300@0
|
483
|
rt300@0
|
484
|
rt300@0
|
485 }
|
rt300@5
|
486
|
rt300@1
|
487 //--------------------------------------------------------------
|
rt300@1
|
488 void testApp::handleScroll(){
|
rt300@6
|
489
|
rt300@1
|
490 TwoVector move = touch0 - prevTouch0;
|
rt300@5
|
491 if(yLocked){
|
rt300@5
|
492 move.y = 0.0;
|
rt300@5
|
493 }
|
rt300@5
|
494 if(xLocked){
|
rt300@5
|
495 move.x = 0.0;
|
rt300@5
|
496 }
|
rt300@5
|
497
|
rt300@6
|
498 // check time since last move - if
|
rt300@6
|
499 unsigned int moveTime = ofGetSystemTimeMicros();
|
rt300@6
|
500 if(moveTime - lastMoveTime > 100000){
|
rt300@6
|
501 moveVel = TwoVector(); // zero
|
rt300@6
|
502 }else{
|
rt300@6
|
503 moveVel = (move*0.3 + prevMove*0.34 + prevMove2*0.38); // use the time
|
rt300@6
|
504
|
rt300@6
|
505 }
|
rt300@6
|
506 lastMoveTime = moveTime;
|
rt300@6
|
507
|
rt300@5
|
508
|
rt300@1
|
509 prevMove2 = prevMove;
|
rt300@1
|
510 prevMove = move;
|
rt300@1
|
511
|
rt300@5
|
512
|
rt300@3
|
513 theGridView.move(move);
|
rt300@3
|
514
|
rt300@3
|
515 // and get new parameter values
|
rt300@3
|
516 setAllGUISliders(theGridView.getParams());
|
rt300@3
|
517 sendParametersToPD();
|
rt300@1
|
518 }
|
rt300@1
|
519 //--------------------------------------------------------------
|
rt300@1
|
520 void testApp::handleZoom(){
|
rt300@1
|
521 // work out change in difference
|
rt300@1
|
522 double dist = touch1.distanceTo(touch0);
|
rt300@1
|
523 double zoomFactor = prevDist/dist;
|
rt300@1
|
524
|
rt300@1
|
525 //TODO check for sensible maximums, e.g. spurious touch data
|
rt300@1
|
526 if(zoomFactor > 2.0 || zoomFactor < 0.5){
|
rt300@1
|
527 cout << "Zoom too much!!!!" << zoomFactor;
|
rt300@1
|
528 zoomFactor = 1.0;
|
rt300@1
|
529 }
|
rt300@1
|
530
|
rt300@1
|
531 zoomVel = (zoomFactor-1)*0.3 + prevZoom*0.34 + prevZoom2*0.38;
|
rt300@1
|
532 prevZoom2 = prevZoom;
|
rt300@1
|
533 prevZoom = (zoomFactor-1);
|
rt300@1
|
534
|
rt300@1
|
535 theGridView.zoom(zoomFactor);
|
rt300@1
|
536
|
rt300@1
|
537 prevDist = dist;
|
rt300@3
|
538
|
rt300@1
|
539 }
|
rt300@0
|
540 //--------------------------------------------------------------
|
rt300@0
|
541 void testApp::touchUp(ofTouchEventArgs &touch){
|
rt300@1
|
542 if(numActiveTouches > 0) numActiveTouches--; // dirty
|
rt300@1
|
543
|
rt300@0
|
544 if(standardGUIShowing){
|
rt300@0
|
545 // check if in GUI area
|
rt300@0
|
546 if(touch.x < 256)
|
rt300@1
|
547
|
rt300@0
|
548 return;
|
rt300@0
|
549 }
|
rt300@7
|
550 // check if in
|
rt300@1
|
551
|
rt300@0
|
552 // which one?
|
rt300@0
|
553 if(touch.id == 0){
|
rt300@0
|
554 // tricky situation - we tried to zoom but may have left non-move finger on
|
rt300@0
|
555 prevTouch0.setCoord(touch.x,touch.y);
|
rt300@0
|
556
|
rt300@0
|
557 }else if(touch.id == 1){
|
rt300@0
|
558
|
rt300@0
|
559
|
rt300@0
|
560 prevTouch1.setCoord(0,0);
|
rt300@6
|
561
|
rt300@6
|
562 }
|
rt300@6
|
563 if(numActiveTouches == 0){
|
rt300@6
|
564 // check time since last move
|
rt300@6
|
565 // check time since last move - if
|
rt300@6
|
566 unsigned int moveTime = ofGetSystemTimeMicros();
|
rt300@6
|
567 if(moveTime - lastMoveTime > 100000){
|
rt300@6
|
568 moveVel = TwoVector(); // zero
|
rt300@6
|
569 }else{
|
rt300@6
|
570 moveVel = (move*0.3 + prevMove*0.34 + prevMove2*0.38); // use the time
|
rt300@6
|
571
|
rt300@6
|
572 }
|
rt300@6
|
573 lastMoveTime = moveTime;
|
rt300@0
|
574 }
|
rt300@0
|
575
|
rt300@0
|
576 }
|
rt300@0
|
577
|
rt300@0
|
578 //--------------------------------------------------------------
|
rt300@0
|
579 void testApp::touchDoubleTap(ofTouchEventArgs &touch){
|
rt300@0
|
580 // preset?
|
rt300@0
|
581
|
rt300@0
|
582 }
|
rt300@0
|
583
|
rt300@0
|
584 //--------------------------------------------------------------
|
rt300@0
|
585 void testApp::lostFocus(){
|
rt300@0
|
586
|
rt300@0
|
587 }
|
rt300@0
|
588
|
rt300@0
|
589 //--------------------------------------------------------------
|
rt300@0
|
590 void testApp::gotFocus(){
|
rt300@0
|
591
|
rt300@0
|
592 }
|
rt300@0
|
593
|
rt300@0
|
594 //--------------------------------------------------------------
|
rt300@0
|
595 void testApp::gotMemoryWarning(){
|
rt300@0
|
596
|
rt300@0
|
597 }
|
rt300@0
|
598
|
rt300@0
|
599 //--------------------------------------------------------------
|
rt300@0
|
600 void testApp::deviceOrientationChanged(int newOrientation){
|
rt300@16
|
601 /*
|
rt300@0
|
602 cout << "orientation: " << newOrientation;
|
rt300@15
|
603
|
rt300@0
|
604 if(newOrientation == 4){
|
rt300@16
|
605 ofxiPhoneSetOrientation( OF_ORIENTATION_DEFAULT );
|
rt300@16
|
606
|
rt300@0
|
607 }else if(newOrientation == 3){
|
rt300@0
|
608 ofxiPhoneSetOrientation( OF_ORIENTATION_90_LEFT );
|
rt300@16
|
609 }else if(newOrientation == 3){
|
rt300@16
|
610 ofxiPhoneSetOrientation( OF_ORIENTATION_90_LEFT );
|
rt300@16
|
611 }
|
rt300@16
|
612
|
rt300@16
|
613
|
rt300@16
|
614 [ofxiPhoneGetGLView() updateDimensions];
|
rt300@16
|
615 */
|
rt300@0
|
616 }
|
rt300@0
|
617
|
rt300@0
|
618
|
rt300@0
|
619 //--------------------------------------------------------------
|
rt300@0
|
620 void testApp::touchCancelled(ofTouchEventArgs& args){
|
rt300@0
|
621
|
rt300@0
|
622 }
|
rt300@3
|
623 //---------------------------------------------------------------
|
rt300@3
|
624 // AUDIO STUFF
|
rt300@3
|
625 //---------------------------------------------------------------
|
rt300@3
|
626
|
rt300@3
|
627 #pragma mark AUDIO STREAMS
|
rt300@3
|
628 //--------------------------------------------------------------
|
rt300@3
|
629 void testApp::audioReceived(float * input, int bufferSize, int nChannels) {
|
rt300@3
|
630 core.audioReceived(input, bufferSize, nChannels);
|
rt300@3
|
631 }
|
rt300@3
|
632
|
rt300@3
|
633 void testApp::audioRequested(float * output, int bufferSize, int nChannels) {
|
rt300@3
|
634 core.audioRequested(output, bufferSize, nChannels);
|
rt300@3
|
635 }
|
rt300@3
|
636 //---------------------------------------------------------------
|
rt300@3
|
637 #pragma mark UTILITIES
|
rt300@0
|
638
|
rt300@0
|
639 // 5hz cut off
|
rt300@0
|
640 const double fB[3] = {0.049489956268677, 0.098979912537354, 0.049489956268677};
|
rt300@0
|
641
|
rt300@0
|
642 const double fA[3] = {1.000000000000000, -1.279632424997809, 0.477592250072517};
|
rt300@0
|
643
|
rt300@0
|
644 // 1hz cut off
|
rt300@0
|
645 //const double fB[3] = {0.002550535158536, 0.005101070317073, 0.002550535158536};
|
rt300@0
|
646
|
rt300@0
|
647 //const double fA[3] = {1.000000000000000, -1.852146485395936, 0.862348626030081};
|
rt300@0
|
648
|
rt300@0
|
649
|
rt300@0
|
650 //a(1)*y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb)- a(2)*y(n-1) - ... - a(na+1)*y(n-na)
|
rt300@0
|
651 //---------------------------------------------------------------
|
rt300@0
|
652 vector<float> testApp::vectorFilter(vector<float> newVec){
|
rt300@0
|
653 static vector<float> x0(10,0);
|
rt300@0
|
654 static vector<float> x1(10,0);
|
rt300@0
|
655 static vector<float> x2(10,0);
|
rt300@0
|
656 static vector<float> y0(10,0);
|
rt300@0
|
657 static vector<float> y1(10,0);
|
rt300@0
|
658 static vector<float> y2(10,0);
|
rt300@0
|
659
|
rt300@0
|
660 x0 = newVec;
|
rt300@0
|
661
|
rt300@0
|
662 // this low passes a bunch of params values all at once
|
rt300@0
|
663 int sz = newVec.size();
|
rt300@0
|
664 for(int i=0; i<sz; i++){
|
rt300@0
|
665 y0[i] = fB[0]*x0[i] + fB[1]*x1[i] + fB[2]*x2[i] - fA[1]*y1[i] - fA[2]*y2[i];
|
rt300@0
|
666 }
|
rt300@0
|
667 // shift
|
rt300@0
|
668 x2 = x1;
|
rt300@0
|
669 x1 = x0;
|
rt300@0
|
670 y2 = y1;
|
rt300@0
|
671 y1 = y0;
|
rt300@0
|
672
|
rt300@0
|
673 return y0;
|
rt300@2
|
674 }
|
rt300@8
|
675 //---------------------------------------------------------------
|
rt300@3
|
676 void testApp::sendOscShape(int ctrlin){
|
rt300@3
|
677
|
rt300@3
|
678 static int numpoints = 5;
|
rt300@3
|
679 static int numcontrols = 5;
|
rt300@3
|
680 //float values[points][controls] =
|
rt300@3
|
681 float ctrlout[numcontrols];
|
rt300@3
|
682 string ctrlName[5] = {"pWidth" , "sqVol", "sawVol", "sineVol", "FMAmt"};
|
rt300@3
|
683 float values[5][5] =
|
rt300@3
|
684 {{0.5, 0., 0., 1., 1.}, // 0
|
rt300@3
|
685 {0.5, 0., 0., 1., 0.}, // 32
|
rt300@3
|
686 {0.5, 0., 1., 0., 0.}, // 64
|
rt300@3
|
687 {0.5, 1., 1., 0., 0.}, // 96
|
rt300@3
|
688 {0.01,1., 1., 0., 0.}}; // 127
|
rt300@3
|
689
|
rt300@3
|
690 float fidx = (numpoints-1)*ctrlin/128.;
|
rt300@3
|
691 int idx = floor(fidx);
|
rt300@3
|
692 float frac = fidx - idx;
|
rt300@3
|
693 for(int i=0; i < numcontrols; i++){
|
rt300@3
|
694 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
|
rt300@3
|
695 // send to PD
|
rt300@3
|
696 List toPD;
|
rt300@3
|
697
|
rt300@3
|
698 toPD.addSymbol(ctrlName[i]);
|
rt300@3
|
699 toPD.addFloat(ctrlout[i]); // rounding here??
|
rt300@3
|
700
|
rt300@3
|
701 core.pd.sendList("fromOF", toPD);
|
rt300@3
|
702 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
|
rt300@3
|
703 }
|
rt300@3
|
704
|
rt300@2
|
705 }
|
rt300@8
|
706 //---------------------------------------------------------------
|
rt300@3
|
707 void testApp::sendFiltType(int ctrlin){
|
rt300@3
|
708 static int numpoints = 3;
|
rt300@3
|
709 static int numcontrols = 4;
|
rt300@3
|
710 //float values[points][controls] =
|
rt300@3
|
711 float ctrlout[numcontrols];
|
rt300@3
|
712 string ctrlName[4] = {"lpLev" , "bpLev", "hpLev", "reson"};
|
rt300@3
|
713 float values[3][4] =
|
rt300@3
|
714 {{1., 0., 0., 1}, // 0
|
rt300@3
|
715 {0., 10., 0., 10}, // 64
|
rt300@3
|
716 {0., 0., 1., 1}}; // 127
|
rt300@3
|
717
|
rt300@3
|
718 float fidx = (numpoints-1)*ctrlin/128.;
|
rt300@3
|
719 int idx = floor(fidx);
|
rt300@3
|
720 float frac = fidx - idx;
|
rt300@3
|
721 for(int i=0; i < numcontrols; i++){
|
rt300@3
|
722 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
|
rt300@3
|
723 // send to PD
|
rt300@3
|
724 List toPD;
|
rt300@3
|
725
|
rt300@3
|
726 toPD.addSymbol(ctrlName[i]);
|
rt300@3
|
727 toPD.addFloat(ctrlout[i]); // rounding here??
|
rt300@3
|
728
|
rt300@3
|
729 core.pd.sendList("fromOF", toPD);
|
rt300@3
|
730 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
|
rt300@3
|
731 }
|
rt300@2
|
732 }
|
rt300@8
|
733 //---------------------------------------------------------------
|
rt300@3
|
734 void testApp::sendFiltFreq(int ctrlin){
|
rt300@3
|
735 List toPD;
|
rt300@3
|
736
|
rt300@3
|
737 toPD.addSymbol("filtFreq");
|
rt300@3
|
738 toPD.addFloat(ctrlin);
|
rt300@3
|
739
|
rt300@3
|
740 core.pd.sendList("fromOF", toPD);
|
rt300@3
|
741 }
|
rt300@8
|
742 //---------------------------------------------------------------
|
rt300@3
|
743 void testApp::sendEnvShape(int ctrlin){
|
rt300@3
|
744 static int numpoints = 5;
|
rt300@3
|
745 static int numcontrols = 3;
|
rt300@3
|
746 //float values[points][controls] =
|
rt300@3
|
747 float ctrlout[numcontrols];
|
rt300@3
|
748 string ctrlName[3] = {"attack" , "decay", "sustain"};
|
rt300@3
|
749 float values[5][3] =
|
rt300@3
|
750 {{0., 0., 0.}, // 0
|
rt300@3
|
751 {0., 0.5, 0.}, // 32
|
rt300@3
|
752 {0.0, 1., 0.8}, // 64
|
rt300@3
|
753 {0.99, 0.3, 0.}, // 96
|
rt300@3
|
754 {0.3, 0.1, 0.}}; // 127
|
rt300@3
|
755
|
rt300@3
|
756 float fidx = (numpoints-1)*ctrlin/128.;
|
rt300@3
|
757 int idx = floor(fidx);
|
rt300@3
|
758 float frac = fidx - idx;
|
rt300@3
|
759 for(int i=0; i < numcontrols; i++){
|
rt300@3
|
760 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
|
rt300@3
|
761 // send to PD
|
rt300@3
|
762 List toPD;
|
rt300@3
|
763
|
rt300@3
|
764 toPD.addSymbol(ctrlName[i]);
|
rt300@3
|
765 toPD.addFloat(ctrlout[i]); // rounding here??
|
rt300@3
|
766
|
rt300@3
|
767 core.pd.sendList("fromOF", toPD);
|
rt300@3
|
768 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
|
rt300@3
|
769 }
|
rt300@3
|
770 }
|
rt300@8
|
771 //---------------------------------------------------------------
|
rt300@3
|
772 void testApp::sendModFreq(int ctrlin){
|
rt300@3
|
773 float fm = ctrlin/127.;
|
rt300@3
|
774 List toPD;
|
rt300@3
|
775
|
rt300@3
|
776 toPD.addSymbol("FMFreq");
|
rt300@3
|
777 toPD.addFloat(fm); // rounding here??
|
rt300@3
|
778
|
rt300@3
|
779 core.pd.sendList("fromOF", toPD);
|
rt300@8
|
780 }
|
rt300@8
|
781 //--------------------------------------------------------------- |