Mercurial > hg > soniczoomios
comparison testApp.mm @ 45:c2fffc8ea84d
10 timbre params.
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Tue, 23 Apr 2013 18:29:55 +0100 |
parents | a1e75b94c505 |
children | 1e266647840d |
comparison
equal
deleted
inserted
replaced
44:a1e75b94c505 | 45:c2fffc8ea84d |
---|---|
550 //-------------------------------------------------------------- | 550 //-------------------------------------------------------------- |
551 //-------------------------------------------------------------- | 551 //-------------------------------------------------------------- |
552 #pragma mark sending to pd and midi | 552 #pragma mark sending to pd and midi |
553 void testApp::sendParametersToPD(){ | 553 void testApp::sendParametersToPD(){ |
554 static int previousSequence; | 554 static int previousSequence; |
555 // frequencer stuff to get 16 steps | 555 |
556 | 556 if(core.patchName == "synth5paramMM.pd"){ |
557 vector<double> vals; | 557 // frequencer stuff to get 16 steps |
558 | 558 |
559 | 559 vector<double> vals; |
560 vals.push_back((sliderVals[0]+32)*8.); // DC offset | 560 |
561 for(int i=1; i<5;i++){ | 561 |
562 vals.push_back((sliderVals[i] - 64)*2.); | 562 vals.push_back((sliderVals[0]+32)*8.); // DC offset |
563 } | 563 for(int i=1; i<5;i++){ |
564 | 564 vals.push_back((sliderVals[i] - 64)*2.); |
565 vector<double> steps = frequencer.freqMagEdit(freqIndexes, vals); | 565 } |
566 List seqSteps; | 566 |
567 seqSteps.addSymbol("seqSteps"); | 567 vector<double> steps = frequencer.freqMagEdit(freqIndexes, vals); |
568 for(int i=0; i < 16; i++){ | 568 List seqSteps; |
569 seqSteps.addFloat(round(steps[i])); | 569 seqSteps.addSymbol("seqSteps"); |
570 } | 570 for(int i=0; i < 16; i++){ |
571 core.pd.sendList("fromOF", seqSteps); | 571 seqSteps.addFloat(round(steps[i])); |
572 } | |
573 core.pd.sendList("fromOF", seqSteps); | |
574 | |
575 | |
576 // send synth params | |
577 sendOscShape(sliderVals[5]); | |
578 sendFiltType(sliderVals[6]); | |
579 sendFiltFreq(sliderVals[7]); | |
580 sendEnvShape(sliderVals[8]); | |
581 sendModFreq(sliderVals[9]); | |
582 | |
583 }else if (core.patchName == "synth10param.pd"){ | |
584 // for 10 param synth we get sequence from saved presets | |
585 // and send 5 extra synth params | |
586 if(currentSequence != previousSequence){ | |
587 List seqSteps; | |
588 | |
589 seqSteps.addSymbol("seqSteps"); | |
590 if(currentSequence >= sequences.size() || currentSequence < 0){ | |
591 cout << "ERROR: not a valid sequence index\n"; | |
592 for(int i=0; i < 16; i++){ | |
593 seqSteps.addFloat(50); | |
594 } | |
595 }else{ | |
596 for(int i=0; i < 16; i++){ | |
597 seqSteps.addFloat(round(sequences[currentSequence][i])); | |
598 } | |
599 } | |
600 | |
601 core.pd.sendList("fromOF", seqSteps); | |
602 previousSequence = currentSequence; | |
603 } | |
604 /* | |
605 @"Amp Env",@"Waveform",@"FM amount",@"FM frequency",@"Reverb", | |
606 @"Filter Type",@"Filter Cut off",@"Filter Resonance",@"Filter Envelope",@"SOMETHING", | |
607 */ | |
608 // send synth params | |
609 sendAmpEnvShape(sliderVals[0]); | |
610 sendOscShape(sliderVals[1]); | |
611 sendFMAmt(sliderVals[2]); | |
612 sendModFreq(sliderVals[3]); | |
613 sendRevAmt(sliderVals[4]); | |
614 | |
615 sendFiltType(sliderVals[5]); | |
616 sendFiltFreq(sliderVals[6]); | |
617 sendResonance(sliderVals[7]); | |
618 sendFiltEnvShape(sliderVals[8]); | |
619 sendFiltEnvModAmt(sliderVals[9]); | |
620 //sendUmame(sliderVals[8]); | |
621 //sendX(sliderVals[2]); | |
622 //sendX(sliderVals[3]); | |
623 | |
624 | |
625 | |
626 | |
627 | |
628 | |
629 } | |
630 | |
572 | 631 |
573 /* | 632 /* |
574 if(currentSequence != previousSequence){ | 633 cout << "SLIDERVALS: "; |
575 List seqSteps; | 634 for(int i=0;i<10;i++){ |
576 | 635 cout << sliderVals[i] << ","; |
577 seqSteps.addSymbol("seqSteps"); | 636 } |
578 if(currentSequence >= sequences.size() || currentSequence < 0){ | 637 cout << '\n'; |
579 cout << "ERROR: not a valid sequence index\n"; | 638 */ |
580 for(int i=0; i < 16; i++){ | |
581 seqSteps.addFloat(50); | |
582 } | |
583 }else{ | |
584 for(int i=0; i < 16; i++){ | |
585 seqSteps.addFloat(round(sequences[currentSequence][i])); | |
586 } | |
587 } | |
588 | |
589 core.pd.sendList("fromOF", seqSteps); | |
590 previousSequence = currentSequence; | |
591 } | |
592 */ | |
593 | |
594 // send synth params | |
595 sendOscShape(sliderVals[5]); | |
596 sendFiltType(sliderVals[6]); | |
597 sendFiltFreq(sliderVals[7]); | |
598 sendEnvShape(sliderVals[8]); | |
599 sendModFreq(sliderVals[9]); | |
600 | |
601 | 639 |
602 } | 640 } |
603 //-------------------------------------------------------------- | 641 //-------------------------------------------------------------- |
604 void testApp::sendMidiParam(int which){ | 642 void testApp::sendMidiParam(int which){ |
605 int midiChannel = 7; | 643 int midiChannel = 7; |
1007 y1 = y0; | 1045 y1 = y0; |
1008 | 1046 |
1009 return y0; | 1047 return y0; |
1010 } | 1048 } |
1011 //--------------------------------------------------------------- | 1049 //--------------------------------------------------------------- |
1050 //--------------------------------------------------------------- | |
1051 //--------------------------------------------------------------- | |
1052 #pragma mark SYNTH PARAM SENDING TO PD CURVES | |
1012 void testApp::sendOscShape(int ctrlin){ | 1053 void testApp::sendOscShape(int ctrlin){ |
1013 if(ctrlin < 0 || ctrlin > 127){ | 1054 if(ctrlin < 0 || ctrlin > 127){ |
1014 cout << "ERROR: bad slider value!"; | 1055 cout << "ERROR: bad slider value!"; |
1015 return; | 1056 return; |
1016 } | 1057 } |
1017 | 1058 |
1018 static int numpoints = 5; | 1059 static int numpoints = 5; |
1019 static int numcontrols = 5; | 1060 static int numcontrols = 5; |
1020 //float values[points][controls] = | 1061 //float values[points][controls] = |
1021 float ctrlout[numcontrols]; | 1062 float ctrlout[numcontrols]; |
1022 string ctrlName[5] = {"pWidth" , "sqVol", "sawVol", "sineVol", "FMAmt"}; | 1063 string ctrlName[4] = {"pWidth" , "sqVol", "sawVol", "sineVol"}; |
1023 float values[5][5] = | 1064 float values[5][4] = |
1024 {{0.5, 0., 0., 1., 1.}, // 0 | 1065 {{0.5, 0., 0., 1.}, // 0 |
1025 {0.5, 0., 0., 1., 0.}, // 32 | 1066 {0.5, 0., 0., 1.}, // 32 |
1026 {0.5, 0., 1., 0., 0.}, // 64 | 1067 {0.5, 0., 1., 0.}, // 64 |
1027 {0.5, 1., 1., 0., 0.}, // 96 | 1068 {0.5, 1., 1., 0.}, // 96 |
1028 {0.01,1., 1., 0., 0.}}; // 127 | 1069 {0.01,1., 1., 0.}}; // 127 |
1029 | 1070 |
1030 float fidx = (numpoints-1)*ctrlin/128.; | 1071 float fidx = (numpoints-1)*ctrlin/128.; |
1031 int idx = floor(fidx); | 1072 int idx = floor(fidx); |
1032 float frac = fidx - idx; | 1073 float frac = fidx - idx; |
1033 for(int i=0; i < numcontrols; i++){ | 1074 for(int i=0; i < numcontrols; i++){ |
1043 } | 1084 } |
1044 | 1085 |
1045 } | 1086 } |
1046 //--------------------------------------------------------------- | 1087 //--------------------------------------------------------------- |
1047 void testApp::sendFiltType(int ctrlin){ | 1088 void testApp::sendFiltType(int ctrlin){ |
1089 if(ctrlin < 0 || ctrlin > 127){ | |
1090 cout << "ERROR: bad slider value!"; | |
1091 return; | |
1092 } | |
1093 /* | |
1094 static int numpoints = 3; | |
1095 static int numcontrols = 2; | |
1096 //float values[points][controls] = | |
1097 float ctrlout[numcontrols]; | |
1098 string ctrlName[2] = {"fType","reson"}; | |
1099 float values[3][2] = | |
1100 {{0., 45}, // 0 | |
1101 {0.5, 120}, // 64 | |
1102 {1., 55}}; // 127 | |
1103 */ | |
1104 | |
1105 static int numpoints = 2; | |
1106 static int numcontrols = 1; | |
1107 //float values[points][controls] = | |
1108 float ctrlout[numcontrols]; | |
1109 string ctrlName[2] = {"fType"}; | |
1110 float values[2][1] = | |
1111 {{0.}, // 0 | |
1112 {1.},}; // 127 | |
1113 | |
1114 float fidx = (numpoints-1)*ctrlin/128.; | |
1115 int idx = floor(fidx); | |
1116 float frac = fidx - idx; | |
1117 | |
1118 for(int i=0; i < numcontrols; i++){ | |
1119 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i]; | |
1120 // send to PD | |
1121 List toPD; | |
1122 | |
1123 toPD.addSymbol(ctrlName[i]); | |
1124 toPD.addFloat(ctrlout[i]); // rounding here?? | |
1125 | |
1126 core.pd.sendList("fromOF", toPD); | |
1127 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n"; | |
1128 } | |
1129 } | |
1130 //--------------------------------------------------------------- | |
1131 void testApp::sendFiltTypeOld(int ctrlin){ | |
1048 if(ctrlin < 0 || ctrlin > 127){ | 1132 if(ctrlin < 0 || ctrlin > 127){ |
1049 cout << "ERROR: bad slider value!"; | 1133 cout << "ERROR: bad slider value!"; |
1050 return; | 1134 return; |
1051 } | 1135 } |
1052 static int numpoints = 3; | 1136 static int numpoints = 3; |
1190 core.pd.sendList("fromOF", toPD); | 1274 core.pd.sendList("fromOF", toPD); |
1191 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n"; | 1275 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n"; |
1192 } | 1276 } |
1193 } | 1277 } |
1194 //--------------------------------------------------------------- | 1278 //--------------------------------------------------------------- |
1279 void testApp::sendFiltEnvModAmt(int ctrlin){ | |
1280 if(ctrlin < 0 || ctrlin > 127){ | |
1281 cout << "ERROR: bad slider value!"; | |
1282 return; | |
1283 } | |
1284 float amt = ctrlin/127.0; | |
1285 List toPD; | |
1286 | |
1287 toPD.addSymbol("fenv"); | |
1288 toPD.addSymbol("amount"); | |
1289 toPD.addFloat(amt); // rounding here?? | |
1290 | |
1291 core.pd.sendList("fromOF", toPD); | |
1292 } | |
1293 //--------------------------------------------------------------- | |
1195 void testApp::sendModFreq(int ctrlin){ | 1294 void testApp::sendModFreq(int ctrlin){ |
1196 if(ctrlin < 0 || ctrlin > 127){ | 1295 if(ctrlin < 0 || ctrlin > 127){ |
1197 cout << "ERROR: bad slider value!"; | 1296 cout << "ERROR: bad slider value!"; |
1198 return; | 1297 return; |
1199 } | 1298 } |
1204 toPD.addFloat(fm); // rounding here?? | 1303 toPD.addFloat(fm); // rounding here?? |
1205 | 1304 |
1206 core.pd.sendList("fromOF", toPD); | 1305 core.pd.sendList("fromOF", toPD); |
1207 } | 1306 } |
1208 //--------------------------------------------------------------- | 1307 //--------------------------------------------------------------- |
1209 | 1308 //--------------------------------------------------------------- |
1210 | 1309 void testApp::sendRevAmt(int ctrlin){ |
1211 | 1310 if(ctrlin < 0 || ctrlin > 127){ |
1311 cout << "ERROR: bad slider value!"; | |
1312 return; | |
1313 } | |
1314 static int numpoints = 5; | |
1315 static int numcontrols = 2; | |
1316 //float values[points][controls] = | |
1317 float ctrlout[numcontrols]; | |
1318 string ctrlName[3] = {"revDryWet" , "revLength"}; | |
1319 float values[5][3] = | |
1320 {{0., 0.1}, // 0 | |
1321 {0., 0.1}, // 32 | |
1322 {0.3, 30.}, // 64 | |
1323 {0.6, 60.}, // 96 | |
1324 {1., 95.}}; // 127 | |
1325 | |
1326 float fidx = (numpoints-1)*ctrlin/128.; | |
1327 int idx = floor(fidx); | |
1328 float frac = fidx - idx; | |
1329 for(int i=0; i < numcontrols; i++){ | |
1330 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i]; | |
1331 // send to PD | |
1332 List toPD; | |
1333 toPD.addSymbol(ctrlName[i]); | |
1334 toPD.addFloat(ctrlout[i]); // rounding here?? | |
1335 | |
1336 core.pd.sendList("fromOF", toPD); | |
1337 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n"; | |
1338 } | |
1339 | |
1340 } | |
1341 //--------------------------------------------------------------- | |
1342 void testApp::sendResonance(int ctrlin){ | |
1343 if(ctrlin < 0 || ctrlin > 127){ | |
1344 cout << "ERROR: bad slider value!"; | |
1345 return; | |
1346 } | |
1347 float res = ctrlin; | |
1348 List toPD; | |
1349 | |
1350 toPD.addSymbol("reson"); | |
1351 toPD.addFloat(res); // rounding here?? | |
1352 | |
1353 core.pd.sendList("fromOF", toPD); | |
1354 } | |
1355 //--------------------------------------------------------------------------- | |
1356 void testApp::sendFMAmt(int ctrlin){ | |
1357 static int numpoints = 4; | |
1358 static int numcontrols = 1; | |
1359 //float values[points][controls] = | |
1360 float ctrlout[numcontrols]; | |
1361 string ctrlName[1] = {"FMAmt"}; | |
1362 float values[4][1] = | |
1363 {{0.}, // 0 | |
1364 {0.}, // | |
1365 {0.3}, // | |
1366 {1.}}; // 127 | |
1367 | |
1368 float fidx = (numpoints-1)*ctrlin/128.; | |
1369 int idx = floor(fidx); | |
1370 float frac = fidx - idx; | |
1371 for(int i=0; i < numcontrols; i++){ | |
1372 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i]; | |
1373 // send to PD | |
1374 List toPD; | |
1375 toPD.addSymbol(ctrlName[i]); | |
1376 toPD.addFloat(ctrlout[i]); // rounding here?? | |
1377 | |
1378 core.pd.sendList("fromOF", toPD); | |
1379 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n"; | |
1380 } | |
1381 } | |
1382 //--------------------------------------------------------------------------- | |
1383 void testApp::sendDistortion(int ctrlin){ | |
1384 static int numpoints = 5; | |
1385 static int numcontrols = 2; | |
1386 //float values[points][controls] = | |
1387 float ctrlout[numcontrols]; | |
1388 string ctrlName[2] = {"sigGain", "sineGain"}; | |
1389 float values[5][2] = | |
1390 {{0., 0.}, // 0 | |
1391 {0., 0.}, // | |
1392 {20, 0.}, // | |
1393 {45 , 0.}, // | |
1394 {0, 18}}; // 127 | |
1395 | |
1396 float fidx = (numpoints-1)*ctrlin/128.; | |
1397 int idx = floor(fidx); | |
1398 float frac = fidx - idx; | |
1399 for(int i=0; i < numcontrols; i++){ | |
1400 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i]; | |
1401 // send to PD | |
1402 List toPD; | |
1403 toPD.addSymbol(ctrlName[i]); | |
1404 toPD.addFloat(ctrlout[i]); // rounding here?? | |
1405 | |
1406 core.pd.sendList("fromOF", toPD); | |
1407 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n"; | |
1408 } | |
1409 } | |
1410 //--------------------------------------------------------------------------- | |
1411 //=========================================================================== | |
1212 //--------------------------------------------------------------------------- | 1412 //--------------------------------------------------------------------------- |
1213 void saveSequences(){ | 1413 void saveSequences(){ |
1214 ofFile sequenceFile(ofxiPhoneGetDocumentsDirectory() + "pilot_sequences.json" ,ofFile::WriteOnly); | 1414 ofFile sequenceFile(ofxiPhoneGetDocumentsDirectory() + "pilot_sequences.json" ,ofFile::WriteOnly); |
1215 | 1415 |
1216 // the 5 harmonics for the frequencer | 1416 // the 5 harmonics for the frequencer |
1252 } | 1452 } |
1253 //=-------------------------------------------------------------------- | 1453 //=-------------------------------------------------------------------- |
1254 void testApp::loadSequences(){ | 1454 void testApp::loadSequences(){ |
1255 | 1455 |
1256 // read in sequence preset file | 1456 // read in sequence preset file |
1257 string jsonFile = ofxiPhoneGetDocumentsDirectory() + "pilot_sequences.json"; | 1457 string jsonFile = ofFilePath::getAbsolutePath(ofToDataPath("pilot_sequences.json")); |
1458 | |
1459 cout << "SQUENCES FILE: " << jsonFile << "\n"; | |
1460 //string jsonFile = ofxiPhoneGetDocumentsDirectory() + "pilot_sequences.json"; | |
1258 | 1461 |
1259 Json::Value root; | 1462 Json::Value root; |
1260 Json::Reader reader; | 1463 Json::Reader reader; |
1261 | 1464 |
1262 ifstream theFile(jsonFile.c_str()); | 1465 ifstream theFile(jsonFile.c_str()); |