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