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