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