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