rt300@0
|
1 #include "testApp.h"
|
rt300@0
|
2 #include "ofAppiOSWindow.h"
|
rt300@0
|
3
|
rt300@0
|
4 extern EventLogger eventLogger;
|
rt300@0
|
5
|
rt300@0
|
6 // static members inited here. not my choice.
|
rt300@0
|
7 int SynthParam::mappingUID = 88000;
|
rt300@0
|
8 //--------------------------------------------------------------
|
rt300@0
|
9 void testApp::setup(){
|
rt300@0
|
10
|
rt300@0
|
11
|
rt300@0
|
12
|
rt300@0
|
13 ofxiPhoneSetOrientation( OF_ORIENTATION_90_LEFT );
|
rt300@0
|
14 //ofxiPhoneExternalDisplay::mirrorOn();
|
rt300@0
|
15 [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
|
rt300@0
|
16 // initilaise
|
rt300@0
|
17
|
rt300@0
|
18
|
rt300@0
|
19 initialiseVariables();
|
rt300@0
|
20
|
rt300@0
|
21
|
rt300@0
|
22 testController = new TestController;
|
rt300@0
|
23
|
rt300@0
|
24 messageOrganiser.init(&core, testController);
|
rt300@0
|
25 timeController.init();
|
rt300@0
|
26 initialiseGUIs();
|
rt300@0
|
27 initialiseMIDI();
|
rt300@0
|
28 setupUIElements();
|
rt300@0
|
29
|
rt300@0
|
30
|
rt300@0
|
31
|
rt300@0
|
32 light.setSpotlight(45. , 1.);
|
rt300@0
|
33 light.enable();
|
rt300@0
|
34 ofEnableSeparateSpecularLight();
|
rt300@0
|
35 ofEnableDepthTest();
|
rt300@0
|
36 ofEnableAlphaBlending();
|
rt300@0
|
37 // in setup:
|
rt300@0
|
38 myfont.loadFont("NewMedia Fett.ttf", 32);
|
rt300@0
|
39
|
rt300@0
|
40 verdBig.loadFont("verdana.ttf", 18, true, true);
|
rt300@0
|
41 verdBig.setLineHeight(18.0f);
|
rt300@0
|
42 verdBig.setLetterSpacing(1.037);
|
rt300@0
|
43
|
rt300@0
|
44 //--------------------------------------
|
rt300@0
|
45
|
rt300@0
|
46 eventLogger.startLoadAll();
|
rt300@0
|
47 //--------------------------------------
|
rt300@0
|
48
|
rt300@0
|
49 // now do things that will affect the start up state of the app
|
rt300@0
|
50
|
rt300@0
|
51 // initialise PD
|
rt300@0
|
52
|
rt300@0
|
53 int ticksPerBuffer = 8; // 8 * 64 = buffer len of 512
|
rt300@0
|
54 core.setup(2, 2, 44100, ticksPerBuffer);
|
rt300@0
|
55
|
rt300@0
|
56 // setup OF sound stream
|
rt300@0
|
57 bufSize = ofxPd::blockSize()*ticksPerBuffer;
|
rt300@0
|
58 wavetableNew = (float *) malloc(bufSize * sizeof(float));
|
rt300@0
|
59
|
rt300@0
|
60 ofSoundStreamSetup(2, 2, this, 44100, ofxPd::blockSize()*ticksPerBuffer, 3);
|
rt300@0
|
61
|
rt300@0
|
62 if(true){ // force start
|
rt300@0
|
63 startTheTests();
|
rt300@0
|
64 }else{
|
rt300@0
|
65
|
rt300@0
|
66 if(eventLogger.questionnaireCompleted){ // then show play again dialog, and log the test number
|
rt300@0
|
67
|
rt300@0
|
68 }else{
|
rt300@0
|
69 // then we're in timed session mode
|
rt300@0
|
70 showIntro();
|
rt300@0
|
71 }
|
rt300@0
|
72 }
|
rt300@0
|
73 paused = false;
|
rt300@0
|
74
|
rt300@0
|
75
|
rt300@0
|
76 eventLogger.logEvent(APP_LOADED);
|
rt300@0
|
77
|
rt300@0
|
78 ofSoundStreamStart();
|
rt300@0
|
79
|
rt300@0
|
80 }
|
rt300@0
|
81
|
rt300@0
|
82 //-----------------------------------------------------------------------------
|
rt300@0
|
83
|
rt300@0
|
84 //DeviceID3523537000
|
rt300@0
|
85 void testApp::initialiseVariables(){
|
rt300@0
|
86 paused = true;
|
rt300@0
|
87 ofBackground( 0, 0, 0 );
|
rt300@0
|
88 //ofEnableAlphaBlending();
|
rt300@0
|
89 //ofEnableSmoothing();
|
rt300@0
|
90
|
rt300@0
|
91 // open an outgoing connection to HOST:PORT for OSC
|
rt300@0
|
92 // sender.setup( OSC_HOST, OSC_PORT );
|
rt300@0
|
93 ofSetFrameRate(60);
|
rt300@0
|
94
|
rt300@0
|
95
|
rt300@0
|
96 }
|
rt300@0
|
97 //---------------------------------------------------------
|
rt300@0
|
98 void testApp::initialiseGUIs(){
|
rt300@0
|
99
|
rt300@0
|
100 // set up iOS gui stuff
|
rt300@0
|
101
|
rt300@0
|
102 helpViewController = [[HelpViewController alloc] initWithNibName:@"HelpViewController" bundle:nil];
|
rt300@0
|
103 [ofxiPhoneGetGLParentView() addSubview:helpViewController.view];
|
rt300@0
|
104 [helpViewController setAppRef:(__bridge id)this];
|
rt300@0
|
105 helpViewController.view.hidden = YES;
|
rt300@0
|
106
|
rt300@0
|
107
|
rt300@0
|
108 usernameAlertViewController = [[UsernameAlertViewController alloc] init];
|
rt300@0
|
109 [usernameAlertViewController setAppRef:(__bridge id)this];
|
rt300@0
|
110
|
rt300@0
|
111 }
|
rt300@0
|
112
|
rt300@0
|
113 //--------------------------------------------------------------
|
rt300@0
|
114 void testApp::setupUIElements(){
|
rt300@0
|
115
|
rt300@0
|
116 // eventually: sliderpanel, topbuttonpanel, submitbuttonpanel, countdown panel,
|
rt300@0
|
117
|
rt300@0
|
118 // --------------------- BUTTONS
|
rt300@0
|
119 UIProps p;
|
rt300@0
|
120 ofBackground(p.generalBackground);
|
rt300@0
|
121
|
rt300@0
|
122 ButtonPanel* bottomButtonPanel = new ButtonPanel(1,160+p.sliderPanelHeight,ofGetWidth(),250,p);
|
rt300@0
|
123
|
rt300@0
|
124 Buttron* playTargetButton = new Buttron(p.buttonWidth*0.2,680, p);
|
rt300@0
|
125 playTargetButton->setLabel("Target");
|
rt300@0
|
126 messageOrganiser.mapButtonToAction(playTargetButton, TRIGGER_TARGET_ID);
|
rt300@0
|
127 bottomButtonPanel->addButton(playTargetButton);
|
rt300@0
|
128 messageOrganiser.setTargetButton(playTargetButton);
|
rt300@0
|
129
|
rt300@0
|
130 Buttron * playCandidateButton = new Buttron(p.buttonWidth*1.4,680, p);
|
rt300@0
|
131 playCandidateButton->setLabel("Current");
|
rt300@0
|
132 messageOrganiser.mapButtonToAction(playCandidateButton, TRIGGER_CANDIDATE_ID);
|
rt300@0
|
133 bottomButtonPanel->addButton(playCandidateButton);
|
rt300@0
|
134
|
rt300@0
|
135
|
rt300@0
|
136 // submit button - only one for now
|
rt300@0
|
137 Buttron * submitButton = new Buttron(ofGetWidth()*0.5 - p.buttonWidth*0.5,680, p);
|
rt300@0
|
138 submitButton->setLabel("Submit");
|
rt300@0
|
139 messageOrganiser.mapButtonToAction(submitButton, SUBMIT_CANDIDATE);
|
rt300@0
|
140 bottomButtonPanel->addButton(submitButton);
|
rt300@0
|
141
|
rt300@0
|
142 // button - just for spacing pruposes
|
rt300@4
|
143 Buttron * saveButton = new Buttron(ofGetWidth()*0.5 - p.buttonWidth*0.5,680, p);
|
rt300@4
|
144 saveButton->setLabel("SAVE");
|
rt300@4
|
145 messageOrganiser.mapButtonToAction(saveButton, SAVE_PRESET_HIT);
|
rt300@4
|
146 bottomButtonPanel->addButton(saveButton);
|
rt300@4
|
147 saveButton->show();
|
rt300@0
|
148
|
rt300@4
|
149 Buttron * recallButton = new Buttron(ofGetWidth()*0.5 - p.buttonWidth*0.5,680, p);
|
rt300@4
|
150 recallButton->setLabel("RECALL");
|
rt300@4
|
151 messageOrganiser.mapButtonToAction(recallButton, RECALL_PRESET_HIT);
|
rt300@4
|
152 bottomButtonPanel->addButton(recallButton);
|
rt300@4
|
153 recallButton->show();
|
rt300@0
|
154
|
rt300@0
|
155 messageOrganiser.setBottomPanel(bottomButtonPanel);
|
rt300@0
|
156 UIElements.push_back(bottomButtonPanel);
|
rt300@0
|
157 bottomButtonPanel->showBorder(false);
|
rt300@0
|
158
|
rt300@0
|
159
|
rt300@0
|
160
|
rt300@0
|
161 // ------------------------------------ SLIDERS
|
rt300@0
|
162
|
rt300@0
|
163 vector<controllerType> sl2;
|
rt300@0
|
164 sl2.push_back(SLIDER);
|
rt300@0
|
165
|
rt300@0
|
166 SliderPanel * controlPanel = new SliderPanel(1,
|
rt300@0
|
167 160,
|
rt300@0
|
168 ofGetWidth(),
|
rt300@0
|
169 p.sliderPanelHeight,
|
rt300@0
|
170 p,
|
rt300@0
|
171 sl2);
|
rt300@0
|
172
|
rt300@0
|
173 UIElements.push_back(controlPanel);
|
rt300@0
|
174 messageOrganiser.setControlPanel(controlPanel);
|
rt300@0
|
175 controlPanel->showBorder(true);
|
rt300@0
|
176
|
rt300@0
|
177 // - - - - - -- - - OTHER BITS
|
rt300@0
|
178
|
rt300@0
|
179 CountdownText * countDownBox = new CountdownText("5" , 500, 380, 455, 455, p);
|
rt300@0
|
180 UIElements.push_back(countDownBox);
|
rt300@0
|
181 messageOrganiser.setCountdownPanel(countDownBox);
|
rt300@0
|
182 countDownBox->hide();
|
rt300@0
|
183
|
rt300@0
|
184 TextPanel * scoreFeedback = new TextPanel("Feedback panel", ofGetWidth()*0.5 - p.buttonWidth*0.5, 666, 400,100,p);
|
rt300@0
|
185 scoreFeedback->setFontSize(SMALLFONT);
|
rt300@0
|
186 UIElements.push_back(scoreFeedback);
|
rt300@0
|
187 messageOrganiser.setScorePanel(scoreFeedback);
|
rt300@0
|
188 scoreFeedback->hide();
|
rt300@0
|
189
|
rt300@0
|
190 TextPanel * finishPanel = new TextPanel("Finish txt panel", 250, 250, 1000,400,p);
|
rt300@0
|
191 finishPanel->setFontSize(LARGEFONT);
|
rt300@0
|
192 finishPanel->setText("Experiment completed");
|
rt300@0
|
193 messageOrganiser.setFinishPanel(finishPanel);
|
rt300@0
|
194
|
rt300@0
|
195 UIElements.push_back(finishPanel);
|
rt300@0
|
196 finishPanel->hide();
|
rt300@0
|
197
|
rt300@0
|
198
|
rt300@0
|
199 Buttron * newTestButton = new Buttron(ofGetWidth()-300,690, p);
|
rt300@0
|
200 newTestButton->setLabel("Next Test");
|
rt300@0
|
201 UIElements.push_back(newTestButton);
|
rt300@0
|
202 messageOrganiser.mapButtonToAction(newTestButton, NEW_TEST_ID);
|
rt300@0
|
203 newTestButton->hide();
|
rt300@0
|
204 messageOrganiser.setNewTestButton(newTestButton);
|
rt300@0
|
205
|
rt300@0
|
206 TargetSymbol* targetSymbol = new TargetSymbol(ofGetWidth()*0.5,160,30,p);
|
rt300@0
|
207 messageOrganiser.setTargetSymbol(targetSymbol);
|
rt300@0
|
208 UIElements.push_back(targetSymbol);
|
rt300@0
|
209
|
rt300@0
|
210 // alternation speed
|
rt300@0
|
211
|
rt300@0
|
212
|
rt300@0
|
213 // ButtronSlider * speedSlider = new ButtronSlider(ofGetWidth()-60, 210, 50, p.sliderHeight/2,FILL, p);
|
rt300@0
|
214 // UIElements.push_back(speedSlider);
|
rt300@0
|
215 // messageOrganiser.mapButtonToAction(speedSlider, SPEED_CHANGE_ID);
|
rt300@0
|
216 //
|
rt300@0
|
217 // Buttron * altButton = new Buttron(ofGetWidth()-60, 500, 50, 50,p);
|
rt300@0
|
218 // UIElements.push_back(altButton);
|
rt300@0
|
219 // altButton->setLabel("Alt");
|
rt300@0
|
220 // messageOrganiser.mapButtonToAction(altButton, START_ALTERNATE_ID);
|
rt300@0
|
221
|
rt300@0
|
222 // TextPanel * speedLabel = new TextPanel("Speed", ofGetWidth()-55, 195, 50,20,p);
|
rt300@0
|
223 // speedLabel->setText("Speed");
|
rt300@0
|
224 // speedLabel->setFontSize(SMALLFONT);
|
rt300@0
|
225 // speedLabel->show();
|
rt300@0
|
226 // UIElements.push_back(speedLabel);
|
rt300@0
|
227
|
rt300@0
|
228 // volume
|
rt300@0
|
229 // ButtronSlider * volumeSlider = new ButtronSlider(50, 210, 30, p.sliderHeight,FILL, p);
|
rt300@0
|
230 // UIElements.push_back(volumeSlider);
|
rt300@0
|
231 // messageOrganiser.mapButtonToAction(volumeSlider, VOLUME_CHANGE_ID);
|
rt300@0
|
232 }
|
rt300@0
|
233 //--------------------------------------------------------------------------
|
rt300@0
|
234 void testApp::initialiseMIDI(){
|
rt300@0
|
235
|
rt300@0
|
236 /////////////////////////
|
rt300@0
|
237 // MIDI
|
rt300@0
|
238
|
rt300@0
|
239 midiChannel = 8;
|
rt300@0
|
240 midiOffset = 0;
|
rt300@0
|
241
|
rt300@0
|
242 // enables the network midi session between iOS and Mac OSX on a
|
rt300@0
|
243 // local wifi network
|
rt300@0
|
244 //
|
rt300@0
|
245 // in ofxMidi: open the input/outport network ports named "Session 1"
|
rt300@0
|
246 //
|
rt300@0
|
247 // on OSX: use the Audio MIDI Setup Utility to connect to the iOS device
|
rt300@0
|
248 //
|
rt300@0
|
249 ofxMidi::enableNetworking();
|
rt300@0
|
250
|
rt300@0
|
251 // list the number of available input & output ports
|
rt300@0
|
252 ofxMidiIn::listPorts();
|
rt300@0
|
253 ofxMidiOut::listPorts();
|
rt300@0
|
254
|
rt300@0
|
255 // create and open input ports
|
rt300@0
|
256 for(int i = 0; i < ofxMidiIn::getNumPorts(); ++i) {
|
rt300@0
|
257
|
rt300@0
|
258 // new object
|
rt300@0
|
259 inputs.push_back(new ofxMidiIn);
|
rt300@0
|
260
|
rt300@0
|
261 // set this class to receive incoming midi events
|
rt300@0
|
262 inputs[i]->addListener(this);
|
rt300@0
|
263
|
rt300@0
|
264 // open input port via port number
|
rt300@0
|
265 inputs[i]->openPort(i);
|
rt300@0
|
266 }
|
rt300@0
|
267
|
rt300@0
|
268 // create and open output ports
|
rt300@0
|
269 for(int i = 0; i < ofxMidiOut::getNumPorts(); ++i) {
|
rt300@0
|
270
|
rt300@0
|
271 // new object
|
rt300@0
|
272 outputs.push_back(new ofxMidiOut);
|
rt300@0
|
273
|
rt300@0
|
274 // open input port via port number
|
rt300@0
|
275 outputs[i]->openPort(i);
|
rt300@0
|
276 }
|
rt300@0
|
277
|
rt300@0
|
278 // set this class to receieve midi device (dis)connection events
|
rt300@0
|
279 ofxMidi::setConnectionListener(this);
|
rt300@0
|
280
|
rt300@0
|
281 // END MIDI
|
rt300@0
|
282
|
rt300@0
|
283 }
|
rt300@0
|
284 //--------------------------------------------------------------
|
rt300@0
|
285
|
rt300@0
|
286 template <class T>
|
rt300@0
|
287 void deleteVectorOfPointers( T * inVectorOfPointers )
|
rt300@0
|
288 {
|
rt300@0
|
289 typename T::iterator i;
|
rt300@0
|
290 for ( i = inVectorOfPointers->begin() ; i < inVectorOfPointers->end(); i++ )
|
rt300@0
|
291 {
|
rt300@0
|
292 delete * i;
|
rt300@0
|
293 }
|
rt300@0
|
294 //delete inVectorOfPointers;
|
rt300@0
|
295 }
|
rt300@0
|
296
|
rt300@0
|
297
|
rt300@0
|
298 //--------------------------------------------------------------
|
rt300@0
|
299 void testApp::exit(){
|
rt300@0
|
300 eventLogger.logEvent(APP_EXITED);
|
rt300@0
|
301 eventLogger.exitAndSave();
|
rt300@0
|
302
|
rt300@0
|
303 core.exit();
|
rt300@0
|
304
|
rt300@0
|
305 // are these handled automatically?
|
rt300@0
|
306 //[introViewController release];
|
rt300@0
|
307 //[topButtonViewController release];
|
rt300@0
|
308 //[bottomTabViewController release];
|
rt300@0
|
309
|
rt300@0
|
310 // clean up MIDI
|
rt300@0
|
311 for(int i = 0; i < inputs.size(); ++i) {
|
rt300@0
|
312 inputs[i]->closePort();
|
rt300@0
|
313 inputs[i]->removeListener(this);
|
rt300@0
|
314 delete inputs[i];
|
rt300@0
|
315 }
|
rt300@0
|
316
|
rt300@0
|
317 for(int i = 0; i < outputs.size(); ++i) {
|
rt300@0
|
318 outputs[i]->closePort();
|
rt300@0
|
319 delete outputs[i];
|
rt300@0
|
320 }
|
rt300@0
|
321 deleteVectorOfPointers(&UIElements); // TODO this crashes??
|
rt300@0
|
322
|
rt300@0
|
323
|
rt300@0
|
324 delete testController;
|
rt300@0
|
325
|
rt300@0
|
326 cout << "exit done \n";
|
rt300@0
|
327 }
|
rt300@0
|
328
|
rt300@0
|
329 #pragma mark GUI
|
rt300@0
|
330 ////////////////////////////
|
rt300@0
|
331 // These functions called from iOS toolbars
|
rt300@0
|
332 //--------------------------------------------------------------
|
rt300@0
|
333
|
rt300@0
|
334 //--------------------------------------------------------------
|
rt300@0
|
335 void testApp::showQuestionnaire(){
|
rt300@0
|
336
|
rt300@0
|
337
|
rt300@0
|
338 questionnaireViewController = [[QuestionnaireViewController alloc] initWithNibName:@"QuestionnaireViewController" bundle:nil];
|
rt300@0
|
339 [ofxiPhoneGetGLParentView() addSubview:questionnaireViewController.view];
|
rt300@0
|
340
|
rt300@0
|
341 [questionnaireViewController setAppRef:(__bridge id)this];
|
rt300@0
|
342 [questionnaireViewController show:(__bridge id)this];
|
rt300@0
|
343
|
rt300@0
|
344 whichInterfaceShowing = QUESTIONNAIRE;
|
rt300@0
|
345
|
rt300@0
|
346
|
rt300@0
|
347 }
|
rt300@0
|
348 //--------------------------------------------------------------
|
rt300@0
|
349 void testApp::questionnaireHidden(vector<int> answers, const char* userComments){
|
rt300@0
|
350 // send answers to server as json
|
rt300@0
|
351 eventLogger.questionnaireAnswersObtained(answers, userComments);
|
rt300@0
|
352
|
rt300@0
|
353 }
|
rt300@0
|
354
|
rt300@0
|
355 //--------------------------------------------------------------
|
rt300@0
|
356 void testApp::showIntro(){
|
rt300@0
|
357
|
rt300@0
|
358 cout << "SHOW INTRO\n";
|
rt300@0
|
359
|
rt300@0
|
360 introViewController = [[IntroViewController alloc] initWithNibName:@"IntroViewController" bundle:nil];
|
rt300@0
|
361 [ofxiPhoneGetGLParentView() addSubview:introViewController.view];
|
rt300@0
|
362
|
rt300@0
|
363 [introViewController setAppRef:(__bridge id)this];
|
rt300@0
|
364 [introViewController show:(__bridge id)this];
|
rt300@0
|
365
|
rt300@0
|
366 whichInterfaceShowing = INTRO;
|
rt300@0
|
367
|
rt300@0
|
368 }
|
rt300@0
|
369 //--------------------------------------------------------------
|
rt300@0
|
370 void testApp::introHidden(){
|
rt300@0
|
371 eventLogger.consentGiven = true;
|
rt300@0
|
372 eventLogger.logEvent(INTRO_CONSENTED);
|
rt300@0
|
373 [usernameAlertViewController showUserNamePrompt];
|
rt300@2
|
374 // after prompt goes it calls usernameEntered()
|
rt300@0
|
375 }
|
rt300@0
|
376
|
rt300@2
|
377 void testApp::usernameEntered(){
|
rt300@2
|
378 // display a thing that gives us an option as to which stage to start
|
rt300@2
|
379 // EXPLORE, PERFORMANCE TRAINING, SEARCH
|
rt300@2
|
380 }
|
rt300@0
|
381 //--------------------------------------------------------------
|
rt300@0
|
382 void testApp::startTheTests(){
|
rt300@0
|
383 eventLogger.logEvent(START_THE_TESTS);
|
rt300@0
|
384 whichInterfaceShowing = COUNT_DOWN;
|
rt300@0
|
385 // do countdown etc
|
rt300@0
|
386 messageOrganiser.countdownToNewTest();
|
rt300@0
|
387 // TODO how is testApp going to kknow whichInterfaceShowing ???
|
rt300@0
|
388
|
rt300@0
|
389 }
|
rt300@0
|
390 //--------------------------------------------------------------
|
rt300@0
|
391 //--------------------------------------------------------------
|
rt300@0
|
392 void testApp::showHelp(){
|
rt300@0
|
393 // stop clock etc
|
rt300@0
|
394 previousInterface = whichInterfaceShowing;
|
rt300@0
|
395 whichInterfaceShowing = HELP;
|
rt300@0
|
396 helpViewController.view.hidden = NO;
|
rt300@0
|
397 eventLogger.logEvent(HELP_PRESSED);
|
rt300@0
|
398
|
rt300@0
|
399 }
|
rt300@0
|
400 void testApp::helpHidden(){
|
rt300@0
|
401 whichInterfaceShowing = previousInterface;
|
rt300@0
|
402
|
rt300@0
|
403 }
|
rt300@0
|
404 //--------------------------------------------------------------
|
rt300@0
|
405 //--------------------------------------------------------------
|
rt300@0
|
406 //--------------------------------------------------------------
|
rt300@0
|
407 #pragma mark sending to pd and midi
|
rt300@0
|
408 void testApp::sendParametersToPD(){
|
rt300@0
|
409
|
rt300@0
|
410
|
rt300@0
|
411 }
|
rt300@0
|
412 //--------------------------------------------------------------
|
rt300@0
|
413 void testApp::sendMidiParam(int which){
|
rt300@0
|
414 int midiChannel = 8;
|
rt300@0
|
415 int offset = 0;
|
rt300@0
|
416
|
rt300@0
|
417 for(int i = 0; i < outputs.size(); ++i) {
|
rt300@0
|
418 outputs[i]->sendControlChange(midiChannel, offset+which, 66);
|
rt300@0
|
419 }
|
rt300@0
|
420
|
rt300@0
|
421
|
rt300@0
|
422 }
|
rt300@0
|
423
|
rt300@0
|
424 //--------------------------------------------------------------
|
rt300@0
|
425 //void testApp::sendOSCParams(){
|
rt300@0
|
426 //
|
rt300@0
|
427 // ofxOscMessage m;
|
rt300@0
|
428 // m.setAddress( "Template" );
|
rt300@0
|
429 //
|
rt300@0
|
430 // m.addFloatArg(9.9999);
|
rt300@0
|
431 //
|
rt300@0
|
432 // sender.sendMessage( m );
|
rt300@0
|
433 //}
|
rt300@0
|
434 //--------------------------------------------------------------
|
rt300@0
|
435
|
rt300@0
|
436 void testApp::setupNewUser(){
|
rt300@0
|
437 // this function is for supervised trials with my ipad
|
rt300@0
|
438 eventLogger.newUser();
|
rt300@0
|
439 }
|
rt300@0
|
440 //--------------------------------------------------------------
|
rt300@0
|
441 #pragma mark STANDARD OF FUNCTIONS
|
rt300@0
|
442 //--------------------------------------------------------------
|
rt300@0
|
443 void testApp::update(){
|
rt300@0
|
444
|
rt300@0
|
445 if(paused) return;
|
rt300@0
|
446
|
rt300@0
|
447 // run timer check here
|
rt300@0
|
448 // look at time, work out difference
|
rt300@0
|
449 timeController.tick();
|
rt300@0
|
450
|
rt300@0
|
451 // test mutex crash thing
|
rt300@0
|
452 //eventLogger.logEvent(CANDIDATE_PLAYED);
|
rt300@0
|
453 }
|
rt300@0
|
454 //--------------------------------------------------------------
|
rt300@0
|
455
|
rt300@0
|
456 void testApp::appModeChange(interfaceType mode){
|
rt300@0
|
457 whichInterfaceShowing = mode;
|
rt300@0
|
458 }
|
rt300@0
|
459
|
rt300@0
|
460
|
rt300@0
|
461 //------------------------------------------------------------------------
|
rt300@0
|
462
|
rt300@0
|
463 void testApp::draw(){
|
rt300@0
|
464
|
rt300@0
|
465 switch (whichInterfaceShowing){
|
rt300@0
|
466 case QUESTIONNAIRE:
|
rt300@0
|
467 break;
|
rt300@0
|
468 case INTRO:
|
rt300@0
|
469 break;
|
rt300@0
|
470 case TEST_IN_PROGRESS:
|
rt300@0
|
471 break;
|
rt300@0
|
472 case SCORE_AND_HINT:
|
rt300@0
|
473 break;
|
rt300@0
|
474 case COUNT_DOWN:
|
rt300@0
|
475 break;
|
rt300@0
|
476 case READY_FOR_NEXT:
|
rt300@0
|
477 break;
|
rt300@0
|
478 default:
|
rt300@0
|
479 break;
|
rt300@0
|
480 }
|
rt300@0
|
481
|
rt300@0
|
482
|
rt300@0
|
483
|
rt300@0
|
484 drawUIElements();
|
rt300@0
|
485
|
rt300@0
|
486 //ofSetColor(234, 234, 234);
|
rt300@0
|
487 //ofLine(0,150,1024,150);
|
rt300@0
|
488
|
rt300@0
|
489 //drawWaveform();
|
rt300@0
|
490 drawScore();
|
rt300@0
|
491
|
rt300@0
|
492
|
rt300@0
|
493
|
rt300@0
|
494 }
|
rt300@0
|
495 //------------------------------------------------------------------------
|
rt300@0
|
496 void testApp::drawUIElements(){
|
rt300@0
|
497
|
rt300@0
|
498 vector<UIElement *>::iterator UIitr;
|
rt300@0
|
499 for(UIitr = UIElements.begin(); UIitr < UIElements.end(); UIitr++){
|
rt300@0
|
500 (*UIitr)->draw();
|
rt300@0
|
501 }
|
rt300@0
|
502 }
|
rt300@0
|
503 //------------------------------------------------------------------------
|
rt300@0
|
504 void testApp::drawScore(){
|
rt300@0
|
505 ofColor txtCol = ofColor(150,235,200,255);
|
rt300@0
|
506
|
rt300@0
|
507 int score = messageOrganiser.getScore();
|
rt300@0
|
508 stringstream msg;
|
rt300@0
|
509
|
rt300@0
|
510 msg << "Test: " << testController->getCurrentTestLetter();
|
rt300@0
|
511 ofSetColor(txtCol);
|
rt300@0
|
512 verdBig.drawString(msg.str(), 40, 140);
|
rt300@0
|
513 msg.str(std::string());
|
rt300@0
|
514
|
rt300@0
|
515 msg << "Score: " << score;
|
rt300@0
|
516 verdBig.drawString(msg.str(), 240, 140);
|
rt300@0
|
517 msg.str(std::string());
|
rt300@0
|
518
|
rt300@0
|
519 pair<int,int> time;
|
rt300@0
|
520 time = messageOrganiser.getTime();
|
rt300@0
|
521 msg << "Time taken: " << time.first << ":" << time.second << endl;
|
rt300@0
|
522 verdBig.drawString(msg.str(), 600, 140);
|
rt300@0
|
523
|
rt300@0
|
524 }
|
rt300@0
|
525 //------------------------------------------------------------------------
|
rt300@0
|
526
|
rt300@0
|
527 //--------------------------------------------------------------
|
rt300@0
|
528 // passes touch to UI elements
|
rt300@0
|
529 //--------------------------------------------------------------
|
rt300@0
|
530
|
rt300@0
|
531 void testApp::touchToUIElements(int x, int y, touchType ttype, int tid){
|
rt300@0
|
532 vector<UIElement *>::iterator UIitr;
|
rt300@0
|
533 for(UIitr = UIElements.begin(); UIitr < UIElements.end(); UIitr++){
|
rt300@0
|
534 (*UIitr)->touch(x,y,ttype, tid);
|
rt300@0
|
535 }
|
rt300@0
|
536 }
|
rt300@0
|
537
|
rt300@0
|
538 //--------------------------------------------------------------
|
rt300@0
|
539 void testApp::touchDown(ofTouchEventArgs &touch){
|
rt300@0
|
540 //touch = transformTouchCoords(touch);
|
rt300@0
|
541 touchToUIElements(touch.x, touch.y, TOUCH_DOWN, touch.id);
|
rt300@0
|
542
|
rt300@0
|
543 }
|
rt300@0
|
544
|
rt300@0
|
545 //--------------------------------------------------------------
|
rt300@0
|
546 void testApp::touchMoved(ofTouchEventArgs &touch){
|
rt300@0
|
547
|
rt300@0
|
548 touchToUIElements(touch.x, touch.y, TOUCH_MOVED, touch.id);
|
rt300@0
|
549
|
rt300@0
|
550 }
|
rt300@0
|
551
|
rt300@0
|
552 //--------------------------------------------------------------
|
rt300@0
|
553 void testApp::touchUp(ofTouchEventArgs &touch){
|
rt300@0
|
554
|
rt300@0
|
555 touchToUIElements(touch.x, touch.y, TOUCH_UP, touch.id);
|
rt300@0
|
556 }
|
rt300@0
|
557
|
rt300@0
|
558
|
rt300@0
|
559 //--------------------------------------------------------------
|
rt300@0
|
560 void testApp::touchDoubleTap(ofTouchEventArgs &touch){
|
rt300@0
|
561
|
rt300@0
|
562 }
|
rt300@0
|
563
|
rt300@0
|
564 //--------------------------------------------------------------
|
rt300@0
|
565 void testApp::lostFocus(){
|
rt300@0
|
566 //exit();
|
rt300@0
|
567 }
|
rt300@0
|
568
|
rt300@0
|
569 //--------------------------------------------------------------
|
rt300@0
|
570 void testApp::gotFocus(){
|
rt300@0
|
571
|
rt300@0
|
572 }
|
rt300@0
|
573
|
rt300@0
|
574 //--------------------------------------------------------------
|
rt300@0
|
575 void testApp::gotMemoryWarning(){
|
rt300@0
|
576
|
rt300@0
|
577 }
|
rt300@0
|
578
|
rt300@0
|
579 //--------------------------------------------------------------
|
rt300@0
|
580
|
rt300@0
|
581 void testApp::deviceOrientationChanged(int newOrientation){
|
rt300@0
|
582
|
rt300@0
|
583 cout << "orientation: " << newOrientation;
|
rt300@0
|
584
|
rt300@0
|
585 // do something here?
|
rt300@0
|
586
|
rt300@0
|
587 }
|
rt300@0
|
588
|
rt300@0
|
589
|
rt300@0
|
590
|
rt300@0
|
591 //--------------------------------------------------------------
|
rt300@0
|
592 void testApp::touchCancelled(ofTouchEventArgs& args){
|
rt300@0
|
593
|
rt300@0
|
594 }
|
rt300@0
|
595 //---------------------------------------------------------------
|
rt300@0
|
596 // AUDIO STUFF
|
rt300@0
|
597 //---------------------------------------------------------------
|
rt300@0
|
598
|
rt300@0
|
599 #pragma mark AUDIO STREAMS
|
rt300@0
|
600 //--------------------------------------------------------------
|
rt300@0
|
601 void testApp::audioReceived(float * input, int bufferSize, int nChannels) {
|
rt300@0
|
602 //core.audioReceived(input, bufferSize, nChannels);
|
rt300@0
|
603 }
|
rt300@0
|
604
|
rt300@0
|
605 void testApp::audioRequested(float * output, int bufferSize, int nChannels) {
|
rt300@0
|
606
|
rt300@0
|
607 core.audioRequested(output, bufferSize, nChannels);
|
rt300@0
|
608 // for(int i=0;i<bufferSize/2;i++){
|
rt300@0
|
609 // output[i] = 0.2;
|
rt300@0
|
610 // }
|
rt300@0
|
611 // // pass buffer to drawable thing
|
rt300@0
|
612 // for(int i=0;i<bufferSize;i++){
|
rt300@0
|
613 // wavetableNew[i] = output[i];
|
rt300@0
|
614 // }
|
rt300@0
|
615
|
rt300@0
|
616 }
|
rt300@0
|
617
|
rt300@0
|
618 void testApp::drawWaveform(){
|
rt300@0
|
619 // draw the actual waveform in the corner
|
rt300@0
|
620
|
rt300@0
|
621 int width = 768;
|
rt300@0
|
622 int height = 128;
|
rt300@0
|
623 double sampval = 0.0;
|
rt300@0
|
624 int leftsampnum = 0;
|
rt300@0
|
625 int rightsampnum = 0;
|
rt300@0
|
626 float sampscale = 0.0, prevsampscale = 0.0, interp = 0.0;
|
rt300@0
|
627
|
rt300@0
|
628 ofSetColor(256, 0, 0);
|
rt300@0
|
629 double step = double(bufSize)/width; // how much we are stepping thru wave per pixel
|
rt300@0
|
630 for(int i = 0; i < width; i++){
|
rt300@0
|
631
|
rt300@0
|
632 leftsampnum = floor(i * step); // basic nearest neighbour interpolation
|
rt300@0
|
633 rightsampnum = ceil(i*step);
|
rt300@0
|
634 interp = (i*step)-leftsampnum;
|
rt300@0
|
635 if(rightsampnum < bufSize){
|
rt300@0
|
636 sampval = (1 - interp)*wavetableNew[leftsampnum] + interp*wavetableNew[rightsampnum];
|
rt300@0
|
637 }
|
rt300@0
|
638 sampscale = (sampval * 700) + height/2.0; // centre and scale
|
rt300@0
|
639 ofSetLineWidth(2);
|
rt300@0
|
640 ofLine(sampscale, i, prevsampscale, i-1); // draw a line from pixel to pixel (?)
|
rt300@0
|
641 prevsampscale = sampscale;
|
rt300@0
|
642 }
|
rt300@0
|
643
|
rt300@0
|
644 }
|
rt300@0
|
645 //---------------------------------------------------------------
|
rt300@0
|
646 #pragma mark UTILITIES
|
rt300@0
|
647 //-------------------------------------------------------------------------
|
rt300@0
|
648 //--------------------------------------------------------------
|
rt300@0
|
649
|
rt300@0
|
650 #pragma mark MIDI
|
rt300@0
|
651 void testApp::addMessage(string msg) {
|
rt300@0
|
652 cout << msg << endl;
|
rt300@0
|
653 messages.push_back(msg);
|
rt300@0
|
654 while(messages.size() > maxMessages)
|
rt300@0
|
655 messages.pop_front();
|
rt300@0
|
656 }
|
rt300@0
|
657
|
rt300@0
|
658 //--------------------------------------------------------------
|
rt300@0
|
659 void testApp::newMidiMessage(ofxMidiMessage& msg) {
|
rt300@0
|
660
|
rt300@2
|
661 // looks out for: 30 31 32... on channel 8
|
rt300@0
|
662 if(msg.channel == midiChannel && msg.status == MIDI_CONTROL_CHANGE){
|
rt300@0
|
663 int ctl_num = msg.control - 30;
|
rt300@0
|
664 int ctl_val = msg.value;
|
rt300@0
|
665 // TODO route control change message here
|
rt300@0
|
666 //cout << " ctrl : " << ctl_num << " : " << ctl_val << endl;
|
rt300@0
|
667 messageOrganiser.midiFromLeap(ctl_num, ctl_val);
|
rt300@0
|
668 }
|
rt300@0
|
669
|
rt300@0
|
670 }
|
rt300@0
|
671
|
rt300@0
|
672 //--------------------------------------------------------------
|
rt300@0
|
673 void testApp::midiInputAdded(string name, bool isNetwork) {
|
rt300@0
|
674 stringstream msg;
|
rt300@0
|
675 msg << "ofxMidi: input added: " << name << " network: " << isNetwork;
|
rt300@0
|
676 cout << msg.str();
|
rt300@0
|
677 addMessage(msg.str());
|
rt300@0
|
678
|
rt300@0
|
679 // create and open a new input port
|
rt300@0
|
680 ofxMidiIn * newInput = new ofxMidiIn;
|
rt300@0
|
681 newInput->openPort(name);
|
rt300@0
|
682 newInput->addListener(this);
|
rt300@0
|
683 inputs.push_back(newInput);
|
rt300@0
|
684 }
|
rt300@0
|
685
|
rt300@0
|
686 //--------------------------------------------------------------
|
rt300@0
|
687 void testApp::midiInputRemoved(string name, bool isNetwork) {
|
rt300@0
|
688 stringstream msg;
|
rt300@0
|
689 msg << "ofxMidi: input removed: " << name << " network: " << isNetwork << endl;
|
rt300@0
|
690 cout << msg.str();
|
rt300@0
|
691 addMessage(msg.str());
|
rt300@0
|
692
|
rt300@0
|
693 // close and remove input port
|
rt300@0
|
694 vector<ofxMidiIn*>::iterator iter;
|
rt300@0
|
695 for(iter = inputs.begin(); iter != inputs.end(); ++iter) {
|
rt300@0
|
696 ofxMidiIn * input = (*iter);
|
rt300@0
|
697 if(input->getName() == name) {
|
rt300@0
|
698 input->closePort();
|
rt300@0
|
699 input->removeListener(this);
|
rt300@0
|
700 delete input;
|
rt300@0
|
701 inputs.erase(iter);
|
rt300@0
|
702 break;
|
rt300@0
|
703 }
|
rt300@0
|
704 }
|
rt300@0
|
705 }
|
rt300@0
|
706
|
rt300@0
|
707 //--------------------------------------------------------------
|
rt300@0
|
708 void testApp::midiOutputAdded(string name, bool isNetwork) {
|
rt300@0
|
709 stringstream msg;
|
rt300@0
|
710 msg << "ofxMidi: output added: " << name << " network: " << isNetwork << endl;
|
rt300@0
|
711 cout << msg.str();
|
rt300@0
|
712 addMessage(msg.str());
|
rt300@0
|
713
|
rt300@0
|
714 // create and open new output port
|
rt300@0
|
715 ofxMidiOut * newOutput = new ofxMidiOut;
|
rt300@0
|
716 newOutput->openPort(name);
|
rt300@0
|
717 outputs.push_back(newOutput);
|
rt300@0
|
718 }
|
rt300@0
|
719
|
rt300@0
|
720 //--------------------------------------------------------------
|
rt300@0
|
721 void testApp::midiOutputRemoved(string name, bool isNetwork) {
|
rt300@0
|
722 stringstream msg;
|
rt300@0
|
723 msg << "ofxMidi: output removed: " << name << " network: " << isNetwork << endl;
|
rt300@0
|
724 cout << msg.str();
|
rt300@0
|
725 addMessage(msg.str());
|
rt300@0
|
726
|
rt300@0
|
727 // close and remove output port
|
rt300@0
|
728 vector<ofxMidiOut*>::iterator iter;
|
rt300@0
|
729 for(iter = outputs.begin(); iter != outputs.end(); ++iter) {
|
rt300@0
|
730 ofxMidiOut * output = (*iter);
|
rt300@0
|
731 if(output->getName() == name) {
|
rt300@0
|
732 output->closePort();
|
rt300@0
|
733 delete output;
|
rt300@0
|
734 outputs.erase(iter);
|
rt300@0
|
735 break;
|
rt300@0
|
736 }
|
rt300@0
|
737 }
|
rt300@0
|
738 }
|