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