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@6
|
140 }
|
rt300@6
|
141 //--------------------------------------------------------------
|
rt300@6
|
142 // gui for the old style tweakathlon stage
|
rt300@6
|
143 void testApp::setupSearchViewPanels(){
|
rt300@6
|
144
|
rt300@0
|
145 UIProps p;
|
rt300@0
|
146 ButtonPanel* bottomButtonPanel = new ButtonPanel(1,160+p.sliderPanelHeight,ofGetWidth(),250,p);
|
rt300@6
|
147
|
rt300@0
|
148 Buttron* playTargetButton = new Buttron(p.buttonWidth*0.2,680, p);
|
rt300@0
|
149 playTargetButton->setLabel("Target");
|
rt300@8
|
150 searchMessageOrganiser.mapButtonToAction(playTargetButton, TRIGGER_TARGET_ID);
|
rt300@0
|
151 bottomButtonPanel->addButton(playTargetButton);
|
rt300@8
|
152 searchMessageOrganiser.setTargetButton(playTargetButton);
|
rt300@6
|
153
|
rt300@0
|
154 Buttron * playCandidateButton = new Buttron(p.buttonWidth*1.4,680, p);
|
rt300@0
|
155 playCandidateButton->setLabel("Current");
|
rt300@8
|
156 searchMessageOrganiser.mapButtonToAction(playCandidateButton, TRIGGER_CANDIDATE_ID);
|
rt300@0
|
157 bottomButtonPanel->addButton(playCandidateButton);
|
rt300@0
|
158
|
rt300@0
|
159
|
rt300@0
|
160 // submit button - only one for now
|
rt300@0
|
161 Buttron * submitButton = new Buttron(ofGetWidth()*0.5 - p.buttonWidth*0.5,680, p);
|
rt300@0
|
162 submitButton->setLabel("Submit");
|
rt300@8
|
163 searchMessageOrganiser.mapButtonToAction(submitButton, SUBMIT_CANDIDATE);
|
rt300@0
|
164 bottomButtonPanel->addButton(submitButton);
|
rt300@0
|
165
|
rt300@0
|
166 // button - just for spacing pruposes
|
rt300@4
|
167 Buttron * saveButton = new Buttron(ofGetWidth()*0.5 - p.buttonWidth*0.5,680, p);
|
rt300@4
|
168 saveButton->setLabel("SAVE");
|
rt300@8
|
169 searchMessageOrganiser.mapButtonToAction(saveButton, SAVE_PRESET_HIT);
|
rt300@4
|
170 bottomButtonPanel->addButton(saveButton);
|
rt300@6
|
171 saveButton->hide();
|
rt300@0
|
172
|
rt300@4
|
173 Buttron * recallButton = new Buttron(ofGetWidth()*0.5 - p.buttonWidth*0.5,680, p);
|
rt300@4
|
174 recallButton->setLabel("RECALL");
|
rt300@8
|
175 searchMessageOrganiser.mapButtonToAction(recallButton, RECALL_PRESET_HIT);
|
rt300@4
|
176 bottomButtonPanel->addButton(recallButton);
|
rt300@6
|
177 recallButton->hide();
|
rt300@0
|
178
|
rt300@8
|
179 searchMessageOrganiser.setBottomPanel(bottomButtonPanel);
|
rt300@0
|
180 UIElements.push_back(bottomButtonPanel);
|
rt300@0
|
181 bottomButtonPanel->showBorder(false);
|
rt300@9
|
182 bottomButtonPanel->hide();
|
rt300@7
|
183 // - - - - - -- - - OTHER BITS
|
rt300@0
|
184
|
rt300@0
|
185 CountdownText * countDownBox = new CountdownText("5" , 500, 380, 455, 455, p);
|
rt300@0
|
186 UIElements.push_back(countDownBox);
|
rt300@8
|
187 searchMessageOrganiser.setCountdownPanel(countDownBox);
|
rt300@0
|
188 countDownBox->hide();
|
rt300@0
|
189
|
rt300@0
|
190 TextPanel * scoreFeedback = new TextPanel("Feedback panel", ofGetWidth()*0.5 - p.buttonWidth*0.5, 666, 400,100,p);
|
rt300@0
|
191 scoreFeedback->setFontSize(SMALLFONT);
|
rt300@0
|
192 UIElements.push_back(scoreFeedback);
|
rt300@8
|
193 searchMessageOrganiser.setScorePanel(scoreFeedback);
|
rt300@0
|
194 scoreFeedback->hide();
|
rt300@0
|
195
|
rt300@0
|
196 TextPanel * finishPanel = new TextPanel("Finish txt panel", 250, 250, 1000,400,p);
|
rt300@0
|
197 finishPanel->setFontSize(LARGEFONT);
|
rt300@0
|
198 finishPanel->setText("Experiment completed");
|
rt300@8
|
199 searchMessageOrganiser.setFinishPanel(finishPanel);
|
rt300@0
|
200
|
rt300@0
|
201 UIElements.push_back(finishPanel);
|
rt300@0
|
202 finishPanel->hide();
|
rt300@7
|
203
|
rt300@0
|
204
|
rt300@0
|
205 Buttron * newTestButton = new Buttron(ofGetWidth()-300,690, p);
|
rt300@0
|
206 newTestButton->setLabel("Next Test");
|
rt300@0
|
207 UIElements.push_back(newTestButton);
|
rt300@8
|
208 searchMessageOrganiser.mapButtonToAction(newTestButton, NEW_TEST_ID);
|
rt300@0
|
209 newTestButton->hide();
|
rt300@8
|
210 searchMessageOrganiser.setNewTestButton(newTestButton);
|
rt300@0
|
211
|
rt300@0
|
212 TargetSymbol* targetSymbol = new TargetSymbol(ofGetWidth()*0.5,160,30,p);
|
rt300@8
|
213 searchMessageOrganiser.setTargetSymbol(targetSymbol);
|
rt300@0
|
214 UIElements.push_back(targetSymbol);
|
rt300@0
|
215
|
rt300@7
|
216 }
|
rt300@7
|
217 //--------------------------------------------------------------
|
rt300@7
|
218 void testApp::setupSliderPanel(){
|
rt300@7
|
219 UIProps p;
|
rt300@7
|
220 vector<controllerType> sl2;
|
rt300@7
|
221 sl2.push_back(SLIDER);
|
rt300@7
|
222
|
rt300@7
|
223 SliderPanel * controlPanel = new SliderPanel(1,
|
rt300@7
|
224 160,
|
rt300@7
|
225 ofGetWidth(),
|
rt300@7
|
226 p.sliderPanelHeight,
|
rt300@7
|
227 p,
|
rt300@7
|
228 sl2);
|
rt300@7
|
229
|
rt300@7
|
230 UIElements.push_back(controlPanel);
|
rt300@8
|
231 searchMessageOrganiser.setControlPanel(controlPanel);
|
rt300@9
|
232 trainingMessageOrganiser.setControlPanel(controlPanel);
|
rt300@7
|
233 controlPanel->showBorder(true);
|
rt300@7
|
234 }
|
rt300@7
|
235 //--------------------------------------------------------------
|
rt300@7
|
236 void testApp::setupUIElements(){
|
rt300@7
|
237
|
rt300@7
|
238 UIProps p;
|
rt300@7
|
239 ofBackground(p.generalBackground);
|
rt300@7
|
240
|
rt300@7
|
241 setupSearchViewPanels();
|
rt300@7
|
242
|
rt300@7
|
243 setupSliderPanel();
|
rt300@0
|
244
|
rt300@9
|
245 setupTrainingViewPanels();
|
rt300@0
|
246 }
|
rt300@0
|
247 //--------------------------------------------------------------------------
|
rt300@0
|
248 void testApp::initialiseMIDI(){
|
rt300@0
|
249
|
rt300@0
|
250 /////////////////////////
|
rt300@0
|
251 // MIDI
|
rt300@0
|
252
|
rt300@0
|
253 midiChannel = 8;
|
rt300@0
|
254 midiOffset = 0;
|
rt300@0
|
255
|
rt300@0
|
256 // enables the network midi session between iOS and Mac OSX on a
|
rt300@0
|
257 // local wifi network
|
rt300@0
|
258 //
|
rt300@0
|
259 // in ofxMidi: open the input/outport network ports named "Session 1"
|
rt300@0
|
260 //
|
rt300@0
|
261 // on OSX: use the Audio MIDI Setup Utility to connect to the iOS device
|
rt300@0
|
262 //
|
rt300@0
|
263 ofxMidi::enableNetworking();
|
rt300@0
|
264
|
rt300@0
|
265 // list the number of available input & output ports
|
rt300@0
|
266 ofxMidiIn::listPorts();
|
rt300@0
|
267 ofxMidiOut::listPorts();
|
rt300@0
|
268
|
rt300@0
|
269 // create and open input ports
|
rt300@0
|
270 for(int i = 0; i < ofxMidiIn::getNumPorts(); ++i) {
|
rt300@0
|
271
|
rt300@0
|
272 // new object
|
rt300@0
|
273 inputs.push_back(new ofxMidiIn);
|
rt300@0
|
274
|
rt300@0
|
275 // set this class to receive incoming midi events
|
rt300@0
|
276 inputs[i]->addListener(this);
|
rt300@0
|
277
|
rt300@0
|
278 // open input port via port number
|
rt300@0
|
279 inputs[i]->openPort(i);
|
rt300@0
|
280 }
|
rt300@0
|
281
|
rt300@0
|
282 // create and open output ports
|
rt300@0
|
283 for(int i = 0; i < ofxMidiOut::getNumPorts(); ++i) {
|
rt300@0
|
284
|
rt300@0
|
285 // new object
|
rt300@0
|
286 outputs.push_back(new ofxMidiOut);
|
rt300@0
|
287
|
rt300@0
|
288 // open input port via port number
|
rt300@0
|
289 outputs[i]->openPort(i);
|
rt300@0
|
290 }
|
rt300@0
|
291
|
rt300@0
|
292 // set this class to receieve midi device (dis)connection events
|
rt300@0
|
293 ofxMidi::setConnectionListener(this);
|
rt300@0
|
294
|
rt300@0
|
295 // END MIDI
|
rt300@0
|
296
|
rt300@0
|
297 }
|
rt300@0
|
298 //--------------------------------------------------------------
|
rt300@0
|
299
|
rt300@0
|
300 template <class T>
|
rt300@0
|
301 void deleteVectorOfPointers( T * inVectorOfPointers )
|
rt300@0
|
302 {
|
rt300@0
|
303 typename T::iterator i;
|
rt300@0
|
304 for ( i = inVectorOfPointers->begin() ; i < inVectorOfPointers->end(); i++ )
|
rt300@0
|
305 {
|
rt300@0
|
306 delete * i;
|
rt300@0
|
307 }
|
rt300@0
|
308 //delete inVectorOfPointers;
|
rt300@0
|
309 }
|
rt300@0
|
310
|
rt300@0
|
311
|
rt300@0
|
312 //--------------------------------------------------------------
|
rt300@0
|
313 void testApp::exit(){
|
rt300@0
|
314 eventLogger.logEvent(APP_EXITED);
|
rt300@0
|
315 eventLogger.exitAndSave();
|
rt300@0
|
316
|
rt300@0
|
317 core.exit();
|
rt300@0
|
318
|
rt300@0
|
319 // are these handled automatically?
|
rt300@0
|
320 //[introViewController release];
|
rt300@0
|
321 //[topButtonViewController release];
|
rt300@0
|
322 //[bottomTabViewController release];
|
rt300@0
|
323
|
rt300@0
|
324 // clean up MIDI
|
rt300@0
|
325 for(int i = 0; i < inputs.size(); ++i) {
|
rt300@0
|
326 inputs[i]->closePort();
|
rt300@0
|
327 inputs[i]->removeListener(this);
|
rt300@0
|
328 delete inputs[i];
|
rt300@0
|
329 }
|
rt300@0
|
330
|
rt300@0
|
331 for(int i = 0; i < outputs.size(); ++i) {
|
rt300@0
|
332 outputs[i]->closePort();
|
rt300@0
|
333 delete outputs[i];
|
rt300@0
|
334 }
|
rt300@0
|
335 deleteVectorOfPointers(&UIElements); // TODO this crashes??
|
rt300@8
|
336
|
rt300@0
|
337
|
rt300@0
|
338 cout << "exit done \n";
|
rt300@0
|
339 }
|
rt300@0
|
340
|
rt300@0
|
341 #pragma mark GUI
|
rt300@0
|
342 ////////////////////////////
|
rt300@0
|
343 // These functions called from iOS toolbars
|
rt300@0
|
344 //--------------------------------------------------------------
|
rt300@0
|
345
|
rt300@0
|
346 //--------------------------------------------------------------
|
rt300@0
|
347 void testApp::showQuestionnaire(){
|
rt300@0
|
348
|
rt300@0
|
349
|
rt300@0
|
350 questionnaireViewController = [[QuestionnaireViewController alloc] initWithNibName:@"QuestionnaireViewController" bundle:nil];
|
rt300@0
|
351 [ofxiPhoneGetGLParentView() addSubview:questionnaireViewController.view];
|
rt300@0
|
352
|
rt300@0
|
353 [questionnaireViewController setAppRef:(__bridge id)this];
|
rt300@0
|
354 [questionnaireViewController show:(__bridge id)this];
|
rt300@0
|
355
|
rt300@0
|
356 whichInterfaceShowing = QUESTIONNAIRE;
|
rt300@0
|
357
|
rt300@0
|
358
|
rt300@0
|
359 }
|
rt300@0
|
360 //--------------------------------------------------------------
|
rt300@0
|
361 void testApp::questionnaireHidden(vector<int> answers, const char* userComments){
|
rt300@0
|
362 // send answers to server as json
|
rt300@0
|
363 eventLogger.questionnaireAnswersObtained(answers, userComments);
|
rt300@0
|
364
|
rt300@0
|
365 }
|
rt300@0
|
366
|
rt300@0
|
367 //--------------------------------------------------------------
|
rt300@0
|
368 void testApp::showIntro(){
|
rt300@0
|
369
|
rt300@0
|
370 cout << "SHOW INTRO\n";
|
rt300@0
|
371
|
rt300@0
|
372 introViewController = [[IntroViewController alloc] initWithNibName:@"IntroViewController" bundle:nil];
|
rt300@0
|
373 [ofxiPhoneGetGLParentView() addSubview:introViewController.view];
|
rt300@0
|
374
|
rt300@0
|
375 [introViewController setAppRef:(__bridge id)this];
|
rt300@0
|
376 [introViewController show:(__bridge id)this];
|
rt300@0
|
377
|
rt300@0
|
378 whichInterfaceShowing = INTRO;
|
rt300@0
|
379
|
rt300@0
|
380 }
|
rt300@0
|
381 //--------------------------------------------------------------
|
rt300@0
|
382 void testApp::introHidden(){
|
rt300@0
|
383 eventLogger.consentGiven = true;
|
rt300@0
|
384 eventLogger.logEvent(INTRO_CONSENTED);
|
rt300@0
|
385 [usernameAlertViewController showUserNamePrompt];
|
rt300@2
|
386 // after prompt goes it calls usernameEntered()
|
rt300@0
|
387 }
|
rt300@0
|
388
|
rt300@2
|
389 void testApp::usernameEntered(){
|
rt300@2
|
390 // display a thing that gives us an option as to which stage to start
|
rt300@2
|
391 // EXPLORE, PERFORMANCE TRAINING, SEARCH
|
rt300@9
|
392
|
rt300@9
|
393
|
rt300@2
|
394 }
|
rt300@0
|
395 //--------------------------------------------------------------
|
rt300@9
|
396 void testApp::startTheSearchTests(){
|
rt300@9
|
397 eventLogger.logEvent(START_THE_SEARCH_TESTS);
|
rt300@0
|
398 whichInterfaceShowing = COUNT_DOWN;
|
rt300@0
|
399 // do countdown etc
|
rt300@8
|
400 searchMessageOrganiser.countdownToNewTest();
|
rt300@0
|
401 // TODO how is testApp going to kknow whichInterfaceShowing ???
|
rt300@0
|
402
|
rt300@0
|
403 }
|
rt300@9
|
404 void testApp::startTheTrainingTests(){
|
rt300@9
|
405 eventLogger.logEvent(START_THE_TRAINING_TESTS);
|
rt300@9
|
406
|
rt300@9
|
407 trainingMessageOrganiser.setupDefaultMapping();
|
rt300@9
|
408
|
rt300@9
|
409 }
|
rt300@0
|
410 //--------------------------------------------------------------
|
rt300@0
|
411 //--------------------------------------------------------------
|
rt300@0
|
412 void testApp::showHelp(){
|
rt300@0
|
413 // stop clock etc
|
rt300@0
|
414 previousInterface = whichInterfaceShowing;
|
rt300@0
|
415 whichInterfaceShowing = HELP;
|
rt300@0
|
416 helpViewController.view.hidden = NO;
|
rt300@0
|
417 eventLogger.logEvent(HELP_PRESSED);
|
rt300@0
|
418
|
rt300@0
|
419 }
|
rt300@0
|
420 void testApp::helpHidden(){
|
rt300@0
|
421 whichInterfaceShowing = previousInterface;
|
rt300@0
|
422
|
rt300@0
|
423 }
|
rt300@0
|
424 //--------------------------------------------------------------
|
rt300@0
|
425 //--------------------------------------------------------------
|
rt300@0
|
426 //--------------------------------------------------------------
|
rt300@0
|
427 #pragma mark sending to pd and midi
|
rt300@0
|
428 void testApp::sendParametersToPD(){
|
rt300@0
|
429
|
rt300@0
|
430
|
rt300@0
|
431 }
|
rt300@0
|
432 //--------------------------------------------------------------
|
rt300@0
|
433 void testApp::sendMidiParam(int which){
|
rt300@0
|
434 int midiChannel = 8;
|
rt300@0
|
435 int offset = 0;
|
rt300@0
|
436
|
rt300@0
|
437 for(int i = 0; i < outputs.size(); ++i) {
|
rt300@0
|
438 outputs[i]->sendControlChange(midiChannel, offset+which, 66);
|
rt300@0
|
439 }
|
rt300@0
|
440
|
rt300@0
|
441
|
rt300@0
|
442 }
|
rt300@0
|
443
|
rt300@0
|
444 //--------------------------------------------------------------
|
rt300@0
|
445 //void testApp::sendOSCParams(){
|
rt300@0
|
446 //
|
rt300@0
|
447 // ofxOscMessage m;
|
rt300@0
|
448 // m.setAddress( "Template" );
|
rt300@0
|
449 //
|
rt300@0
|
450 // m.addFloatArg(9.9999);
|
rt300@0
|
451 //
|
rt300@0
|
452 // sender.sendMessage( m );
|
rt300@0
|
453 //}
|
rt300@0
|
454 //--------------------------------------------------------------
|
rt300@0
|
455
|
rt300@0
|
456 void testApp::setupNewUser(){
|
rt300@0
|
457 // this function is for supervised trials with my ipad
|
rt300@0
|
458 eventLogger.newUser();
|
rt300@0
|
459 }
|
rt300@0
|
460 //--------------------------------------------------------------
|
rt300@0
|
461 #pragma mark STANDARD OF FUNCTIONS
|
rt300@0
|
462 //--------------------------------------------------------------
|
rt300@0
|
463 void testApp::update(){
|
rt300@0
|
464
|
rt300@0
|
465 if(paused) return;
|
rt300@0
|
466
|
rt300@0
|
467 // run timer check here
|
rt300@0
|
468 // look at time, work out difference
|
rt300@0
|
469 timeController.tick();
|
rt300@0
|
470
|
rt300@0
|
471 // test mutex crash thing
|
rt300@0
|
472 //eventLogger.logEvent(CANDIDATE_PLAYED);
|
rt300@0
|
473 }
|
rt300@0
|
474 //--------------------------------------------------------------
|
rt300@0
|
475
|
rt300@0
|
476 void testApp::appModeChange(interfaceType mode){
|
rt300@0
|
477 whichInterfaceShowing = mode;
|
rt300@0
|
478 }
|
rt300@0
|
479
|
rt300@0
|
480
|
rt300@0
|
481 //------------------------------------------------------------------------
|
rt300@0
|
482
|
rt300@0
|
483 void testApp::draw(){
|
rt300@0
|
484
|
rt300@0
|
485 switch (whichInterfaceShowing){
|
rt300@0
|
486 case QUESTIONNAIRE:
|
rt300@0
|
487 break;
|
rt300@0
|
488 case INTRO:
|
rt300@0
|
489 break;
|
rt300@0
|
490 case TEST_IN_PROGRESS:
|
rt300@0
|
491 break;
|
rt300@0
|
492 case SCORE_AND_HINT:
|
rt300@0
|
493 break;
|
rt300@0
|
494 case COUNT_DOWN:
|
rt300@0
|
495 break;
|
rt300@0
|
496 case READY_FOR_NEXT:
|
rt300@0
|
497 break;
|
rt300@0
|
498 default:
|
rt300@0
|
499 break;
|
rt300@0
|
500 }
|
rt300@0
|
501
|
rt300@0
|
502
|
rt300@0
|
503
|
rt300@0
|
504 drawUIElements();
|
rt300@0
|
505
|
rt300@0
|
506 //ofSetColor(234, 234, 234);
|
rt300@0
|
507 //ofLine(0,150,1024,150);
|
rt300@0
|
508
|
rt300@0
|
509 //drawWaveform();
|
rt300@9
|
510 if (currentStage == SEARCH)
|
rt300@9
|
511 searchMessageOrganiser.drawScore();
|
rt300@0
|
512
|
rt300@0
|
513
|
rt300@0
|
514
|
rt300@0
|
515 }
|
rt300@0
|
516 //------------------------------------------------------------------------
|
rt300@0
|
517 void testApp::drawUIElements(){
|
rt300@0
|
518
|
rt300@0
|
519 vector<UIElement *>::iterator UIitr;
|
rt300@0
|
520 for(UIitr = UIElements.begin(); UIitr < UIElements.end(); UIitr++){
|
rt300@0
|
521 (*UIitr)->draw();
|
rt300@0
|
522 }
|
rt300@0
|
523 }
|
rt300@8
|
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@9
|
667 if (currentStage == SEARCH)
|
rt300@9
|
668 searchMessageOrganiser.midiFromLeap(ctl_num, ctl_val);
|
rt300@9
|
669
|
rt300@9
|
670
|
rt300@0
|
671 }
|
rt300@0
|
672
|
rt300@0
|
673 }
|
rt300@0
|
674
|
rt300@0
|
675 //--------------------------------------------------------------
|
rt300@0
|
676 void testApp::midiInputAdded(string name, bool isNetwork) {
|
rt300@0
|
677 stringstream msg;
|
rt300@0
|
678 msg << "ofxMidi: input added: " << name << " network: " << isNetwork;
|
rt300@0
|
679 cout << msg.str();
|
rt300@0
|
680 addMessage(msg.str());
|
rt300@0
|
681
|
rt300@0
|
682 // create and open a new input port
|
rt300@0
|
683 ofxMidiIn * newInput = new ofxMidiIn;
|
rt300@0
|
684 newInput->openPort(name);
|
rt300@0
|
685 newInput->addListener(this);
|
rt300@0
|
686 inputs.push_back(newInput);
|
rt300@0
|
687 }
|
rt300@0
|
688
|
rt300@0
|
689 //--------------------------------------------------------------
|
rt300@0
|
690 void testApp::midiInputRemoved(string name, bool isNetwork) {
|
rt300@0
|
691 stringstream msg;
|
rt300@0
|
692 msg << "ofxMidi: input removed: " << name << " network: " << isNetwork << endl;
|
rt300@0
|
693 cout << msg.str();
|
rt300@0
|
694 addMessage(msg.str());
|
rt300@0
|
695
|
rt300@0
|
696 // close and remove input port
|
rt300@0
|
697 vector<ofxMidiIn*>::iterator iter;
|
rt300@0
|
698 for(iter = inputs.begin(); iter != inputs.end(); ++iter) {
|
rt300@0
|
699 ofxMidiIn * input = (*iter);
|
rt300@0
|
700 if(input->getName() == name) {
|
rt300@0
|
701 input->closePort();
|
rt300@0
|
702 input->removeListener(this);
|
rt300@0
|
703 delete input;
|
rt300@0
|
704 inputs.erase(iter);
|
rt300@0
|
705 break;
|
rt300@0
|
706 }
|
rt300@0
|
707 }
|
rt300@0
|
708 }
|
rt300@0
|
709
|
rt300@0
|
710 //--------------------------------------------------------------
|
rt300@0
|
711 void testApp::midiOutputAdded(string name, bool isNetwork) {
|
rt300@0
|
712 stringstream msg;
|
rt300@0
|
713 msg << "ofxMidi: output added: " << name << " network: " << isNetwork << endl;
|
rt300@0
|
714 cout << msg.str();
|
rt300@0
|
715 addMessage(msg.str());
|
rt300@0
|
716
|
rt300@0
|
717 // create and open new output port
|
rt300@0
|
718 ofxMidiOut * newOutput = new ofxMidiOut;
|
rt300@0
|
719 newOutput->openPort(name);
|
rt300@0
|
720 outputs.push_back(newOutput);
|
rt300@0
|
721 }
|
rt300@0
|
722
|
rt300@0
|
723 //--------------------------------------------------------------
|
rt300@0
|
724 void testApp::midiOutputRemoved(string name, bool isNetwork) {
|
rt300@0
|
725 stringstream msg;
|
rt300@0
|
726 msg << "ofxMidi: output removed: " << name << " network: " << isNetwork << endl;
|
rt300@0
|
727 cout << msg.str();
|
rt300@0
|
728 addMessage(msg.str());
|
rt300@0
|
729
|
rt300@0
|
730 // close and remove output port
|
rt300@0
|
731 vector<ofxMidiOut*>::iterator iter;
|
rt300@0
|
732 for(iter = outputs.begin(); iter != outputs.end(); ++iter) {
|
rt300@0
|
733 ofxMidiOut * output = (*iter);
|
rt300@0
|
734 if(output->getName() == name) {
|
rt300@0
|
735 output->closePort();
|
rt300@0
|
736 delete output;
|
rt300@0
|
737 outputs.erase(iter);
|
rt300@0
|
738 break;
|
rt300@0
|
739 }
|
rt300@0
|
740 }
|
rt300@0
|
741 }
|