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@32
|
13 ofxiPhoneSetOrientation( OF_ORIENTATION_90_RIGHT );
|
rt300@0
|
14 //ofxiPhoneExternalDisplay::mirrorOn();
|
rt300@0
|
15 [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
|
rt300@14
|
16
|
rt300@0
|
17 initialiseVariables();
|
rt300@8
|
18
|
rt300@6
|
19
|
rt300@18
|
20
|
rt300@6
|
21
|
rt300@6
|
22 //presetManager.startLoadAll();
|
rt300@6
|
23
|
rt300@8
|
24 targetSynth.init(&core,"targetSynth");
|
rt300@8
|
25 candidateSynth.init(&core,"candidateSynth");
|
rt300@0
|
26
|
rt300@32
|
27 // searchMessageOrganiser.init(targetSynth, candidateSynth);
|
rt300@32
|
28 // trainingMessageOrganiser.init(targetSynth,candidateSynth);
|
rt300@32
|
29 // expMessageOrganiser.init(targetSynth,candidateSynth);
|
rt300@16
|
30
|
rt300@0
|
31 timeController.init();
|
rt300@0
|
32 initialiseGUIs();
|
rt300@0
|
33 initialiseMIDI();
|
rt300@0
|
34 setupUIElements();
|
rt300@0
|
35
|
rt300@24
|
36 light.setSpotlight(45. , 1.);
|
rt300@24
|
37 light.enable();
|
rt300@24
|
38 ofEnableSeparateSpecularLight();
|
rt300@24
|
39
|
rt300@0
|
40 ofEnableDepthTest();
|
rt300@25
|
41 glEnable(GL_DEPTH_TEST);
|
rt300@25
|
42 // ofEnableAlphaBlending();
|
rt300@18
|
43
|
rt300@0
|
44
|
rt300@0
|
45 //--------------------------------------
|
rt300@0
|
46
|
rt300@0
|
47 int ticksPerBuffer = 8; // 8 * 64 = buffer len of 512
|
rt300@0
|
48 core.setup(2, 2, 44100, ticksPerBuffer);
|
rt300@0
|
49
|
rt300@0
|
50 // setup OF sound stream
|
rt300@0
|
51 bufSize = ofxPd::blockSize()*ticksPerBuffer;
|
rt300@0
|
52 wavetableNew = (float *) malloc(bufSize * sizeof(float));
|
rt300@0
|
53
|
rt300@0
|
54 ofSoundStreamSetup(2, 2, this, 44100, ofxPd::blockSize()*ticksPerBuffer, 3);
|
rt300@0
|
55
|
rt300@26
|
56 if(false){ // force start
|
rt300@26
|
57 startTheTrainingTests();
|
rt300@0
|
58 }else{
|
rt300@0
|
59
|
rt300@0
|
60 if(eventLogger.questionnaireCompleted){ // then show play again dialog, and log the test number
|
rt300@0
|
61
|
rt300@0
|
62 }else{
|
rt300@0
|
63 // then we're in timed session mode
|
rt300@20
|
64 [usernameAlertViewController showUserNamePrompt];
|
rt300@0
|
65 }
|
rt300@0
|
66 }
|
rt300@0
|
67 paused = false;
|
rt300@0
|
68
|
rt300@0
|
69 eventLogger.logEvent(APP_LOADED);
|
rt300@0
|
70
|
rt300@0
|
71 ofSoundStreamStart();
|
rt300@0
|
72
|
rt300@0
|
73 }
|
rt300@0
|
74
|
rt300@0
|
75 //-----------------------------------------------------------------------------
|
rt300@0
|
76
|
rt300@0
|
77 //DeviceID3523537000
|
rt300@0
|
78 void testApp::initialiseVariables(){
|
rt300@0
|
79 paused = true;
|
rt300@0
|
80 ofBackground( 0, 0, 0 );
|
rt300@0
|
81 //ofEnableAlphaBlending();
|
rt300@0
|
82 //ofEnableSmoothing();
|
rt300@0
|
83
|
rt300@0
|
84 // open an outgoing connection to HOST:PORT for OSC
|
rt300@0
|
85 // sender.setup( OSC_HOST, OSC_PORT );
|
rt300@34
|
86 ofSetFrameRate(40);
|
rt300@14
|
87 props = new UIProps();
|
rt300@45
|
88 screenWidth = ofGetHeight();
|
rt300@45
|
89 screenHeight = ofGetWidth();
|
rt300@0
|
90
|
rt300@0
|
91 }
|
rt300@0
|
92 //---------------------------------------------------------
|
rt300@0
|
93 void testApp::initialiseGUIs(){
|
rt300@0
|
94
|
rt300@0
|
95 // set up iOS gui stuff
|
rt300@0
|
96
|
rt300@0
|
97 helpViewController = [[HelpViewController alloc] initWithNibName:@"HelpViewController" bundle:nil];
|
rt300@0
|
98 [ofxiPhoneGetGLParentView() addSubview:helpViewController.view];
|
rt300@0
|
99 [helpViewController setAppRef:(__bridge id)this];
|
rt300@0
|
100 helpViewController.view.hidden = YES;
|
rt300@0
|
101
|
rt300@0
|
102
|
rt300@0
|
103 usernameAlertViewController = [[UsernameAlertViewController alloc] init];
|
rt300@0
|
104 [usernameAlertViewController setAppRef:(__bridge id)this];
|
rt300@0
|
105
|
rt300@0
|
106 }
|
rt300@0
|
107
|
rt300@0
|
108 //--------------------------------------------------------------
|
rt300@6
|
109 // GUI for finding and saving presets to express concepts
|
rt300@6
|
110 void testApp::setupExpressViewPanels(){
|
rt300@45
|
111 ButtonPanel* bottomButtonPanel = new ButtonPanel(1,160+props->sliderPanelHeight,screenWidth,250,*props);
|
rt300@0
|
112
|
rt300@16
|
113 Buttron * playCandidateButton = new Buttron(props->buttonWidth*1.4,680, *props);
|
rt300@16
|
114 playCandidateButton->setLabel("PLAY");
|
rt300@16
|
115 expMessageOrganiser.mapButtonToAction(playCandidateButton, TRIGGER_CANDIDATE_ID);
|
rt300@16
|
116 bottomButtonPanel->addButton(playCandidateButton);
|
rt300@16
|
117
|
rt300@16
|
118 Buttron * savePresetButton = new Buttron(props->buttonWidth*1.4,680, *props);
|
rt300@44
|
119 savePresetButton->setLabel("SAVE");
|
rt300@16
|
120 expMessageOrganiser.mapButtonToAction(savePresetButton, SAVE_PRESET_HIT);
|
rt300@16
|
121 bottomButtonPanel->addButton(savePresetButton);
|
rt300@16
|
122
|
rt300@44
|
123 Buttron * nextPresetButton = new Buttron(props->buttonWidth*1.4,680, *props);
|
rt300@44
|
124 nextPresetButton->setLabel("NEXT");
|
rt300@44
|
125 expMessageOrganiser.mapButtonToAction(nextPresetButton, NEXT_PRESET_HIT);
|
rt300@44
|
126 bottomButtonPanel->addButton(nextPresetButton);
|
rt300@50
|
127 expMessageOrganiser.setNextButton(nextPresetButton);
|
rt300@50
|
128 nextPresetButton->hide();
|
rt300@42
|
129
|
rt300@42
|
130 Buttron * menuButton = new Buttron(props->buttonWidth*1.4,680, *props);
|
rt300@42
|
131 menuButton->setLabel("MENU");
|
rt300@42
|
132 mapButtonToAction(menuButton, TO_MENU_ID);
|
rt300@42
|
133 //trainingMessageOrganiser.mapButtonToAction(menuButton, TO_MENU_ID);
|
rt300@42
|
134 bottomButtonPanel->addButton(menuButton);
|
rt300@42
|
135
|
rt300@16
|
136 expMessageOrganiser.setBottomPanel(bottomButtonPanel);
|
rt300@16
|
137 UIElements.push_back(bottomButtonPanel);
|
rt300@16
|
138 bottomButtonPanel->hide();
|
rt300@16
|
139
|
rt300@32
|
140 TextPanel * instructionPanel = new TextPanel("Instruction panel", 10, 50, 300,150,(*props));
|
rt300@28
|
141 instructionPanel->setFontSize(MEDIUMFONT);
|
rt300@16
|
142 UIElements.push_back(instructionPanel);
|
rt300@16
|
143 expMessageOrganiser.setInstructionPanel(instructionPanel);
|
rt300@16
|
144 instructionPanel->show();
|
rt300@6
|
145 }
|
rt300@6
|
146 //--------------------------------------------------------------
|
rt300@6
|
147 // gui for the main training stage
|
rt300@6
|
148 void testApp::setupTrainingViewPanels(){
|
rt300@14
|
149
|
rt300@45
|
150 cout << ofGetWidth() << "," << ofGetHeight() << endl;
|
rt300@45
|
151
|
rt300@45
|
152 ButtonPanel* bottomButtonPanel = new ButtonPanel(1,160+props->sliderPanelHeight,screenWidth,250,*props);
|
rt300@6
|
153
|
rt300@9
|
154 // play and submit are now same thing
|
rt300@38
|
155
|
rt300@38
|
156
|
rt300@38
|
157 Buttron * forgotButton = new Buttron(props->buttonWidth*1.4,680, *props);
|
rt300@43
|
158 forgotButton->setLabel("FORGOT!");
|
rt300@38
|
159 trainingMessageOrganiser.mapButtonToAction(forgotButton, FORGOT_SEQ_ID);
|
rt300@38
|
160 trainingMessageOrganiser.setForgotButton(forgotButton);
|
rt300@38
|
161 UIElements.push_back(forgotButton);
|
rt300@38
|
162 forgotButton->setMode(Buttron::TOGGLE);
|
rt300@38
|
163 forgotButton->setXPosition(40);
|
rt300@42
|
164 forgotButton->hide();
|
rt300@38
|
165
|
rt300@50
|
166 Buttron * playCandidateButton = new Buttron(props->buttonWidth*1.4,680, props->buttonWidth*1.4,props->buttonHeight ,*props);
|
rt300@50
|
167 playCandidateButton->setLabel("START NEXT RUN");
|
rt300@29
|
168 trainingMessageOrganiser.mapButtonToAction(playCandidateButton, START_TRAINING_SEQUENCE_ID);
|
rt300@9
|
169 bottomButtonPanel->addButton(playCandidateButton);
|
rt300@37
|
170
|
rt300@50
|
171 // Buttron * menuButton = new Buttron(props->buttonWidth*1.4,680, *props);
|
rt300@50
|
172 // menuButton->setLabel("TO MENU");
|
rt300@50
|
173 // mapButtonToAction(menuButton, TO_MENU_ID);
|
rt300@50
|
174 // //trainingMessageOrganiser.mapButtonToAction(menuButton, TO_MENU_ID);
|
rt300@50
|
175 // bottomButtonPanel->addButton(menuButton);
|
rt300@37
|
176
|
rt300@50
|
177 Buttron * skipButton = new Buttron(props->buttonWidth*0.5,680, props->buttonHeight*1.4,props->buttonHeight , *props);
|
rt300@50
|
178 skipButton->setLabel(">> 2");
|
rt300@43
|
179 trainingMessageOrganiser.mapButtonToAction(skipButton, SKIP_RUN_ID);
|
rt300@43
|
180 trainingMessageOrganiser.setSkipButton(skipButton);
|
rt300@43
|
181 //trainingMessageOrganiser.mapButtonToAction(menuButton, TO_MENU_ID);
|
rt300@43
|
182 bottomButtonPanel->addButton(skipButton);
|
rt300@43
|
183
|
rt300@26
|
184 bottomButtonPanel->hide();
|
rt300@44
|
185
|
rt300@36
|
186
|
rt300@9
|
187 trainingMessageOrganiser.setBottomPanel(bottomButtonPanel);
|
rt300@9
|
188 UIElements.push_back(bottomButtonPanel);
|
rt300@9
|
189 bottomButtonPanel->hide();
|
rt300@28
|
190
|
rt300@16
|
191
|
rt300@14
|
192 TextPanel * instructionPanel = new TextPanel("Instrcution panel", 10, 50, 300,150,(*props));
|
rt300@37
|
193 instructionPanel->setFontSize(LARGEFONT);
|
rt300@14
|
194 UIElements.push_back(instructionPanel);
|
rt300@14
|
195 trainingMessageOrganiser.setInstructionPanel(instructionPanel);
|
rt300@21
|
196 instructionPanel->hide();
|
rt300@14
|
197
|
rt300@24
|
198
|
rt300@6
|
199 }
|
rt300@6
|
200 //--------------------------------------------------------------
|
rt300@6
|
201 // gui for the old style tweakathlon stage
|
rt300@6
|
202 void testApp::setupSearchViewPanels(){
|
rt300@14
|
203
|
rt300@45
|
204 ButtonPanel* bottomButtonPanel = new ButtonPanel(1,160+(*props).sliderPanelHeight,screenWidth,250,(*props));
|
rt300@6
|
205
|
rt300@14
|
206 Buttron* playTargetButton = new Buttron((*props).buttonWidth*0.2,680, (*props));
|
rt300@0
|
207 playTargetButton->setLabel("Target");
|
rt300@8
|
208 searchMessageOrganiser.mapButtonToAction(playTargetButton, TRIGGER_TARGET_ID);
|
rt300@0
|
209 bottomButtonPanel->addButton(playTargetButton);
|
rt300@8
|
210 searchMessageOrganiser.setTargetButton(playTargetButton);
|
rt300@6
|
211
|
rt300@14
|
212 Buttron * playCandidateButton = new Buttron((*props).buttonWidth*1.4,680, (*props));
|
rt300@0
|
213 playCandidateButton->setLabel("Current");
|
rt300@8
|
214 searchMessageOrganiser.mapButtonToAction(playCandidateButton, TRIGGER_CANDIDATE_ID);
|
rt300@0
|
215 bottomButtonPanel->addButton(playCandidateButton);
|
rt300@0
|
216
|
rt300@0
|
217
|
rt300@0
|
218 // submit button - only one for now
|
rt300@45
|
219 Buttron * submitButton = new Buttron(screenWidth*0.5 - (*props).buttonWidth*0.5,680, (*props));
|
rt300@0
|
220 submitButton->setLabel("Submit");
|
rt300@8
|
221 searchMessageOrganiser.mapButtonToAction(submitButton, SUBMIT_CANDIDATE);
|
rt300@0
|
222 bottomButtonPanel->addButton(submitButton);
|
rt300@0
|
223
|
rt300@0
|
224 // button - just for spacing pruposes
|
rt300@45
|
225 Buttron * saveButton = new Buttron(screenWidth*0.5 - (*props).buttonWidth*0.5,680, (*props));
|
rt300@4
|
226 saveButton->setLabel("SAVE");
|
rt300@8
|
227 searchMessageOrganiser.mapButtonToAction(saveButton, SAVE_PRESET_HIT);
|
rt300@4
|
228 bottomButtonPanel->addButton(saveButton);
|
rt300@6
|
229 saveButton->hide();
|
rt300@0
|
230
|
rt300@45
|
231 Buttron * recallButton = new Buttron(screenWidth*0.5 - (*props).buttonWidth*0.5,680, (*props));
|
rt300@4
|
232 recallButton->setLabel("RECALL");
|
rt300@8
|
233 searchMessageOrganiser.mapButtonToAction(recallButton, RECALL_PRESET_HIT);
|
rt300@4
|
234 bottomButtonPanel->addButton(recallButton);
|
rt300@6
|
235 recallButton->hide();
|
rt300@0
|
236
|
rt300@8
|
237 searchMessageOrganiser.setBottomPanel(bottomButtonPanel);
|
rt300@0
|
238 UIElements.push_back(bottomButtonPanel);
|
rt300@0
|
239 bottomButtonPanel->showBorder(false);
|
rt300@9
|
240 bottomButtonPanel->hide();
|
rt300@7
|
241 // - - - - - -- - - OTHER BITS
|
rt300@0
|
242
|
rt300@14
|
243 CountdownText * countDownBox = new CountdownText("5" , 500, 380, 455, 455, (*props));
|
rt300@0
|
244 UIElements.push_back(countDownBox);
|
rt300@8
|
245 searchMessageOrganiser.setCountdownPanel(countDownBox);
|
rt300@0
|
246 countDownBox->hide();
|
rt300@0
|
247
|
rt300@45
|
248 TextPanel * scoreFeedback = new TextPanel("Feedback panel", screenWidth*0.5 - (*props).buttonWidth*0.5, 666, 400,100,(*props));
|
rt300@0
|
249 scoreFeedback->setFontSize(SMALLFONT);
|
rt300@0
|
250 UIElements.push_back(scoreFeedback);
|
rt300@8
|
251 searchMessageOrganiser.setScorePanel(scoreFeedback);
|
rt300@0
|
252 scoreFeedback->hide();
|
rt300@0
|
253
|
rt300@14
|
254 TextPanel * finishPanel = new TextPanel("Finish txt panel", 250, 250, 1000,400,(*props));
|
rt300@0
|
255 finishPanel->setFontSize(LARGEFONT);
|
rt300@0
|
256 finishPanel->setText("Experiment completed");
|
rt300@8
|
257 searchMessageOrganiser.setFinishPanel(finishPanel);
|
rt300@0
|
258
|
rt300@0
|
259 UIElements.push_back(finishPanel);
|
rt300@0
|
260 finishPanel->hide();
|
rt300@7
|
261
|
rt300@0
|
262
|
rt300@45
|
263 Buttron * newTestButton = new Buttron(screenWidth-300,690, (*props));
|
rt300@0
|
264 newTestButton->setLabel("Next Test");
|
rt300@0
|
265 UIElements.push_back(newTestButton);
|
rt300@8
|
266 searchMessageOrganiser.mapButtonToAction(newTestButton, NEW_TEST_ID);
|
rt300@0
|
267 newTestButton->hide();
|
rt300@8
|
268 searchMessageOrganiser.setNewTestButton(newTestButton);
|
rt300@0
|
269
|
rt300@28
|
270 TextPanel * instructionPanel = new TextPanel("Instrcution panel", 10, 50, 300,150,(*props));
|
rt300@28
|
271 instructionPanel->setFontSize(MEDIUMFONT);
|
rt300@28
|
272 UIElements.push_back(instructionPanel);
|
rt300@28
|
273 searchMessageOrganiser.setInstructionPanel(instructionPanel);
|
rt300@28
|
274 instructionPanel->hide();
|
rt300@28
|
275
|
rt300@21
|
276 // TargetSymbol* targetSymbol = new TargetSymbol(ofGetWidth()*0.5,160,30,(*props));
|
rt300@21
|
277 // searchMessageOrganiser.setTargetSymbol(targetSymbol);
|
rt300@21
|
278 // UIElements.push_back(targetSymbol);
|
rt300@21
|
279 //
|
rt300@7
|
280 }
|
rt300@7
|
281 //--------------------------------------------------------------
|
rt300@7
|
282 void testApp::setupSliderPanel(){
|
rt300@28
|
283 // setupMutualPanels
|
rt300@7
|
284 vector<controllerType> sl2;
|
rt300@7
|
285 sl2.push_back(SLIDER);
|
rt300@7
|
286
|
rt300@7
|
287 SliderPanel * controlPanel = new SliderPanel(1,
|
rt300@7
|
288 160,
|
rt300@45
|
289 screenWidth,
|
rt300@14
|
290 (*props).sliderPanelHeight,
|
rt300@14
|
291 (*props),
|
rt300@7
|
292 sl2);
|
rt300@7
|
293
|
rt300@7
|
294 UIElements.push_back(controlPanel);
|
rt300@28
|
295 AnimatedUIElements.push_back(controlPanel);
|
rt300@8
|
296 searchMessageOrganiser.setControlPanel(controlPanel);
|
rt300@9
|
297 trainingMessageOrganiser.setControlPanel(controlPanel);
|
rt300@16
|
298 expMessageOrganiser.setControlPanel(controlPanel);
|
rt300@7
|
299 controlPanel->showBorder(true);
|
rt300@25
|
300 controlPanel->hide();
|
rt300@25
|
301
|
rt300@28
|
302
|
rt300@28
|
303 IconPanel* iconPanel = new IconPanel(420, 10, 150, 150, *props);
|
rt300@28
|
304 trainingMessageOrganiser.setIconPanel(iconPanel);
|
rt300@28
|
305 expMessageOrganiser.setIconPanel(iconPanel);
|
rt300@28
|
306 searchMessageOrganiser.setIconPanel(iconPanel);
|
rt300@28
|
307 UIElements.push_back(iconPanel);
|
rt300@28
|
308 iconPanel->hide();
|
rt300@28
|
309
|
rt300@44
|
310 TextPanel* seqNumPanel = new TextPanel(" ",470, 185, 150, 150, *props);
|
rt300@32
|
311 trainingMessageOrganiser.setSeqNumPanel(seqNumPanel);
|
rt300@32
|
312 expMessageOrganiser.setSeqNumPanel(seqNumPanel);
|
rt300@32
|
313 searchMessageOrganiser.setSeqNumPanel(seqNumPanel);
|
rt300@32
|
314 seqNumPanel->setFontSize(LARGEFONT);
|
rt300@32
|
315 UIElements.push_back(seqNumPanel);
|
rt300@36
|
316 seqNumPanel->show();
|
rt300@32
|
317
|
rt300@32
|
318 TextPanel* scoreNumPanel = new TextPanel("SCORE: ",700, 60, 150, 150, *props);
|
rt300@32
|
319 trainingMessageOrganiser.setScoreNumPanel(scoreNumPanel);
|
rt300@32
|
320 expMessageOrganiser.setScoreNumPanel(scoreNumPanel);
|
rt300@32
|
321 searchMessageOrganiser.setScoreNumPanel(scoreNumPanel);
|
rt300@32
|
322 scoreNumPanel->setFontSize(LARGEFONT);
|
rt300@32
|
323 UIElements.push_back(scoreNumPanel);
|
rt300@32
|
324 scoreNumPanel->show();
|
rt300@28
|
325
|
rt300@50
|
326 TextPanel * middlePanel = new TextPanel("Middle panel", 250, 400, 400,400,(*props));
|
rt300@44
|
327
|
rt300@43
|
328 middlePanel->setFontSize(LARGEFONT);
|
rt300@43
|
329 UIElements.push_back(middlePanel);
|
rt300@43
|
330 expMessageOrganiser.setMiddlePanel(middlePanel);
|
rt300@43
|
331 trainingMessageOrganiser.setMiddlePanel(middlePanel);
|
rt300@43
|
332 searchMessageOrganiser.setMiddlePanel(middlePanel);
|
rt300@43
|
333 middlePanel->hide();
|
rt300@43
|
334
|
rt300@44
|
335
|
rt300@45
|
336 ButtronSlider* distanceSlider = new ButtronSlider(screenWidth-80, 200, 60, screenHeight-400, FILL, *props);
|
rt300@44
|
337 trainingMessageOrganiser.setDistanceSlider(distanceSlider);
|
rt300@44
|
338 expMessageOrganiser.setDistanceSlider(distanceSlider);
|
rt300@44
|
339 distanceSlider->hide();
|
rt300@44
|
340 UIElements.push_back(distanceSlider);
|
rt300@44
|
341
|
rt300@27
|
342 // Leap6DBox * box = new Leap6DBox(400 , 210 , (*props).XYsize*0.75,(*props).XYsize*0.75,150,50, *props);
|
rt300@27
|
343 // searchMessageOrganiser.setBox(box);
|
rt300@27
|
344 // trainingMessageOrganiser.setBox(box);
|
rt300@27
|
345 // expMessageOrganiser.setBox(box);
|
rt300@27
|
346 // UIElements.push_back(box);
|
rt300@27
|
347 // box->show();
|
rt300@7
|
348 }
|
rt300@7
|
349 //--------------------------------------------------------------
|
rt300@7
|
350 void testApp::setupUIElements(){
|
rt300@7
|
351
|
rt300@28
|
352 ofBackground(0,0,0);
|
rt300@7
|
353
|
rt300@7
|
354 setupSearchViewPanels();
|
rt300@7
|
355
|
rt300@7
|
356 setupSliderPanel();
|
rt300@0
|
357
|
rt300@9
|
358 setupTrainingViewPanels();
|
rt300@16
|
359
|
rt300@16
|
360 setupExpressViewPanels();
|
rt300@0
|
361 }
|
rt300@0
|
362 //--------------------------------------------------------------------------
|
rt300@0
|
363 void testApp::initialiseMIDI(){
|
rt300@0
|
364
|
rt300@0
|
365 /////////////////////////
|
rt300@0
|
366 // MIDI
|
rt300@0
|
367
|
rt300@0
|
368 midiChannel = 8;
|
rt300@0
|
369 midiOffset = 0;
|
rt300@0
|
370
|
rt300@0
|
371 // enables the network midi session between iOS and Mac OSX on a
|
rt300@0
|
372 // local wifi network
|
rt300@0
|
373 //
|
rt300@0
|
374 // in ofxMidi: open the input/outport network ports named "Session 1"
|
rt300@0
|
375 //
|
rt300@0
|
376 // on OSX: use the Audio MIDI Setup Utility to connect to the iOS device
|
rt300@0
|
377 //
|
rt300@0
|
378 ofxMidi::enableNetworking();
|
rt300@0
|
379
|
rt300@0
|
380 // list the number of available input & output ports
|
rt300@0
|
381 ofxMidiIn::listPorts();
|
rt300@0
|
382 ofxMidiOut::listPorts();
|
rt300@0
|
383
|
rt300@0
|
384 // create and open input ports
|
rt300@0
|
385 for(int i = 0; i < ofxMidiIn::getNumPorts(); ++i) {
|
rt300@0
|
386
|
rt300@0
|
387 // new object
|
rt300@0
|
388 inputs.push_back(new ofxMidiIn);
|
rt300@0
|
389
|
rt300@0
|
390 // set this class to receive incoming midi events
|
rt300@0
|
391 inputs[i]->addListener(this);
|
rt300@0
|
392
|
rt300@0
|
393 // open input port via port number
|
rt300@0
|
394 inputs[i]->openPort(i);
|
rt300@0
|
395 }
|
rt300@0
|
396
|
rt300@0
|
397 // create and open output ports
|
rt300@0
|
398 for(int i = 0; i < ofxMidiOut::getNumPorts(); ++i) {
|
rt300@0
|
399
|
rt300@0
|
400 // new object
|
rt300@0
|
401 outputs.push_back(new ofxMidiOut);
|
rt300@0
|
402
|
rt300@0
|
403 // open input port via port number
|
rt300@0
|
404 outputs[i]->openPort(i);
|
rt300@0
|
405 }
|
rt300@0
|
406
|
rt300@0
|
407 // set this class to receieve midi device (dis)connection events
|
rt300@0
|
408 ofxMidi::setConnectionListener(this);
|
rt300@0
|
409
|
rt300@0
|
410 // END MIDI
|
rt300@0
|
411
|
rt300@0
|
412 }
|
rt300@0
|
413 //--------------------------------------------------------------
|
rt300@0
|
414
|
rt300@0
|
415 template <class T>
|
rt300@0
|
416 void deleteVectorOfPointers( T * inVectorOfPointers )
|
rt300@0
|
417 {
|
rt300@0
|
418 typename T::iterator i;
|
rt300@0
|
419 for ( i = inVectorOfPointers->begin() ; i < inVectorOfPointers->end(); i++ )
|
rt300@0
|
420 {
|
rt300@0
|
421 delete * i;
|
rt300@0
|
422 }
|
rt300@0
|
423 //delete inVectorOfPointers;
|
rt300@0
|
424 }
|
rt300@0
|
425
|
rt300@0
|
426
|
rt300@0
|
427 //--------------------------------------------------------------
|
rt300@0
|
428 void testApp::exit(){
|
rt300@0
|
429 eventLogger.logEvent(APP_EXITED);
|
rt300@0
|
430 eventLogger.exitAndSave();
|
rt300@0
|
431
|
rt300@0
|
432 core.exit();
|
rt300@0
|
433
|
rt300@0
|
434 // are these handled automatically?
|
rt300@0
|
435 //[introViewController release];
|
rt300@0
|
436 //[topButtonViewController release];
|
rt300@0
|
437 //[bottomTabViewController release];
|
rt300@0
|
438
|
rt300@0
|
439 // clean up MIDI
|
rt300@0
|
440 for(int i = 0; i < inputs.size(); ++i) {
|
rt300@0
|
441 inputs[i]->closePort();
|
rt300@0
|
442 inputs[i]->removeListener(this);
|
rt300@0
|
443 delete inputs[i];
|
rt300@0
|
444 }
|
rt300@0
|
445
|
rt300@0
|
446 for(int i = 0; i < outputs.size(); ++i) {
|
rt300@0
|
447 outputs[i]->closePort();
|
rt300@0
|
448 delete outputs[i];
|
rt300@0
|
449 }
|
rt300@0
|
450 deleteVectorOfPointers(&UIElements); // TODO this crashes??
|
rt300@8
|
451
|
rt300@0
|
452
|
rt300@0
|
453 cout << "exit done \n";
|
rt300@0
|
454 }
|
rt300@0
|
455
|
rt300@0
|
456 #pragma mark GUI
|
rt300@0
|
457 ////////////////////////////
|
rt300@0
|
458 // These functions called from iOS toolbars
|
rt300@0
|
459 //--------------------------------------------------------------
|
rt300@0
|
460
|
rt300@0
|
461 //--------------------------------------------------------------
|
rt300@0
|
462 void testApp::showQuestionnaire(){
|
rt300@0
|
463
|
rt300@0
|
464
|
rt300@0
|
465 questionnaireViewController = [[QuestionnaireViewController alloc] initWithNibName:@"QuestionnaireViewController" bundle:nil];
|
rt300@0
|
466 [ofxiPhoneGetGLParentView() addSubview:questionnaireViewController.view];
|
rt300@0
|
467
|
rt300@0
|
468 [questionnaireViewController setAppRef:(__bridge id)this];
|
rt300@0
|
469 [questionnaireViewController show:(__bridge id)this];
|
rt300@0
|
470
|
rt300@0
|
471 whichInterfaceShowing = QUESTIONNAIRE;
|
rt300@0
|
472
|
rt300@0
|
473
|
rt300@0
|
474 }
|
rt300@0
|
475 //--------------------------------------------------------------
|
rt300@0
|
476 void testApp::questionnaireHidden(vector<int> answers, const char* userComments){
|
rt300@0
|
477 // send answers to server as json
|
rt300@0
|
478 eventLogger.questionnaireAnswersObtained(answers, userComments);
|
rt300@0
|
479
|
rt300@0
|
480 }
|
rt300@0
|
481
|
rt300@0
|
482 //--------------------------------------------------------------
|
rt300@0
|
483 void testApp::showIntro(){
|
rt300@20
|
484 // display a thing that gives us an option as to which stage to start
|
rt300@20
|
485 // EXPLORE, PERFORMANCE TRAINING, SEARCH
|
rt300@0
|
486 cout << "SHOW INTRO\n";
|
rt300@0
|
487
|
rt300@0
|
488 introViewController = [[IntroViewController alloc] initWithNibName:@"IntroViewController" bundle:nil];
|
rt300@0
|
489 [ofxiPhoneGetGLParentView() addSubview:introViewController.view];
|
rt300@0
|
490
|
rt300@0
|
491 [introViewController setAppRef:(__bridge id)this];
|
rt300@0
|
492 [introViewController show:(__bridge id)this];
|
rt300@0
|
493
|
rt300@0
|
494 whichInterfaceShowing = INTRO;
|
rt300@0
|
495
|
rt300@0
|
496 }
|
rt300@0
|
497 //--------------------------------------------------------------
|
rt300@20
|
498 //void testApp::introHidden(){
|
rt300@20
|
499 // eventLogger.consentGiven = true;
|
rt300@20
|
500 // eventLogger.logEvent(INTRO_CONSENTED);
|
rt300@20
|
501 // [usernameAlertViewController showUserNamePrompt];
|
rt300@20
|
502 // // after prompt goes it calls usernameEntered()
|
rt300@20
|
503 //}
|
rt300@20
|
504 //--------------------------------------------------------------
|
rt300@20
|
505 void testApp::introHidden(int mode){
|
rt300@0
|
506 eventLogger.consentGiven = true;
|
rt300@0
|
507 eventLogger.logEvent(INTRO_CONSENTED);
|
rt300@20
|
508
|
rt300@20
|
509 if(mode == 1){
|
rt300@20
|
510 startTheExpTests();
|
rt300@20
|
511 }else if(mode == 2){
|
rt300@20
|
512 startTheTrainingTests();
|
rt300@20
|
513 }else if(mode == 3){
|
rt300@20
|
514 startTheSearchTests();
|
rt300@32
|
515 }else if(mode == 4){
|
rt300@32
|
516 startThePerformanceTests();
|
rt300@32
|
517
|
rt300@45
|
518 }else if(mode == 5){
|
rt300@45
|
519 startTheTrainingDemo();
|
rt300@45
|
520
|
rt300@20
|
521 }
|
rt300@20
|
522
|
rt300@0
|
523 }
|
rt300@38
|
524 void testApp::backToMainMenu(){
|
rt300@50
|
525 //expMessageOrganiser.reset();
|
rt300@38
|
526 expMessageOrganiser.hideMyPanels();
|
rt300@50
|
527 //trainingMessageOrganiser.reset();
|
rt300@38
|
528 trainingMessageOrganiser.hideMyPanels();
|
rt300@50
|
529 //searchMessageOrganiser.reset();
|
rt300@38
|
530 searchMessageOrganiser.hideMyPanels();
|
rt300@38
|
531 [introViewController show:(__bridge id)this];
|
rt300@43
|
532 eventLogger.logEvent(RUN_SKIPPED);
|
rt300@50
|
533 eventLogger.saveSessionToFile();
|
rt300@38
|
534 }
|
rt300@27
|
535 //-------------------------------
|
rt300@27
|
536 void testApp::interfaceSelected(int interfaceSelection){
|
rt300@27
|
537 if (interfaceSelection == 0){
|
rt300@27
|
538 whichInterfaceAreWeUsing = ALL_SLIDERS;
|
rt300@27
|
539 }else{
|
rt300@27
|
540 whichInterfaceAreWeUsing = LEAP6DOF;
|
rt300@27
|
541 }
|
rt300@27
|
542 }
|
rt300@20
|
543 //--------------------------------------------------------------
|
rt300@20
|
544 void testApp::usernameEntered(){
|
rt300@32
|
545
|
rt300@18
|
546 eventLogger.onUsernameEntered();
|
rt300@18
|
547 expPresetManager.onAppLoad();
|
rt300@9
|
548
|
rt300@20
|
549 showIntro();
|
rt300@9
|
550
|
rt300@2
|
551 }
|
rt300@0
|
552 //--------------------------------------------------------------
|
rt300@16
|
553 void testApp::startTheExpTests(){
|
rt300@16
|
554 eventLogger.logEvent(START_THE_EXP_TESTS);
|
rt300@32
|
555
|
rt300@32
|
556 expMessageOrganiser.init(targetSynth,candidateSynth);
|
rt300@32
|
557
|
rt300@16
|
558 whichInterfaceShowing = COUNT_DOWN;
|
rt300@16
|
559 // do countdown etc
|
rt300@16
|
560
|
rt300@16
|
561 trainingMessageOrganiser.hideMyPanels();
|
rt300@28
|
562 searchMessageOrganiser.hideMyPanels();
|
rt300@27
|
563 expMessageOrganiser.setup(whichInterfaceAreWeUsing);
|
rt300@16
|
564
|
rt300@27
|
565 expMessageOrganiser.showMyPanels();
|
rt300@27
|
566
|
rt300@23
|
567 currentStage = EXPRESS;
|
rt300@23
|
568
|
rt300@16
|
569 }
|
rt300@16
|
570 //--------------------------------------------------------------
|
rt300@9
|
571 void testApp::startTheSearchTests(){
|
rt300@38
|
572 searchMessageOrganiser.init(targetSynth,candidateSynth);
|
rt300@9
|
573 eventLogger.logEvent(START_THE_SEARCH_TESTS);
|
rt300@0
|
574 whichInterfaceShowing = COUNT_DOWN;
|
rt300@0
|
575 // do countdown etc
|
rt300@16
|
576
|
rt300@16
|
577 trainingMessageOrganiser.hideMyPanels();
|
rt300@8
|
578 searchMessageOrganiser.countdownToNewTest();
|
rt300@0
|
579 // TODO how is testApp going to kknow whichInterfaceShowing ???
|
rt300@23
|
580 currentStage = SEARCH;
|
rt300@0
|
581 }
|
rt300@33
|
582 //--------------------------------------------------------------
|
rt300@9
|
583 void testApp::startTheTrainingTests(){
|
rt300@9
|
584 eventLogger.logEvent(START_THE_TRAINING_TESTS);
|
rt300@38
|
585 expMessageOrganiser.hideMyPanels();
|
rt300@45
|
586 trainingMessageOrganiser.init(targetSynth,candidateSynth, false,whichInterfaceAreWeUsing, false);
|
rt300@43
|
587
|
rt300@32
|
588 trainingMessageOrganiser.showMyPanels();
|
rt300@32
|
589 currentStage = TRAINING;
|
rt300@32
|
590 }
|
rt300@33
|
591 //--------------------------------------------------------------
|
rt300@45
|
592 void testApp::startTheTrainingDemo(){
|
rt300@45
|
593 eventLogger.logEvent(START_THE_TRAINING_DEMO);
|
rt300@45
|
594 expMessageOrganiser.hideMyPanels();
|
rt300@45
|
595 trainingMessageOrganiser.init(targetSynth,candidateSynth, false,whichInterfaceAreWeUsing, true);
|
rt300@45
|
596
|
rt300@45
|
597 trainingMessageOrganiser.showMyPanels();
|
rt300@45
|
598 currentStage = DEMO;
|
rt300@45
|
599 }
|
rt300@45
|
600 //--------------------------------------------------------------
|
rt300@32
|
601 void testApp::startThePerformanceTests(){
|
rt300@32
|
602 eventLogger.logEvent(START_THE_PERFORMANCE_TESTS);
|
rt300@32
|
603
|
rt300@45
|
604 trainingMessageOrganiser.init(targetSynth,candidateSynth, true,whichInterfaceAreWeUsing, false);
|
rt300@43
|
605
|
rt300@16
|
606 trainingMessageOrganiser.showMyPanels();
|
rt300@23
|
607 currentStage = TRAINING;
|
rt300@9
|
608 }
|
rt300@0
|
609 //--------------------------------------------------------------
|
rt300@0
|
610 //--------------------------------------------------------------
|
rt300@0
|
611 void testApp::showHelp(){
|
rt300@0
|
612 // stop clock etc
|
rt300@0
|
613 previousInterface = whichInterfaceShowing;
|
rt300@0
|
614 whichInterfaceShowing = HELP;
|
rt300@0
|
615 helpViewController.view.hidden = NO;
|
rt300@0
|
616 eventLogger.logEvent(HELP_PRESSED);
|
rt300@0
|
617
|
rt300@0
|
618 }
|
rt300@0
|
619 void testApp::helpHidden(){
|
rt300@0
|
620 whichInterfaceShowing = previousInterface;
|
rt300@0
|
621
|
rt300@0
|
622 }
|
rt300@0
|
623 //--------------------------------------------------------------
|
rt300@0
|
624 //--------------------------------------------------------------
|
rt300@0
|
625 //--------------------------------------------------------------
|
rt300@0
|
626 #pragma mark sending to pd and midi
|
rt300@0
|
627 void testApp::sendParametersToPD(){
|
rt300@0
|
628
|
rt300@0
|
629
|
rt300@0
|
630 }
|
rt300@0
|
631 //--------------------------------------------------------------
|
rt300@0
|
632 void testApp::sendMidiParam(int which){
|
rt300@0
|
633 int midiChannel = 8;
|
rt300@0
|
634 int offset = 0;
|
rt300@0
|
635
|
rt300@0
|
636 for(int i = 0; i < outputs.size(); ++i) {
|
rt300@0
|
637 outputs[i]->sendControlChange(midiChannel, offset+which, 66);
|
rt300@0
|
638 }
|
rt300@0
|
639
|
rt300@0
|
640
|
rt300@0
|
641 }
|
rt300@0
|
642
|
rt300@0
|
643 void testApp::setupNewUser(){
|
rt300@0
|
644 // this function is for supervised trials with my ipad
|
rt300@0
|
645 eventLogger.newUser();
|
rt300@0
|
646 }
|
rt300@0
|
647 //--------------------------------------------------------------
|
rt300@0
|
648 #pragma mark STANDARD OF FUNCTIONS
|
rt300@0
|
649 //--------------------------------------------------------------
|
rt300@0
|
650 void testApp::update(){
|
rt300@0
|
651
|
rt300@0
|
652 if(paused) return;
|
rt300@0
|
653
|
rt300@0
|
654 // run timer check here
|
rt300@0
|
655 // look at time, work out difference
|
rt300@0
|
656 timeController.tick();
|
rt300@0
|
657
|
rt300@28
|
658 vector<UIElement *>::iterator UIitr;
|
rt300@28
|
659 for(UIitr = AnimatedUIElements.begin(); UIitr < AnimatedUIElements.end(); UIitr++){
|
rt300@28
|
660 (*UIitr)->update();
|
rt300@28
|
661 }
|
rt300@0
|
662 }
|
rt300@0
|
663 //--------------------------------------------------------------
|
rt300@0
|
664
|
rt300@0
|
665 void testApp::appModeChange(interfaceType mode){
|
rt300@0
|
666 whichInterfaceShowing = mode;
|
rt300@0
|
667 }
|
rt300@0
|
668
|
rt300@0
|
669
|
rt300@0
|
670 //------------------------------------------------------------------------
|
rt300@0
|
671
|
rt300@0
|
672 void testApp::draw(){
|
rt300@0
|
673
|
rt300@0
|
674 switch (whichInterfaceShowing){
|
rt300@0
|
675 case QUESTIONNAIRE:
|
rt300@0
|
676 break;
|
rt300@0
|
677 case INTRO:
|
rt300@0
|
678 break;
|
rt300@0
|
679 case TEST_IN_PROGRESS:
|
rt300@0
|
680 break;
|
rt300@0
|
681 case SCORE_AND_HINT:
|
rt300@0
|
682 break;
|
rt300@0
|
683 case COUNT_DOWN:
|
rt300@0
|
684 break;
|
rt300@0
|
685 case READY_FOR_NEXT:
|
rt300@0
|
686 break;
|
rt300@0
|
687 default:
|
rt300@0
|
688 break;
|
rt300@0
|
689 }
|
rt300@0
|
690
|
rt300@0
|
691
|
rt300@0
|
692
|
rt300@0
|
693 drawUIElements();
|
rt300@50
|
694
|
rt300@0
|
695
|
rt300@0
|
696 //ofSetColor(234, 234, 234);
|
rt300@0
|
697 //ofLine(0,150,1024,150);
|
rt300@0
|
698
|
rt300@0
|
699 //drawWaveform();
|
rt300@9
|
700 if (currentStage == SEARCH)
|
rt300@9
|
701 searchMessageOrganiser.drawScore();
|
rt300@0
|
702
|
rt300@14
|
703 //image.draw(10,10,200,200);
|
rt300@50
|
704
|
rt300@50
|
705 stringstream s;
|
rt300@50
|
706 s << " MIDI " << endl;
|
rt300@50
|
707 for (int i = 0; i < outputs.size(); i++){
|
rt300@50
|
708 s << inputs[i]->getName() << endl;;
|
rt300@50
|
709 }
|
rt300@50
|
710 props->smallFont.drawString(s.str(), 10, 10);
|
rt300@0
|
711
|
rt300@0
|
712 }
|
rt300@0
|
713 //------------------------------------------------------------------------
|
rt300@0
|
714 void testApp::drawUIElements(){
|
rt300@0
|
715
|
rt300@0
|
716 vector<UIElement *>::iterator UIitr;
|
rt300@0
|
717 for(UIitr = UIElements.begin(); UIitr < UIElements.end(); UIitr++){
|
rt300@0
|
718 (*UIitr)->draw();
|
rt300@0
|
719 }
|
rt300@0
|
720 }
|
rt300@8
|
721
|
rt300@0
|
722 //------------------------------------------------------------------------
|
rt300@0
|
723
|
rt300@0
|
724 //--------------------------------------------------------------
|
rt300@0
|
725 // passes touch to UI elements
|
rt300@0
|
726 //--------------------------------------------------------------
|
rt300@0
|
727
|
rt300@0
|
728 void testApp::touchToUIElements(int x, int y, touchType ttype, int tid){
|
rt300@0
|
729 vector<UIElement *>::iterator UIitr;
|
rt300@0
|
730 for(UIitr = UIElements.begin(); UIitr < UIElements.end(); UIitr++){
|
rt300@0
|
731 (*UIitr)->touch(x,y,ttype, tid);
|
rt300@0
|
732 }
|
rt300@0
|
733 }
|
rt300@0
|
734
|
rt300@0
|
735 //--------------------------------------------------------------
|
rt300@0
|
736 void testApp::touchDown(ofTouchEventArgs &touch){
|
rt300@0
|
737 //touch = transformTouchCoords(touch);
|
rt300@0
|
738 touchToUIElements(touch.x, touch.y, TOUCH_DOWN, touch.id);
|
rt300@0
|
739
|
rt300@0
|
740 }
|
rt300@0
|
741
|
rt300@0
|
742 //--------------------------------------------------------------
|
rt300@0
|
743 void testApp::touchMoved(ofTouchEventArgs &touch){
|
rt300@0
|
744
|
rt300@0
|
745 touchToUIElements(touch.x, touch.y, TOUCH_MOVED, touch.id);
|
rt300@0
|
746
|
rt300@0
|
747 }
|
rt300@0
|
748
|
rt300@0
|
749 //--------------------------------------------------------------
|
rt300@0
|
750 void testApp::touchUp(ofTouchEventArgs &touch){
|
rt300@0
|
751
|
rt300@0
|
752 touchToUIElements(touch.x, touch.y, TOUCH_UP, touch.id);
|
rt300@0
|
753 }
|
rt300@0
|
754
|
rt300@0
|
755
|
rt300@0
|
756 //--------------------------------------------------------------
|
rt300@0
|
757 void testApp::touchDoubleTap(ofTouchEventArgs &touch){
|
rt300@0
|
758
|
rt300@0
|
759 }
|
rt300@0
|
760
|
rt300@0
|
761 //--------------------------------------------------------------
|
rt300@0
|
762 void testApp::lostFocus(){
|
rt300@0
|
763 //exit();
|
rt300@0
|
764 }
|
rt300@0
|
765
|
rt300@0
|
766 //--------------------------------------------------------------
|
rt300@0
|
767 void testApp::gotFocus(){
|
rt300@0
|
768
|
rt300@0
|
769 }
|
rt300@0
|
770
|
rt300@0
|
771 //--------------------------------------------------------------
|
rt300@0
|
772 void testApp::gotMemoryWarning(){
|
rt300@0
|
773
|
rt300@0
|
774 }
|
rt300@0
|
775
|
rt300@0
|
776 //--------------------------------------------------------------
|
rt300@0
|
777
|
rt300@0
|
778 void testApp::deviceOrientationChanged(int newOrientation){
|
rt300@0
|
779
|
rt300@37
|
780 //cout << "orientation: " << newOrientation;
|
rt300@0
|
781
|
rt300@0
|
782 // do something here?
|
rt300@0
|
783
|
rt300@0
|
784 }
|
rt300@0
|
785
|
rt300@0
|
786
|
rt300@0
|
787
|
rt300@0
|
788 //--------------------------------------------------------------
|
rt300@0
|
789 void testApp::touchCancelled(ofTouchEventArgs& args){
|
rt300@0
|
790
|
rt300@0
|
791 }
|
rt300@0
|
792 //---------------------------------------------------------------
|
rt300@0
|
793 // AUDIO STUFF
|
rt300@0
|
794 //---------------------------------------------------------------
|
rt300@0
|
795
|
rt300@0
|
796 #pragma mark AUDIO STREAMS
|
rt300@0
|
797 //--------------------------------------------------------------
|
rt300@0
|
798 void testApp::audioReceived(float * input, int bufferSize, int nChannels) {
|
rt300@0
|
799 //core.audioReceived(input, bufferSize, nChannels);
|
rt300@0
|
800 }
|
rt300@0
|
801
|
rt300@0
|
802 void testApp::audioRequested(float * output, int bufferSize, int nChannels) {
|
rt300@0
|
803
|
rt300@0
|
804 core.audioRequested(output, bufferSize, nChannels);
|
rt300@0
|
805 // for(int i=0;i<bufferSize/2;i++){
|
rt300@0
|
806 // output[i] = 0.2;
|
rt300@0
|
807 // }
|
rt300@0
|
808 // // pass buffer to drawable thing
|
rt300@0
|
809 // for(int i=0;i<bufferSize;i++){
|
rt300@0
|
810 // wavetableNew[i] = output[i];
|
rt300@0
|
811 // }
|
rt300@0
|
812
|
rt300@0
|
813 }
|
rt300@0
|
814
|
rt300@0
|
815 void testApp::drawWaveform(){
|
rt300@0
|
816 // draw the actual waveform in the corner
|
rt300@0
|
817
|
rt300@0
|
818 int width = 768;
|
rt300@0
|
819 int height = 128;
|
rt300@0
|
820 double sampval = 0.0;
|
rt300@0
|
821 int leftsampnum = 0;
|
rt300@0
|
822 int rightsampnum = 0;
|
rt300@0
|
823 float sampscale = 0.0, prevsampscale = 0.0, interp = 0.0;
|
rt300@0
|
824
|
rt300@0
|
825 ofSetColor(256, 0, 0);
|
rt300@0
|
826 double step = double(bufSize)/width; // how much we are stepping thru wave per pixel
|
rt300@0
|
827 for(int i = 0; i < width; i++){
|
rt300@0
|
828
|
rt300@0
|
829 leftsampnum = floor(i * step); // basic nearest neighbour interpolation
|
rt300@0
|
830 rightsampnum = ceil(i*step);
|
rt300@0
|
831 interp = (i*step)-leftsampnum;
|
rt300@0
|
832 if(rightsampnum < bufSize){
|
rt300@0
|
833 sampval = (1 - interp)*wavetableNew[leftsampnum] + interp*wavetableNew[rightsampnum];
|
rt300@0
|
834 }
|
rt300@0
|
835 sampscale = (sampval * 700) + height/2.0; // centre and scale
|
rt300@0
|
836 ofSetLineWidth(2);
|
rt300@0
|
837 ofLine(sampscale, i, prevsampscale, i-1); // draw a line from pixel to pixel (?)
|
rt300@0
|
838 prevsampscale = sampscale;
|
rt300@0
|
839 }
|
rt300@0
|
840
|
rt300@0
|
841 }
|
rt300@0
|
842 //---------------------------------------------------------------
|
rt300@0
|
843 #pragma mark UTILITIES
|
rt300@0
|
844 //-------------------------------------------------------------------------
|
rt300@0
|
845 //--------------------------------------------------------------
|
rt300@0
|
846
|
rt300@0
|
847 #pragma mark MIDI
|
rt300@0
|
848 void testApp::addMessage(string msg) {
|
rt300@0
|
849 cout << msg << endl;
|
rt300@0
|
850 messages.push_back(msg);
|
rt300@0
|
851 while(messages.size() > maxMessages)
|
rt300@0
|
852 messages.pop_front();
|
rt300@0
|
853 }
|
rt300@0
|
854
|
rt300@0
|
855 //--------------------------------------------------------------
|
rt300@0
|
856 void testApp::newMidiMessage(ofxMidiMessage& msg) {
|
rt300@50
|
857 static int n = 0;
|
rt300@50
|
858 n++;
|
rt300@50
|
859 stringstream s;
|
rt300@50
|
860 s << n;
|
rt300@50
|
861 midiPorts = s.str();
|
rt300@2
|
862 // looks out for: 30 31 32... on channel 8
|
rt300@0
|
863 if(msg.channel == midiChannel && msg.status == MIDI_CONTROL_CHANGE){
|
rt300@0
|
864 int ctl_num = msg.control - 30;
|
rt300@32
|
865
|
rt300@0
|
866 int ctl_val = msg.value;
|
rt300@0
|
867 // TODO route control change message here
|
rt300@0
|
868 //cout << " ctrl : " << ctl_num << " : " << ctl_val << endl;
|
rt300@9
|
869 if (currentStage == SEARCH)
|
rt300@9
|
870 searchMessageOrganiser.midiFromLeap(ctl_num, ctl_val);
|
rt300@23
|
871 if (currentStage == EXPRESS)
|
rt300@23
|
872 expMessageOrganiser.midiFromLeap(ctl_num, ctl_val);
|
rt300@50
|
873 if (currentStage == TRAINING || currentStage == DEMO)
|
rt300@23
|
874 trainingMessageOrganiser.midiFromLeap(ctl_num, ctl_val);
|
rt300@9
|
875
|
rt300@0
|
876 }
|
rt300@43
|
877
|
rt300@43
|
878 if(msg.channel == midiChannel && msg.status == MIDI_NOTE_ON){
|
rt300@43
|
879 // if(msg.value;
|
rt300@43
|
880 // turn on forget button
|
rt300@43
|
881 if (currentStage == TRAINING)
|
rt300@43
|
882 trainingMessageOrganiser.forgotByMidi();
|
rt300@43
|
883 }
|
rt300@0
|
884
|
rt300@0
|
885 }
|
rt300@0
|
886
|
rt300@0
|
887 //--------------------------------------------------------------
|
rt300@0
|
888 void testApp::midiInputAdded(string name, bool isNetwork) {
|
rt300@0
|
889 stringstream msg;
|
rt300@0
|
890 msg << "ofxMidi: input added: " << name << " network: " << isNetwork;
|
rt300@0
|
891 cout << msg.str();
|
rt300@0
|
892 addMessage(msg.str());
|
rt300@50
|
893 midiPorts = msg.str();
|
rt300@0
|
894 // create and open a new input port
|
rt300@0
|
895 ofxMidiIn * newInput = new ofxMidiIn;
|
rt300@0
|
896 newInput->openPort(name);
|
rt300@0
|
897 newInput->addListener(this);
|
rt300@0
|
898 inputs.push_back(newInput);
|
rt300@0
|
899 }
|
rt300@0
|
900
|
rt300@0
|
901 //--------------------------------------------------------------
|
rt300@0
|
902 void testApp::midiInputRemoved(string name, bool isNetwork) {
|
rt300@0
|
903 stringstream msg;
|
rt300@0
|
904 msg << "ofxMidi: input removed: " << name << " network: " << isNetwork << endl;
|
rt300@0
|
905 cout << msg.str();
|
rt300@0
|
906 addMessage(msg.str());
|
rt300@0
|
907
|
rt300@0
|
908 // close and remove input port
|
rt300@0
|
909 vector<ofxMidiIn*>::iterator iter;
|
rt300@0
|
910 for(iter = inputs.begin(); iter != inputs.end(); ++iter) {
|
rt300@0
|
911 ofxMidiIn * input = (*iter);
|
rt300@0
|
912 if(input->getName() == name) {
|
rt300@0
|
913 input->closePort();
|
rt300@0
|
914 input->removeListener(this);
|
rt300@0
|
915 delete input;
|
rt300@0
|
916 inputs.erase(iter);
|
rt300@0
|
917 break;
|
rt300@0
|
918 }
|
rt300@0
|
919 }
|
rt300@0
|
920 }
|
rt300@0
|
921
|
rt300@0
|
922 //--------------------------------------------------------------
|
rt300@0
|
923 void testApp::midiOutputAdded(string name, bool isNetwork) {
|
rt300@50
|
924 static int howmany = 0;
|
rt300@50
|
925 howmany++;
|
rt300@0
|
926 stringstream msg;
|
rt300@50
|
927 msg << "Midi out add: " << howmany << " \n" << name << " network: " << isNetwork << endl;
|
rt300@0
|
928 cout << msg.str();
|
rt300@50
|
929
|
rt300@0
|
930 addMessage(msg.str());
|
rt300@0
|
931
|
rt300@0
|
932 // create and open new output port
|
rt300@0
|
933 ofxMidiOut * newOutput = new ofxMidiOut;
|
rt300@0
|
934 newOutput->openPort(name);
|
rt300@0
|
935 outputs.push_back(newOutput);
|
rt300@0
|
936 }
|
rt300@0
|
937
|
rt300@0
|
938 //--------------------------------------------------------------
|
rt300@0
|
939 void testApp::midiOutputRemoved(string name, bool isNetwork) {
|
rt300@0
|
940 stringstream msg;
|
rt300@0
|
941 msg << "ofxMidi: output removed: " << name << " network: " << isNetwork << endl;
|
rt300@0
|
942 cout << msg.str();
|
rt300@0
|
943 addMessage(msg.str());
|
rt300@0
|
944
|
rt300@0
|
945 // close and remove output port
|
rt300@0
|
946 vector<ofxMidiOut*>::iterator iter;
|
rt300@0
|
947 for(iter = outputs.begin(); iter != outputs.end(); ++iter) {
|
rt300@0
|
948 ofxMidiOut * output = (*iter);
|
rt300@0
|
949 if(output->getName() == name) {
|
rt300@0
|
950 output->closePort();
|
rt300@0
|
951 delete output;
|
rt300@0
|
952 outputs.erase(iter);
|
rt300@0
|
953 break;
|
rt300@0
|
954 }
|
rt300@0
|
955 }
|
rt300@0
|
956 }
|
rt300@38
|
957 //-----------------------------------------------------------
|
rt300@38
|
958 void testApp::mapButtonToAction(UIElement* control, int mappingID){
|
rt300@38
|
959 UICallbackFunction callbackF;
|
rt300@38
|
960 callbackF = boost::bind(&testApp::buttonPressCallback, this, _1,_2);
|
rt300@38
|
961 control->addHandler(callbackF, mappingID);
|
rt300@38
|
962 }
|
rt300@38
|
963 void testApp::buttonPressCallback(int mappingID, int value){
|
rt300@38
|
964 if (mappingID == TO_MENU_ID){
|
rt300@38
|
965 backToMainMenu();
|
rt300@38
|
966 }
|
rt300@38
|
967 }
|