rt300@0
|
1 #include "testApp.h"
|
rt300@2
|
2
|
rt300@39
|
3
|
rt300@0
|
4 extern Grid theGridView;
|
rt300@0
|
5 extern PresetManager presetManager;
|
rt300@1
|
6 extern EventLogger eventLogger;
|
rt300@3
|
7 extern Frequencer frequencer;
|
rt300@35
|
8 extern Hilbert hilbert;
|
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@46
|
15 // really GUI and all that stuff should be somewhere else
|
rt300@46
|
16
|
rt300@43
|
17 //--------------------------------------------------------------
|
rt300@43
|
18 void testApp::setup(){
|
rt300@43
|
19
|
rt300@43
|
20 // initilaise
|
rt300@43
|
21
|
rt300@43
|
22 initialiseVariables();
|
rt300@43
|
23 initialiseGUIs();
|
rt300@43
|
24
|
rt300@43
|
25 // initialise PD
|
rt300@43
|
26
|
rt300@43
|
27 int ticksPerBuffer = 8; // 8 * 64 = buffer len of 512
|
rt300@43
|
28 core.setup(2, 1, 44100, ticksPerBuffer);
|
rt300@46
|
29 // send to PD
|
rt300@46
|
30 List toPD;
|
rt300@46
|
31 toPD.addSymbol("smoothing");
|
rt300@46
|
32 toPD.addFloat(70); // rounding here??
|
rt300@46
|
33 core.pd.sendList("fromOF", toPD);
|
rt300@46
|
34 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
|
rt300@43
|
35
|
rt300@43
|
36 // setup OF sound stream
|
rt300@43
|
37 ofSoundStreamSetup(2, 1, this, 44100, ofxPd::blockSize()*ticksPerBuffer, 3);
|
rt300@43
|
38
|
rt300@43
|
39 tsc = [[TimedSessionController alloc] init];
|
rt300@43
|
40 [tsc setAppRef:(id)this];
|
rt300@43
|
41
|
rt300@43
|
42 //--------------------------------------
|
rt300@43
|
43 // load stuff
|
rt300@43
|
44 loadSequences();
|
rt300@43
|
45
|
rt300@43
|
46 // load presets
|
rt300@43
|
47 presetManager.startLoadAll();
|
rt300@43
|
48
|
rt300@43
|
49 eventLogger.startLoadAll();
|
rt300@43
|
50 //--------------------------------------
|
rt300@43
|
51
|
rt300@43
|
52 // now do things that will affect the start up state of the app
|
rt300@43
|
53
|
rt300@46
|
54 //if(true){
|
rt300@46
|
55 if(eventLogger.questionnaireCompleted){ // then we go into do-what-you-like mode
|
rt300@43
|
56
|
rt300@43
|
57 freeUseMode();
|
rt300@46
|
58 randomise();
|
rt300@43
|
59 }else{
|
rt300@43
|
60 // then we're in timed session mode
|
rt300@43
|
61 showIntro();
|
rt300@43
|
62 }
|
rt300@44
|
63
|
rt300@44
|
64 //freeUseMode();
|
rt300@43
|
65 // GO
|
rt300@43
|
66 paused = false;
|
rt300@43
|
67 eventLogger.logEvent(APP_STARTED);
|
rt300@43
|
68 }
|
rt300@24
|
69
|
rt300@43
|
70 //-----------------------------------------------------------------------------
|
rt300@35
|
71
|
rt300@7
|
72 //DeviceID3523537000
|
rt300@42
|
73 void testApp::initialiseVariables(){
|
rt300@46
|
74 animatingGrid = false;
|
rt300@16
|
75 paused = true;
|
rt300@39
|
76 sendMIDIAndOSC = false;
|
rt300@46
|
77 allowAnimation = false;
|
rt300@16
|
78 ofBackground( 0, 0, 0 );
|
rt300@0
|
79 ofEnableAlphaBlending();
|
rt300@36
|
80 currentSequence = 0;
|
rt300@40
|
81 //ofEnableSmoothing();
|
rt300@37
|
82
|
rt300@29
|
83 // open an outgoing connection to HOST:PORT for OSC
|
rt300@29
|
84
|
rt300@29
|
85 sender.setup( OSC_HOST, OSC_PORT );
|
rt300@28
|
86 ofSetFrameRate(50);
|
rt300@43
|
87
|
rt300@6
|
88 lastMoveTime = ofGetSystemTimeMicros();
|
rt300@0
|
89 prevTouchX = 0;
|
rt300@0
|
90 prevTouchY = 0;
|
rt300@0
|
91
|
rt300@0
|
92 xLocked = false;
|
rt300@0
|
93 yLocked = false;
|
rt300@0
|
94
|
rt300@0
|
95 numActiveTouches = 0;
|
rt300@3
|
96 touch0.setCoord(17./7., 2./3.);
|
rt300@0
|
97 touch1.setCoord(10,20);
|
rt300@3
|
98
|
rt300@0
|
99 prevTouch0.setCoord(1,2);
|
rt300@0
|
100 prevTouch1.setCoord(10,20);
|
rt300@0
|
101 prevDist = 10;
|
rt300@16
|
102 slowFactor = 0.98;
|
rt300@27
|
103 preventingMovePostScroll = false;
|
rt300@16
|
104
|
rt300@16
|
105 // the 5 harmonics for the frequencer
|
rt300@16
|
106 freqIndexes.push_back(0);
|
rt300@16
|
107 freqIndexes.push_back(4);
|
rt300@16
|
108 freqIndexes.push_back(6);
|
rt300@16
|
109 freqIndexes.push_back(7);
|
rt300@16
|
110 freqIndexes.push_back(8);
|
rt300@16
|
111
|
rt300@16
|
112
|
rt300@42
|
113 ofxiPhoneSetOrientation( OFXIPHONE_ORIENTATION_PORTRAIT );
|
rt300@42
|
114 ofxiPhoneExternalDisplay::mirrorOn();
|
rt300@42
|
115 }
|
rt300@43
|
116 //---------------------------------------------------------
|
rt300@42
|
117 void testApp::initialiseGUIs(){
|
rt300@0
|
118 theGridView.init();
|
rt300@0
|
119
|
rt300@43
|
120
|
rt300@43
|
121 //SLIDER
|
rt300@44
|
122 //setupSliderGui();
|
rt300@44
|
123 //sliderGUI->setVisible(false);
|
rt300@0
|
124
|
rt300@0
|
125 // initial slider vals
|
rt300@0
|
126 for(int i=0; i<10;i++){
|
rt300@0
|
127 sliderVals.push_back(64);
|
rt300@0
|
128 }
|
rt300@37
|
129
|
rt300@37
|
130
|
rt300@24
|
131 // set up iOS gui stuff
|
rt300@24
|
132 bottomTabViewController = [[BottomTabViewController alloc] initWithNibName:@"BottomTabViewController" bundle:nil];
|
rt300@24
|
133 [ofxiPhoneGetGLParentView() addSubview:bottomTabViewController.view];
|
rt300@24
|
134
|
rt300@24
|
135 [bottomTabViewController setAppRef:(id)this];
|
rt300@24
|
136 bottomTabViewController.view.frame = CGRectMake(0,getHeight()-44,getWidth(),44);
|
rt300@29
|
137 bottomTabViewController.view.hidden = YES;
|
rt300@37
|
138
|
rt300@24
|
139 /////
|
rt300@24
|
140
|
rt300@24
|
141 topButtonViewController = [[TopButtonViewController alloc] initWithNibName:@"TopButtonViewController" bundle:nil];
|
rt300@24
|
142 [ofxiPhoneGetGLParentView() addSubview:topButtonViewController.view];
|
rt300@24
|
143 [topButtonViewController setAppRef:(id)this];
|
rt300@24
|
144 [topButtonViewController show:(id)this];
|
rt300@24
|
145 topButtonViewController.view.frame = CGRectMake(0,0,getWidth(),44);
|
rt300@24
|
146
|
rt300@44
|
147
|
rt300@44
|
148
|
rt300@44
|
149 //SLIDER
|
rt300@44
|
150
|
rt300@44
|
151 sliderViewController = [[SliderViewController alloc] initWithNibName:@"SliderViewController" bundle:nil];
|
rt300@44
|
152 [ofxiPhoneGetGLParentView() addSubview:sliderViewController.view];
|
rt300@44
|
153 [sliderViewController setAppRef:(id)this];
|
rt300@44
|
154 sliderViewController.view.frame = CGRectMake(0,getHeight()-43 - 278,getWidth(),278);
|
rt300@44
|
155 [sliderViewController show:(id)this];
|
rt300@26
|
156
|
rt300@27
|
157 helpViewController = [[HelpViewController alloc] initWithNibName:@"HelpViewController" bundle:nil];
|
rt300@27
|
158 [ofxiPhoneGetGLParentView() addSubview:helpViewController.view];
|
rt300@27
|
159 [helpViewController setAppRef:(id)this];
|
rt300@27
|
160 helpViewController.view.hidden = YES;
|
rt300@27
|
161
|
rt300@44
|
162
|
rt300@44
|
163 usernameAlertViewController = [[UsernameAlertViewController alloc] init];
|
rt300@44
|
164 [usernameAlertViewController setAppRef:(id)this];
|
rt300@36
|
165
|
rt300@42
|
166 setAllGUISliders(theGridView.getParams());
|
rt300@25
|
167
|
rt300@42
|
168 }
|
rt300@43
|
169 //--------------------------------------------------------------------------
|
rt300@42
|
170 void testApp::initialiseMIDI(){
|
rt300@36
|
171
|
rt300@39
|
172 /////////////////////////
|
rt300@39
|
173 // MIDI
|
rt300@39
|
174
|
rt300@39
|
175 midiChannel = 7;
|
rt300@39
|
176 midiOffset = 0;
|
rt300@39
|
177
|
rt300@39
|
178 // enables the network midi session between iOS and Mac OSX on a
|
rt300@39
|
179 // local wifi network
|
rt300@39
|
180 //
|
rt300@39
|
181 // in ofxMidi: open the input/outport network ports named "Session 1"
|
rt300@39
|
182 //
|
rt300@39
|
183 // on OSX: use the Audio MIDI Setup Utility to connect to the iOS device
|
rt300@39
|
184 //
|
rt300@39
|
185 ofxMidi::enableNetworking();
|
rt300@39
|
186
|
rt300@39
|
187 // list the number of available input & output ports
|
rt300@39
|
188 ofxMidiIn::listPorts();
|
rt300@39
|
189 ofxMidiOut::listPorts();
|
rt300@39
|
190
|
rt300@39
|
191 // create and open input ports
|
rt300@39
|
192 for(int i = 0; i < ofxMidiIn::getNumPorts(); ++i) {
|
rt300@39
|
193
|
rt300@39
|
194 // new object
|
rt300@39
|
195 inputs.push_back(new ofxMidiIn);
|
rt300@39
|
196
|
rt300@39
|
197 // set this class to receive incoming midi events
|
rt300@39
|
198 inputs[i]->addListener(this);
|
rt300@39
|
199
|
rt300@39
|
200 // open input port via port number
|
rt300@39
|
201 inputs[i]->openPort(i);
|
rt300@39
|
202 }
|
rt300@39
|
203
|
rt300@39
|
204 // create and open output ports
|
rt300@39
|
205 for(int i = 0; i < ofxMidiOut::getNumPorts(); ++i) {
|
rt300@39
|
206
|
rt300@39
|
207 // new object
|
rt300@39
|
208 outputs.push_back(new ofxMidiOut);
|
rt300@39
|
209
|
rt300@39
|
210 // open input port via port number
|
rt300@39
|
211 outputs[i]->openPort(i);
|
rt300@39
|
212 }
|
rt300@39
|
213
|
rt300@39
|
214 // set this class to receieve midi device (dis)connection events
|
rt300@39
|
215 ofxMidi::setConnectionListener(this);
|
rt300@39
|
216
|
rt300@39
|
217 // END MIDI
|
rt300@42
|
218
|
rt300@42
|
219 }
|
rt300@24
|
220
|
rt300@24
|
221
|
rt300@24
|
222 //--------------------------------------------------------------
|
rt300@24
|
223 void testApp::exit(){
|
rt300@37
|
224
|
rt300@25
|
225 presetManager.exitAndSaveAll();
|
rt300@25
|
226 eventLogger.exitAndSave();
|
rt300@37
|
227
|
rt300@24
|
228 core.exit();
|
rt300@24
|
229
|
rt300@25
|
230 // are these handled automatically?
|
rt300@25
|
231 //[introViewController release];
|
rt300@25
|
232 //[topButtonViewController release];
|
rt300@25
|
233 //[bottomTabViewController release];
|
rt300@24
|
234
|
rt300@39
|
235 // clean up MIDI
|
rt300@39
|
236 for(int i = 0; i < inputs.size(); ++i) {
|
rt300@39
|
237 inputs[i]->closePort();
|
rt300@39
|
238 inputs[i]->removeListener(this);
|
rt300@39
|
239 delete inputs[i];
|
rt300@39
|
240 }
|
rt300@39
|
241
|
rt300@39
|
242 for(int i = 0; i < outputs.size(); ++i) {
|
rt300@39
|
243 outputs[i]->closePort();
|
rt300@39
|
244 delete outputs[i];
|
rt300@39
|
245 }
|
rt300@39
|
246
|
rt300@43
|
247 //SLIDER
|
rt300@44
|
248 //delete sliderGUI;
|
rt300@37
|
249
|
rt300@24
|
250 cout << "exit done \n";
|
rt300@0
|
251 }
|
rt300@24
|
252
|
rt300@24
|
253 //--------------------------------------------------------------
|
rt300@3
|
254 #pragma mark GUI
|
rt300@16
|
255 //--
|
rt300@16
|
256 float testApp::getWidth(){
|
rt300@16
|
257 // depends on orientation
|
rt300@16
|
258 return ofGetWidth();
|
rt300@16
|
259
|
rt300@16
|
260 }
|
rt300@16
|
261 float testApp::getHeight(){
|
rt300@16
|
262 // depends on orientation
|
rt300@16
|
263 return ofGetHeight();
|
rt300@16
|
264
|
rt300@16
|
265 }
|
rt300@24
|
266 #pragma mark GUI
|
rt300@24
|
267 ////////////////////////////
|
rt300@24
|
268 // These functions called from iOS toolbars
|
rt300@24
|
269 //--------------------------------------------------------------
|
rt300@24
|
270 void testApp::lockSequencerPressed(bool locked){
|
rt300@24
|
271 theGridView.shiftCentreToSnapped();
|
rt300@24
|
272 xLocked = locked;
|
rt300@39
|
273 eventLogger.logEvent(SEQ_LOCKED); // TODO whatabout unlock?
|
rt300@25
|
274
|
rt300@24
|
275
|
rt300@24
|
276 }
|
rt300@24
|
277 //--------------------------------------------------------------
|
rt300@24
|
278 void testApp::lockSynthPressed(bool locked){
|
rt300@24
|
279 theGridView.shiftCentreToSnapped();
|
rt300@24
|
280 yLocked = locked;
|
rt300@25
|
281 eventLogger.logEvent(SYNTH_LOCKED);
|
rt300@24
|
282
|
rt300@24
|
283 }
|
rt300@24
|
284 //--------------------------------------------------------------
|
rt300@24
|
285 void testApp::seqStartStop(bool go){
|
rt300@24
|
286 if(!go){ //stop
|
rt300@24
|
287 core.pd.startMessage();
|
rt300@24
|
288 core.pd.addFloat(0);
|
rt300@24
|
289 core.pd.finishMessage("fromOF", "seqStartStop");
|
rt300@25
|
290 eventLogger.logEvent(PAUSE_PRESSED);
|
rt300@24
|
291 }else { // play
|
rt300@24
|
292 //stopSequencer();
|
rt300@24
|
293 core.pd.startMessage();
|
rt300@24
|
294 core.pd.addFloat(1);
|
rt300@24
|
295 core.pd.finishMessage("fromOF", "seqStartStop");
|
rt300@25
|
296 eventLogger.logEvent(PLAY_PRESSED);
|
rt300@24
|
297 }
|
rt300@24
|
298 }
|
rt300@24
|
299 //--------------------------------------------------------------
|
rt300@24
|
300 void testApp::showQuestionnaire(){
|
rt300@24
|
301 // stop updating / drawing
|
rt300@37
|
302
|
rt300@24
|
303 // if(eventLogger.questionnaireCompleted) return;
|
rt300@37
|
304
|
rt300@27
|
305 [topButtonViewController pausePressed:(id)this];
|
rt300@24
|
306
|
rt300@24
|
307 //stopSequencer
|
rt300@27
|
308 seqStartStop(false);
|
rt300@24
|
309
|
rt300@24
|
310 questionnaireViewController = [[QuestionnaireViewController alloc] initWithNibName:@"QuestionnaireViewController" bundle:nil];
|
rt300@24
|
311 [ofxiPhoneGetGLParentView() addSubview:questionnaireViewController.view];
|
rt300@24
|
312
|
rt300@24
|
313 [questionnaireViewController setAppRef:(id)this];
|
rt300@24
|
314 [questionnaireViewController show:(id)this];
|
rt300@24
|
315
|
rt300@24
|
316 whichInterfaceShowing = QUESTIONNAIRE;
|
rt300@24
|
317
|
rt300@37
|
318
|
rt300@24
|
319 }
|
rt300@24
|
320 //--------------------------------------------------------------
|
rt300@28
|
321 void testApp::questionnaireHidden(vector<int> answers, const char* userComments){
|
rt300@24
|
322 // send answers to server as json
|
rt300@28
|
323 eventLogger.questionnaireAnswersObtained(answers, userComments);
|
rt300@39
|
324
|
rt300@39
|
325 freeUseMode();
|
rt300@37
|
326
|
rt300@39
|
327 }
|
rt300@39
|
328 //--------------------------------------------------------------
|
rt300@39
|
329 // shortcut function for testing
|
rt300@39
|
330 void testApp::justStart(){
|
rt300@39
|
331 freeUseMode();
|
rt300@39
|
332 }
|
rt300@39
|
333 //--------------------------------------------------------------
|
rt300@39
|
334 void testApp::freeUseMode(){
|
rt300@38
|
335 interfaceSelected(1);
|
rt300@32
|
336 [bottomTabViewController show:(id)this withSelection:1];
|
rt300@24
|
337
|
rt300@38
|
338 [topButtonViewController enableSmoothSwitch:(id)this];
|
rt300@37
|
339
|
rt300@39
|
340 sendMIDIAndOSC = true;
|
rt300@46
|
341 allowAnimation = true;
|
rt300@38
|
342 }
|
rt300@38
|
343 //--------------------------------------------------------------
|
rt300@38
|
344 void testApp::setInterp(int state){
|
rt300@38
|
345 if(state == 0){
|
rt300@38
|
346 theGridView.setInterpolation(Grid::NO_INTERPOLATION);
|
rt300@39
|
347 eventLogger.logEvent(SMOOTHING_OFF);
|
rt300@38
|
348 }else if(state == 1){
|
rt300@38
|
349 theGridView.setInterpolation(Grid::INTERPOLATE_GRID);
|
rt300@39
|
350 eventLogger.logEvent(SMOOTHING_ON);
|
rt300@38
|
351 }
|
rt300@38
|
352 // tell sliders and PD
|
rt300@38
|
353 setAllGUISliders(theGridView.getParams());
|
rt300@39
|
354
|
rt300@33
|
355 }
|
rt300@33
|
356 //--------------------------------------------------------------
|
rt300@24
|
357 void testApp::showIntro(){
|
rt300@37
|
358
|
rt300@24
|
359 cout << "SHOW INTRO\n";
|
rt300@37
|
360
|
rt300@29
|
361 [tsc cancelTimers];
|
rt300@29
|
362 bottomTabViewController.view.hidden = YES;
|
rt300@24
|
363 introViewController = [[IntroViewController alloc] initWithNibName:@"IntroViewController" bundle:nil];
|
rt300@24
|
364 [ofxiPhoneGetGLParentView() addSubview:introViewController.view];
|
rt300@24
|
365
|
rt300@24
|
366 [introViewController setAppRef:(id)this];
|
rt300@24
|
367 [introViewController show:(id)this];
|
rt300@24
|
368
|
rt300@24
|
369
|
rt300@24
|
370 whichInterfaceShowing = INTRO;
|
rt300@24
|
371
|
rt300@24
|
372 }
|
rt300@24
|
373 //--------------------------------------------------------------
|
rt300@24
|
374 void testApp::introHidden(bool OK){
|
rt300@24
|
375 if(OK){
|
rt300@25
|
376 eventLogger.consentGiven = true;
|
rt300@29
|
377 //
|
rt300@29
|
378 // clear presets?
|
rt300@46
|
379 //presetManager.clearAll();
|
rt300@25
|
380 // show username prompt
|
rt300@25
|
381 [usernameAlertViewController showUserNamePrompt];
|
rt300@32
|
382 // reset top buttons
|
rt300@32
|
383 [topButtonViewController unlockAll];
|
rt300@32
|
384 randomise();
|
rt300@24
|
385 }
|
rt300@24
|
386 // no unOK
|
rt300@24
|
387 }
|
rt300@24
|
388 //--------------------------------------------------------------
|
rt300@42
|
389 void testApp::startTimedSession(){
|
rt300@42
|
390 [tsc startTimer];
|
rt300@42
|
391 // timer will show alert and set interface
|
rt300@42
|
392 }
|
rt300@42
|
393 //--------------------------------------------------------------
|
rt300@39
|
394 // called from BottomTabViewController iOS segmented thing, also timed session controller
|
rt300@24
|
395 void testApp::interfaceSelected(int which){
|
rt300@24
|
396 switch (which){
|
rt300@39
|
397 case 0: // slider
|
rt300@43
|
398 //SLIDER
|
rt300@24
|
399 whichInterfaceShowing = SLIDERS;
|
rt300@43
|
400
|
rt300@43
|
401 [sliderViewController show:(id)this];
|
rt300@24
|
402 // set the slider values to stuff got from zoomer
|
rt300@24
|
403 sliderVals = theGridView.getParams();
|
rt300@24
|
404 setAllGUISliders(sliderVals);
|
rt300@25
|
405
|
rt300@24
|
406 break;
|
rt300@39
|
407 case 1: // both
|
rt300@43
|
408 //SLIDER
|
rt300@24
|
409 whichInterfaceShowing = BOTH;
|
rt300@43
|
410
|
rt300@43
|
411 [sliderViewController show:(id)this];
|
rt300@24
|
412 // set the slider values to stuff got from zoomer
|
rt300@24
|
413 sliderVals = theGridView.getParams();
|
rt300@24
|
414 setAllGUISliders(sliderVals);
|
rt300@39
|
415
|
rt300@24
|
416 break;
|
rt300@39
|
417 case 2: // zoomer
|
rt300@43
|
418 //SLIDER
|
rt300@43
|
419
|
rt300@43
|
420 [sliderViewController hide:(id)this];
|
rt300@24
|
421 whichInterfaceShowing = ZOOMER;
|
rt300@24
|
422 break;
|
rt300@24
|
423 }
|
rt300@39
|
424 eventLogger.logEvent(SWAP_VIEW,theGridView.getCoord(),theGridView.getScale(), which);
|
rt300@24
|
425 }
|
rt300@24
|
426 //--------------------------------------------------------------
|
rt300@24
|
427 //--------------------------------------------------------------
|
rt300@24
|
428 void testApp::setupSliderGui(){
|
rt300@43
|
429 //SLIDER not used
|
rt300@24
|
430 float length = SLIDER_GUI_WIDTH - (OFX_UI_GLOBAL_WIDGET_SPACING*2);
|
rt300@24
|
431
|
rt300@24
|
432
|
rt300@24
|
433 //float dim = 42;
|
rt300@24
|
434
|
rt300@24
|
435 // make this iphone size...?
|
rt300@24
|
436 int height = 480;
|
rt300@39
|
437
|
rt300@24
|
438 float dim = (height-10.0*OFX_UI_GLOBAL_WIDGET_SPACING)/10.0;
|
rt300@24
|
439 // LEFT GUI
|
rt300@42
|
440 sliderGUI = new ofxUICanvas(10,160,SLIDER_GUI_WIDTH,getHeight());
|
rt300@37
|
441
|
rt300@24
|
442 // Uh.. loop this
|
rt300@24
|
443 for(int i = 1; i<=10;i++){
|
rt300@37
|
444
|
rt300@24
|
445 ofxUISlider *slider;
|
rt300@25
|
446 slider = (ofxUISlider *)sliderGUI->addWidgetDown(new ofxUISlider(length,dim,0.0,127,64,sliderParamNames[i-1]));
|
rt300@24
|
447 slider->setDrawPadding(true);
|
rt300@28
|
448 slider->setDrawPaddingOutline(true);
|
rt300@24
|
449 if(i <= 5){
|
rt300@24
|
450 slider->setColorFill(ofColor(0,0,255));
|
rt300@24
|
451 slider->setColorFillHighlight(ofColor(0,0,255));
|
rt300@24
|
452 }else{
|
rt300@24
|
453 slider->setColorFill(ofColor(255,0,0));
|
rt300@24
|
454 slider->setColorFillHighlight(ofColor(255,0,0));
|
rt300@24
|
455 }
|
rt300@24
|
456
|
rt300@24
|
457 sliders.push_back(slider);
|
rt300@24
|
458 }
|
rt300@24
|
459
|
rt300@37
|
460
|
rt300@24
|
461
|
rt300@24
|
462 ofAddListener(sliderGUI->newGUIEvent, this, &testApp::sliderGUIEvent);
|
rt300@37
|
463
|
rt300@24
|
464 }
|
rt300@24
|
465 //--------------------------------------------------------------
|
rt300@24
|
466 void testApp::sliderGUIEvent(ofxUIEventArgs &e){
|
rt300@43
|
467 //SLIDER not used
|
rt300@24
|
468 if(whichInterfaceShowing == ZOOMER){
|
rt300@24
|
469 cout << "GUI ERROR";
|
rt300@24
|
470 return;
|
rt300@24
|
471 }
|
rt300@37
|
472
|
rt300@0
|
473 // "normal" parameter changes
|
rt300@0
|
474 for(int i = 1; i<=10;i++){
|
rt300@0
|
475
|
rt300@24
|
476 if(e.widget->getName() == sliderParamNames[i-1])
|
rt300@0
|
477 {
|
rt300@0
|
478 //cout << "param change: " << p;
|
rt300@0
|
479 ofxUISlider *slider = (ofxUISlider *) e.widget;
|
rt300@3
|
480 sliderMoved(i-1,slider->getScaledValue()); // internal array 0 indexed
|
rt300@0
|
481 }
|
rt300@0
|
482 }
|
rt300@37
|
483
|
rt300@0
|
484 }
|
rt300@43
|
485
|
rt300@0
|
486 //--------------------------------------------------------------
|
rt300@3
|
487 void testApp::sliderMoved(int which, float value){
|
rt300@43
|
488
|
rt300@3
|
489 // an update caused by slider view being touched
|
rt300@0
|
490 sliderVals[which] = (int)value;
|
rt300@0
|
491 theGridView.setParams(sliderVals);
|
rt300@37
|
492
|
rt300@3
|
493 sendParametersToPD();
|
rt300@39
|
494 if(sendMIDIAndOSC){
|
rt300@39
|
495
|
rt300@39
|
496 sendMidiParam(which);
|
rt300@39
|
497 sendOSCParams();
|
rt300@39
|
498 }
|
rt300@5
|
499
|
rt300@44
|
500 eventLogger.logEvent(CHANGE_SLIDER, theGridView.getCoord(),0.0,which , value);
|
rt300@44
|
501
|
rt300@0
|
502 }
|
rt300@0
|
503 //--------------------------------------------------------------
|
rt300@3
|
504 void testApp::setAllGUISliders(vector<int> vals){
|
rt300@44
|
505
|
rt300@3
|
506 // an update caused by zoomer view being moved
|
rt300@46
|
507 // can be called by theGridView or testApp
|
rt300@46
|
508 // casues PD and midi to be sent
|
rt300@46
|
509
|
rt300@25
|
510 for(int i = 0; i<NUM_PARAMS;i++){
|
rt300@44
|
511 //sliders[i]->setValue(vals[i]);
|
rt300@1
|
512 sliderVals[i] = vals[i];
|
rt300@43
|
513
|
rt300@43
|
514 [sliderViewController setSlider:i to:vals[i]];
|
rt300@0
|
515 }
|
rt300@3
|
516
|
rt300@39
|
517 sendParametersToPD();
|
rt300@39
|
518 if(sendMIDIAndOSC){
|
rt300@39
|
519
|
rt300@39
|
520 sendMidiParams();
|
rt300@39
|
521 sendOSCParams();
|
rt300@39
|
522 }
|
rt300@39
|
523
|
rt300@0
|
524 }
|
rt300@0
|
525 //--------------------------------------------------------------
|
rt300@25
|
526 void testApp::randomise(){
|
rt300@25
|
527 // pick random settings for all params
|
rt300@39
|
528
|
rt300@39
|
529 // random zoom? no.
|
rt300@25
|
530 for(int i=0; i < NUM_PARAMS ; i++){
|
rt300@25
|
531 sliderVals[i] = ofRandom(0, 127);
|
rt300@25
|
532
|
rt300@25
|
533 }
|
rt300@37
|
534 currentSequence = ofRandom(0, sequences.size()-1);
|
rt300@25
|
535 // send to grid, sliders and PD
|
rt300@25
|
536 theGridView.setParams(sliderVals);
|
rt300@25
|
537 setAllGUISliders(sliderVals);
|
rt300@39
|
538
|
rt300@39
|
539
|
rt300@44
|
540 eventLogger.logEvent(RANDOMISE, theGridView.getCoord() ,theGridView.getScale());
|
rt300@25
|
541
|
rt300@25
|
542 }
|
rt300@39
|
543 //--------------------------------------------------------------
|
rt300@27
|
544 void testApp::showHelp(){
|
rt300@46
|
545 previousInterface = whichInterfaceShowing;
|
rt300@29
|
546 whichInterfaceShowing = HELP;
|
rt300@27
|
547 seqStartStop(false);
|
rt300@27
|
548 [topButtonViewController pausePressed:(id)this];
|
rt300@27
|
549 helpViewController.view.hidden = NO;
|
rt300@27
|
550 eventLogger.logEvent(HELP_PRESSED);
|
rt300@46
|
551
|
rt300@27
|
552 }
|
rt300@27
|
553 void testApp::helpHidden(){
|
rt300@46
|
554 whichInterfaceShowing = previousInterface;
|
rt300@27
|
555 // start seq?
|
rt300@27
|
556
|
rt300@27
|
557 }
|
rt300@25
|
558 //--------------------------------------------------------------
|
rt300@46
|
559 int testApp::nextSequence(){
|
rt300@36
|
560 currentSequence++;
|
rt300@36
|
561 if(currentSequence >= sequences.size()){
|
rt300@36
|
562 currentSequence = 0;
|
rt300@36
|
563 }
|
rt300@36
|
564 sendParametersToPD();
|
rt300@46
|
565 return currentSequence;
|
rt300@36
|
566 }
|
rt300@36
|
567 //--------------------------------------------------------------
|
rt300@39
|
568 //--------------------------------------------------------------
|
rt300@39
|
569 #pragma mark sending to pd and midi
|
rt300@3
|
570 void testApp::sendParametersToPD(){
|
rt300@37
|
571 static int previousSequence;
|
rt300@36
|
572
|
rt300@45
|
573 if(core.patchName == "synth5paramMM.pd"){
|
rt300@45
|
574 // frequencer stuff to get 16 steps
|
rt300@45
|
575
|
rt300@45
|
576 vector<double> vals;
|
rt300@45
|
577
|
rt300@45
|
578
|
rt300@45
|
579 vals.push_back((sliderVals[0]+32)*8.); // DC offset
|
rt300@45
|
580 for(int i=1; i<5;i++){
|
rt300@45
|
581 vals.push_back((sliderVals[i] - 64)*2.);
|
rt300@45
|
582 }
|
rt300@45
|
583
|
rt300@45
|
584 vector<double> steps = frequencer.freqMagEdit(freqIndexes, vals);
|
rt300@45
|
585 List seqSteps;
|
rt300@45
|
586 seqSteps.addSymbol("seqSteps");
|
rt300@45
|
587 for(int i=0; i < 16; i++){
|
rt300@45
|
588 seqSteps.addFloat(round(steps[i]));
|
rt300@45
|
589 }
|
rt300@45
|
590 core.pd.sendList("fromOF", seqSteps);
|
rt300@45
|
591
|
rt300@45
|
592
|
rt300@45
|
593 // send synth params
|
rt300@45
|
594 sendOscShape(sliderVals[5]);
|
rt300@45
|
595 sendFiltType(sliderVals[6]);
|
rt300@45
|
596 sendFiltFreq(sliderVals[7]);
|
rt300@45
|
597 sendEnvShape(sliderVals[8]);
|
rt300@45
|
598 sendModFreq(sliderVals[9]);
|
rt300@45
|
599
|
rt300@45
|
600 }else if (core.patchName == "synth10param.pd"){
|
rt300@45
|
601 // for 10 param synth we get sequence from saved presets
|
rt300@45
|
602 // and send 5 extra synth params
|
rt300@45
|
603 if(currentSequence != previousSequence){
|
rt300@45
|
604 List seqSteps;
|
rt300@45
|
605
|
rt300@45
|
606 seqSteps.addSymbol("seqSteps");
|
rt300@45
|
607 if(currentSequence >= sequences.size() || currentSequence < 0){
|
rt300@45
|
608 cout << "ERROR: not a valid sequence index\n";
|
rt300@45
|
609 for(int i=0; i < 16; i++){
|
rt300@45
|
610 seqSteps.addFloat(50);
|
rt300@45
|
611 }
|
rt300@45
|
612 }else{
|
rt300@45
|
613 for(int i=0; i < 16; i++){
|
rt300@45
|
614 seqSteps.addFloat(round(sequences[currentSequence][i]));
|
rt300@45
|
615 }
|
rt300@45
|
616 }
|
rt300@45
|
617
|
rt300@45
|
618 core.pd.sendList("fromOF", seqSteps);
|
rt300@45
|
619 previousSequence = currentSequence;
|
rt300@45
|
620 }
|
rt300@45
|
621 /*
|
rt300@45
|
622 @"Amp Env",@"Waveform",@"FM amount",@"FM frequency",@"Reverb",
|
rt300@45
|
623 @"Filter Type",@"Filter Cut off",@"Filter Resonance",@"Filter Envelope",@"SOMETHING",
|
rt300@45
|
624 */
|
rt300@45
|
625 // send synth params
|
rt300@45
|
626 sendAmpEnvShape(sliderVals[0]);
|
rt300@45
|
627 sendOscShape(sliderVals[1]);
|
rt300@45
|
628 sendFMAmt(sliderVals[2]);
|
rt300@45
|
629 sendModFreq(sliderVals[3]);
|
rt300@45
|
630 sendRevAmt(sliderVals[4]);
|
rt300@45
|
631
|
rt300@45
|
632 sendFiltType(sliderVals[5]);
|
rt300@45
|
633 sendFiltFreq(sliderVals[6]);
|
rt300@45
|
634 sendResonance(sliderVals[7]);
|
rt300@45
|
635 sendFiltEnvShape(sliderVals[8]);
|
rt300@45
|
636 sendFiltEnvModAmt(sliderVals[9]);
|
rt300@45
|
637 //sendUmame(sliderVals[8]);
|
rt300@45
|
638 //sendX(sliderVals[2]);
|
rt300@45
|
639 //sendX(sliderVals[3]);
|
rt300@45
|
640
|
rt300@45
|
641
|
rt300@45
|
642
|
rt300@45
|
643
|
rt300@45
|
644
|
rt300@45
|
645
|
rt300@37
|
646 }
|
rt300@45
|
647
|
rt300@37
|
648
|
rt300@36
|
649 /*
|
rt300@45
|
650 cout << "SLIDERVALS: ";
|
rt300@45
|
651 for(int i=0;i<10;i++){
|
rt300@45
|
652 cout << sliderVals[i] << ",";
|
rt300@3
|
653 }
|
rt300@45
|
654 cout << '\n';
|
rt300@45
|
655 */
|
rt300@3
|
656
|
rt300@3
|
657 }
|
rt300@39
|
658 //--------------------------------------------------------------
|
rt300@39
|
659 void testApp::sendMidiParam(int which){
|
rt300@39
|
660 int midiChannel = 7;
|
rt300@39
|
661 int offset = 0;
|
rt300@39
|
662
|
rt300@39
|
663 for(int i = 0; i < outputs.size(); ++i) {
|
rt300@39
|
664 outputs[i]->sendControlChange(midiChannel, offset+which, sliderVals[which]);
|
rt300@39
|
665 }
|
rt300@39
|
666
|
rt300@39
|
667
|
rt300@39
|
668 }
|
rt300@39
|
669 //--------------------------------------------------------------
|
rt300@39
|
670 void testApp::sendMidiParams(){
|
rt300@39
|
671
|
rt300@39
|
672 for(int i = 0; i< sliderVals.size(); i++){
|
rt300@39
|
673 for(int j = 0; j < outputs.size(); ++j) {
|
rt300@39
|
674 outputs[j]->sendControlChange(midiChannel, midiOffset+i, sliderVals[i]);
|
rt300@39
|
675 }
|
rt300@39
|
676 }
|
rt300@39
|
677
|
rt300@39
|
678 }
|
rt300@39
|
679 //--------------------------------------------------------------
|
rt300@39
|
680 void testApp::sendOSCParams(){
|
rt300@39
|
681
|
rt300@39
|
682 ofxOscMessage m;
|
rt300@39
|
683 m.setAddress( "sonicZoom" );
|
rt300@39
|
684
|
rt300@39
|
685 for(int i = 0; i< sliderVals.size(); i++){
|
rt300@39
|
686
|
rt300@39
|
687 m.addFloatArg(sliderVals[i]);
|
rt300@39
|
688
|
rt300@39
|
689 }
|
rt300@39
|
690 sender.sendMessage( m );
|
rt300@39
|
691 }
|
rt300@39
|
692 //--------------------------------------------------------------
|
rt300@39
|
693
|
rt300@27
|
694 void testApp::setupNewUser(){
|
rt300@27
|
695 // this function is for supervised trials with my ipad
|
rt300@27
|
696 eventLogger.newUser();
|
rt300@27
|
697 }
|
rt300@8
|
698 //--------------------------------------------------------------
|
rt300@3
|
699 #pragma mark STANDARD OF FUNCTIONS
|
rt300@3
|
700 //--------------------------------------------------------------
|
rt300@0
|
701 void testApp::update(){
|
rt300@37
|
702
|
rt300@16
|
703 if(paused) return;
|
rt300@16
|
704
|
rt300@46
|
705 if(theGridView.automatedMovementInProgress){
|
rt300@46
|
706 theGridView.update();
|
rt300@46
|
707 return;
|
rt300@46
|
708 }
|
rt300@46
|
709
|
rt300@32
|
710 if(ofxiPhoneExternalDisplay::isExternalScreenConnected()){
|
rt300@32
|
711 if(!ofxiPhoneExternalDisplay::isMirroring()){
|
rt300@32
|
712 ofxiPhoneExternalDisplay::mirrorOn();
|
rt300@32
|
713 printf("turned on Mirroring!\n");
|
rt300@32
|
714 }
|
rt300@32
|
715 }
|
rt300@32
|
716
|
rt300@46
|
717 if(animatingGrid){
|
rt300@46
|
718 // theGrid
|
rt300@46
|
719
|
rt300@46
|
720 }
|
rt300@27
|
721 // continiue to move or zoom at velocity, unless snapped
|
rt300@3
|
722
|
rt300@3
|
723 if (numActiveTouches == 0){ // no touches, use momentum
|
rt300@32
|
724 // ZOOM MOMENTUM
|
rt300@32
|
725 // continiue to zoom at velocity
|
rt300@32
|
726 if (numActiveTouches < 2 && abs(zoomVel)>0.001){
|
rt300@32
|
727 theGridView.zoom(zoomVel + 1.0); // +1 because zoomVel factor is + or - , wheras zoom is a multiplier near 1
|
rt300@32
|
728 zoomVel = zoomVel*slowFactor;
|
rt300@32
|
729 moveVel.setCoord(0.0,0.0);; // don't move if zooming! Too many events!
|
rt300@35
|
730
|
rt300@37
|
731 setAllGUISliders(theGridView.getParams());
|
rt300@39
|
732
|
rt300@32
|
733 }
|
rt300@44
|
734 // MOVE MOMENTUM
|
rt300@22
|
735 if(moveVel.norm() > 0.3){
|
rt300@22
|
736 if(theGridView.snapped){
|
rt300@28
|
737 // stop it (snap check sends snap event)
|
rt300@22
|
738 moveVel.setCoord(0.0,0.0);
|
rt300@22
|
739 }else{
|
rt300@22
|
740 theGridView.move(moveVel);
|
rt300@22
|
741 moveVel = moveVel*slowFactor;
|
rt300@22
|
742 }
|
rt300@37
|
743 // and get new parameter values
|
rt300@5
|
744 setAllGUISliders(theGridView.getParams());
|
rt300@39
|
745
|
rt300@22
|
746 }else if(moveVel.norm() > 0.01){ // and less than 0.3
|
rt300@3
|
747 // stop it
|
rt300@3
|
748 moveVel.setCoord(0.0,0.0);
|
rt300@5
|
749 setAllGUISliders(theGridView.getParams());
|
rt300@39
|
750
|
rt300@5
|
751 eventLogger.logEvent(SCROLL_STOPPED, theGridView.getCoord() );
|
rt300@22
|
752
|
rt300@3
|
753 }else{
|
rt300@3
|
754 // stopped - do nothing
|
rt300@3
|
755 }
|
rt300@37
|
756
|
rt300@0
|
757 }
|
rt300@37
|
758
|
rt300@0
|
759 }
|
rt300@0
|
760 //--------------------------------------------------------------
|
rt300@39
|
761
|
rt300@0
|
762 void testApp::draw(){
|
rt300@37
|
763
|
rt300@24
|
764 switch (whichInterfaceShowing){
|
rt300@24
|
765 case SLIDERS:
|
rt300@24
|
766 break;
|
rt300@24
|
767 case ZOOMER:
|
rt300@24
|
768 theGridView.draw();
|
rt300@37
|
769
|
rt300@24
|
770 break;
|
rt300@24
|
771 case BOTH:
|
rt300@33
|
772
|
rt300@33
|
773 theGridView.draw();
|
rt300@37
|
774
|
rt300@24
|
775 break;
|
rt300@24
|
776 case INTRO:
|
rt300@24
|
777 break;
|
rt300@24
|
778
|
rt300@24
|
779 case QUESTIONNAIRE:
|
rt300@24
|
780 break;
|
rt300@24
|
781
|
rt300@0
|
782 }
|
rt300@4
|
783
|
rt300@0
|
784 }
|
rt300@0
|
785
|
rt300@0
|
786 //--------------------------------------------------------------
|
rt300@0
|
787 void testApp::touchDown(ofTouchEventArgs &touch){
|
rt300@46
|
788 if(theGridView.automatedMovementInProgress) return;
|
rt300@46
|
789 if(whichInterfaceShowing == SLIDERS){
|
rt300@46
|
790 return;
|
rt300@46
|
791 }
|
rt300@0
|
792 numActiveTouches++;
|
rt300@27
|
793 preventingMovePostScroll = false;
|
rt300@44
|
794 tapFlag = false; // unless touch 0
|
rt300@0
|
795 if(touch.id == 0){
|
rt300@0
|
796 touch0.setCoord(touch.x,touch.y);
|
rt300@0
|
797 prevTouch0 = touch0;
|
rt300@32
|
798 // stop zoom
|
rt300@32
|
799 zoomVel = 0.0;
|
rt300@44
|
800 tapFlag = true;
|
rt300@0
|
801 }else if(touch.id == 1){
|
rt300@0
|
802
|
rt300@0
|
803 touch1.setCoord(touch.x,touch.y);
|
rt300@0
|
804 prevTouch1 = touch1;
|
rt300@0
|
805
|
rt300@0
|
806 }
|
rt300@0
|
807 if(numActiveTouches == 1){
|
rt300@0
|
808 moveVel.setCoord(0.0, 0.0);
|
rt300@0
|
809 prevMove.setCoord(0.0, 0.0);
|
rt300@0
|
810 prevMove2.setCoord(0.0, 0.0);
|
rt300@27
|
811
|
rt300@0
|
812 }else if(numActiveTouches == 2){
|
rt300@0
|
813 zoomVel = 0.0;
|
rt300@0
|
814 prevZoom = 0.0;
|
rt300@0
|
815 prevZoom2 = 0.0;
|
rt300@0
|
816 double dist = touch1.distanceTo(touch0);
|
rt300@0
|
817 prevDist = dist;
|
rt300@0
|
818 }
|
rt300@37
|
819
|
rt300@0
|
820 }
|
rt300@0
|
821
|
rt300@0
|
822 //--------------------------------------------------------------
|
rt300@0
|
823 void testApp::touchMoved(ofTouchEventArgs &touch){
|
rt300@46
|
824 if(theGridView.automatedMovementInProgress) return;
|
rt300@46
|
825 if(whichInterfaceShowing == SLIDERS){
|
rt300@46
|
826 return;
|
rt300@46
|
827 }
|
rt300@46
|
828
|
rt300@44
|
829 tapFlag = false;
|
rt300@1
|
830 // which one? keep track of each touch point
|
rt300@0
|
831 if(touch.id == 0){
|
rt300@0
|
832 touch0.setCoord(touch.x,touch.y);
|
rt300@0
|
833
|
rt300@0
|
834 }else if(touch.id == 1){
|
rt300@0
|
835
|
rt300@0
|
836 touch1.setCoord(touch.x,touch.y);
|
rt300@0
|
837 }
|
rt300@37
|
838
|
rt300@1
|
839 if(numActiveTouches == 1){
|
rt300@27
|
840 if(preventingMovePostScroll) return;
|
rt300@1
|
841 handleScroll();
|
rt300@0
|
842 }else if(numActiveTouches == 2){
|
rt300@1
|
843 handleZoom();
|
rt300@0
|
844
|
rt300@0
|
845 }
|
rt300@0
|
846 prevTouch0 = touch0;
|
rt300@37
|
847
|
rt300@0
|
848
|
rt300@0
|
849 }
|
rt300@5
|
850
|
rt300@1
|
851 //--------------------------------------------------------------
|
rt300@44
|
852 void testApp::touchUp(ofTouchEventArgs &touch){
|
rt300@46
|
853 if(theGridView.automatedMovementInProgress) return;
|
rt300@46
|
854 if(whichInterfaceShowing == SLIDERS){
|
rt300@46
|
855 return;
|
rt300@46
|
856 }
|
rt300@44
|
857 if(numActiveTouches > 0) numActiveTouches--; // dirty
|
rt300@44
|
858 preventingMovePostScroll = false;
|
rt300@44
|
859 // TODO check if in gui area!!!
|
rt300@44
|
860 //SLIDER
|
rt300@44
|
861 if(whichInterfaceShowing == SLIDERS){
|
rt300@44
|
862 return;
|
rt300@44
|
863 }
|
rt300@44
|
864
|
rt300@44
|
865 if(tapFlag){
|
rt300@44
|
866 cout << "TAP!!\n";
|
rt300@44
|
867 // look for close preset
|
rt300@46
|
868
|
rt300@44
|
869 theGridView.tap(TwoVector(touch.x,touch.y));
|
rt300@44
|
870 }
|
rt300@44
|
871 tapFlag = false;
|
rt300@44
|
872 // which one?
|
rt300@44
|
873 if(touch.id == 0){
|
rt300@44
|
874 // tricky situation - we tried to zoom but may have left non-move finger on
|
rt300@44
|
875 prevTouch0.setCoord(touch.x,touch.y);
|
rt300@44
|
876
|
rt300@44
|
877 }else if(touch.id == 1){
|
rt300@44
|
878
|
rt300@44
|
879
|
rt300@44
|
880 prevTouch1.setCoord(0,0);
|
rt300@44
|
881
|
rt300@44
|
882 }
|
rt300@44
|
883 if(numActiveTouches == 0){
|
rt300@44
|
884 // check time since last move
|
rt300@44
|
885 // check time since last move - if
|
rt300@44
|
886 unsigned int moveTime = ofGetSystemTimeMicros();
|
rt300@44
|
887 if(moveTime - lastMoveTime > 100000){
|
rt300@44
|
888 moveVel = TwoVector(); // zero
|
rt300@44
|
889 }else{
|
rt300@44
|
890 moveVel = (move*0.3 + prevMove*0.34 + prevMove2*0.38); // use the time
|
rt300@44
|
891
|
rt300@44
|
892 }
|
rt300@44
|
893 lastMoveTime = moveTime;
|
rt300@44
|
894 }else if (numActiveTouches == 1){
|
rt300@44
|
895 // just zoomed , but now lifted one of the fingers
|
rt300@44
|
896 // can be bad if moved so create special mode to stop scroll (special modes bad!)
|
rt300@44
|
897 preventingMovePostScroll = true;
|
rt300@44
|
898 }
|
rt300@44
|
899
|
rt300@44
|
900 }
|
rt300@44
|
901
|
rt300@44
|
902
|
rt300@44
|
903 //--------------------------------------------------------------
|
rt300@27
|
904 // handle a finger being dragged
|
rt300@1
|
905 void testApp::handleScroll(){
|
rt300@37
|
906
|
rt300@1
|
907 TwoVector move = touch0 - prevTouch0;
|
rt300@5
|
908 if(yLocked){
|
rt300@5
|
909 move.y = 0.0;
|
rt300@5
|
910 }
|
rt300@5
|
911 if(xLocked){
|
rt300@5
|
912 move.x = 0.0;
|
rt300@5
|
913 }
|
rt300@37
|
914
|
rt300@6
|
915 // check time since last move - if
|
rt300@6
|
916 unsigned int moveTime = ofGetSystemTimeMicros();
|
rt300@6
|
917 if(moveTime - lastMoveTime > 100000){
|
rt300@6
|
918 moveVel = TwoVector(); // zero
|
rt300@6
|
919 }else{
|
rt300@6
|
920 moveVel = (move*0.3 + prevMove*0.34 + prevMove2*0.38); // use the time
|
rt300@6
|
921
|
rt300@6
|
922 }
|
rt300@6
|
923 lastMoveTime = moveTime;
|
rt300@6
|
924
|
rt300@37
|
925
|
rt300@1
|
926 prevMove2 = prevMove;
|
rt300@1
|
927 prevMove = move;
|
rt300@1
|
928
|
rt300@37
|
929
|
rt300@3
|
930 theGridView.move(move);
|
rt300@3
|
931
|
rt300@3
|
932 // and get new parameter values
|
rt300@3
|
933 setAllGUISliders(theGridView.getParams());
|
rt300@39
|
934
|
rt300@1
|
935 }
|
rt300@1
|
936 //--------------------------------------------------------------
|
rt300@27
|
937 // handle pinch movememnt
|
rt300@1
|
938 void testApp::handleZoom(){
|
rt300@1
|
939 // work out change in difference
|
rt300@1
|
940 double dist = touch1.distanceTo(touch0);
|
rt300@1
|
941 double zoomFactor = prevDist/dist;
|
rt300@1
|
942
|
rt300@1
|
943 //TODO check for sensible maximums, e.g. spurious touch data
|
rt300@1
|
944 if(zoomFactor > 2.0 || zoomFactor < 0.5){
|
rt300@1
|
945 cout << "Zoom too much!!!!" << zoomFactor;
|
rt300@1
|
946 zoomFactor = 1.0;
|
rt300@1
|
947 }
|
rt300@1
|
948
|
rt300@1
|
949 zoomVel = (zoomFactor-1)*0.3 + prevZoom*0.34 + prevZoom2*0.38;
|
rt300@1
|
950 prevZoom2 = prevZoom;
|
rt300@1
|
951 prevZoom = (zoomFactor-1);
|
rt300@1
|
952
|
rt300@1
|
953 theGridView.zoom(zoomFactor);
|
rt300@1
|
954
|
rt300@1
|
955 prevDist = dist;
|
rt300@35
|
956
|
rt300@3
|
957
|
rt300@37
|
958 setAllGUISliders(theGridView.getParams());
|
rt300@39
|
959
|
rt300@37
|
960
|
rt300@37
|
961
|
rt300@1
|
962 }
|
rt300@0
|
963 //--------------------------------------------------------------
|
rt300@0
|
964 void testApp::touchDoubleTap(ofTouchEventArgs &touch){
|
rt300@0
|
965 // preset?
|
rt300@25
|
966
|
rt300@25
|
967 /* ballses everything for some reason
|
rt300@37
|
968 TwoVector centre = TwoVector(getWidth()*0.5,getHeight()*0.5);
|
rt300@37
|
969 // if near centre
|
rt300@37
|
970 if((touch.x < centre.x+10) && (touch.x > centre.x-10) && (touch.y < centre.y+10) && (touch.y > centre.y-10)){
|
rt300@37
|
971 numActiveTouches = 0; // dirty
|
rt300@37
|
972 presetManager.showNameDialog();
|
rt300@37
|
973
|
rt300@37
|
974 }
|
rt300@25
|
975 */
|
rt300@25
|
976
|
rt300@0
|
977 }
|
rt300@0
|
978
|
rt300@0
|
979 //--------------------------------------------------------------
|
rt300@0
|
980 void testApp::lostFocus(){
|
rt300@37
|
981
|
rt300@0
|
982 }
|
rt300@0
|
983
|
rt300@0
|
984 //--------------------------------------------------------------
|
rt300@0
|
985 void testApp::gotFocus(){
|
rt300@37
|
986
|
rt300@0
|
987 }
|
rt300@0
|
988
|
rt300@0
|
989 //--------------------------------------------------------------
|
rt300@0
|
990 void testApp::gotMemoryWarning(){
|
rt300@37
|
991
|
rt300@0
|
992 }
|
rt300@0
|
993
|
rt300@0
|
994 //--------------------------------------------------------------
|
rt300@0
|
995 void testApp::deviceOrientationChanged(int newOrientation){
|
rt300@37
|
996 /*
|
rt300@37
|
997 cout << "orientation: " << newOrientation;
|
rt300@37
|
998
|
rt300@37
|
999 if(newOrientation == 4){
|
rt300@37
|
1000 ofxiPhoneSetOrientation( OF_ORIENTATION_DEFAULT );
|
rt300@37
|
1001
|
rt300@37
|
1002 }else if(newOrientation == 3){
|
rt300@37
|
1003 ofxiPhoneSetOrientation( OF_ORIENTATION_90_LEFT );
|
rt300@37
|
1004 }else if(newOrientation == 3){
|
rt300@37
|
1005 ofxiPhoneSetOrientation( OF_ORIENTATION_90_LEFT );
|
rt300@37
|
1006 }
|
rt300@37
|
1007
|
rt300@37
|
1008
|
rt300@37
|
1009 [ofxiPhoneGetGLView() updateDimensions];
|
rt300@37
|
1010 */
|
rt300@0
|
1011 }
|
rt300@0
|
1012
|
rt300@0
|
1013
|
rt300@0
|
1014 //--------------------------------------------------------------
|
rt300@0
|
1015 void testApp::touchCancelled(ofTouchEventArgs& args){
|
rt300@37
|
1016
|
rt300@0
|
1017 }
|
rt300@3
|
1018 //---------------------------------------------------------------
|
rt300@3
|
1019 // AUDIO STUFF
|
rt300@3
|
1020 //---------------------------------------------------------------
|
rt300@3
|
1021
|
rt300@3
|
1022 #pragma mark AUDIO STREAMS
|
rt300@3
|
1023 //--------------------------------------------------------------
|
rt300@3
|
1024 void testApp::audioReceived(float * input, int bufferSize, int nChannels) {
|
rt300@3
|
1025 core.audioReceived(input, bufferSize, nChannels);
|
rt300@3
|
1026 }
|
rt300@3
|
1027
|
rt300@3
|
1028 void testApp::audioRequested(float * output, int bufferSize, int nChannels) {
|
rt300@3
|
1029 core.audioRequested(output, bufferSize, nChannels);
|
rt300@3
|
1030 }
|
rt300@3
|
1031 //---------------------------------------------------------------
|
rt300@3
|
1032 #pragma mark UTILITIES
|
rt300@0
|
1033
|
rt300@0
|
1034 // 5hz cut off
|
rt300@0
|
1035 const double fB[3] = {0.049489956268677, 0.098979912537354, 0.049489956268677};
|
rt300@0
|
1036
|
rt300@0
|
1037 const double fA[3] = {1.000000000000000, -1.279632424997809, 0.477592250072517};
|
rt300@0
|
1038
|
rt300@0
|
1039 // 1hz cut off
|
rt300@0
|
1040 //const double fB[3] = {0.002550535158536, 0.005101070317073, 0.002550535158536};
|
rt300@0
|
1041
|
rt300@0
|
1042 //const double fA[3] = {1.000000000000000, -1.852146485395936, 0.862348626030081};
|
rt300@0
|
1043
|
rt300@0
|
1044
|
rt300@0
|
1045 //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
|
1046 //---------------------------------------------------------------
|
rt300@0
|
1047 vector<float> testApp::vectorFilter(vector<float> newVec){
|
rt300@0
|
1048 static vector<float> x0(10,0);
|
rt300@0
|
1049 static vector<float> x1(10,0);
|
rt300@0
|
1050 static vector<float> x2(10,0);
|
rt300@0
|
1051 static vector<float> y0(10,0);
|
rt300@0
|
1052 static vector<float> y1(10,0);
|
rt300@0
|
1053 static vector<float> y2(10,0);
|
rt300@0
|
1054
|
rt300@0
|
1055 x0 = newVec;
|
rt300@0
|
1056
|
rt300@0
|
1057 // this low passes a bunch of params values all at once
|
rt300@0
|
1058 int sz = newVec.size();
|
rt300@0
|
1059 for(int i=0; i<sz; i++){
|
rt300@0
|
1060 y0[i] = fB[0]*x0[i] + fB[1]*x1[i] + fB[2]*x2[i] - fA[1]*y1[i] - fA[2]*y2[i];
|
rt300@0
|
1061 }
|
rt300@0
|
1062 // shift
|
rt300@0
|
1063 x2 = x1;
|
rt300@0
|
1064 x1 = x0;
|
rt300@0
|
1065 y2 = y1;
|
rt300@0
|
1066 y1 = y0;
|
rt300@0
|
1067
|
rt300@0
|
1068 return y0;
|
rt300@2
|
1069 }
|
rt300@35
|
1070 //---------------------------------------------------------------
|
rt300@24
|
1071 float ctrlSmoother(float newsamp){
|
rt300@24
|
1072 static float x1,x2,y1,y2;
|
rt300@24
|
1073 float x0, y0;
|
rt300@37
|
1074
|
rt300@24
|
1075 x0 = newsamp;
|
rt300@37
|
1076
|
rt300@24
|
1077 y0 = fB[0]*x0 + fB[1]*x1 + fB[2]*x2 - fA[1]*y1 - fA[2]*y2;
|
rt300@37
|
1078
|
rt300@24
|
1079 // shift
|
rt300@24
|
1080 x2 = x1;
|
rt300@24
|
1081 x1 = x0;
|
rt300@24
|
1082 y2 = y1;
|
rt300@24
|
1083 y1 = y0;
|
rt300@24
|
1084
|
rt300@24
|
1085 return y0;
|
rt300@24
|
1086 }
|
rt300@8
|
1087 //---------------------------------------------------------------
|
rt300@45
|
1088 //---------------------------------------------------------------
|
rt300@45
|
1089 //---------------------------------------------------------------
|
rt300@45
|
1090 #pragma mark SYNTH PARAM SENDING TO PD CURVES
|
rt300@3
|
1091 void testApp::sendOscShape(int ctrlin){
|
rt300@35
|
1092 if(ctrlin < 0 || ctrlin > 127){
|
rt300@35
|
1093 cout << "ERROR: bad slider value!";
|
rt300@35
|
1094 return;
|
rt300@35
|
1095 }
|
rt300@3
|
1096
|
rt300@3
|
1097 static int numpoints = 5;
|
rt300@3
|
1098 static int numcontrols = 5;
|
rt300@3
|
1099 //float values[points][controls] =
|
rt300@3
|
1100 float ctrlout[numcontrols];
|
rt300@45
|
1101 string ctrlName[4] = {"pWidth" , "sqVol", "sawVol", "sineVol"};
|
rt300@45
|
1102 float values[5][4] =
|
rt300@45
|
1103 {{0.5, 0., 0., 1.}, // 0
|
rt300@45
|
1104 {0.5, 0., 0., 1.}, // 32
|
rt300@45
|
1105 {0.5, 0., 1., 0.}, // 64
|
rt300@45
|
1106 {0.5, 1., 1., 0.}, // 96
|
rt300@45
|
1107 {0.01,1., 1., 0.}}; // 127
|
rt300@37
|
1108
|
rt300@3
|
1109 float fidx = (numpoints-1)*ctrlin/128.;
|
rt300@3
|
1110 int idx = floor(fidx);
|
rt300@3
|
1111 float frac = fidx - idx;
|
rt300@3
|
1112 for(int i=0; i < numcontrols; i++){
|
rt300@3
|
1113 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
|
rt300@3
|
1114 // send to PD
|
rt300@3
|
1115 List toPD;
|
rt300@3
|
1116
|
rt300@3
|
1117 toPD.addSymbol(ctrlName[i]);
|
rt300@3
|
1118 toPD.addFloat(ctrlout[i]); // rounding here??
|
rt300@37
|
1119
|
rt300@3
|
1120 core.pd.sendList("fromOF", toPD);
|
rt300@3
|
1121 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
|
rt300@3
|
1122 }
|
rt300@3
|
1123
|
rt300@2
|
1124 }
|
rt300@8
|
1125 //---------------------------------------------------------------
|
rt300@3
|
1126 void testApp::sendFiltType(int ctrlin){
|
rt300@35
|
1127 if(ctrlin < 0 || ctrlin > 127){
|
rt300@35
|
1128 cout << "ERROR: bad slider value!";
|
rt300@35
|
1129 return;
|
rt300@35
|
1130 }
|
rt300@45
|
1131 /*
|
rt300@45
|
1132 static int numpoints = 3;
|
rt300@45
|
1133 static int numcontrols = 2;
|
rt300@45
|
1134 //float values[points][controls] =
|
rt300@45
|
1135 float ctrlout[numcontrols];
|
rt300@45
|
1136 string ctrlName[2] = {"fType","reson"};
|
rt300@45
|
1137 float values[3][2] =
|
rt300@45
|
1138 {{0., 45}, // 0
|
rt300@45
|
1139 {0.5, 120}, // 64
|
rt300@45
|
1140 {1., 55}}; // 127
|
rt300@45
|
1141 */
|
rt300@45
|
1142
|
rt300@45
|
1143 static int numpoints = 2;
|
rt300@45
|
1144 static int numcontrols = 1;
|
rt300@45
|
1145 //float values[points][controls] =
|
rt300@45
|
1146 float ctrlout[numcontrols];
|
rt300@45
|
1147 string ctrlName[2] = {"fType"};
|
rt300@45
|
1148 float values[2][1] =
|
rt300@45
|
1149 {{0.}, // 0
|
rt300@45
|
1150 {1.},}; // 127
|
rt300@45
|
1151
|
rt300@45
|
1152 float fidx = (numpoints-1)*ctrlin/128.;
|
rt300@45
|
1153 int idx = floor(fidx);
|
rt300@45
|
1154 float frac = fidx - idx;
|
rt300@45
|
1155
|
rt300@45
|
1156 for(int i=0; i < numcontrols; i++){
|
rt300@45
|
1157 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
|
rt300@45
|
1158 // send to PD
|
rt300@45
|
1159 List toPD;
|
rt300@45
|
1160
|
rt300@45
|
1161 toPD.addSymbol(ctrlName[i]);
|
rt300@45
|
1162 toPD.addFloat(ctrlout[i]); // rounding here??
|
rt300@45
|
1163
|
rt300@45
|
1164 core.pd.sendList("fromOF", toPD);
|
rt300@45
|
1165 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
|
rt300@45
|
1166 }
|
rt300@45
|
1167 }
|
rt300@45
|
1168 //---------------------------------------------------------------
|
rt300@45
|
1169 void testApp::sendFiltTypeOld(int ctrlin){
|
rt300@45
|
1170 if(ctrlin < 0 || ctrlin > 127){
|
rt300@45
|
1171 cout << "ERROR: bad slider value!";
|
rt300@45
|
1172 return;
|
rt300@45
|
1173 }
|
rt300@3
|
1174 static int numpoints = 3;
|
rt300@3
|
1175 static int numcontrols = 4;
|
rt300@3
|
1176 //float values[points][controls] =
|
rt300@3
|
1177 float ctrlout[numcontrols];
|
rt300@3
|
1178 string ctrlName[4] = {"lpLev" , "bpLev", "hpLev", "reson"};
|
rt300@3
|
1179 float values[3][4] =
|
rt300@37
|
1180 {{2., 0., 0., 1.}, // 0
|
rt300@24
|
1181 {0., 10., 0., 10.}, // 64
|
rt300@24
|
1182 {0., 0., 1., 1.}}; // 127
|
rt300@3
|
1183
|
rt300@3
|
1184 float fidx = (numpoints-1)*ctrlin/128.;
|
rt300@3
|
1185 int idx = floor(fidx);
|
rt300@3
|
1186 float frac = fidx - idx;
|
rt300@3
|
1187 for(int i=0; i < numcontrols; i++){
|
rt300@3
|
1188 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
|
rt300@3
|
1189 // send to PD
|
rt300@3
|
1190 List toPD;
|
rt300@3
|
1191
|
rt300@3
|
1192 toPD.addSymbol(ctrlName[i]);
|
rt300@3
|
1193 toPD.addFloat(ctrlout[i]); // rounding here??
|
rt300@3
|
1194
|
rt300@3
|
1195 core.pd.sendList("fromOF", toPD);
|
rt300@3
|
1196 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
|
rt300@3
|
1197 }
|
rt300@2
|
1198 }
|
rt300@8
|
1199 //---------------------------------------------------------------
|
rt300@3
|
1200 void testApp::sendFiltFreq(int ctrlin){
|
rt300@35
|
1201 if(ctrlin < 0 || ctrlin > 127){
|
rt300@35
|
1202 cout << "ERROR: bad slider value!";
|
rt300@35
|
1203 return;
|
rt300@35
|
1204 }
|
rt300@24
|
1205 // smooth this
|
rt300@24
|
1206 float fin = ctrlin;
|
rt300@24
|
1207 float fout;
|
rt300@24
|
1208 fout = (int)ctrlSmoother(fin);
|
rt300@3
|
1209 List toPD;
|
rt300@3
|
1210
|
rt300@3
|
1211 toPD.addSymbol("filtFreq");
|
rt300@37
|
1212 toPD.addFloat(fout);
|
rt300@3
|
1213
|
rt300@3
|
1214 core.pd.sendList("fromOF", toPD);
|
rt300@3
|
1215 }
|
rt300@8
|
1216 //---------------------------------------------------------------
|
rt300@3
|
1217 void testApp::sendEnvShape(int ctrlin){
|
rt300@35
|
1218 if(ctrlin < 0 || ctrlin > 127){
|
rt300@35
|
1219 cout << "ERROR: bad slider value!";
|
rt300@35
|
1220 return;
|
rt300@35
|
1221 }
|
rt300@3
|
1222 static int numpoints = 5;
|
rt300@3
|
1223 static int numcontrols = 3;
|
rt300@3
|
1224 //float values[points][controls] =
|
rt300@3
|
1225 float ctrlout[numcontrols];
|
rt300@3
|
1226 string ctrlName[3] = {"attack" , "decay", "sustain"};
|
rt300@3
|
1227 float values[5][3] =
|
rt300@37
|
1228 {{0., 0., 0.}, // 0
|
rt300@3
|
1229 {0., 0.5, 0.}, // 32
|
rt300@3
|
1230 {0.0, 1., 0.8}, // 64
|
rt300@3
|
1231 {0.99, 0.3, 0.}, // 96
|
rt300@3
|
1232 {0.3, 0.1, 0.}}; // 127
|
rt300@3
|
1233
|
rt300@3
|
1234 float fidx = (numpoints-1)*ctrlin/128.;
|
rt300@3
|
1235 int idx = floor(fidx);
|
rt300@3
|
1236 float frac = fidx - idx;
|
rt300@3
|
1237 for(int i=0; i < numcontrols; i++){
|
rt300@3
|
1238 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
|
rt300@3
|
1239 // send to PD
|
rt300@3
|
1240 List toPD;
|
rt300@3
|
1241
|
rt300@3
|
1242 toPD.addSymbol(ctrlName[i]);
|
rt300@3
|
1243 toPD.addFloat(ctrlout[i]); // rounding here??
|
rt300@3
|
1244
|
rt300@3
|
1245 core.pd.sendList("fromOF", toPD);
|
rt300@3
|
1246 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
|
rt300@3
|
1247 }
|
rt300@3
|
1248 }
|
rt300@8
|
1249 //---------------------------------------------------------------
|
rt300@43
|
1250 // alternative envelopes: seperate for amp and filt
|
rt300@43
|
1251 void testApp::sendAmpEnvShape(int ctrlin){
|
rt300@43
|
1252 if(ctrlin < 0 || ctrlin > 127){
|
rt300@43
|
1253 cout << "ERROR: bad slider value!";
|
rt300@43
|
1254 return;
|
rt300@43
|
1255 }
|
rt300@43
|
1256 static int numpoints = 5;
|
rt300@43
|
1257 static int numcontrols = 3;
|
rt300@43
|
1258 //float values[points][controls] =
|
rt300@43
|
1259 float ctrlout[numcontrols];
|
rt300@43
|
1260 string ctrlName[3] = {"attack" , "decay", "sustain"};
|
rt300@43
|
1261 float values[5][3] =
|
rt300@43
|
1262 {{0., 0., 0.}, // 0
|
rt300@43
|
1263 {0., 0.5, 0.}, // 32
|
rt300@43
|
1264 {0.0, 1., 0.8}, // 64
|
rt300@43
|
1265 {0.99, 0.3, 0.}, // 96
|
rt300@43
|
1266 {0.3, 0.1, 0.}}; // 127
|
rt300@43
|
1267
|
rt300@43
|
1268 float fidx = (numpoints-1)*ctrlin/128.;
|
rt300@43
|
1269 int idx = floor(fidx);
|
rt300@43
|
1270 float frac = fidx - idx;
|
rt300@43
|
1271 for(int i=0; i < numcontrols; i++){
|
rt300@43
|
1272 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
|
rt300@43
|
1273 // send to PD
|
rt300@43
|
1274 List toPD;
|
rt300@43
|
1275 toPD.addSymbol("aenv");
|
rt300@43
|
1276 toPD.addSymbol(ctrlName[i]);
|
rt300@43
|
1277 toPD.addFloat(ctrlout[i]); // rounding here??
|
rt300@43
|
1278
|
rt300@43
|
1279 core.pd.sendList("fromOF", toPD);
|
rt300@43
|
1280 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
|
rt300@43
|
1281 }
|
rt300@43
|
1282 }
|
rt300@43
|
1283 //---------------------------------------------------------------
|
rt300@43
|
1284 void testApp::sendFiltEnvShape(int ctrlin){
|
rt300@43
|
1285 if(ctrlin < 0 || ctrlin > 127){
|
rt300@43
|
1286 cout << "ERROR: bad slider value!";
|
rt300@43
|
1287 return;
|
rt300@43
|
1288 }
|
rt300@43
|
1289 static int numpoints = 5;
|
rt300@43
|
1290 static int numcontrols = 3;
|
rt300@43
|
1291 //float values[points][controls] =
|
rt300@43
|
1292 float ctrlout[numcontrols];
|
rt300@43
|
1293 string ctrlName[3] = {"attack" , "decay", "sustain"};
|
rt300@43
|
1294 float values[5][3] =
|
rt300@43
|
1295 {{0., 0., 0.}, // 0
|
rt300@43
|
1296 {0., 0.5, 0.}, // 32
|
rt300@43
|
1297 {0.0, 1., 0.8}, // 64
|
rt300@43
|
1298 {0.99, 0.3, 0.}, // 96
|
rt300@43
|
1299 {0.3, 0.1, 0.}}; // 127
|
rt300@43
|
1300
|
rt300@43
|
1301 float fidx = (numpoints-1)*ctrlin/128.;
|
rt300@43
|
1302 int idx = floor(fidx);
|
rt300@43
|
1303 float frac = fidx - idx;
|
rt300@43
|
1304 for(int i=0; i < numcontrols; i++){
|
rt300@43
|
1305 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
|
rt300@43
|
1306 // send to PD
|
rt300@43
|
1307 List toPD;
|
rt300@43
|
1308 toPD.addSymbol("fenv");
|
rt300@43
|
1309 toPD.addSymbol(ctrlName[i]);
|
rt300@43
|
1310 toPD.addFloat(ctrlout[i]); // rounding here??
|
rt300@43
|
1311
|
rt300@43
|
1312 core.pd.sendList("fromOF", toPD);
|
rt300@43
|
1313 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
|
rt300@43
|
1314 }
|
rt300@43
|
1315 }
|
rt300@43
|
1316 //---------------------------------------------------------------
|
rt300@45
|
1317 void testApp::sendFiltEnvModAmt(int ctrlin){
|
rt300@45
|
1318 if(ctrlin < 0 || ctrlin > 127){
|
rt300@45
|
1319 cout << "ERROR: bad slider value!";
|
rt300@45
|
1320 return;
|
rt300@45
|
1321 }
|
rt300@45
|
1322 float amt = ctrlin/127.0;
|
rt300@45
|
1323 List toPD;
|
rt300@45
|
1324
|
rt300@45
|
1325 toPD.addSymbol("fenv");
|
rt300@45
|
1326 toPD.addSymbol("amount");
|
rt300@45
|
1327 toPD.addFloat(amt); // rounding here??
|
rt300@45
|
1328
|
rt300@45
|
1329 core.pd.sendList("fromOF", toPD);
|
rt300@45
|
1330 }
|
rt300@45
|
1331 //---------------------------------------------------------------
|
rt300@3
|
1332 void testApp::sendModFreq(int ctrlin){
|
rt300@35
|
1333 if(ctrlin < 0 || ctrlin > 127){
|
rt300@35
|
1334 cout << "ERROR: bad slider value!";
|
rt300@35
|
1335 return;
|
rt300@35
|
1336 }
|
rt300@3
|
1337 float fm = ctrlin/127.;
|
rt300@3
|
1338 List toPD;
|
rt300@3
|
1339
|
rt300@3
|
1340 toPD.addSymbol("FMFreq");
|
rt300@3
|
1341 toPD.addFloat(fm); // rounding here??
|
rt300@3
|
1342
|
rt300@3
|
1343 core.pd.sendList("fromOF", toPD);
|
rt300@8
|
1344 }
|
rt300@35
|
1345 //---------------------------------------------------------------
|
rt300@45
|
1346 //---------------------------------------------------------------
|
rt300@45
|
1347 void testApp::sendRevAmt(int ctrlin){
|
rt300@45
|
1348 if(ctrlin < 0 || ctrlin > 127){
|
rt300@45
|
1349 cout << "ERROR: bad slider value!";
|
rt300@45
|
1350 return;
|
rt300@45
|
1351 }
|
rt300@45
|
1352 static int numpoints = 5;
|
rt300@45
|
1353 static int numcontrols = 2;
|
rt300@45
|
1354 //float values[points][controls] =
|
rt300@45
|
1355 float ctrlout[numcontrols];
|
rt300@45
|
1356 string ctrlName[3] = {"revDryWet" , "revLength"};
|
rt300@45
|
1357 float values[5][3] =
|
rt300@45
|
1358 {{0., 0.1}, // 0
|
rt300@45
|
1359 {0., 0.1}, // 32
|
rt300@45
|
1360 {0.3, 30.}, // 64
|
rt300@45
|
1361 {0.6, 60.}, // 96
|
rt300@45
|
1362 {1., 95.}}; // 127
|
rt300@45
|
1363
|
rt300@45
|
1364 float fidx = (numpoints-1)*ctrlin/128.;
|
rt300@45
|
1365 int idx = floor(fidx);
|
rt300@45
|
1366 float frac = fidx - idx;
|
rt300@45
|
1367 for(int i=0; i < numcontrols; i++){
|
rt300@45
|
1368 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
|
rt300@45
|
1369 // send to PD
|
rt300@45
|
1370 List toPD;
|
rt300@45
|
1371 toPD.addSymbol(ctrlName[i]);
|
rt300@45
|
1372 toPD.addFloat(ctrlout[i]); // rounding here??
|
rt300@45
|
1373
|
rt300@45
|
1374 core.pd.sendList("fromOF", toPD);
|
rt300@45
|
1375 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
|
rt300@45
|
1376 }
|
rt300@35
|
1377
|
rt300@45
|
1378 }
|
rt300@45
|
1379 //---------------------------------------------------------------
|
rt300@45
|
1380 void testApp::sendResonance(int ctrlin){
|
rt300@45
|
1381 if(ctrlin < 0 || ctrlin > 127){
|
rt300@45
|
1382 cout << "ERROR: bad slider value!";
|
rt300@45
|
1383 return;
|
rt300@45
|
1384 }
|
rt300@45
|
1385 float res = ctrlin;
|
rt300@45
|
1386 List toPD;
|
rt300@45
|
1387
|
rt300@45
|
1388 toPD.addSymbol("reson");
|
rt300@45
|
1389 toPD.addFloat(res); // rounding here??
|
rt300@45
|
1390
|
rt300@45
|
1391 core.pd.sendList("fromOF", toPD);
|
rt300@45
|
1392 }
|
rt300@45
|
1393 //---------------------------------------------------------------------------
|
rt300@45
|
1394 void testApp::sendFMAmt(int ctrlin){
|
rt300@45
|
1395 static int numpoints = 4;
|
rt300@45
|
1396 static int numcontrols = 1;
|
rt300@45
|
1397 //float values[points][controls] =
|
rt300@45
|
1398 float ctrlout[numcontrols];
|
rt300@45
|
1399 string ctrlName[1] = {"FMAmt"};
|
rt300@45
|
1400 float values[4][1] =
|
rt300@45
|
1401 {{0.}, // 0
|
rt300@45
|
1402 {0.}, //
|
rt300@45
|
1403 {0.3}, //
|
rt300@45
|
1404 {1.}}; // 127
|
rt300@45
|
1405
|
rt300@45
|
1406 float fidx = (numpoints-1)*ctrlin/128.;
|
rt300@45
|
1407 int idx = floor(fidx);
|
rt300@45
|
1408 float frac = fidx - idx;
|
rt300@45
|
1409 for(int i=0; i < numcontrols; i++){
|
rt300@45
|
1410 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
|
rt300@45
|
1411 // send to PD
|
rt300@45
|
1412 List toPD;
|
rt300@45
|
1413 toPD.addSymbol(ctrlName[i]);
|
rt300@45
|
1414 toPD.addFloat(ctrlout[i]); // rounding here??
|
rt300@45
|
1415
|
rt300@45
|
1416 core.pd.sendList("fromOF", toPD);
|
rt300@45
|
1417 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
|
rt300@45
|
1418 }
|
rt300@45
|
1419 }
|
rt300@45
|
1420 //---------------------------------------------------------------------------
|
rt300@45
|
1421 void testApp::sendDistortion(int ctrlin){
|
rt300@45
|
1422 static int numpoints = 5;
|
rt300@45
|
1423 static int numcontrols = 2;
|
rt300@45
|
1424 //float values[points][controls] =
|
rt300@45
|
1425 float ctrlout[numcontrols];
|
rt300@45
|
1426 string ctrlName[2] = {"sigGain", "sineGain"};
|
rt300@45
|
1427 float values[5][2] =
|
rt300@45
|
1428 {{0., 0.}, // 0
|
rt300@45
|
1429 {0., 0.}, //
|
rt300@45
|
1430 {20, 0.}, //
|
rt300@45
|
1431 {45 , 0.}, //
|
rt300@45
|
1432 {0, 18}}; // 127
|
rt300@45
|
1433
|
rt300@45
|
1434 float fidx = (numpoints-1)*ctrlin/128.;
|
rt300@45
|
1435 int idx = floor(fidx);
|
rt300@45
|
1436 float frac = fidx - idx;
|
rt300@45
|
1437 for(int i=0; i < numcontrols; i++){
|
rt300@45
|
1438 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
|
rt300@45
|
1439 // send to PD
|
rt300@45
|
1440 List toPD;
|
rt300@45
|
1441 toPD.addSymbol(ctrlName[i]);
|
rt300@45
|
1442 toPD.addFloat(ctrlout[i]); // rounding here??
|
rt300@45
|
1443
|
rt300@45
|
1444 core.pd.sendList("fromOF", toPD);
|
rt300@45
|
1445 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
|
rt300@45
|
1446 }
|
rt300@45
|
1447 }
|
rt300@45
|
1448 //---------------------------------------------------------------------------
|
rt300@45
|
1449 //===========================================================================
|
rt300@35
|
1450 //---------------------------------------------------------------------------
|
rt300@35
|
1451 void saveSequences(){
|
rt300@35
|
1452 ofFile sequenceFile(ofxiPhoneGetDocumentsDirectory() + "pilot_sequences.json" ,ofFile::WriteOnly);
|
rt300@35
|
1453
|
rt300@35
|
1454 // the 5 harmonics for the frequencer
|
rt300@35
|
1455 vector<int> freqIndexes;
|
rt300@35
|
1456 freqIndexes.push_back(0);
|
rt300@35
|
1457 freqIndexes.push_back(4);
|
rt300@35
|
1458 freqIndexes.push_back(6);
|
rt300@35
|
1459 freqIndexes.push_back(7);
|
rt300@35
|
1460 freqIndexes.push_back(8);
|
rt300@35
|
1461
|
rt300@35
|
1462 // loop thru all presets
|
rt300@35
|
1463 int N = presetManager.thePresets.size();
|
rt300@35
|
1464
|
rt300@35
|
1465 vector<int> sliderVals;
|
rt300@35
|
1466
|
rt300@35
|
1467 Json::Value root;
|
rt300@35
|
1468
|
rt300@35
|
1469 vector<double> vals;
|
rt300@35
|
1470
|
rt300@35
|
1471 for(int i = 0; i< N ; i++){
|
rt300@44
|
1472 sliderVals = theGridView.calculateParamsFromCoord(presetManager.thePresets[i].coordinates);
|
rt300@35
|
1473
|
rt300@35
|
1474 vals.push_back((sliderVals[0]+32)*8.); // DC offset
|
rt300@35
|
1475 for(int i=1; i<5;i++){
|
rt300@35
|
1476 vals.push_back((sliderVals[i] - 64)*2.);
|
rt300@35
|
1477 }
|
rt300@35
|
1478
|
rt300@35
|
1479
|
rt300@35
|
1480 vector<double> steps = frequencer.freqMagEdit(freqIndexes, vals);
|
rt300@35
|
1481
|
rt300@35
|
1482 for(int j = 0; j<16;j++){
|
rt300@35
|
1483 root["sequences"][i][j] = int(steps[j]);
|
rt300@35
|
1484 }
|
rt300@35
|
1485 vals.clear();
|
rt300@35
|
1486 }
|
rt300@35
|
1487
|
rt300@35
|
1488 //cout << root;
|
rt300@35
|
1489 sequenceFile << root;
|
rt300@35
|
1490 }
|
rt300@35
|
1491 //=--------------------------------------------------------------------
|
rt300@36
|
1492 void testApp::loadSequences(){
|
rt300@36
|
1493
|
rt300@36
|
1494 // read in sequence preset file
|
rt300@45
|
1495 string jsonFile = ofFilePath::getAbsolutePath(ofToDataPath("pilot_sequences.json"));
|
rt300@45
|
1496
|
rt300@45
|
1497 cout << "SQUENCES FILE: " << jsonFile << "\n";
|
rt300@45
|
1498 //string jsonFile = ofxiPhoneGetDocumentsDirectory() + "pilot_sequences.json";
|
rt300@37
|
1499
|
rt300@36
|
1500 Json::Value root;
|
rt300@36
|
1501 Json::Reader reader;
|
rt300@37
|
1502
|
rt300@36
|
1503 ifstream theFile(jsonFile.c_str());
|
rt300@36
|
1504 stringstream fileText;
|
rt300@36
|
1505 string line;
|
rt300@36
|
1506 if(!theFile){
|
rt300@36
|
1507 cout<<"can't find sequence file: " << jsonFile.c_str() << "\n";
|
rt300@36
|
1508 return;
|
rt300@36
|
1509 }else{
|
rt300@36
|
1510
|
rt300@36
|
1511 while(theFile){
|
rt300@36
|
1512 theFile >> line;
|
rt300@36
|
1513 // cout << line << "\n"; // lots?
|
rt300@37
|
1514 fileText << line;
|
rt300@36
|
1515 }
|
rt300@36
|
1516
|
rt300@36
|
1517 theFile.close();
|
rt300@36
|
1518 }
|
rt300@36
|
1519
|
rt300@36
|
1520 bool parsingSuccessful = reader.parse( fileText.str(), root );
|
rt300@36
|
1521
|
rt300@36
|
1522 if ( !parsingSuccessful )
|
rt300@36
|
1523 {
|
rt300@36
|
1524 // report to the user the failure and their locations in the document.
|
rt300@36
|
1525 std::cout << "Failed to parse sequence JSON: \n"
|
rt300@36
|
1526 << reader.getFormattedErrorMessages();
|
rt300@36
|
1527 return;
|
rt300@36
|
1528 }
|
rt300@36
|
1529
|
rt300@36
|
1530 // now put into variables
|
rt300@36
|
1531 const Json::Value jseqs = root["sequences"];
|
rt300@36
|
1532 int N = jseqs.size();
|
rt300@36
|
1533 for(int i=0; i<N; i++){
|
rt300@36
|
1534 sequences.push_back(vector<int>());
|
rt300@36
|
1535 for(int j=0; j<jseqs[i].size(); j++){
|
rt300@36
|
1536 sequences.back().push_back(jseqs[i][j].asInt());
|
rt300@36
|
1537 }
|
rt300@36
|
1538 }
|
rt300@36
|
1539 // currentSequence
|
rt300@37
|
1540
|
rt300@37
|
1541 currentSequence = ofRandom(0,N-1);
|
rt300@36
|
1542
|
rt300@36
|
1543 }
|
rt300@39
|
1544 //-------------------------------------------------------------------------
|
rt300@39
|
1545 //--------------------------------------------------------------
|
rt300@39
|
1546
|
rt300@39
|
1547 #pragma mark MIDI
|
rt300@39
|
1548 void testApp::addMessage(string msg) {
|
rt300@39
|
1549 cout << msg << endl;
|
rt300@39
|
1550 messages.push_back(msg);
|
rt300@39
|
1551 while(messages.size() > maxMessages)
|
rt300@39
|
1552 messages.pop_front();
|
rt300@39
|
1553 }
|
rt300@39
|
1554
|
rt300@39
|
1555 //--------------------------------------------------------------
|
rt300@39
|
1556 void testApp::newMidiMessage(ofxMidiMessage& msg) {
|
rt300@39
|
1557 //addMessage(msg.toString());
|
rt300@39
|
1558
|
rt300@39
|
1559 // look at what it is
|
rt300@39
|
1560
|
rt300@39
|
1561 if(msg.channel == midiChannel && msg.status == MIDI_CONTROL_CHANGE){
|
rt300@39
|
1562 int ctl_num = msg.control;
|
rt300@39
|
1563 int ctl_val = msg.value;
|
rt300@39
|
1564 if(ctl_num - midiOffset >= 0 && ctl_num - midiOffset < sliderVals.size()){
|
rt300@39
|
1565 sliderVals[ctl_num] = (int)ctl_val;
|
rt300@39
|
1566 sliders[ctl_num]->setValue(ctl_val);
|
rt300@39
|
1567 theGridView.setParams(sliderVals);
|
rt300@39
|
1568 }
|
rt300@39
|
1569 }
|
rt300@39
|
1570
|
rt300@39
|
1571 }
|
rt300@39
|
1572
|
rt300@39
|
1573 //--------------------------------------------------------------
|
rt300@39
|
1574 void testApp::midiInputAdded(string name, bool isNetwork) {
|
rt300@39
|
1575 stringstream msg;
|
rt300@39
|
1576 msg << "ofxMidi: input added: " << name << " network: " << isNetwork;
|
rt300@39
|
1577 cout << msg.str();
|
rt300@39
|
1578 addMessage(msg.str());
|
rt300@39
|
1579
|
rt300@39
|
1580 // create and open a new input port
|
rt300@39
|
1581 ofxMidiIn * newInput = new ofxMidiIn;
|
rt300@39
|
1582 newInput->openPort(name);
|
rt300@39
|
1583 newInput->addListener(this);
|
rt300@39
|
1584 inputs.push_back(newInput);
|
rt300@39
|
1585 }
|
rt300@39
|
1586
|
rt300@39
|
1587 //--------------------------------------------------------------
|
rt300@39
|
1588 void testApp::midiInputRemoved(string name, bool isNetwork) {
|
rt300@39
|
1589 stringstream msg;
|
rt300@39
|
1590 msg << "ofxMidi: input removed: " << name << " network: " << isNetwork << endl;
|
rt300@39
|
1591 cout << msg.str();
|
rt300@39
|
1592 addMessage(msg.str());
|
rt300@39
|
1593
|
rt300@39
|
1594 // close and remove input port
|
rt300@39
|
1595 vector<ofxMidiIn*>::iterator iter;
|
rt300@39
|
1596 for(iter = inputs.begin(); iter != inputs.end(); ++iter) {
|
rt300@39
|
1597 ofxMidiIn * input = (*iter);
|
rt300@39
|
1598 if(input->getName() == name) {
|
rt300@39
|
1599 input->closePort();
|
rt300@39
|
1600 input->removeListener(this);
|
rt300@39
|
1601 delete input;
|
rt300@39
|
1602 inputs.erase(iter);
|
rt300@39
|
1603 break;
|
rt300@39
|
1604 }
|
rt300@39
|
1605 }
|
rt300@39
|
1606 }
|
rt300@39
|
1607
|
rt300@39
|
1608 //--------------------------------------------------------------
|
rt300@39
|
1609 void testApp::midiOutputAdded(string name, bool isNetwork) {
|
rt300@39
|
1610 stringstream msg;
|
rt300@39
|
1611 msg << "ofxMidi: output added: " << name << " network: " << isNetwork << endl;
|
rt300@39
|
1612 cout << msg.str();
|
rt300@39
|
1613 addMessage(msg.str());
|
rt300@39
|
1614
|
rt300@39
|
1615 // create and open new output port
|
rt300@39
|
1616 ofxMidiOut * newOutput = new ofxMidiOut;
|
rt300@39
|
1617 newOutput->openPort(name);
|
rt300@39
|
1618 outputs.push_back(newOutput);
|
rt300@39
|
1619 }
|
rt300@39
|
1620
|
rt300@39
|
1621 //--------------------------------------------------------------
|
rt300@39
|
1622 void testApp::midiOutputRemoved(string name, bool isNetwork) {
|
rt300@39
|
1623 stringstream msg;
|
rt300@39
|
1624 msg << "ofxMidi: output removed: " << name << " network: " << isNetwork << endl;
|
rt300@39
|
1625 cout << msg.str();
|
rt300@39
|
1626 addMessage(msg.str());
|
rt300@39
|
1627
|
rt300@39
|
1628 // close and remove output port
|
rt300@39
|
1629 vector<ofxMidiOut*>::iterator iter;
|
rt300@39
|
1630 for(iter = outputs.begin(); iter != outputs.end(); ++iter) {
|
rt300@39
|
1631 ofxMidiOut * output = (*iter);
|
rt300@39
|
1632 if(output->getName() == name) {
|
rt300@39
|
1633 output->closePort();
|
rt300@39
|
1634 delete output;
|
rt300@39
|
1635 outputs.erase(iter);
|
rt300@39
|
1636 break;
|
rt300@39
|
1637 }
|
rt300@39
|
1638 }
|
rt300@39
|
1639 }
|
rt300@39
|
1640 //-------------------------------------------------------------- |