rt300@0
|
1 #include "testApp.h"
|
rt300@2
|
2
|
rt300@24
|
3 #define SLIDER_GUI_WIDTH 256
|
rt300@25
|
4 #define NUM_PARAMS 10
|
rt300@0
|
5 extern Grid theGridView;
|
rt300@0
|
6 extern PresetManager presetManager;
|
rt300@1
|
7 extern EventLogger eventLogger;
|
rt300@3
|
8 extern Frequencer frequencer;
|
rt300@35
|
9 extern Hilbert hilbert;
|
rt300@9
|
10
|
rt300@24
|
11 const vector<string> parameterNames;
|
rt300@24
|
12
|
rt300@24
|
13 const string sliderParamNames[10] = {"Transpose", "1/4 note","1/6 note","1/7 note","1/8 note","Waveform", "Filter Type","Filter Freq", "Envelope","FM amt"};
|
rt300@24
|
14 //const vector<const string> v(ra[0],ra[1]);
|
rt300@24
|
15
|
rt300@24
|
16
|
rt300@35
|
17
|
rt300@7
|
18 //DeviceID3523537000
|
rt300@0
|
19 //--------------------------------------------------------------
|
rt300@0
|
20 void testApp::setup(){
|
rt300@16
|
21 paused = true;
|
rt300@37
|
22
|
rt300@37
|
23
|
rt300@16
|
24 ofBackground( 0, 0, 0 );
|
rt300@0
|
25 ofEnableAlphaBlending();
|
rt300@36
|
26 currentSequence = 0;
|
rt300@21
|
27 //ofEnableSmoothing();
|
rt300@37
|
28
|
rt300@29
|
29 // open an outgoing connection to HOST:PORT for OSC
|
rt300@29
|
30
|
rt300@29
|
31 sender.setup( OSC_HOST, OSC_PORT );
|
rt300@28
|
32 ofSetFrameRate(50);
|
rt300@0
|
33 // reciever
|
rt300@6
|
34 lastMoveTime = ofGetSystemTimeMicros();
|
rt300@0
|
35 prevTouchX = 0;
|
rt300@0
|
36 prevTouchY = 0;
|
rt300@0
|
37
|
rt300@0
|
38 xLocked = false;
|
rt300@0
|
39 yLocked = false;
|
rt300@0
|
40
|
rt300@0
|
41 numActiveTouches = 0;
|
rt300@3
|
42 touch0.setCoord(17./7., 2./3.);
|
rt300@0
|
43 touch1.setCoord(10,20);
|
rt300@3
|
44
|
rt300@0
|
45 prevTouch0.setCoord(1,2);
|
rt300@0
|
46 prevTouch1.setCoord(10,20);
|
rt300@0
|
47 prevDist = 10;
|
rt300@16
|
48 slowFactor = 0.98;
|
rt300@27
|
49 preventingMovePostScroll = false;
|
rt300@16
|
50
|
rt300@16
|
51 // the 5 harmonics for the frequencer
|
rt300@16
|
52 freqIndexes.push_back(0);
|
rt300@16
|
53 freqIndexes.push_back(4);
|
rt300@16
|
54 freqIndexes.push_back(6);
|
rt300@16
|
55 freqIndexes.push_back(7);
|
rt300@16
|
56 freqIndexes.push_back(8);
|
rt300@16
|
57
|
rt300@16
|
58
|
rt300@16
|
59 ofxiPhoneSetOrientation( OFXIPHONE_ORIENTATION_PORTRAIT ); // do this before setting up all the other objects
|
rt300@37
|
60 /*
|
rt300@37
|
61 sliderViewController = [[SliderViewController alloc] initWithNibName:@"SliderViewController" bundle:nil];
|
rt300@37
|
62 [ofxiPhoneGetGLParentView() addSubview:sliderViewController.view];
|
rt300@37
|
63 [sliderViewController setAppRef:(id)this];
|
rt300@37
|
64 sliderViewController.view.frame = CGRectMake(0,getHeight()-43 - 363,getWidth(),363);
|
rt300@37
|
65 */
|
rt300@24
|
66 // initialise the interfaces
|
rt300@0
|
67 theGridView.init();
|
rt300@0
|
68
|
rt300@24
|
69 setupSliderGui();
|
rt300@24
|
70 sliderGUI->setVisible(true);
|
rt300@0
|
71
|
rt300@0
|
72 // initial slider vals
|
rt300@0
|
73 for(int i=0; i<10;i++){
|
rt300@0
|
74 sliderVals.push_back(64);
|
rt300@0
|
75 }
|
rt300@37
|
76
|
rt300@24
|
77 // initialise PD
|
rt300@24
|
78
|
rt300@2
|
79 int ticksPerBuffer = 8; // 8 * 64 = buffer len of 512
|
rt300@2
|
80
|
rt300@2
|
81 // setup the app core
|
rt300@2
|
82 core.setup(2, 1, 44100, ticksPerBuffer);
|
rt300@2
|
83
|
rt300@2
|
84 // setup OF sound stream
|
rt300@2
|
85 ofSoundStreamSetup(2, 1, this, 44100, ofxPd::blockSize()*ticksPerBuffer, 3);
|
rt300@1
|
86
|
rt300@37
|
87
|
rt300@37
|
88
|
rt300@24
|
89 // set up iOS gui stuff
|
rt300@24
|
90 bottomTabViewController = [[BottomTabViewController alloc] initWithNibName:@"BottomTabViewController" bundle:nil];
|
rt300@24
|
91 [ofxiPhoneGetGLParentView() addSubview:bottomTabViewController.view];
|
rt300@24
|
92
|
rt300@24
|
93 [bottomTabViewController setAppRef:(id)this];
|
rt300@24
|
94 bottomTabViewController.view.frame = CGRectMake(0,getHeight()-44,getWidth(),44);
|
rt300@29
|
95 bottomTabViewController.view.hidden = YES;
|
rt300@37
|
96
|
rt300@24
|
97 /////
|
rt300@24
|
98
|
rt300@24
|
99 topButtonViewController = [[TopButtonViewController alloc] initWithNibName:@"TopButtonViewController" bundle:nil];
|
rt300@24
|
100 [ofxiPhoneGetGLParentView() addSubview:topButtonViewController.view];
|
rt300@24
|
101 [topButtonViewController setAppRef:(id)this];
|
rt300@24
|
102 [topButtonViewController show:(id)this];
|
rt300@24
|
103 topButtonViewController.view.frame = CGRectMake(0,0,getWidth(),44);
|
rt300@24
|
104
|
rt300@25
|
105 usernameAlertViewController = [[UsernameAlertViewController alloc] init];
|
rt300@26
|
106
|
rt300@27
|
107 helpViewController = [[HelpViewController alloc] initWithNibName:@"HelpViewController" bundle:nil];
|
rt300@27
|
108 [ofxiPhoneGetGLParentView() addSubview:helpViewController.view];
|
rt300@27
|
109 [helpViewController setAppRef:(id)this];
|
rt300@27
|
110 helpViewController.view.hidden = YES;
|
rt300@27
|
111
|
rt300@36
|
112
|
rt300@25
|
113
|
rt300@36
|
114 // load preset sequences
|
rt300@36
|
115 loadSequences();
|
rt300@36
|
116
|
rt300@24
|
117 // initialise user logging stuff
|
rt300@30
|
118 presetManager.startLoadAll();
|
rt300@29
|
119 tsc = [[TimedSessionController alloc] init];
|
rt300@29
|
120 [tsc setAppRef:(id)this];
|
rt300@7
|
121 eventLogger.init();
|
rt300@24
|
122
|
rt300@28
|
123 // timer.init();
|
rt300@29
|
124 whichInterfaceShowing = BOTH; // but timer will change this
|
rt300@37
|
125
|
rt300@28
|
126
|
rt300@29
|
127 if(eventLogger.questionnaireCompleted){
|
rt300@29
|
128 [bottomTabViewController show:(id)this withSelection:1];
|
rt300@29
|
129 }
|
rt300@27
|
130 setAllGUISliders(theGridView.getParams());
|
rt300@24
|
131 // GO
|
rt300@16
|
132 paused = false;
|
rt300@37
|
133
|
rt300@36
|
134 randomise(); // everyone starts from random position (or where they left off??)
|
rt300@32
|
135
|
rt300@32
|
136 ofxiPhoneExternalDisplay::mirrorOn();
|
rt300@37
|
137
|
rt300@37
|
138 //[sliderViewController show:(id)this];
|
rt300@36
|
139
|
rt300@24
|
140 }
|
rt300@24
|
141
|
rt300@24
|
142
|
rt300@24
|
143 //--------------------------------------------------------------
|
rt300@24
|
144 void testApp::exit(){
|
rt300@37
|
145
|
rt300@25
|
146 presetManager.exitAndSaveAll();
|
rt300@25
|
147 eventLogger.exitAndSave();
|
rt300@37
|
148
|
rt300@24
|
149 core.exit();
|
rt300@24
|
150
|
rt300@25
|
151 // are these handled automatically?
|
rt300@25
|
152 //[introViewController release];
|
rt300@25
|
153 //[topButtonViewController release];
|
rt300@25
|
154 //[bottomTabViewController release];
|
rt300@24
|
155
|
rt300@24
|
156 delete sliderGUI;
|
rt300@37
|
157
|
rt300@24
|
158 cout << "exit done \n";
|
rt300@0
|
159 }
|
rt300@24
|
160
|
rt300@24
|
161 //--------------------------------------------------------------
|
rt300@3
|
162 #pragma mark GUI
|
rt300@16
|
163 //--
|
rt300@16
|
164 float testApp::getWidth(){
|
rt300@16
|
165 // depends on orientation
|
rt300@16
|
166 return ofGetWidth();
|
rt300@16
|
167
|
rt300@16
|
168 }
|
rt300@16
|
169 float testApp::getHeight(){
|
rt300@16
|
170 // depends on orientation
|
rt300@16
|
171 return ofGetHeight();
|
rt300@16
|
172
|
rt300@16
|
173 }
|
rt300@24
|
174 #pragma mark GUI
|
rt300@24
|
175 ////////////////////////////
|
rt300@24
|
176 // These functions called from iOS toolbars
|
rt300@24
|
177 //--------------------------------------------------------------
|
rt300@24
|
178 void testApp::lockSequencerPressed(bool locked){
|
rt300@24
|
179 theGridView.shiftCentreToSnapped();
|
rt300@24
|
180 xLocked = locked;
|
rt300@25
|
181 eventLogger.logEvent(SEQ_LOCKED);
|
rt300@25
|
182
|
rt300@24
|
183
|
rt300@24
|
184 }
|
rt300@24
|
185 //--------------------------------------------------------------
|
rt300@24
|
186 void testApp::lockSynthPressed(bool locked){
|
rt300@24
|
187 theGridView.shiftCentreToSnapped();
|
rt300@24
|
188 yLocked = locked;
|
rt300@25
|
189 eventLogger.logEvent(SYNTH_LOCKED);
|
rt300@24
|
190
|
rt300@24
|
191 }
|
rt300@24
|
192 //--------------------------------------------------------------
|
rt300@24
|
193 void testApp::seqStartStop(bool go){
|
rt300@24
|
194 if(!go){ //stop
|
rt300@24
|
195 core.pd.startMessage();
|
rt300@24
|
196 core.pd.addFloat(0);
|
rt300@24
|
197 core.pd.finishMessage("fromOF", "seqStartStop");
|
rt300@25
|
198 eventLogger.logEvent(PAUSE_PRESSED);
|
rt300@24
|
199 }else { // play
|
rt300@24
|
200 //stopSequencer();
|
rt300@24
|
201 core.pd.startMessage();
|
rt300@24
|
202 core.pd.addFloat(1);
|
rt300@24
|
203 core.pd.finishMessage("fromOF", "seqStartStop");
|
rt300@25
|
204 eventLogger.logEvent(PLAY_PRESSED);
|
rt300@24
|
205 }
|
rt300@24
|
206 }
|
rt300@24
|
207 //--------------------------------------------------------------
|
rt300@24
|
208 void testApp::showQuestionnaire(){
|
rt300@24
|
209 // stop updating / drawing
|
rt300@37
|
210
|
rt300@24
|
211 // if(eventLogger.questionnaireCompleted) return;
|
rt300@37
|
212
|
rt300@27
|
213 [topButtonViewController pausePressed:(id)this];
|
rt300@24
|
214
|
rt300@24
|
215 //stopSequencer
|
rt300@27
|
216 seqStartStop(false);
|
rt300@24
|
217
|
rt300@24
|
218 questionnaireViewController = [[QuestionnaireViewController alloc] initWithNibName:@"QuestionnaireViewController" bundle:nil];
|
rt300@24
|
219 [ofxiPhoneGetGLParentView() addSubview:questionnaireViewController.view];
|
rt300@24
|
220
|
rt300@24
|
221 [questionnaireViewController setAppRef:(id)this];
|
rt300@24
|
222 [questionnaireViewController show:(id)this];
|
rt300@24
|
223
|
rt300@24
|
224 whichInterfaceShowing = QUESTIONNAIRE;
|
rt300@24
|
225
|
rt300@37
|
226
|
rt300@24
|
227 }
|
rt300@24
|
228 //--------------------------------------------------------------
|
rt300@28
|
229 void testApp::questionnaireHidden(vector<int> answers, const char* userComments){
|
rt300@24
|
230 // send answers to server as json
|
rt300@28
|
231 eventLogger.questionnaireAnswersObtained(answers, userComments);
|
rt300@37
|
232
|
rt300@32
|
233 // tell bottomtabviewcontroller to show and select both interface
|
rt300@38
|
234 interfaceSelected(1);
|
rt300@32
|
235 [bottomTabViewController show:(id)this withSelection:1];
|
rt300@24
|
236
|
rt300@38
|
237 [topButtonViewController enableSmoothSwitch:(id)this];
|
rt300@37
|
238
|
rt300@24
|
239 }
|
rt300@24
|
240 //--------------------------------------------------------------
|
rt300@33
|
241 // shortcut function for testing
|
rt300@33
|
242 void testApp::justStart(){
|
rt300@38
|
243 interfaceSelected(1);
|
rt300@33
|
244 [bottomTabViewController show:(id)this withSelection:1];
|
rt300@38
|
245 [topButtonViewController enableSmoothSwitch:(id)this];
|
rt300@38
|
246 }
|
rt300@38
|
247 //--------------------------------------------------------------
|
rt300@38
|
248 void testApp::setInterp(int state){
|
rt300@38
|
249 if(state == 0){
|
rt300@38
|
250 theGridView.setInterpolation(Grid::NO_INTERPOLATION);
|
rt300@38
|
251 }else if(state == 1){
|
rt300@38
|
252 theGridView.setInterpolation(Grid::INTERPOLATE_GRID);
|
rt300@38
|
253 }
|
rt300@38
|
254 // tell sliders and PD
|
rt300@38
|
255 setAllGUISliders(theGridView.getParams());
|
rt300@38
|
256 sendParametersToPD();
|
rt300@33
|
257 }
|
rt300@33
|
258 //--------------------------------------------------------------
|
rt300@24
|
259 void testApp::showIntro(){
|
rt300@37
|
260
|
rt300@24
|
261 cout << "SHOW INTRO\n";
|
rt300@37
|
262
|
rt300@29
|
263 [tsc cancelTimers];
|
rt300@29
|
264 bottomTabViewController.view.hidden = YES;
|
rt300@24
|
265 introViewController = [[IntroViewController alloc] initWithNibName:@"IntroViewController" bundle:nil];
|
rt300@24
|
266 [ofxiPhoneGetGLParentView() addSubview:introViewController.view];
|
rt300@24
|
267
|
rt300@24
|
268 [introViewController setAppRef:(id)this];
|
rt300@24
|
269 [introViewController show:(id)this];
|
rt300@24
|
270
|
rt300@24
|
271
|
rt300@24
|
272 whichInterfaceShowing = INTRO;
|
rt300@24
|
273
|
rt300@24
|
274 }
|
rt300@24
|
275 //--------------------------------------------------------------
|
rt300@24
|
276 void testApp::introHidden(bool OK){
|
rt300@24
|
277 if(OK){
|
rt300@25
|
278 eventLogger.consentGiven = true;
|
rt300@29
|
279 //
|
rt300@29
|
280 // clear presets?
|
rt300@29
|
281 presetManager.clearAll();
|
rt300@25
|
282 // show username prompt
|
rt300@25
|
283 [usernameAlertViewController showUserNamePrompt];
|
rt300@32
|
284 // reset top buttons
|
rt300@32
|
285 [topButtonViewController unlockAll];
|
rt300@32
|
286 randomise();
|
rt300@24
|
287 }
|
rt300@24
|
288 // no unOK
|
rt300@24
|
289 }
|
rt300@24
|
290 //--------------------------------------------------------------
|
rt300@24
|
291 // called from BottomTabViewController iOS segmented thing
|
rt300@24
|
292 void testApp::interfaceSelected(int which){
|
rt300@24
|
293 switch (which){
|
rt300@24
|
294 case 0:
|
rt300@37
|
295
|
rt300@24
|
296 whichInterfaceShowing = SLIDERS;
|
rt300@24
|
297 sliderGUI->setVisible(true);
|
rt300@24
|
298 // set the slider values to stuff got from zoomer
|
rt300@24
|
299 sliderVals = theGridView.getParams();
|
rt300@24
|
300 setAllGUISliders(sliderVals);
|
rt300@25
|
301
|
rt300@24
|
302 break;
|
rt300@24
|
303 case 1:
|
rt300@37
|
304
|
rt300@24
|
305 whichInterfaceShowing = BOTH;
|
rt300@24
|
306 sliderGUI->setVisible(true);
|
rt300@24
|
307 // set the slider values to stuff got from zoomer
|
rt300@24
|
308 sliderVals = theGridView.getParams();
|
rt300@24
|
309 setAllGUISliders(sliderVals);
|
rt300@24
|
310 break;
|
rt300@24
|
311 case 2:
|
rt300@37
|
312
|
rt300@24
|
313 sliderGUI->setVisible(false);
|
rt300@24
|
314 whichInterfaceShowing = ZOOMER;
|
rt300@24
|
315 break;
|
rt300@24
|
316 }
|
rt300@25
|
317 eventLogger.logEvent(SWAP_VIEW,TwoVector(),0.0, which);
|
rt300@24
|
318 }
|
rt300@24
|
319 //--------------------------------------------------------------
|
rt300@24
|
320 //--------------------------------------------------------------
|
rt300@24
|
321 void testApp::setupSliderGui(){
|
rt300@24
|
322 float xInit = OFX_UI_GLOBAL_WIDGET_SPACING;
|
rt300@24
|
323 float length = SLIDER_GUI_WIDTH - (OFX_UI_GLOBAL_WIDGET_SPACING*2);
|
rt300@24
|
324
|
rt300@24
|
325
|
rt300@24
|
326 //float dim = 42;
|
rt300@24
|
327
|
rt300@24
|
328 // make this iphone size...?
|
rt300@24
|
329 int height = 480;
|
rt300@24
|
330 int width = 320;
|
rt300@24
|
331 float dim = (height-10.0*OFX_UI_GLOBAL_WIDGET_SPACING)/10.0;
|
rt300@24
|
332 // LEFT GUI
|
rt300@30
|
333 sliderGUI = new ofxUICanvas(0,160,SLIDER_GUI_WIDTH,getHeight());
|
rt300@37
|
334
|
rt300@24
|
335 // Uh.. loop this
|
rt300@24
|
336 for(int i = 1; i<=10;i++){
|
rt300@37
|
337
|
rt300@24
|
338 ofxUISlider *slider;
|
rt300@25
|
339 slider = (ofxUISlider *)sliderGUI->addWidgetDown(new ofxUISlider(length,dim,0.0,127,64,sliderParamNames[i-1]));
|
rt300@24
|
340 slider->setDrawPadding(true);
|
rt300@28
|
341 slider->setDrawPaddingOutline(true);
|
rt300@24
|
342 if(i <= 5){
|
rt300@24
|
343 slider->setColorFill(ofColor(0,0,255));
|
rt300@24
|
344 slider->setColorFillHighlight(ofColor(0,0,255));
|
rt300@24
|
345 }else{
|
rt300@24
|
346 slider->setColorFill(ofColor(255,0,0));
|
rt300@24
|
347 slider->setColorFillHighlight(ofColor(255,0,0));
|
rt300@24
|
348 }
|
rt300@24
|
349
|
rt300@24
|
350 sliders.push_back(slider);
|
rt300@24
|
351 }
|
rt300@24
|
352
|
rt300@37
|
353
|
rt300@24
|
354
|
rt300@24
|
355 ofAddListener(sliderGUI->newGUIEvent, this, &testApp::sliderGUIEvent);
|
rt300@37
|
356
|
rt300@24
|
357 }
|
rt300@24
|
358 //--------------------------------------------------------------
|
rt300@24
|
359 void testApp::sliderGUIEvent(ofxUIEventArgs &e){
|
rt300@24
|
360 if(whichInterfaceShowing == ZOOMER){
|
rt300@24
|
361 cout << "GUI ERROR";
|
rt300@24
|
362 return;
|
rt300@24
|
363 }
|
rt300@37
|
364
|
rt300@0
|
365 // "normal" parameter changes
|
rt300@0
|
366 for(int i = 1; i<=10;i++){
|
rt300@0
|
367
|
rt300@24
|
368 if(e.widget->getName() == sliderParamNames[i-1])
|
rt300@0
|
369 {
|
rt300@0
|
370 //cout << "param change: " << p;
|
rt300@0
|
371 ofxUISlider *slider = (ofxUISlider *) e.widget;
|
rt300@3
|
372 sliderMoved(i-1,slider->getScaledValue()); // internal array 0 indexed
|
rt300@0
|
373 }
|
rt300@0
|
374 }
|
rt300@37
|
375
|
rt300@0
|
376 }
|
rt300@0
|
377 //--------------------------------------------------------------
|
rt300@3
|
378 void testApp::sliderMoved(int which, float value){
|
rt300@3
|
379 // an update caused by slider view being touched
|
rt300@0
|
380 sliderVals[which] = (int)value;
|
rt300@0
|
381 theGridView.setParams(sliderVals);
|
rt300@37
|
382
|
rt300@3
|
383 sendParametersToPD();
|
rt300@5
|
384
|
rt300@9
|
385 eventLogger.logEvent(CHANGE_SLIDER, TwoVector(),0.0,which , value);
|
rt300@5
|
386
|
rt300@0
|
387 }
|
rt300@0
|
388 //--------------------------------------------------------------
|
rt300@3
|
389 void testApp::setAllGUISliders(vector<int> vals){
|
rt300@3
|
390 // an update caused by zoomer view being moved
|
rt300@25
|
391 for(int i = 0; i<NUM_PARAMS;i++){
|
rt300@0
|
392 sliders[i]->setValue(vals[i]);
|
rt300@1
|
393 sliderVals[i] = vals[i];
|
rt300@0
|
394 }
|
rt300@3
|
395
|
rt300@0
|
396 }
|
rt300@0
|
397 //--------------------------------------------------------------
|
rt300@25
|
398 void testApp::randomise(){
|
rt300@25
|
399 // pick random settings for all params
|
rt300@25
|
400 for(int i=0; i < NUM_PARAMS ; i++){
|
rt300@25
|
401 sliderVals[i] = ofRandom(0, 127);
|
rt300@25
|
402
|
rt300@25
|
403 }
|
rt300@37
|
404 currentSequence = ofRandom(0, sequences.size()-1);
|
rt300@25
|
405 // send to grid, sliders and PD
|
rt300@25
|
406 theGridView.setParams(sliderVals);
|
rt300@25
|
407 setAllGUISliders(sliderVals);
|
rt300@25
|
408 sendParametersToPD();
|
rt300@25
|
409
|
rt300@25
|
410 eventLogger.logEvent(RANDOMISE, theGridView.getCoord() ,0.0);
|
rt300@25
|
411
|
rt300@25
|
412 }
|
rt300@27
|
413 //-
|
rt300@27
|
414 void testApp::showHelp(){
|
rt300@29
|
415 whichInterfaceShowing = HELP;
|
rt300@27
|
416 seqStartStop(false);
|
rt300@27
|
417 [topButtonViewController pausePressed:(id)this];
|
rt300@27
|
418 helpViewController.view.hidden = NO;
|
rt300@27
|
419 eventLogger.logEvent(HELP_PRESSED);
|
rt300@27
|
420 }
|
rt300@27
|
421 void testApp::helpHidden(){
|
rt300@29
|
422 whichInterfaceShowing = BOTH;
|
rt300@27
|
423 // start seq?
|
rt300@27
|
424
|
rt300@27
|
425 }
|
rt300@25
|
426 //--------------------------------------------------------------
|
rt300@36
|
427 void testApp::nextSequence(){
|
rt300@36
|
428 currentSequence++;
|
rt300@36
|
429 if(currentSequence >= sequences.size()){
|
rt300@36
|
430 currentSequence = 0;
|
rt300@36
|
431 }
|
rt300@36
|
432 sendParametersToPD();
|
rt300@36
|
433 }
|
rt300@36
|
434 //--------------------------------------------------------------
|
rt300@3
|
435 void testApp::sendParametersToPD(){
|
rt300@37
|
436 static int previousSequence;
|
rt300@37
|
437 // frequencer stuff to get 16 steps
|
rt300@36
|
438
|
rt300@37
|
439 vector<double> vals;
|
rt300@37
|
440
|
rt300@37
|
441
|
rt300@37
|
442 vals.push_back((sliderVals[0]+32)*8.); // DC offset
|
rt300@37
|
443 for(int i=1; i<5;i++){
|
rt300@37
|
444 vals.push_back((sliderVals[i] - 64)*2.);
|
rt300@37
|
445 }
|
rt300@37
|
446
|
rt300@37
|
447 vector<double> steps = frequencer.freqMagEdit(freqIndexes, vals);
|
rt300@37
|
448 List seqSteps;
|
rt300@37
|
449 seqSteps.addSymbol("seqSteps");
|
rt300@37
|
450 for(int i=0; i < 16; i++){
|
rt300@37
|
451 seqSteps.addFloat(round(steps[i]));
|
rt300@37
|
452 }
|
rt300@37
|
453 core.pd.sendList("fromOF", seqSteps);
|
rt300@37
|
454
|
rt300@36
|
455 /*
|
rt300@37
|
456 if(currentSequence != previousSequence){
|
rt300@37
|
457 List seqSteps;
|
rt300@37
|
458
|
rt300@37
|
459 seqSteps.addSymbol("seqSteps");
|
rt300@37
|
460 if(currentSequence >= sequences.size() || currentSequence < 0){
|
rt300@37
|
461 cout << "ERROR: not a valid sequence index\n";
|
rt300@37
|
462 for(int i=0; i < 16; i++){
|
rt300@37
|
463 seqSteps.addFloat(50);
|
rt300@37
|
464 }
|
rt300@37
|
465 }else{
|
rt300@37
|
466 for(int i=0; i < 16; i++){
|
rt300@37
|
467 seqSteps.addFloat(round(sequences[currentSequence][i]));
|
rt300@37
|
468 }
|
rt300@37
|
469 }
|
rt300@37
|
470
|
rt300@37
|
471 core.pd.sendList("fromOF", seqSteps);
|
rt300@37
|
472 previousSequence = currentSequence;
|
rt300@3
|
473 }
|
rt300@36
|
474 */
|
rt300@36
|
475
|
rt300@37
|
476 // send synth params
|
rt300@3
|
477 sendOscShape(sliderVals[5]);
|
rt300@3
|
478 sendFiltType(sliderVals[6]);
|
rt300@3
|
479 sendFiltFreq(sliderVals[7]);
|
rt300@3
|
480 sendEnvShape(sliderVals[8]);
|
rt300@3
|
481 sendModFreq(sliderVals[9]);
|
rt300@3
|
482
|
rt300@3
|
483 }
|
rt300@27
|
484 void testApp::setupNewUser(){
|
rt300@27
|
485 // this function is for supervised trials with my ipad
|
rt300@27
|
486 eventLogger.newUser();
|
rt300@27
|
487 }
|
rt300@8
|
488 //--------------------------------------------------------------
|
rt300@3
|
489 #pragma mark STANDARD OF FUNCTIONS
|
rt300@3
|
490 //--------------------------------------------------------------
|
rt300@0
|
491 void testApp::update(){
|
rt300@37
|
492
|
rt300@16
|
493 if(paused) return;
|
rt300@16
|
494
|
rt300@32
|
495 if(ofxiPhoneExternalDisplay::isExternalScreenConnected()){
|
rt300@32
|
496 if(!ofxiPhoneExternalDisplay::isMirroring()){
|
rt300@32
|
497 ofxiPhoneExternalDisplay::mirrorOn();
|
rt300@32
|
498 printf("turned on Mirroring!\n");
|
rt300@32
|
499 }
|
rt300@32
|
500 }
|
rt300@32
|
501
|
rt300@27
|
502 // continiue to move or zoom at velocity, unless snapped
|
rt300@3
|
503
|
rt300@3
|
504 if (numActiveTouches == 0){ // no touches, use momentum
|
rt300@32
|
505 // ZOOM MOMENTUM
|
rt300@32
|
506 // continiue to zoom at velocity
|
rt300@32
|
507 if (numActiveTouches < 2 && abs(zoomVel)>0.001){
|
rt300@32
|
508 theGridView.zoom(zoomVel + 1.0); // +1 because zoomVel factor is + or - , wheras zoom is a multiplier near 1
|
rt300@32
|
509 zoomVel = zoomVel*slowFactor;
|
rt300@32
|
510 moveVel.setCoord(0.0,0.0);; // don't move if zooming! Too many events!
|
rt300@35
|
511
|
rt300@37
|
512 setAllGUISliders(theGridView.getParams());
|
rt300@37
|
513 sendParametersToPD();
|
rt300@32
|
514 }
|
rt300@32
|
515
|
rt300@22
|
516 if(moveVel.norm() > 0.3){
|
rt300@22
|
517 if(theGridView.snapped){
|
rt300@28
|
518 // stop it (snap check sends snap event)
|
rt300@22
|
519 moveVel.setCoord(0.0,0.0);
|
rt300@22
|
520 }else{
|
rt300@22
|
521 theGridView.move(moveVel);
|
rt300@22
|
522 moveVel = moveVel*slowFactor;
|
rt300@22
|
523 }
|
rt300@37
|
524 // and get new parameter values
|
rt300@5
|
525 setAllGUISliders(theGridView.getParams());
|
rt300@3
|
526 sendParametersToPD();
|
rt300@22
|
527 }else if(moveVel.norm() > 0.01){ // and less than 0.3
|
rt300@3
|
528 // stop it
|
rt300@3
|
529 moveVel.setCoord(0.0,0.0);
|
rt300@5
|
530 setAllGUISliders(theGridView.getParams());
|
rt300@3
|
531 sendParametersToPD();
|
rt300@5
|
532 eventLogger.logEvent(SCROLL_STOPPED, theGridView.getCoord() );
|
rt300@22
|
533
|
rt300@3
|
534 }else{
|
rt300@3
|
535 // stopped - do nothing
|
rt300@3
|
536 }
|
rt300@37
|
537
|
rt300@0
|
538 }
|
rt300@37
|
539
|
rt300@0
|
540 }
|
rt300@0
|
541 //--------------------------------------------------------------
|
rt300@0
|
542 void testApp::sendOSCParams(){
|
rt300@0
|
543
|
rt300@0
|
544 vector<int> params = theGridView.getParams(); // FILTER HERE? NEED FLOATS...
|
rt300@0
|
545 vector<int>::iterator iter = params.begin();
|
rt300@0
|
546
|
rt300@0
|
547 ofxOscMessage m;
|
rt300@0
|
548 m.setAddress( "p" );
|
rt300@0
|
549
|
rt300@0
|
550 for(;iter < params.end();iter++){
|
rt300@0
|
551
|
rt300@0
|
552 m.addFloatArg( *iter );
|
rt300@0
|
553
|
rt300@0
|
554 }
|
rt300@0
|
555 sender.sendMessage( m );
|
rt300@0
|
556 }
|
rt300@0
|
557 //--------------------------------------------------------------
|
rt300@0
|
558 void testApp::draw(){
|
rt300@37
|
559
|
rt300@24
|
560 switch (whichInterfaceShowing){
|
rt300@24
|
561 case SLIDERS:
|
rt300@24
|
562 break;
|
rt300@24
|
563 case ZOOMER:
|
rt300@24
|
564 theGridView.draw();
|
rt300@37
|
565
|
rt300@24
|
566 break;
|
rt300@24
|
567 case BOTH:
|
rt300@33
|
568
|
rt300@33
|
569 theGridView.draw();
|
rt300@37
|
570
|
rt300@24
|
571 break;
|
rt300@24
|
572 case INTRO:
|
rt300@24
|
573 break;
|
rt300@24
|
574
|
rt300@24
|
575 case QUESTIONNAIRE:
|
rt300@24
|
576 break;
|
rt300@24
|
577
|
rt300@0
|
578 }
|
rt300@4
|
579
|
rt300@0
|
580 }
|
rt300@0
|
581
|
rt300@0
|
582 //--------------------------------------------------------------
|
rt300@0
|
583 void testApp::touchDown(ofTouchEventArgs &touch){
|
rt300@27
|
584 // in slider gui area?
|
rt300@24
|
585 if(whichInterfaceShowing == SLIDERS){
|
rt300@24
|
586 return;
|
rt300@24
|
587 }else if (whichInterfaceShowing == BOTH && touch.x < (SLIDER_GUI_WIDTH+10)){
|
rt300@24
|
588 return;
|
rt300@24
|
589
|
rt300@24
|
590 }// otherwise we're good to let the zoomer handle touch
|
rt300@0
|
591
|
rt300@0
|
592 numActiveTouches++;
|
rt300@27
|
593 preventingMovePostScroll = false;
|
rt300@37
|
594
|
rt300@0
|
595 if(touch.id == 0){
|
rt300@0
|
596 touch0.setCoord(touch.x,touch.y);
|
rt300@0
|
597 prevTouch0 = touch0;
|
rt300@32
|
598 // stop zoom
|
rt300@32
|
599 zoomVel = 0.0;
|
rt300@0
|
600 }else if(touch.id == 1){
|
rt300@0
|
601
|
rt300@0
|
602 touch1.setCoord(touch.x,touch.y);
|
rt300@0
|
603 prevTouch1 = touch1;
|
rt300@0
|
604
|
rt300@0
|
605 }
|
rt300@0
|
606 if(numActiveTouches == 1){
|
rt300@0
|
607 moveVel.setCoord(0.0, 0.0);
|
rt300@0
|
608 prevMove.setCoord(0.0, 0.0);
|
rt300@0
|
609 prevMove2.setCoord(0.0, 0.0);
|
rt300@27
|
610
|
rt300@0
|
611 }else if(numActiveTouches == 2){
|
rt300@0
|
612 zoomVel = 0.0;
|
rt300@0
|
613 prevZoom = 0.0;
|
rt300@0
|
614 prevZoom2 = 0.0;
|
rt300@0
|
615 double dist = touch1.distanceTo(touch0);
|
rt300@0
|
616 prevDist = dist;
|
rt300@0
|
617 }
|
rt300@37
|
618
|
rt300@0
|
619 }
|
rt300@0
|
620
|
rt300@0
|
621 //--------------------------------------------------------------
|
rt300@0
|
622 void testApp::touchMoved(ofTouchEventArgs &touch){
|
rt300@1
|
623
|
rt300@24
|
624 // TODO check if in gui area!!!
|
rt300@24
|
625 if(whichInterfaceShowing == SLIDERS){
|
rt300@24
|
626 return;
|
rt300@24
|
627 }else if (whichInterfaceShowing == BOTH && touch.x < (SLIDER_GUI_WIDTH+10)){
|
rt300@24
|
628 return;
|
rt300@24
|
629
|
rt300@27
|
630 }
|
rt300@24
|
631
|
rt300@27
|
632 // otherwise we're good to let the zoomer handle touch
|
rt300@37
|
633
|
rt300@1
|
634 // which one? keep track of each touch point
|
rt300@0
|
635 if(touch.id == 0){
|
rt300@0
|
636 touch0.setCoord(touch.x,touch.y);
|
rt300@0
|
637
|
rt300@0
|
638 }else if(touch.id == 1){
|
rt300@0
|
639
|
rt300@0
|
640 touch1.setCoord(touch.x,touch.y);
|
rt300@0
|
641 }
|
rt300@37
|
642
|
rt300@1
|
643 if(numActiveTouches == 1){
|
rt300@27
|
644 if(preventingMovePostScroll) return;
|
rt300@1
|
645 handleScroll();
|
rt300@0
|
646 }else if(numActiveTouches == 2){
|
rt300@1
|
647 handleZoom();
|
rt300@0
|
648
|
rt300@0
|
649 }
|
rt300@0
|
650 prevTouch0 = touch0;
|
rt300@37
|
651
|
rt300@0
|
652
|
rt300@0
|
653 }
|
rt300@5
|
654
|
rt300@1
|
655 //--------------------------------------------------------------
|
rt300@27
|
656 // handle a finger being dragged
|
rt300@1
|
657 void testApp::handleScroll(){
|
rt300@37
|
658
|
rt300@1
|
659 TwoVector move = touch0 - prevTouch0;
|
rt300@5
|
660 if(yLocked){
|
rt300@5
|
661 move.y = 0.0;
|
rt300@5
|
662 }
|
rt300@5
|
663 if(xLocked){
|
rt300@5
|
664 move.x = 0.0;
|
rt300@5
|
665 }
|
rt300@37
|
666
|
rt300@6
|
667 // check time since last move - if
|
rt300@6
|
668 unsigned int moveTime = ofGetSystemTimeMicros();
|
rt300@6
|
669 if(moveTime - lastMoveTime > 100000){
|
rt300@6
|
670 moveVel = TwoVector(); // zero
|
rt300@6
|
671 }else{
|
rt300@6
|
672 moveVel = (move*0.3 + prevMove*0.34 + prevMove2*0.38); // use the time
|
rt300@6
|
673
|
rt300@6
|
674 }
|
rt300@6
|
675 lastMoveTime = moveTime;
|
rt300@6
|
676
|
rt300@37
|
677
|
rt300@1
|
678 prevMove2 = prevMove;
|
rt300@1
|
679 prevMove = move;
|
rt300@1
|
680
|
rt300@37
|
681
|
rt300@3
|
682 theGridView.move(move);
|
rt300@3
|
683
|
rt300@3
|
684 // and get new parameter values
|
rt300@3
|
685 setAllGUISliders(theGridView.getParams());
|
rt300@3
|
686 sendParametersToPD();
|
rt300@1
|
687 }
|
rt300@1
|
688 //--------------------------------------------------------------
|
rt300@27
|
689 // handle pinch movememnt
|
rt300@1
|
690 void testApp::handleZoom(){
|
rt300@1
|
691 // work out change in difference
|
rt300@1
|
692 double dist = touch1.distanceTo(touch0);
|
rt300@1
|
693 double zoomFactor = prevDist/dist;
|
rt300@1
|
694
|
rt300@1
|
695 //TODO check for sensible maximums, e.g. spurious touch data
|
rt300@1
|
696 if(zoomFactor > 2.0 || zoomFactor < 0.5){
|
rt300@1
|
697 cout << "Zoom too much!!!!" << zoomFactor;
|
rt300@1
|
698 zoomFactor = 1.0;
|
rt300@1
|
699 }
|
rt300@1
|
700
|
rt300@1
|
701 zoomVel = (zoomFactor-1)*0.3 + prevZoom*0.34 + prevZoom2*0.38;
|
rt300@1
|
702 prevZoom2 = prevZoom;
|
rt300@1
|
703 prevZoom = (zoomFactor-1);
|
rt300@1
|
704
|
rt300@1
|
705 theGridView.zoom(zoomFactor);
|
rt300@1
|
706
|
rt300@1
|
707 prevDist = dist;
|
rt300@35
|
708
|
rt300@3
|
709
|
rt300@37
|
710 setAllGUISliders(theGridView.getParams());
|
rt300@37
|
711 sendParametersToPD();
|
rt300@37
|
712
|
rt300@37
|
713
|
rt300@1
|
714 }
|
rt300@0
|
715 //--------------------------------------------------------------
|
rt300@0
|
716 void testApp::touchUp(ofTouchEventArgs &touch){
|
rt300@1
|
717 if(numActiveTouches > 0) numActiveTouches--; // dirty
|
rt300@27
|
718 preventingMovePostScroll = false;
|
rt300@24
|
719 // TODO check if in gui area!!!
|
rt300@24
|
720 if(whichInterfaceShowing == SLIDERS){
|
rt300@24
|
721 return;
|
rt300@24
|
722 }else if (whichInterfaceShowing == BOTH && touch.x < 256){
|
rt300@24
|
723 return;
|
rt300@1
|
724
|
rt300@24
|
725 }// otherwise we're good to let the zoomer handle touch
|
rt300@24
|
726
|
rt300@37
|
727
|
rt300@0
|
728 // which one?
|
rt300@0
|
729 if(touch.id == 0){
|
rt300@0
|
730 // tricky situation - we tried to zoom but may have left non-move finger on
|
rt300@0
|
731 prevTouch0.setCoord(touch.x,touch.y);
|
rt300@0
|
732
|
rt300@0
|
733 }else if(touch.id == 1){
|
rt300@0
|
734
|
rt300@37
|
735
|
rt300@0
|
736 prevTouch1.setCoord(0,0);
|
rt300@6
|
737
|
rt300@6
|
738 }
|
rt300@6
|
739 if(numActiveTouches == 0){
|
rt300@6
|
740 // check time since last move
|
rt300@6
|
741 // check time since last move - if
|
rt300@6
|
742 unsigned int moveTime = ofGetSystemTimeMicros();
|
rt300@6
|
743 if(moveTime - lastMoveTime > 100000){
|
rt300@6
|
744 moveVel = TwoVector(); // zero
|
rt300@6
|
745 }else{
|
rt300@6
|
746 moveVel = (move*0.3 + prevMove*0.34 + prevMove2*0.38); // use the time
|
rt300@6
|
747
|
rt300@6
|
748 }
|
rt300@6
|
749 lastMoveTime = moveTime;
|
rt300@27
|
750 }else if (numActiveTouches == 1){
|
rt300@27
|
751 // just zoomed , but now lifted one of the fingers
|
rt300@27
|
752 // can be bad if moved so create special mode to stop scroll (special modes bad!)
|
rt300@27
|
753 preventingMovePostScroll = true;
|
rt300@0
|
754 }
|
rt300@37
|
755
|
rt300@0
|
756 }
|
rt300@0
|
757
|
rt300@0
|
758 //--------------------------------------------------------------
|
rt300@0
|
759 void testApp::touchDoubleTap(ofTouchEventArgs &touch){
|
rt300@0
|
760 // preset?
|
rt300@25
|
761
|
rt300@25
|
762 /* ballses everything for some reason
|
rt300@37
|
763 TwoVector centre = TwoVector(getWidth()*0.5,getHeight()*0.5);
|
rt300@37
|
764 // if near centre
|
rt300@37
|
765 if((touch.x < centre.x+10) && (touch.x > centre.x-10) && (touch.y < centre.y+10) && (touch.y > centre.y-10)){
|
rt300@37
|
766 numActiveTouches = 0; // dirty
|
rt300@37
|
767 presetManager.showNameDialog();
|
rt300@37
|
768
|
rt300@37
|
769 }
|
rt300@25
|
770 */
|
rt300@25
|
771
|
rt300@0
|
772 }
|
rt300@0
|
773
|
rt300@0
|
774 //--------------------------------------------------------------
|
rt300@0
|
775 void testApp::lostFocus(){
|
rt300@37
|
776
|
rt300@0
|
777 }
|
rt300@0
|
778
|
rt300@0
|
779 //--------------------------------------------------------------
|
rt300@0
|
780 void testApp::gotFocus(){
|
rt300@37
|
781
|
rt300@0
|
782 }
|
rt300@0
|
783
|
rt300@0
|
784 //--------------------------------------------------------------
|
rt300@0
|
785 void testApp::gotMemoryWarning(){
|
rt300@37
|
786
|
rt300@0
|
787 }
|
rt300@0
|
788
|
rt300@0
|
789 //--------------------------------------------------------------
|
rt300@0
|
790 void testApp::deviceOrientationChanged(int newOrientation){
|
rt300@37
|
791 /*
|
rt300@37
|
792 cout << "orientation: " << newOrientation;
|
rt300@37
|
793
|
rt300@37
|
794 if(newOrientation == 4){
|
rt300@37
|
795 ofxiPhoneSetOrientation( OF_ORIENTATION_DEFAULT );
|
rt300@37
|
796
|
rt300@37
|
797 }else if(newOrientation == 3){
|
rt300@37
|
798 ofxiPhoneSetOrientation( OF_ORIENTATION_90_LEFT );
|
rt300@37
|
799 }else if(newOrientation == 3){
|
rt300@37
|
800 ofxiPhoneSetOrientation( OF_ORIENTATION_90_LEFT );
|
rt300@37
|
801 }
|
rt300@37
|
802
|
rt300@37
|
803
|
rt300@37
|
804 [ofxiPhoneGetGLView() updateDimensions];
|
rt300@37
|
805 */
|
rt300@0
|
806 }
|
rt300@0
|
807
|
rt300@0
|
808
|
rt300@0
|
809 //--------------------------------------------------------------
|
rt300@0
|
810 void testApp::touchCancelled(ofTouchEventArgs& args){
|
rt300@37
|
811
|
rt300@0
|
812 }
|
rt300@3
|
813 //---------------------------------------------------------------
|
rt300@3
|
814 // AUDIO STUFF
|
rt300@3
|
815 //---------------------------------------------------------------
|
rt300@3
|
816
|
rt300@3
|
817 #pragma mark AUDIO STREAMS
|
rt300@3
|
818 //--------------------------------------------------------------
|
rt300@3
|
819 void testApp::audioReceived(float * input, int bufferSize, int nChannels) {
|
rt300@3
|
820 core.audioReceived(input, bufferSize, nChannels);
|
rt300@3
|
821 }
|
rt300@3
|
822
|
rt300@3
|
823 void testApp::audioRequested(float * output, int bufferSize, int nChannels) {
|
rt300@3
|
824 core.audioRequested(output, bufferSize, nChannels);
|
rt300@3
|
825 }
|
rt300@3
|
826 //---------------------------------------------------------------
|
rt300@3
|
827 #pragma mark UTILITIES
|
rt300@0
|
828
|
rt300@0
|
829 // 5hz cut off
|
rt300@0
|
830 const double fB[3] = {0.049489956268677, 0.098979912537354, 0.049489956268677};
|
rt300@0
|
831
|
rt300@0
|
832 const double fA[3] = {1.000000000000000, -1.279632424997809, 0.477592250072517};
|
rt300@0
|
833
|
rt300@0
|
834 // 1hz cut off
|
rt300@0
|
835 //const double fB[3] = {0.002550535158536, 0.005101070317073, 0.002550535158536};
|
rt300@0
|
836
|
rt300@0
|
837 //const double fA[3] = {1.000000000000000, -1.852146485395936, 0.862348626030081};
|
rt300@0
|
838
|
rt300@0
|
839
|
rt300@0
|
840 //a(1)*y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb)- a(2)*y(n-1) - ... - a(na+1)*y(n-na)
|
rt300@0
|
841 //---------------------------------------------------------------
|
rt300@0
|
842 vector<float> testApp::vectorFilter(vector<float> newVec){
|
rt300@0
|
843 static vector<float> x0(10,0);
|
rt300@0
|
844 static vector<float> x1(10,0);
|
rt300@0
|
845 static vector<float> x2(10,0);
|
rt300@0
|
846 static vector<float> y0(10,0);
|
rt300@0
|
847 static vector<float> y1(10,0);
|
rt300@0
|
848 static vector<float> y2(10,0);
|
rt300@0
|
849
|
rt300@0
|
850 x0 = newVec;
|
rt300@0
|
851
|
rt300@0
|
852 // this low passes a bunch of params values all at once
|
rt300@0
|
853 int sz = newVec.size();
|
rt300@0
|
854 for(int i=0; i<sz; i++){
|
rt300@0
|
855 y0[i] = fB[0]*x0[i] + fB[1]*x1[i] + fB[2]*x2[i] - fA[1]*y1[i] - fA[2]*y2[i];
|
rt300@0
|
856 }
|
rt300@0
|
857 // shift
|
rt300@0
|
858 x2 = x1;
|
rt300@0
|
859 x1 = x0;
|
rt300@0
|
860 y2 = y1;
|
rt300@0
|
861 y1 = y0;
|
rt300@0
|
862
|
rt300@0
|
863 return y0;
|
rt300@2
|
864 }
|
rt300@35
|
865 //---------------------------------------------------------------
|
rt300@24
|
866 float ctrlSmoother(float newsamp){
|
rt300@24
|
867 static float x1,x2,y1,y2;
|
rt300@24
|
868 float x0, y0;
|
rt300@37
|
869
|
rt300@24
|
870 x0 = newsamp;
|
rt300@37
|
871
|
rt300@24
|
872 y0 = fB[0]*x0 + fB[1]*x1 + fB[2]*x2 - fA[1]*y1 - fA[2]*y2;
|
rt300@37
|
873
|
rt300@24
|
874 // shift
|
rt300@24
|
875 x2 = x1;
|
rt300@24
|
876 x1 = x0;
|
rt300@24
|
877 y2 = y1;
|
rt300@24
|
878 y1 = y0;
|
rt300@24
|
879
|
rt300@24
|
880 return y0;
|
rt300@24
|
881 }
|
rt300@8
|
882 //---------------------------------------------------------------
|
rt300@3
|
883 void testApp::sendOscShape(int ctrlin){
|
rt300@35
|
884 if(ctrlin < 0 || ctrlin > 127){
|
rt300@35
|
885 cout << "ERROR: bad slider value!";
|
rt300@35
|
886 return;
|
rt300@35
|
887 }
|
rt300@3
|
888
|
rt300@3
|
889 static int numpoints = 5;
|
rt300@3
|
890 static int numcontrols = 5;
|
rt300@3
|
891 //float values[points][controls] =
|
rt300@3
|
892 float ctrlout[numcontrols];
|
rt300@3
|
893 string ctrlName[5] = {"pWidth" , "sqVol", "sawVol", "sineVol", "FMAmt"};
|
rt300@3
|
894 float values[5][5] =
|
rt300@37
|
895 {{0.5, 0., 0., 1., 1.}, // 0
|
rt300@37
|
896 {0.5, 0., 0., 1., 0.}, // 32
|
rt300@3
|
897 {0.5, 0., 1., 0., 0.}, // 64
|
rt300@3
|
898 {0.5, 1., 1., 0., 0.}, // 96
|
rt300@3
|
899 {0.01,1., 1., 0., 0.}}; // 127
|
rt300@37
|
900
|
rt300@3
|
901 float fidx = (numpoints-1)*ctrlin/128.;
|
rt300@3
|
902 int idx = floor(fidx);
|
rt300@3
|
903 float frac = fidx - idx;
|
rt300@3
|
904 for(int i=0; i < numcontrols; i++){
|
rt300@3
|
905 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
|
rt300@3
|
906 // send to PD
|
rt300@3
|
907 List toPD;
|
rt300@3
|
908
|
rt300@3
|
909 toPD.addSymbol(ctrlName[i]);
|
rt300@3
|
910 toPD.addFloat(ctrlout[i]); // rounding here??
|
rt300@37
|
911
|
rt300@3
|
912 core.pd.sendList("fromOF", toPD);
|
rt300@3
|
913 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
|
rt300@3
|
914 }
|
rt300@3
|
915
|
rt300@2
|
916 }
|
rt300@8
|
917 //---------------------------------------------------------------
|
rt300@3
|
918 void testApp::sendFiltType(int ctrlin){
|
rt300@35
|
919 if(ctrlin < 0 || ctrlin > 127){
|
rt300@35
|
920 cout << "ERROR: bad slider value!";
|
rt300@35
|
921 return;
|
rt300@35
|
922 }
|
rt300@3
|
923 static int numpoints = 3;
|
rt300@3
|
924 static int numcontrols = 4;
|
rt300@3
|
925 //float values[points][controls] =
|
rt300@3
|
926 float ctrlout[numcontrols];
|
rt300@3
|
927 string ctrlName[4] = {"lpLev" , "bpLev", "hpLev", "reson"};
|
rt300@3
|
928 float values[3][4] =
|
rt300@37
|
929 {{2., 0., 0., 1.}, // 0
|
rt300@24
|
930 {0., 10., 0., 10.}, // 64
|
rt300@24
|
931 {0., 0., 1., 1.}}; // 127
|
rt300@3
|
932
|
rt300@3
|
933 float fidx = (numpoints-1)*ctrlin/128.;
|
rt300@3
|
934 int idx = floor(fidx);
|
rt300@3
|
935 float frac = fidx - idx;
|
rt300@3
|
936 for(int i=0; i < numcontrols; i++){
|
rt300@3
|
937 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
|
rt300@3
|
938 // send to PD
|
rt300@3
|
939 List toPD;
|
rt300@3
|
940
|
rt300@3
|
941 toPD.addSymbol(ctrlName[i]);
|
rt300@3
|
942 toPD.addFloat(ctrlout[i]); // rounding here??
|
rt300@3
|
943
|
rt300@3
|
944 core.pd.sendList("fromOF", toPD);
|
rt300@3
|
945 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
|
rt300@3
|
946 }
|
rt300@2
|
947 }
|
rt300@8
|
948 //---------------------------------------------------------------
|
rt300@3
|
949 void testApp::sendFiltFreq(int ctrlin){
|
rt300@35
|
950 if(ctrlin < 0 || ctrlin > 127){
|
rt300@35
|
951 cout << "ERROR: bad slider value!";
|
rt300@35
|
952 return;
|
rt300@35
|
953 }
|
rt300@24
|
954 // smooth this
|
rt300@24
|
955 float fin = ctrlin;
|
rt300@24
|
956 float fout;
|
rt300@24
|
957 fout = (int)ctrlSmoother(fin);
|
rt300@3
|
958 List toPD;
|
rt300@3
|
959
|
rt300@3
|
960 toPD.addSymbol("filtFreq");
|
rt300@37
|
961 toPD.addFloat(fout);
|
rt300@3
|
962
|
rt300@3
|
963 core.pd.sendList("fromOF", toPD);
|
rt300@3
|
964 }
|
rt300@8
|
965 //---------------------------------------------------------------
|
rt300@3
|
966 void testApp::sendEnvShape(int ctrlin){
|
rt300@35
|
967 if(ctrlin < 0 || ctrlin > 127){
|
rt300@35
|
968 cout << "ERROR: bad slider value!";
|
rt300@35
|
969 return;
|
rt300@35
|
970 }
|
rt300@3
|
971 static int numpoints = 5;
|
rt300@3
|
972 static int numcontrols = 3;
|
rt300@3
|
973 //float values[points][controls] =
|
rt300@3
|
974 float ctrlout[numcontrols];
|
rt300@3
|
975 string ctrlName[3] = {"attack" , "decay", "sustain"};
|
rt300@3
|
976 float values[5][3] =
|
rt300@37
|
977 {{0., 0., 0.}, // 0
|
rt300@3
|
978 {0., 0.5, 0.}, // 32
|
rt300@3
|
979 {0.0, 1., 0.8}, // 64
|
rt300@3
|
980 {0.99, 0.3, 0.}, // 96
|
rt300@3
|
981 {0.3, 0.1, 0.}}; // 127
|
rt300@3
|
982
|
rt300@3
|
983 float fidx = (numpoints-1)*ctrlin/128.;
|
rt300@3
|
984 int idx = floor(fidx);
|
rt300@3
|
985 float frac = fidx - idx;
|
rt300@3
|
986 for(int i=0; i < numcontrols; i++){
|
rt300@3
|
987 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
|
rt300@3
|
988 // send to PD
|
rt300@3
|
989 List toPD;
|
rt300@3
|
990
|
rt300@3
|
991 toPD.addSymbol(ctrlName[i]);
|
rt300@3
|
992 toPD.addFloat(ctrlout[i]); // rounding here??
|
rt300@3
|
993
|
rt300@3
|
994 core.pd.sendList("fromOF", toPD);
|
rt300@3
|
995 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
|
rt300@3
|
996 }
|
rt300@3
|
997 }
|
rt300@8
|
998 //---------------------------------------------------------------
|
rt300@3
|
999 void testApp::sendModFreq(int ctrlin){
|
rt300@35
|
1000 if(ctrlin < 0 || ctrlin > 127){
|
rt300@35
|
1001 cout << "ERROR: bad slider value!";
|
rt300@35
|
1002 return;
|
rt300@35
|
1003 }
|
rt300@3
|
1004 float fm = ctrlin/127.;
|
rt300@3
|
1005 List toPD;
|
rt300@3
|
1006
|
rt300@3
|
1007 toPD.addSymbol("FMFreq");
|
rt300@3
|
1008 toPD.addFloat(fm); // rounding here??
|
rt300@3
|
1009
|
rt300@3
|
1010 core.pd.sendList("fromOF", toPD);
|
rt300@8
|
1011 }
|
rt300@35
|
1012 //---------------------------------------------------------------
|
rt300@35
|
1013
|
rt300@35
|
1014
|
rt300@35
|
1015
|
rt300@35
|
1016 //---------------------------------------------------------------------------
|
rt300@35
|
1017 void saveSequences(){
|
rt300@35
|
1018 ofFile sequenceFile(ofxiPhoneGetDocumentsDirectory() + "pilot_sequences.json" ,ofFile::WriteOnly);
|
rt300@35
|
1019
|
rt300@35
|
1020 // the 5 harmonics for the frequencer
|
rt300@35
|
1021 vector<int> freqIndexes;
|
rt300@35
|
1022 freqIndexes.push_back(0);
|
rt300@35
|
1023 freqIndexes.push_back(4);
|
rt300@35
|
1024 freqIndexes.push_back(6);
|
rt300@35
|
1025 freqIndexes.push_back(7);
|
rt300@35
|
1026 freqIndexes.push_back(8);
|
rt300@35
|
1027
|
rt300@35
|
1028 // loop thru all presets
|
rt300@35
|
1029 int N = presetManager.thePresets.size();
|
rt300@35
|
1030
|
rt300@35
|
1031 vector<int> sliderVals;
|
rt300@35
|
1032
|
rt300@35
|
1033 Json::Value root;
|
rt300@35
|
1034
|
rt300@35
|
1035 vector<double> vals;
|
rt300@35
|
1036
|
rt300@35
|
1037 for(int i = 0; i< N ; i++){
|
rt300@35
|
1038 sliderVals = theGridView.calculateParamsFromCoord(presetManager.thePresets[i]->coordinates);
|
rt300@35
|
1039
|
rt300@35
|
1040 vals.push_back((sliderVals[0]+32)*8.); // DC offset
|
rt300@35
|
1041 for(int i=1; i<5;i++){
|
rt300@35
|
1042 vals.push_back((sliderVals[i] - 64)*2.);
|
rt300@35
|
1043 }
|
rt300@35
|
1044
|
rt300@35
|
1045
|
rt300@35
|
1046 vector<double> steps = frequencer.freqMagEdit(freqIndexes, vals);
|
rt300@35
|
1047
|
rt300@35
|
1048 for(int j = 0; j<16;j++){
|
rt300@35
|
1049 root["sequences"][i][j] = int(steps[j]);
|
rt300@35
|
1050 }
|
rt300@35
|
1051 vals.clear();
|
rt300@35
|
1052 }
|
rt300@35
|
1053
|
rt300@35
|
1054 //cout << root;
|
rt300@35
|
1055 sequenceFile << root;
|
rt300@35
|
1056 }
|
rt300@35
|
1057 //=--------------------------------------------------------------------
|
rt300@36
|
1058 void testApp::loadSequences(){
|
rt300@36
|
1059
|
rt300@36
|
1060 // read in sequence preset file
|
rt300@36
|
1061 string jsonFile = ofxiPhoneGetDocumentsDirectory() + "pilot_sequences.json";
|
rt300@37
|
1062
|
rt300@36
|
1063 Json::Value root;
|
rt300@36
|
1064 Json::Reader reader;
|
rt300@37
|
1065
|
rt300@36
|
1066 ifstream theFile(jsonFile.c_str());
|
rt300@36
|
1067 stringstream fileText;
|
rt300@36
|
1068 string line;
|
rt300@36
|
1069 if(!theFile){
|
rt300@36
|
1070 cout<<"can't find sequence file: " << jsonFile.c_str() << "\n";
|
rt300@36
|
1071 return;
|
rt300@36
|
1072 }else{
|
rt300@36
|
1073
|
rt300@36
|
1074 while(theFile){
|
rt300@36
|
1075 theFile >> line;
|
rt300@36
|
1076 // cout << line << "\n"; // lots?
|
rt300@37
|
1077 fileText << line;
|
rt300@36
|
1078 }
|
rt300@36
|
1079
|
rt300@36
|
1080 theFile.close();
|
rt300@36
|
1081 }
|
rt300@36
|
1082
|
rt300@36
|
1083 bool parsingSuccessful = reader.parse( fileText.str(), root );
|
rt300@36
|
1084
|
rt300@36
|
1085 if ( !parsingSuccessful )
|
rt300@36
|
1086 {
|
rt300@36
|
1087 // report to the user the failure and their locations in the document.
|
rt300@36
|
1088 std::cout << "Failed to parse sequence JSON: \n"
|
rt300@36
|
1089 << reader.getFormattedErrorMessages();
|
rt300@36
|
1090 return;
|
rt300@36
|
1091 }
|
rt300@36
|
1092
|
rt300@36
|
1093 // now put into variables
|
rt300@36
|
1094 const Json::Value jseqs = root["sequences"];
|
rt300@36
|
1095 int N = jseqs.size();
|
rt300@36
|
1096 for(int i=0; i<N; i++){
|
rt300@36
|
1097 sequences.push_back(vector<int>());
|
rt300@36
|
1098 for(int j=0; j<jseqs[i].size(); j++){
|
rt300@36
|
1099 sequences.back().push_back(jseqs[i][j].asInt());
|
rt300@36
|
1100 }
|
rt300@36
|
1101 }
|
rt300@36
|
1102 // currentSequence
|
rt300@37
|
1103
|
rt300@37
|
1104 currentSequence = ofRandom(0,N-1);
|
rt300@36
|
1105
|
rt300@36
|
1106 }
|