Mercurial > hg > tweakathon2ios
comparison MessageOrganiser.h @ 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 | 92850a2b099c |
children | d5e928887f51 |
comparison
equal
deleted
inserted
replaced
7:4e00f92567d9 | 8:d59de9fd3496 |
---|---|
17 | 17 |
18 #include <UIElement.h> | 18 #include <UIElement.h> |
19 #include <Buttron.h> | 19 #include <Buttron.h> |
20 #include <ButtronSlider.h> | 20 #include <ButtronSlider.h> |
21 #include <ButtronXY.h> | 21 #include <ButtronXY.h> |
22 #include "AppCore.h" | |
23 #include "ofxPd.h" | |
24 #include "TestController.h" | 22 #include "TestController.h" |
25 #include "timeController.h" | 23 #include "timeController.h" |
26 #include "PDSynthWrapper.h" | 24 #include "PDSynthWrapper.h" |
27 #include "ofxTimer.h" | 25 #include "ofxTimer.h" |
28 #include "sliderPanel.h" | 26 #include "sliderPanel.h" |
58 extern ExplorePresetManager expPresetManager; | 56 extern ExplorePresetManager expPresetManager; |
59 | 57 |
60 typedef boost::function<void(void)> AppModeChangeFunction; | 58 typedef boost::function<void(void)> AppModeChangeFunction; |
61 | 59 |
62 class MessageOrganiser { | 60 class MessageOrganiser { |
63 private: | 61 |
64 AppCore* core; | 62 public: |
65 //testApp* theOFApp; | 63 void init(PDSynthWrapper& cs, PDSynthWrapper& ts){ |
64 candidateSynth = cs; | |
65 targetSynth = ts; | |
66 } | |
67 // could template for ui element type?? | |
68 void mapButtonToAction(UIElement* control, int mappingID){ | |
69 UICallbackFunction callbackF; | |
70 callbackF = boost::bind(&MessageOrganiser::buttonPressCallback, this, _1,_2); | |
71 control->addHandler(callbackF, mappingID); | |
72 currentMapping.insert(std::pair<int,UIElement*>(mappingID,control)); | |
73 } | |
74 protected: | |
75 | |
76 PDSynthWrapper candidateSynth; | |
66 PDSynthWrapper targetSynth; | 77 PDSynthWrapper targetSynth; |
67 PDSynthWrapper candidateSynth; | 78 |
68 | 79 |
69 map<int,UIElement*> currentMapping; // could get more sophisticated if not 1-1 ? | 80 map<int,UIElement*> currentMapping; // could get more sophisticated if not 1-1 ? |
70 | 81 |
71 SliderPanel* panel; | 82 SliderPanel* panel; |
72 TimeController altPlaybackController; | |
73 | 83 |
74 TestController* testController; | |
75 Buttron* newTestButton; | |
76 //Buttron* submitButton; | |
77 | |
78 ButtonPanel* bottomPanel; // shows during test : play buttons and submit | |
79 Buttron* targetPlayButton; // so we can hide target in memory test. this pointer stuff is getting out of hand | |
80 CountdownText* countdownPanel; | |
81 TargetSymbol* targetSymbol; | |
82 Leap3DBoxGL* box3D; | |
83 TextPanel* scorePanel; | |
84 TextPanel* finishPanel; | |
85 AppModeChangeFunction testAppModeChange; | |
86 | |
87 //int scoreRunningTotal; | |
88 TimerID currentSoundPlayTimer; | |
89 | |
90 int alternationSpeed; // ms between cand and target | |
91 bool playingAlternating; | |
92 | |
93 bool okToGetLeapMidi; | |
94 | 84 |
95 void testsFinished(){ | |
96 panel->hide(); | |
97 bottomPanel->hide(); | |
98 newTestButton->hide(); | |
99 | |
100 vector<int> eData; | |
101 eData.push_back(testController->getScoreRunningTotal()); | |
102 eventLogger.logEvent(ALL_TESTS_COMPLETED, eData); | |
103 | |
104 // TODO set final score screen txt to testController->getScoreRunningTotal() | |
105 finishPanel->show(); | |
106 | |
107 string user = eventLogger.getUsername(); | |
108 stringstream s; | |
109 s << "Experiment completed" | |
110 << endl << endl | |
111 << "You scored: " << testController->getScoreRunningTotal() << " well done " << user << endl << endl | |
112 << "to retake test please close " << endl << endl | |
113 << "the app and restart with username<num test>"; | |
114 finishPanel->setText(s.str()); | |
115 // get test app to do something... | |
116 | |
117 eventLogger.saveSessionToFile(); | |
118 }; | |
119 | |
120 void setupNewTest(){ | |
121 // get mapping for new test and make sure we have right controls and stuff | |
122 | |
123 | |
124 Test newTest = testController->goToNextTest(); | |
125 | |
126 // V0.2 put details about what kind of test it is | |
127 vector<int> eData; | |
128 eData.push_back(newTest.isPractice()); | |
129 eData.push_back(newTest.isWithHint()); | |
130 eData.push_back(newTest.isMemoryTest()); | |
131 eventLogger.logEvent(NEW_TEST, eData); | |
132 | |
133 | |
134 vector<int> mappingIDsForChangeableParams = setSynthsUpForNewTest(newTest); | |
135 | |
136 vector<UIElement*> UIElemHandles = panel->generateControls(testController->getCurrentListOfControls(), testController->getCurrentPanelType()); | |
137 | |
138 mapUIToNewTestParams(UIElemHandles, mappingIDsForChangeableParams); | |
139 | |
140 countdownPanel->setTestTypeString(newTest.getTestTypeAdvanceWarning()); | |
141 | |
142 | |
143 }; | |
144 void startNewTest(){ | |
145 Test t = testController->getCurrentTest(); | |
146 | |
147 countdownPanel->hide(); | |
148 panel->show(); | |
149 panel->setActive(true); | |
150 if(t.isWithHint()){ | |
151 panel->showHint(true); | |
152 } | |
153 | |
154 bottomPanel->show(); | |
155 targetPlayButton->show(); // incase it was memory test | |
156 if (t.isMemoryTest()){ | |
157 targetPlayButton->setLabel("Memorise!"); | |
158 }else{ | |
159 targetPlayButton->setLabel("Target"); | |
160 } | |
161 //startAlternatingPlayback(); | |
162 //timeController.scheduleEvent(boost::bind(&MessageOrganiser::sendSynthValuesAgain, this), 200); | |
163 timeController.startStopwatch(); | |
164 eventLogger.logEvent(TEST_TIMER_STARTED); | |
165 | |
166 | |
167 if(t.getListOfControlTypes()[0] == LEAP3D){ | |
168 okToGetLeapMidi = true; | |
169 } | |
170 }; | |
171 | |
172 vector<int> setSynthsUpForNewTest(Test newTest){ | |
173 targetSynth.setAllParams(newTest.getTargetValues()); | |
174 eventLogger.logEvent(TARGET_PARAM_SET, newTest.getTargetValues()); // unless something goes wrong in setAllParams | |
175 | |
176 candidateSynth.setAllParams(newTest.getStartingCandidateValues()); | |
177 eventLogger.logEvent(CANDIDATE_PARAM_SET,newTest.getStartingCandidateValues()); | |
178 | |
179 // eventLogger.logEvent(NEW_TARGET_PARAMS, vector<int> ); | |
180 // eventLogger.logEvent(NEW_CANDIDATE_PARAMS, vector<int> ); | |
181 | |
182 vector<int> mids = candidateSynth.getMappingIDForIndices(newTest.getChangeableIndices()); | |
183 | |
184 eventLogger.logEvent(CANDIDATE_CHANGEABLE_IDX, newTest.getChangeableIndices()); | |
185 eventLogger.logEvent(CANDIDATE_MAPPING_IDS, mids); | |
186 | |
187 return mids; | |
188 }; | |
189 void sendSynthValuesAgain(){ | 85 void sendSynthValuesAgain(){ |
190 candidateSynth.sendAllParams(); | 86 candidateSynth.sendAllParams(); |
191 targetSynth.sendAllParams(); | 87 targetSynth.sendAllParams(); |
192 }; | 88 }; |
193 | 89 |
194 // could have been cleverer. takes forever due to searching ??? | |
195 void mapUIToNewTestParams(vector<UIElement*> elems, vector<int> mids){ | |
196 | |
197 vector<UIElement*>::iterator elit; | |
198 vector<int> typeListLog; | |
199 int i = 0; | |
200 for(elit=elems.begin(); elit<elems.end();elit++){ | |
201 if ( (*elit)->getType() == XYPAD){ | |
202 if(i+1 >= mids.size()){ | |
203 cout << "ERROR ERROR: too many controls for mapping IDs" << endl; | |
204 } | |
205 | |
206 ButtronXY* theXY = (ButtronXY*)(*elit); | |
207 mapXYToParams(theXY, mids[i], mids[i+1]); | |
208 theXY->setValueAndScale(candidateSynth.getParamValueForID(mids[i]), candidateSynth.getParamValueForID(mids[i+1])); | |
209 theXY->setHintValue(targetSynth.getParamValueFromName(candidateSynth.getNameForMappingID(mids[i])) | |
210 ,targetSynth.getParamValueFromName(candidateSynth.getNameForMappingID(mids[i+1]))); | |
211 i+=2; | |
212 typeListLog.push_back(int(XYPAD)); | |
213 }else if ( (*elit)->getType() == SLIDER){ | |
214 if(i >= mids.size()){ | |
215 | |
216 cout << "ERROR ERROR: too many controls for mapping IDs: " << mids.size() << endl; | |
217 } | |
218 | |
219 ButtronSlider* theSlider = (ButtronSlider*)(*elit); | |
220 mapControlToParam((*elit), mids[i]); | |
221 theSlider->setValueAndScale(candidateSynth.getParamValueForID(mids[i])); | |
222 cout << "Hint Value " << targetSynth.getParamValueFromName(candidateSynth.getNameForMappingID(mids[i])) << endl; | |
223 theSlider->setHintValue(targetSynth.getParamValueFromName(candidateSynth.getNameForMappingID(mids[i]))); | |
224 i++; | |
225 typeListLog.push_back(int(SLIDER)); | |
226 }else if ( (*elit)->getType() == LEAP3D ){ | |
227 set3Dbox((Leap3DBoxGL*)(*elit)); | |
228 // UH | |
229 string nameX = candidateSynth.getNameForMappingID(mids[i]); | |
230 box3D->setHintValue(0,targetSynth.getParamValueFromName(nameX)); | |
231 box3D->setValueAndScale(0, candidateSynth.getParamValueForID(mids[i])); | |
232 i++; | |
233 | |
234 string nameY = candidateSynth.getNameForMappingID(mids[i]); | |
235 box3D->setHintValue(1,targetSynth.getParamValueFromName(nameY)); | |
236 box3D->setValueAndScale(1, candidateSynth.getParamValueForID(mids[i])); | |
237 i++; | |
238 | |
239 string nameZ = candidateSynth.getNameForMappingID(mids[i]); | |
240 box3D->setHintValue(2,targetSynth.getParamValueFromName(nameZ)); | |
241 box3D->setValueAndScale(2, candidateSynth.getParamValueForID(mids[i])); | |
242 i++; | |
243 | |
244 | |
245 box3D->setLabels(nameX,nameY,nameZ); | |
246 typeListLog.push_back(int(LEAP3D)); | |
247 | |
248 }else{ | |
249 cout << "ERROR ERROR: ui type not handled my mapping function !" << endl; | |
250 } | |
251 } | |
252 | |
253 eventLogger.logEvent(CONTROL_LIST,typeListLog); | |
254 }; | |
255 | |
256 // TODO - no, triggering playback needs to be logged | |
257 void startAlternatingPlayback(){ | |
258 | |
259 cout << "start alt playback" << endl; | |
260 // use our special timer to fire off play to pd | |
261 // sets off timed alternating playback | |
262 | |
263 playAlternating(); | |
264 playingAlternating = true; | |
265 | |
266 }; | |
267 void stopAlternatingPlayback(){ | |
268 cout << "stop alt playback" << endl; | |
269 // kill the alternation | |
270 timeController.cancelEvent(currentSoundPlayTimer); | |
271 playingAlternating = false; | |
272 }; | |
273 | |
274 void playAlternating(){ | |
275 | |
276 static bool alt; | |
277 int nextTime; | |
278 if (alt){ | |
279 targetSynth.trigger(); | |
280 // flash the target thingy | |
281 targetSymbol->flash(); | |
282 nextTime = alternationSpeed*1.503; // gap after target | |
283 }else{ | |
284 sendSynthValuesAgain(); // and again and again | |
285 candidateSynth.trigger(); | |
286 panel->flash(); | |
287 nextTime = alternationSpeed; | |
288 } | |
289 alt = !alt; | |
290 candidateSynth.setNoteLength(alternationSpeed); | |
291 targetSynth.setNoteLength(alternationSpeed); // could be user alterable | |
292 currentSoundPlayTimer = timeController.scheduleEvent(boost::bind(&MessageOrganiser::playAlternating,this), nextTime); | |
293 | |
294 | |
295 | |
296 }; | |
297 | |
298 void delayedShowNewTest(){ | |
299 newTestButton->show(); | |
300 // JUST IN CASE IT CRASHES near end... | |
301 //eventLogger.saveSessionToFile(); | |
302 }; | |
303 void submitSingleControl(){ | |
304 // if last one | |
305 // submitPressed() | |
306 | |
307 // else | |
308 | |
309 // grey out that slider, | |
310 // activate next slider and show it's button (same button but moved!???) | |
311 | |
312 }; | |
313 | |
314 | |
315 void submitPressed(){ | |
316 | |
317 // depending on mode go to next control | |
318 // if(testController->getCurrentPanelType() == SEQUENTIAL){ | |
319 // submitSingleControl(); | |
320 // return; | |
321 // } | |
322 // otherwise do this other - or call | |
323 | |
324 okToGetLeapMidi = false; | |
325 | |
326 TimerMillisec timeTaken = timeController.stopStopwatch(); | |
327 vector<int> answer = candidateSynth.getAllParamValues(); | |
328 | |
329 eventLogger.logEvent(SUBMIT_PRESSED, answer); //, answer, scoreRunningTotal, time taken (why not?)); | |
330 | |
331 TestResult result = testController->submitAnswer(answer, timeTaken); // TODO returns all the results | |
332 | |
333 vector<int> logResult; | |
334 logResult.push_back(result.realDistanceToTarget*1000); // measured in milliCC !??! | |
335 logResult.push_back(result.timeTaken); // milliseconds | |
336 logResult.push_back(result.score); | |
337 logResult.push_back(result.targetBandHit); | |
338 logResult.push_back(result.timeWindowHit); | |
339 | |
340 eventLogger.logEvent(DISTANCE_TIME_SCORE, logResult); | |
341 | |
342 | |
343 // gui stuff - different controller? | |
344 panel->setActive(false); | |
345 panel->showHint(true); // add some encouraging feedback to hint | |
346 bottomPanel->hide(); | |
347 | |
348 showScoreForTest(result); | |
349 | |
350 stopAlternatingPlayback(); | |
351 | |
352 // was it the final sumbit? | |
353 if(testController->isLastTest()){ | |
354 // thats it - show a final score screen etc | |
355 timeController.scheduleEvent(boost::bind(&MessageOrganiser::testsFinished, this), 500); | |
356 return; | |
357 }else{ | |
358 timeController.scheduleEvent(boost::bind(&MessageOrganiser::delayedShowNewTest, this), 300); | |
359 } | |
360 | |
361 | |
362 }; | |
363 | |
364 void showScoreForTest(TestResult result){ | |
365 scorePanel->setText(result.displayText); | |
366 scorePanel->show(); | |
367 | |
368 ofColor c; | |
369 if(result.targetBandHit == 1){ | |
370 // yellow red blue | |
371 c = ofColor(255,255,0,255); | |
372 }else if(result.targetBandHit == 2){ | |
373 c = ofColor(255,0,0,255); | |
374 }else if(result.targetBandHit == 3){ | |
375 c = ofColor(45,45,255,255); | |
376 }else if(result.targetBandHit == 4){ | |
377 c = ofColor(0,255,0,255); | |
378 }else{ | |
379 c = ofColor(150,235,200,255); | |
380 } | |
381 scorePanel->setColor(c); | |
382 panel->setHintColor(c); | |
383 }; | |
384 | 90 |
385 void setAllSlidersToValues(vector<int> values){ | 91 void setAllSlidersToValues(vector<int> values){ |
386 for(int i = 0; i < values.size(); i++){ | 92 for(int i = 0; i < values.size(); i++){ |
387 setUIToParam(i, values[i]); | 93 setUIToParam(i, values[i]); |
388 } | 94 } |
433 cout << " Mapped control to XID: " << mappingIDX << "Name: " << candidateSynth.getNameForMappingID(mappingIDX) << endl; | 139 cout << " Mapped control to XID: " << mappingIDX << "Name: " << candidateSynth.getNameForMappingID(mappingIDX) << endl; |
434 cout << " Mapped control to YID: " << mappingIDY << "Name: " << candidateSynth.getNameForMappingID(mappingIDY) << endl; | 140 cout << " Mapped control to YID: " << mappingIDY << "Name: " << candidateSynth.getNameForMappingID(mappingIDY) << endl; |
435 control->setLabel(candidateSynth.getNameForMappingID(mappingIDX), candidateSynth.getNameForMappingID(mappingIDY)); | 141 control->setLabel(candidateSynth.getNameForMappingID(mappingIDX), candidateSynth.getNameForMappingID(mappingIDY)); |
436 | 142 |
437 }; | 143 }; |
438 | 144 |
439 void mapLeapToParams(ButtronXY* control, int mappingIDX, int mappingIDY, int mappingIDZ){ | |
440 // UICallbackFunction callbackX; | |
441 // UICallbackFunction callbackY; | |
442 // UICallbackFunction callbackZ; | |
443 // | |
444 // callbackX = boost::bind(&MessageOrganiser::paramChangeCallback, this, _1,_2); | |
445 // callbackY = boost::bind(&MessageOrganiser::paramChangeCallback, this, _1,_2); | |
446 // callbackZ = boost::bind(&MessageOrganiser::paramChangeCallback, this, _1,_2); | |
447 // | |
448 // control->addHandler(callbackX, mappingIDX); | |
449 // control->addHandler(callbackY, mappingIDY); | |
450 // | |
451 // // put in our map so we can send param values to gui | |
452 // //currentMapping.insert(std::pair<int,UIElement*>(mappingID,control)); | |
453 // | |
454 // | |
455 // cout << " Mapped control to XID: " << mappingIDX << "Name: " << candidateSynth.getNameForMappingID(mappingIDX) << endl; | |
456 // cout << " Mapped control to YID: " << mappingIDY << "Name: " << candidateSynth.getNameForMappingID(mappingIDY) << endl; | |
457 // control->setLabel(candidateSynth.getNameForMappingID(mappingIDX), candidateSynth.getNameForMappingID(mappingIDY)); | |
458 | |
459 }; | |
460 | 145 |
461 void mapControlToParam(UIElement* control, string paramName){ | 146 void mapControlToParam(UIElement* control, string paramName){ |
462 // get mapping ID from synth | 147 // get mapping ID from synth |
463 int mappingID = candidateSynth.getMappingIDForName(paramName); | 148 int mappingID = candidateSynth.getMappingIDForName(paramName); |
464 mapControlToParam(control, mappingID); | 149 mapControlToParam(control, mappingID); |
465 control->setLabel(paramName); | 150 control->setLabel(paramName); |
466 }; | 151 }; |
467 public: | |
468 void init(AppCore* aCore, TestController* tc){ | |
469 // set PD core... | |
470 | 152 |
471 core = aCore; | 153 virtual void paramChangeCallback(int mappingID, int value){ |
472 targetSynth.init(aCore,"targetSynth"); | 154 // virtual? |
473 candidateSynth.init(aCore,"candidateSynth"); | |
474 | |
475 testController = tc; | |
476 currentSoundPlayTimer = -1; | |
477 okToGetLeapMidi = false; | |
478 | |
479 alternationSpeed = 200; | |
480 | |
481 candidateSynth.setNoteLength(alternationSpeed); | |
482 targetSynth.setNoteLength(alternationSpeed); | |
483 | |
484 playingAlternating = false; | |
485 }; | 155 }; |
486 void setNewTestButton(Buttron * ntb){ | 156 virtual void buttonPressCallback(int mappingID, int value){ |
487 newTestButton = ntb; | |
488 }; | |
489 void set3Dbox(Leap3DBoxGL* box){ | |
490 box3D = box; | |
491 }; | |
492 void setBottomPanel(ButtonPanel * ntb){ | |
493 bottomPanel = ntb; | |
494 }; | |
495 void setControlPanel(SliderPanel* p){ | |
496 panel = p; | |
497 | 157 |
498 }; | 158 }; |
499 void setCountdownPanel(CountdownText* cd){ | |
500 countdownPanel = cd; | |
501 }; | |
502 void setTargetSymbol(TargetSymbol* ts){ | |
503 targetSymbol = ts; | |
504 }; | |
505 void setScorePanel(TextPanel* tp){ | |
506 scorePanel = tp; | |
507 }; | |
508 void setFinishPanel(TextPanel* fp){ | |
509 finishPanel = fp; | |
510 } | |
511 void setTargetButton(Buttron* tb){ | |
512 targetPlayButton = tb; | |
513 } | |
514 int getScore(){ | |
515 return testController->getScoreRunningTotal(); | |
516 }; | |
517 | |
518 pair<int,int> getTime(){ | |
519 TimerMillisec tms = timeController.getStopwatchElapsedTime(); | |
520 int s = int(tms/1000); | |
521 int hs = int((tms%1000)/10); | |
522 pair<int,int> p(s,hs); | |
523 return p; | |
524 }; | |
525 void countdownToNewTest(){ | |
526 | |
527 panel->hide(); | |
528 panel->setActive(false); | |
529 scorePanel->hide(); | |
530 bottomPanel->hide(); | |
531 newTestButton->hide(); | |
532 | |
533 // set up stuff | |
534 setupNewTest(); | |
535 eventLogger.logEvent(COUNTDOWN_INITIATED); | |
536 | |
537 countdownPanel->showAndStart(3); | |
538 | |
539 timeController.scheduleEvent(boost::bind(&MessageOrganiser::startNewTest, this), 3000); | |
540 | |
541 }; | |
542 void sendToGUI(vector<int> paramsToMap){ | |
543 // look up these ids in mapping table | |
544 }; | |
545 void saveGoodTest(Test t){ | |
546 | |
547 }; | |
548 void playTargetButtonPressed(){ | |
549 | |
550 static int numPlays = 3; | |
551 | |
552 Test* t = testController->getCurrentTestPtr(); | |
553 if (!t->checkTargetPlaysRemaining()){ | |
554 cout << t->getTargetPlaysLeft() << endl; | |
555 | |
556 sendSynthValuesAgain(); | |
557 targetSynth.trigger(); | |
558 eventLogger.logEvent(TARGET_PLAYED); | |
559 targetPlayButton->hide(); | |
560 return; | |
561 | |
562 } | |
563 cout << t->getTargetPlaysLeft() << endl; | |
564 | |
565 sendSynthValuesAgain(); | |
566 targetSynth.trigger(); | |
567 eventLogger.logEvent(TARGET_PLAYED); | |
568 | |
569 return; | |
570 } | |
571 void playCandidateButtonPressed(){ | |
572 // | |
573 } | |
574 void buttonPressCallback(int mappingID, int value){ | |
575 if(mappingID == VOLUME_CHANGE_ID){ | |
576 targetSynth.sendVolume(value); | |
577 candidateSynth.sendVolume(value); | |
578 | |
579 } | |
580 if(mappingID == SPEED_CHANGE_ID){ | |
581 alternationSpeed = 2*(140 - value); | |
582 vector<int> eData; | |
583 eData.push_back(alternationSpeed); | |
584 eventLogger.logEvent(SPEED_CHANGED, eData); | |
585 } | |
586 if(mappingID == NEW_TEST_ID){ | |
587 countdownToNewTest(); | |
588 return; | |
589 } | |
590 if (mappingID == START_ALTERNATE_ID){ | |
591 if(!playingAlternating){ | |
592 startAlternatingPlayback(); | |
593 | |
594 }else{ | |
595 stopAlternatingPlayback(); | |
596 } | |
597 return; | |
598 } | |
599 if(mappingID == GOOD_TEST_ID){ | |
600 Test t = testController->getCurrentTest(); | |
601 saveGoodTest(t); | |
602 } | |
603 if (mappingID == RANDOMISE_TARGET_ID){ // bleyeueurrrr | |
604 targetSynth.randomiseParams(); | |
605 return; | |
606 } | |
607 if (mappingID == TRIGGER_TARGET_ID){ | |
608 playTargetButtonPressed(); | |
609 | |
610 } | |
611 if (mappingID == TRIGGER_CANDIDATE_ID){ | |
612 // log event | |
613 sendSynthValuesAgain(); | |
614 candidateSynth.trigger(); | |
615 eventLogger.logEvent(CANDIDATE_PLAYED); | |
616 // flash panel? | |
617 panel->flash(); | |
618 return; | |
619 } | |
620 if (mappingID == SUBMIT_CANDIDATE){ | |
621 // log event | |
622 submitPressed(); | |
623 | |
624 return; | |
625 } | |
626 if (mappingID == CRAP_TEST_ID){ | |
627 // this is rubbish! send a log of target values, and mapping ids | |
628 vector<int> data; | |
629 vector<int> tvals = targetSynth.getAllParamValues(); | |
630 vector<int> pidx = testController->getCurrentChangeableParams(); | |
631 data.insert(data.end(), tvals.begin(), tvals.end()); | |
632 data.insert(data.end(), pidx.begin(), pidx.end()); | |
633 | |
634 eventLogger.logEvent(CRAP_TEST, data); | |
635 } | |
636 if(mappingID == SHOW_HIDE_PANEL){ | |
637 static bool showing; | |
638 | |
639 if(showing){ | |
640 cout << " showing"<<endl; | |
641 | |
642 panel->show(); | |
643 | |
644 }else{ | |
645 cout << " hiding"<<endl; | |
646 panel->hide(); | |
647 } | |
648 showing = !showing; | |
649 } | |
650 if(mappingID == SHOW_HIDE_HINT){ | |
651 static bool showingHint; | |
652 if(showingHint){ | |
653 panel->showHint(false); | |
654 showingHint = false; | |
655 }else{ | |
656 panel->showHint(true); | |
657 showingHint = true; | |
658 } | |
659 } | |
660 if(mappingID == SAVE_PRESET_HIT){ | |
661 expPresetManager.savePreset("blah", candidateSynth.getAllParamValues()); | |
662 | |
663 } | |
664 if(mappingID == RECALL_PRESET_HIT){ | |
665 | |
666 loadPreset("blah"); | |
667 //candidateSynth.startMetronome(); | |
668 | |
669 } | |
670 } | |
671 void loadPreset(string pname){ | |
672 | |
673 vector<int> values = expPresetManager.recallPreset(pname); | |
674 if (values.size()){ | |
675 candidateSynth.setAllParams(values); | |
676 setAllSlidersToValues(values); | |
677 }else{ | |
678 cout << "ERROR, no preset found" << endl; | |
679 } | |
680 } | |
681 // called from UI | |
682 void paramChangeCallback(int mappingID, int value){ | |
683 candidateSynth.paramChangeCallback(mappingID, value); | |
684 vector<int> evtData; | |
685 evtData.push_back(mappingID); // or just index? | |
686 evtData.push_back(value); | |
687 | |
688 eventLogger.logEvent(CANDIDATE_PARAM_ADJUSTED, evtData); | |
689 }; | |
690 | |
691 // could template for ui element type?? | |
692 void mapButtonToAction(UIElement* control, int mappingID){ | |
693 UICallbackFunction callbackF; | |
694 callbackF = boost::bind(&MessageOrganiser::buttonPressCallback, this, _1,_2); | |
695 control->addHandler(callbackF, mappingID); | |
696 currentMapping.insert(std::pair<int,UIElement*>(mappingID,control)); | |
697 } | |
698 | |
699 | |
700 void midiFromLeap(int ctl_num, int ctl_val){ | |
701 | |
702 | |
703 if (!okToGetLeapMidi){ | |
704 return; | |
705 } | |
706 | |
707 | |
708 Test *theTest = testController->getCurrentTestPtr(); | |
709 if (theTest == NULL) return; | |
710 | |
711 | |
712 | |
713 | |
714 | |
715 vector<int> ci = theTest->getChangeableIndices(); | |
716 vector<int> mids = candidateSynth.getMappingIDForIndices(ci); | |
717 if (ctl_num >= mids.size() || ctl_num < 0) return; | |
718 | |
719 candidateSynth.paramChangeCallback(mids[ctl_num], ctl_val); | |
720 | |
721 setUIToParam(ctl_num, ctl_val); | |
722 | |
723 vector<int> evtData; | |
724 evtData.push_back(mids[ctl_num]); // or just index? | |
725 evtData.push_back(ctl_val); | |
726 | |
727 eventLogger.logEvent(CANDIDATE_PARAM_ADJUSTED, evtData); | |
728 // also call UI object | |
729 // get mapping ID for | |
730 // setUIToParam(ctl_num, ctl_val); | |
731 } | |
732 // void setSlidersFromLeap(int i, int val){ | |
733 // ButtronSlider* theSlider = (ButtronSlider*)panel->getSlider(i); | |
734 // theSlider->setValueAndScale(val); | |
735 // } | |
736 | |
737 | 159 |
738 | 160 |
739 void setSlidersToTarget(){ | 161 void setSlidersToTarget(){ |
740 // this will actually show sliders with target vals - for "memorisation" purposes mwa heh heh | 162 // this will actually show sliders with target vals - for "memorisation" purposes mwa heh heh |
741 // get target values | 163 // get target values |