Mercurial > hg > tweakathon2ios
comparison testApp.mm @ 8:d59de9fd3496
Refactored messageController, ready for instroduction of other stages and tests.
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Fri, 17 Oct 2014 16:35:22 +0100 |
parents | 4e00f92567d9 |
children | d5e928887f51 |
comparison
equal
deleted
inserted
replaced
7:4e00f92567d9 | 8:d59de9fd3496 |
---|---|
15 [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; | 15 [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; |
16 // initilaise | 16 // initilaise |
17 | 17 |
18 | 18 |
19 initialiseVariables(); | 19 initialiseVariables(); |
20 | 20 |
21 | |
22 testController = new TestController; | |
23 | 21 |
24 expPresetManager.onAppLoad(); | 22 expPresetManager.onAppLoad(); |
25 | 23 |
26 //presetManager.startLoadAll(); | 24 //presetManager.startLoadAll(); |
27 | 25 |
28 | 26 targetSynth.init(&core,"targetSynth"); |
29 messageOrganiser.init(&core, testController); | 27 candidateSynth.init(&core,"candidateSynth"); |
28 | |
29 searchMessageOrganiser.init(targetSynth, candidateSynth); | |
30 timeController.init(); | 30 timeController.init(); |
31 initialiseGUIs(); | 31 initialiseGUIs(); |
32 initialiseMIDI(); | 32 initialiseMIDI(); |
33 setupUIElements(); | 33 setupUIElements(); |
34 | |
34 | 35 |
35 | 36 |
36 | 37 |
37 light.setSpotlight(45. , 1.); | 38 light.setSpotlight(45. , 1.); |
38 light.enable(); | 39 light.enable(); |
132 UIProps p; | 133 UIProps p; |
133 ButtonPanel* bottomButtonPanel = new ButtonPanel(1,160+p.sliderPanelHeight,ofGetWidth(),250,p); | 134 ButtonPanel* bottomButtonPanel = new ButtonPanel(1,160+p.sliderPanelHeight,ofGetWidth(),250,p); |
134 | 135 |
135 Buttron* playTargetButton = new Buttron(p.buttonWidth*0.2,680, p); | 136 Buttron* playTargetButton = new Buttron(p.buttonWidth*0.2,680, p); |
136 playTargetButton->setLabel("Target"); | 137 playTargetButton->setLabel("Target"); |
137 messageOrganiser.mapButtonToAction(playTargetButton, TRIGGER_TARGET_ID); | 138 searchMessageOrganiser.mapButtonToAction(playTargetButton, TRIGGER_TARGET_ID); |
138 bottomButtonPanel->addButton(playTargetButton); | 139 bottomButtonPanel->addButton(playTargetButton); |
139 messageOrganiser.setTargetButton(playTargetButton); | 140 searchMessageOrganiser.setTargetButton(playTargetButton); |
140 | 141 |
141 Buttron * playCandidateButton = new Buttron(p.buttonWidth*1.4,680, p); | 142 Buttron * playCandidateButton = new Buttron(p.buttonWidth*1.4,680, p); |
142 playCandidateButton->setLabel("Current"); | 143 playCandidateButton->setLabel("Current"); |
143 messageOrganiser.mapButtonToAction(playCandidateButton, TRIGGER_CANDIDATE_ID); | 144 searchMessageOrganiser.mapButtonToAction(playCandidateButton, TRIGGER_CANDIDATE_ID); |
144 bottomButtonPanel->addButton(playCandidateButton); | 145 bottomButtonPanel->addButton(playCandidateButton); |
145 | 146 |
146 | 147 |
147 // submit button - only one for now | 148 // submit button - only one for now |
148 Buttron * submitButton = new Buttron(ofGetWidth()*0.5 - p.buttonWidth*0.5,680, p); | 149 Buttron * submitButton = new Buttron(ofGetWidth()*0.5 - p.buttonWidth*0.5,680, p); |
149 submitButton->setLabel("Submit"); | 150 submitButton->setLabel("Submit"); |
150 messageOrganiser.mapButtonToAction(submitButton, SUBMIT_CANDIDATE); | 151 searchMessageOrganiser.mapButtonToAction(submitButton, SUBMIT_CANDIDATE); |
151 bottomButtonPanel->addButton(submitButton); | 152 bottomButtonPanel->addButton(submitButton); |
152 | 153 |
153 // button - just for spacing pruposes | 154 // button - just for spacing pruposes |
154 Buttron * saveButton = new Buttron(ofGetWidth()*0.5 - p.buttonWidth*0.5,680, p); | 155 Buttron * saveButton = new Buttron(ofGetWidth()*0.5 - p.buttonWidth*0.5,680, p); |
155 saveButton->setLabel("SAVE"); | 156 saveButton->setLabel("SAVE"); |
156 messageOrganiser.mapButtonToAction(saveButton, SAVE_PRESET_HIT); | 157 searchMessageOrganiser.mapButtonToAction(saveButton, SAVE_PRESET_HIT); |
157 bottomButtonPanel->addButton(saveButton); | 158 bottomButtonPanel->addButton(saveButton); |
158 saveButton->hide(); | 159 saveButton->hide(); |
159 | 160 |
160 Buttron * recallButton = new Buttron(ofGetWidth()*0.5 - p.buttonWidth*0.5,680, p); | 161 Buttron * recallButton = new Buttron(ofGetWidth()*0.5 - p.buttonWidth*0.5,680, p); |
161 recallButton->setLabel("RECALL"); | 162 recallButton->setLabel("RECALL"); |
162 messageOrganiser.mapButtonToAction(recallButton, RECALL_PRESET_HIT); | 163 searchMessageOrganiser.mapButtonToAction(recallButton, RECALL_PRESET_HIT); |
163 bottomButtonPanel->addButton(recallButton); | 164 bottomButtonPanel->addButton(recallButton); |
164 recallButton->hide(); | 165 recallButton->hide(); |
165 | 166 |
166 messageOrganiser.setBottomPanel(bottomButtonPanel); | 167 searchMessageOrganiser.setBottomPanel(bottomButtonPanel); |
167 UIElements.push_back(bottomButtonPanel); | 168 UIElements.push_back(bottomButtonPanel); |
168 bottomButtonPanel->showBorder(false); | 169 bottomButtonPanel->showBorder(false); |
169 | 170 |
170 // - - - - - -- - - OTHER BITS | 171 // - - - - - -- - - OTHER BITS |
171 | 172 |
172 CountdownText * countDownBox = new CountdownText("5" , 500, 380, 455, 455, p); | 173 CountdownText * countDownBox = new CountdownText("5" , 500, 380, 455, 455, p); |
173 UIElements.push_back(countDownBox); | 174 UIElements.push_back(countDownBox); |
174 messageOrganiser.setCountdownPanel(countDownBox); | 175 searchMessageOrganiser.setCountdownPanel(countDownBox); |
175 countDownBox->hide(); | 176 countDownBox->hide(); |
176 | 177 |
177 TextPanel * scoreFeedback = new TextPanel("Feedback panel", ofGetWidth()*0.5 - p.buttonWidth*0.5, 666, 400,100,p); | 178 TextPanel * scoreFeedback = new TextPanel("Feedback panel", ofGetWidth()*0.5 - p.buttonWidth*0.5, 666, 400,100,p); |
178 scoreFeedback->setFontSize(SMALLFONT); | 179 scoreFeedback->setFontSize(SMALLFONT); |
179 UIElements.push_back(scoreFeedback); | 180 UIElements.push_back(scoreFeedback); |
180 messageOrganiser.setScorePanel(scoreFeedback); | 181 searchMessageOrganiser.setScorePanel(scoreFeedback); |
181 scoreFeedback->hide(); | 182 scoreFeedback->hide(); |
182 | 183 |
183 TextPanel * finishPanel = new TextPanel("Finish txt panel", 250, 250, 1000,400,p); | 184 TextPanel * finishPanel = new TextPanel("Finish txt panel", 250, 250, 1000,400,p); |
184 finishPanel->setFontSize(LARGEFONT); | 185 finishPanel->setFontSize(LARGEFONT); |
185 finishPanel->setText("Experiment completed"); | 186 finishPanel->setText("Experiment completed"); |
186 messageOrganiser.setFinishPanel(finishPanel); | 187 searchMessageOrganiser.setFinishPanel(finishPanel); |
187 | 188 |
188 UIElements.push_back(finishPanel); | 189 UIElements.push_back(finishPanel); |
189 finishPanel->hide(); | 190 finishPanel->hide(); |
190 | 191 |
191 | 192 |
192 Buttron * newTestButton = new Buttron(ofGetWidth()-300,690, p); | 193 Buttron * newTestButton = new Buttron(ofGetWidth()-300,690, p); |
193 newTestButton->setLabel("Next Test"); | 194 newTestButton->setLabel("Next Test"); |
194 UIElements.push_back(newTestButton); | 195 UIElements.push_back(newTestButton); |
195 messageOrganiser.mapButtonToAction(newTestButton, NEW_TEST_ID); | 196 searchMessageOrganiser.mapButtonToAction(newTestButton, NEW_TEST_ID); |
196 newTestButton->hide(); | 197 newTestButton->hide(); |
197 messageOrganiser.setNewTestButton(newTestButton); | 198 searchMessageOrganiser.setNewTestButton(newTestButton); |
198 | 199 |
199 TargetSymbol* targetSymbol = new TargetSymbol(ofGetWidth()*0.5,160,30,p); | 200 TargetSymbol* targetSymbol = new TargetSymbol(ofGetWidth()*0.5,160,30,p); |
200 messageOrganiser.setTargetSymbol(targetSymbol); | 201 searchMessageOrganiser.setTargetSymbol(targetSymbol); |
201 UIElements.push_back(targetSymbol); | 202 UIElements.push_back(targetSymbol); |
202 | 203 |
203 } | 204 } |
204 //-------------------------------------------------------------- | 205 //-------------------------------------------------------------- |
205 void testApp::setupSliderPanel(){ | 206 void testApp::setupSliderPanel(){ |
213 p.sliderPanelHeight, | 214 p.sliderPanelHeight, |
214 p, | 215 p, |
215 sl2); | 216 sl2); |
216 | 217 |
217 UIElements.push_back(controlPanel); | 218 UIElements.push_back(controlPanel); |
218 messageOrganiser.setControlPanel(controlPanel); | 219 searchMessageOrganiser.setControlPanel(controlPanel); |
219 controlPanel->showBorder(true); | 220 controlPanel->showBorder(true); |
220 } | 221 } |
221 //-------------------------------------------------------------- | 222 //-------------------------------------------------------------- |
222 void testApp::setupUIElements(){ | 223 void testApp::setupUIElements(){ |
223 | 224 |
317 for(int i = 0; i < outputs.size(); ++i) { | 318 for(int i = 0; i < outputs.size(); ++i) { |
318 outputs[i]->closePort(); | 319 outputs[i]->closePort(); |
319 delete outputs[i]; | 320 delete outputs[i]; |
320 } | 321 } |
321 deleteVectorOfPointers(&UIElements); // TODO this crashes?? | 322 deleteVectorOfPointers(&UIElements); // TODO this crashes?? |
322 | 323 |
323 | |
324 delete testController; | |
325 | 324 |
326 cout << "exit done \n"; | 325 cout << "exit done \n"; |
327 } | 326 } |
328 | 327 |
329 #pragma mark GUI | 328 #pragma mark GUI |
381 //-------------------------------------------------------------- | 380 //-------------------------------------------------------------- |
382 void testApp::startTheTests(){ | 381 void testApp::startTheTests(){ |
383 eventLogger.logEvent(START_THE_TESTS); | 382 eventLogger.logEvent(START_THE_TESTS); |
384 whichInterfaceShowing = COUNT_DOWN; | 383 whichInterfaceShowing = COUNT_DOWN; |
385 // do countdown etc | 384 // do countdown etc |
386 messageOrganiser.countdownToNewTest(); | 385 searchMessageOrganiser.countdownToNewTest(); |
387 // TODO how is testApp going to kknow whichInterfaceShowing ??? | 386 // TODO how is testApp going to kknow whichInterfaceShowing ??? |
388 | 387 |
389 } | 388 } |
390 //-------------------------------------------------------------- | 389 //-------------------------------------------------------------- |
391 //-------------------------------------------------------------- | 390 //-------------------------------------------------------------- |
485 | 484 |
486 //ofSetColor(234, 234, 234); | 485 //ofSetColor(234, 234, 234); |
487 //ofLine(0,150,1024,150); | 486 //ofLine(0,150,1024,150); |
488 | 487 |
489 //drawWaveform(); | 488 //drawWaveform(); |
490 drawScore(); | 489 searchMessageOrganiser.drawScore(); |
491 | 490 |
492 | 491 |
493 | 492 |
494 } | 493 } |
495 //------------------------------------------------------------------------ | 494 //------------------------------------------------------------------------ |
498 vector<UIElement *>::iterator UIitr; | 497 vector<UIElement *>::iterator UIitr; |
499 for(UIitr = UIElements.begin(); UIitr < UIElements.end(); UIitr++){ | 498 for(UIitr = UIElements.begin(); UIitr < UIElements.end(); UIitr++){ |
500 (*UIitr)->draw(); | 499 (*UIitr)->draw(); |
501 } | 500 } |
502 } | 501 } |
503 //------------------------------------------------------------------------ | 502 |
504 void testApp::drawScore(){ | |
505 ofColor txtCol = ofColor(150,235,200,255); | |
506 | |
507 int score = messageOrganiser.getScore(); | |
508 stringstream msg; | |
509 | |
510 msg << "Test: " << testController->getCurrentTestLetter(); | |
511 ofSetColor(txtCol); | |
512 verdBig.drawString(msg.str(), 40, 140); | |
513 msg.str(std::string()); | |
514 | |
515 msg << "Score: " << score; | |
516 verdBig.drawString(msg.str(), 240, 140); | |
517 msg.str(std::string()); | |
518 | |
519 pair<int,int> time; | |
520 time = messageOrganiser.getTime(); | |
521 msg << "Time taken: " << time.first << ":" << time.second << endl; | |
522 verdBig.drawString(msg.str(), 600, 140); | |
523 | |
524 } | |
525 //------------------------------------------------------------------------ | 503 //------------------------------------------------------------------------ |
526 | 504 |
527 //-------------------------------------------------------------- | 505 //-------------------------------------------------------------- |
528 // passes touch to UI elements | 506 // passes touch to UI elements |
529 //-------------------------------------------------------------- | 507 //-------------------------------------------------------------- |
662 if(msg.channel == midiChannel && msg.status == MIDI_CONTROL_CHANGE){ | 640 if(msg.channel == midiChannel && msg.status == MIDI_CONTROL_CHANGE){ |
663 int ctl_num = msg.control - 30; | 641 int ctl_num = msg.control - 30; |
664 int ctl_val = msg.value; | 642 int ctl_val = msg.value; |
665 // TODO route control change message here | 643 // TODO route control change message here |
666 //cout << " ctrl : " << ctl_num << " : " << ctl_val << endl; | 644 //cout << " ctrl : " << ctl_num << " : " << ctl_val << endl; |
667 messageOrganiser.midiFromLeap(ctl_num, ctl_val); | 645 searchMessageOrganiser.midiFromLeap(ctl_num, ctl_val); |
668 } | 646 } |
669 | 647 |
670 } | 648 } |
671 | 649 |
672 //-------------------------------------------------------------- | 650 //-------------------------------------------------------------- |