OSC-CV Converter
Dependencies: Bonjour OSCReceiver TextLCD mbed mbed-rpc BurstSPI DebouncedInterrupt FastIO MIDI OSC OSCtoCV ClockControl
OSC to CV Converter
http://gtbts.tumblr.com/post/125663817741/osc-to-cv-converter-ver2-mbed-osctocv
Diff: main.cpp
- Revision:
- 6:5796b63c70ef
- Parent:
- 5:e305509d53f3
- Child:
- 7:a04f8378662e
--- a/main.cpp Sat Jan 26 02:04:03 2013 +0000 +++ b/main.cpp Mon Jan 28 12:30:15 2013 +0000 @@ -233,12 +233,12 @@ static float gSeq_cv1[8]; static float gSeq_cv2[8]; static float gGlide; -unsigned int gMode; +volatile static int gMode; // Variables for Control float gCtrl[2]; -unsigned int gCtrlSW[4]; +volatile int gCtrlSW[4]; //------------------------------------------------------------- // mbed Functions @@ -268,7 +268,7 @@ int main() { - float pot, _pot; + static float pot, _pot; int bpm, _bpm; int shift1, shift2, shift3, shift4; @@ -315,62 +315,64 @@ _pot = gAIN.read(); } - if(gMode == MODE_SEQ) // Mode Sequencer & Shift Register + switch(gMode) { - if(gCtrlSW[0] == 1) // Stop (gCtrlSW[0]) - { - bpm = 0; - - } else { + case MODE_SEQ: bpm = (gCtrl[0] * 300 + 10); // Set BPM (gCtrl[0]) - } - if(abs(bpm - _bpm) > 1) - { - UpdateGate(bpm, NRESET, GATEALL, 3, 0); // Reset (if bpm change) - - _bpm = bpm; - } + if(abs(bpm - _bpm) > 1) + { + UpdateGate(bpm, NRESET, GATEALL, 3, 0); // Reset (if bpm change) + _bpm = bpm; + + } else if (gCtrlSW[0] == 1) { // Stop (gCtrlSW[0]) + + bpm = 0; + } - if(gCtrlSW[2] == 0 && gCtrlSW[3] == 0) // Sequencer Mode1 - { - shift1 = UpdateGate(bpm, N16TH, GATE1, 3, 0); // Shift Timming 16th note + if(gCtrlSW[2] == 0 && gCtrlSW[3] == 0) // Sequencer Mode1 + { + shift1 = UpdateGate(bpm, N16TH, GATE1, 3, 0); // Shift Timming 16th note - UpdateGate(bpm, N8TH, GATE2, 3, 0); - UpdateGate(bpm, NDOT8, GATE3, 3, 0); - UpdateGate(bpm, TRIP4, GATE4, 3, 0); + UpdateGate(bpm, N8TH, GATE2, 3, 0); + UpdateGate(bpm, NDOT8, GATE3, 3, 0); + UpdateGate(bpm, TRIP4, GATE4, 3, 0); - SeqCV(shift1); // Do shift ch all + SeqCV(shift1); // Do shift ch all + continue; - } else if (gCtrlSW[2] == 1 && gCtrlSW[3] == 0) { // Sequencer Mode2 (if gCtrlSW[2] ON) + } else if (gCtrlSW[2] == 1 && gCtrlSW[3] == 0) { // Sequencer Mode2 (if gCtrlSW[2] ON) - shift1 = UpdateGate(bpm, N16TH, GATE1, 3, 0); - shift2 = UpdateGate(bpm, N8TH, GATE2, 3, 0); - shift3 = UpdateGate(bpm, NDOT4, GATE3, 3, 0); - shift4 = UpdateGate(bpm, TRIP8, GATE4, 3, 0); + shift1 = UpdateGate(bpm, N16TH, GATE1, 3, 0); + shift2 = UpdateGate(bpm, N8TH, GATE2, 3, 0); + shift3 = UpdateGate(bpm, NDOT4, GATE3, 3, 0); + shift4 = UpdateGate(bpm, TRIP8, GATE4, 3, 0); - SeqCV(shift1); // Do shift ch 1~5 - SeqCV(shift2); // Do shift ch 6 - SeqCV(shift3); // Do shift ch 7 - SeqCV(shift4); // Do shift ch 8 + SeqCV(shift1); // Do shift ch 1~5 + SeqCV(shift2); // Do shift ch 6 + SeqCV(shift3); // Do shift ch 7 + SeqCV(shift4); // Do shift ch 8 + continue; - } else if (gCtrlSW[3] == 1) { // Sequencer Mode3 (if gCtrlSW[3] ON) - // (ch6,7,8, short loop) - shift1 = UpdateGate(bpm, N16TH, GATE1, 3, 0); - shift2 = UpdateGate(bpm, N8TH, GATE2, 3, 0); - shift3 = UpdateGate(bpm, NDOT8, GATE3, 3, 0); - shift4 = UpdateGate(bpm, TRIP4, GATE4, 3, 0); + } else if (gCtrlSW[3] == 1) { // Sequencer Mode3 (if gCtrlSW[3] ON) + // (ch6,7,8, short loop) + shift1 = UpdateGate(bpm, N16TH, GATE1, 3, 0); + shift2 = UpdateGate(bpm, N8TH, GATE2, 3, 0); + shift3 = UpdateGate(bpm, NDOT8, GATE3, 3, 0); + shift4 = UpdateGate(bpm, TRIP4, GATE4, 3, 0); - SeqCV(shift1); // Do shift ch 1~5 - SeqCV(shift2); // Do shift ch 6 - SeqCV(shift3); // Do shift ch 7 - SeqCV(shift4); // Do shift ch 8 - } + SeqCV(shift1); // Do shift ch 1~5 + SeqCV(shift2); // Do shift ch 6 + SeqCV(shift3); // Do shift ch 7 + SeqCV(shift4); // Do shift ch 8 + continue; + } + + default: - } else { - - SetCV(); + SetCV(); + continue; } } } @@ -693,10 +695,11 @@ void SeqCV(int shift) { + int i, j, k; static int ch; static int cnt1, cnt2, cnt3; static int cntloop1, cntloop2, cntloop3; - static unsigned int SeqMode; + static int SeqMode; static float glidecv[8]; unsigned int cv[8]; static float shiftcv[8]; @@ -821,55 +824,34 @@ break; } - if((gCtrlSW[2] == 0 || gCtrlSW[2] == 1) && gCtrlSW[3] == 0) + if((gCtrlSW[2] == 0 || gCtrlSW[2] == 1) && gCtrlSW[3] == 0)// Sequencer Mode1 { - for(int i = 1; i < 8; ++i) + for(i = 1; i < 8; ++i) { glidecv[i] = glidecv[i] * gGlide + shiftcv[i] * (1.0f - gGlide); cv[i] = (unsigned int)glidecv[i]; UpdateCV(WRITE_UPDATE_N, i, &cv[i]); + + if(shift == 1) // GATE1 + { + for(i = 1; i < 8; ++i) // Shift ch2~8 + { + shiftcv[i] = glidecv[i-1]; + } + + ch++; + ch &= 0x0F; + } + + cnt1 = cnt2 = cnt3 = 0; } - } else if (gCtrlSW[3] == 1) { - - for(int j = 1; j < 5; ++j) - { - glidecv[j] = glidecv[j] * gGlide + shiftcv[j] * (1.0f - gGlide); - cv[j] = (unsigned int)glidecv[j]; - - UpdateCV(WRITE_UPDATE_N, j, &cv[j]); - } - - for(int k = 5; k < 8; ++k) - { - glidecv[k] = glidecv[k] * gGlide + loopcv[k - 5] * (1.0f - gGlide); - cv[k] = (unsigned int)glidecv[k]; - - UpdateCV(WRITE_UPDATE_N, k, &cv[k]); - } - } - - if(gCtrlSW[2] == 0 && gCtrlSW[3] == 0) // Sequencer Mode1 - { - if(shift == 1) // GATE1 - { - for(int i = 1; i < 8; ++i) // Shift ch2~8 - { - shiftcv[i] = glidecv[i-1]; - } - - ch++; - ch &= 0x0F; - } - - cnt1 = cnt2 = cnt3 = 0; - } else if (gCtrlSW[2] == 1 && gCtrlSW[3] == 0) { // Sequencer Mode2 if(shift == 1) // GATE1 { - for(int j = 1; j < 5; ++j) + for(j = 1; j < 5; ++j) { shiftcv[j] = glidecv[j-1]; // Shift ch2~5 } @@ -888,13 +870,29 @@ } else if (shift == 4) { // GATE4 shiftcv[7] = glidecv[3]; // Shift ch8 - } - + } + } else if (gCtrlSW[3] == 1) { // Sequencer Mode3 + for(j = 1; j < 5; ++j) + { + glidecv[j] = glidecv[j] * gGlide + shiftcv[j] * (1.0f - gGlide); + cv[j] = (unsigned int)glidecv[j]; + + UpdateCV(WRITE_UPDATE_N, j, &cv[j]); + } + + for(k = 5; k < 8; ++k) + { + glidecv[k] = glidecv[k] * gGlide + loopcv[k - 5] * (1.0f - gGlide); + cv[k] = (unsigned int)glidecv[k]; + + UpdateCV(WRITE_UPDATE_N, k, &cv[k]); + } + if(shift == 1) // GATE1 { - for(int i = 1; i < 8; ++i) + for(i = 1; i < 8; ++i) { shiftcv[i] = glidecv[i-1]; // Shift ch2~5 } @@ -1003,7 +1001,7 @@ void CVMeter(int ch, const unsigned int *level) { - unsigned int cvmeter; + static unsigned int cvmeter; cvmeter = *level / (SCALING_N / 7.9); @@ -1116,7 +1114,8 @@ { union OSCarg msg[10]; static int num; - + unsigned int absv; + switch(e) { case UDPSOCKET_READABLE: // The only event for now @@ -1141,11 +1140,10 @@ else num = -1; - unsigned int absv = msg[2].f + 0; //convert -0 to 0 + absv = msg[2].f + 0; //convert -0 to 0 // address pattern SYNC & GATE (Type Tag int, float) - if((strncmp(msg[0].address+(len-1)-4, "sync", 4)==0) && (num == -1)) { - if(num > 1) break; + if(strncmp(msg[0].address+(len-1)-4, "sync", 4)==0) { if(absv >= 1 || msg[2].i >= 1) gCLOCKOUT = 1; else gCLOCKOUT = 0; break;