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