Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Bonjour OSCReceiver TextLCD mbed mbed-rpc BurstSPI DebouncedInterrupt FastIO MIDI OSC OSCtoCV ClockControl
Revision 3:ca15241dd6b4, committed 2013-01-11
- Comitter:
- casiotone401
- Date:
- Fri Jan 11 11:33:55 2013 +0000
- Parent:
- 2:83bc45c48526
- Child:
- 4:b9f5ae574447
- Commit message:
- change scale & performance improvement
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Dec 26 11:28:01 2012 +0000
+++ b/main.cpp Fri Jan 11 11:33:55 2013 +0000
@@ -39,21 +39,22 @@
#define MODE_QChr 1 // Chromatic ~Quantize Mode
#define MODE_QMaj 2 // Major
#define MODE_QDor 3 // Dorian
-#define MODE_QPen 4 // Pentatonic
+#define MODE_Q5th 4 // 5th
+#define MODE_QWht 5 // Wholetone
#define QUAN_RES1 116 // Quantize voltage Steps
#define QUAN_RES2 69
#define QUAN_RES3 68
-#define QUAN_RES4 48
+#define QUAN_RES4 17
+#define QUAN_RES5 58
-#define MODE_NUM 5 // Modes
+#define MODE_NUM 6 // Modes
#define SPI_RATE 40000000 // 40Mbps SPI Clock
#define SCALING_N 38400.0
-#define INPUT_PORT 12345 // Input Port Number
+#define INPUT_PORT 12345 // Input Port Number
-#define UPDATE_INTERVAL 200 // CV Update Interval (us)
-#define POLLING_INTERVAL 20 // Polling Interval (us)
+#define POLLING_INTERVAL 20 // Polling Interval (us)
//-------------------------------------------------------------
// DAC8568 Control Bits
@@ -154,18 +155,30 @@
0.86309946, 0.90686423, 0.97196496
};
-// Pentatonic Scale
+// 5th
const float calibMap4[QUAN_RES4] = {
-0.01433030, 0.02972930, 0.04512830, 0.06822681, 0.08362581,
-0.10672431, 0.12212331, 0.13671936, 0.15833676, 0.17274836,
-0.19436575, 0.20877735, 0.22318897, 0.24480636, 0.25926629,
-0.28099698, 0.29548413, 0.30997124, 0.33170196, 0.34618911,
-0.36791980, 0.38241133, 0.39690709, 0.41865072, 0.43314645,
-0.45489007, 0.46938580, 0.48388156, 0.50566339, 0.52025765,
-0.54214907, 0.55674326, 0.57133752, 0.59322894, 0.60782319,
-0.62976688, 0.64452308, 0.65927929, 0.68141359, 0.69616979,
-0.71830410, 0.73306036, 0.74781656, 0.78151548, 0.80482519,
-0.83978975, 0.86309946, 0.90686423
+0.00663080, 0.06052731, 0.11442380, 0.16554256, 0.21598317,
+0.26650983, 0.31721482, 0.36791980, 0.41865072, 0.46938580,
+0.52025765, 0.57133752, 0.62241745, 0.67403549, 0.72568226,
+0.79317033, 0.87475431
+
+};
+
+// 5th
+const float calibMap5[QUAN_RES5] = {
+0.00663080, 0.02202980, 0.03742880, 0.05282781, 0.06822681,
+0.08362581, 0.09902481, 0.11442380, 0.12951356, 0.14392516,
+0.15833676, 0.17274836, 0.18715996, 0.20157155, 0.21598317,
+0.23039477, 0.24480636, 0.25926629, 0.27375340, 0.28824055,
+0.30272770, 0.31721482, 0.33170196, 0.34618911, 0.36067623,
+0.37516347, 0.38965923, 0.40415496, 0.41865072, 0.43314645,
+0.44764221, 0.46213794, 0.47663370, 0.49112943, 0.50566339,
+0.52025765, 0.53485191, 0.54944617, 0.56404042, 0.57863468,
+0.59322894, 0.60782319, 0.62241745, 0.63714498, 0.65190119,
+0.66665739, 0.68141359, 0.69616979, 0.71092600, 0.72568226,
+0.74043846, 0.75820577, 0.78151548, 0.80482519, 0.82813489,
+0.85144460, 0.87475431, 0.93941462
+
};
//-------------------------------------------------------------
@@ -216,7 +229,8 @@
int main()
{
int i;
-
+ float pot, _pot;
+
if(SetupEthNetIf() == -1)
{
for(i = 0; i < 4; i++)
@@ -237,46 +251,27 @@
InitOSCCV();
+ pot = _pot = 0;
+
+ gLCD.locate( 9, 0 );
+ gLCD.printf("OSC-CV");
+ gLCD.locate( 0, 1 );
+ gLCD.printf("12345678 G>>%3.2f", gGlide);
+
+
// loop
while(1)
{
- gGlide = gAIN.read();
-
- gLCD.locate( 0, 1 );
- gLCD.printf("12345678 G>>%3.2f", gGlide);
+ gGlide = pot = gAIN.read();
- switch(gMode)
- {
- case MODE_LIN:
- gLCD.locate( 9, 0 );
- gLCD.printf("OSC-CV");
- break;
-
- case MODE_QChr:
- gLCD.locate( 9, 0 );
- gLCD.printf("QUAN_C");
- break;
-
- case MODE_QMaj:
- gLCD.locate( 9, 0 );
- gLCD.printf("QUAN_M");
- break;
-
- case MODE_QDor:
- gLCD.locate( 9, 0 );
- gLCD.printf("QUAN_D");
- break;
-
- case MODE_QPen:
- gLCD.locate( 9, 0 );
- gLCD.printf("QUAN_P");
- break;
- }
- //CV Meter
- for(i = 0; i < 8; i++)
+ if(abs(pot - _pot) > 0.01)
{
- CVMeter(i, (unsigned int)gOSC_cv[i]);
+ gLCD.locate( 0, 1 );
+ gLCD.printf("12345678 G>>%3.2f", gGlide);
+ _pot = gAIN.read();
}
+
+ SetCV();
}
}
@@ -315,10 +310,10 @@
gMode = 0;
- gSW.fall(&CheckSW); // InterruptIn falling edge(ModeSW)
- gSetter.attach_us(&SetCV, UPDATE_INTERVAL); // Ticker SetCV
+ gSW.rise(&CheckSW); // InterruptIn rising edge(ModeSW)
gPoller.attach_us(&NetPoll, POLLING_INTERVAL); // Ticker Polling
- wait(0.5);
+
+ wait(0.2);
}
//-------------------------------------------------------------
@@ -427,7 +422,7 @@
UpdateCV(WRITE_UPDATE_N, ch, cv[ch]);
break;
- case MODE_QPen:
+ case MODE_Q5th:
quan = 43690 / QUAN_RES4;
qcv = calibMap4[(unsigned int)(gOSC_cv[ch] / quan )];
@@ -438,8 +433,21 @@
UpdateCV(WRITE_UPDATE_N, ch, cv[ch]);
break;
+
+ case MODE_QWht:
+
+ quan = 43690 / QUAN_RES5;
+ qcv = calibMap5[(unsigned int)(gOSC_cv[ch] / quan )];
+
+ glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
+ oldcv[ch] = glidecv[ch];
+ cv[ch] = (unsigned int)glidecv[ch];
+
+ UpdateCV(WRITE_UPDATE_N, ch, cv[ch]);
+ break;
}
+ CVMeter(ch, cv[ch]);
ch++;
ch &= 0x07;
}
@@ -449,14 +457,47 @@
void CheckSW()
{
- if (gMode < MODE_NUM - 1)
+ if(gMode < MODE_NUM - 1)
{
gMode++;
-
+
} else {
gMode = 0;
}
+
+ switch(gMode)
+ {
+ case MODE_LIN:
+ gLCD.locate( 9, 0 );
+ gLCD.printf("OSC-CV ");
+ break;
+
+ case MODE_QChr:
+ gLCD.locate( 9, 0 );
+ gLCD.printf("QUAN_C ");
+ break;
+
+ case MODE_QMaj:
+ gLCD.locate( 9, 0 );
+ gLCD.printf("QUAN_M ");
+ break;
+
+ case MODE_QDor:
+ gLCD.locate( 9, 0 );
+ gLCD.printf("QUAN_D ");
+ break;
+
+ case MODE_Q5th:
+ gLCD.locate( 9, 0 );
+ gLCD.printf("QUAN_5 ");
+ break;
+
+ case MODE_QWht:
+ gLCD.locate( 9, 0 );
+ gLCD.printf("QUAN_W ");
+ break;
+ }
}
//-------------------------------------------------------------
@@ -467,6 +508,7 @@
unsigned int cvmeter;
cvmeter = level / (SCALING_N / 7.9);
+
gLCD.locate ( ch, 0 );
gLCD.putc(cvmeter); // put custom char
}
@@ -551,25 +593,25 @@
unsigned int absv = msg[2].f * 1; //convert -0 to 0
// address pattern SYNC & GATE (Type Tag int, float)
- if((strncmp(msg[0].address,"/1/sync",7)==0) && (num == -1)) {
+ if((strncmp(msg[0].address+(len-1)-4, "sync", 4)==0) && (num == -1)) {
if(num > 1) break;
if(absv >= 1 || msg[2].i >= 1) gCLOCKOUT = 1;
else gCLOCKOUT = 0;
break;
- } else if ((strncmp(msg[0].address,"/1/gate",7)==0) && (num != -1)) {
+ } else if ((strncmp(msg[0].address+(len-1)-4, "gate", 4)==0) && (num != -1)) {
if(num > 3) break;
if(absv >= 1 || msg[2].i >= 1) gLEDS[num] = gGATES[num] = 1;
else gLEDS[num] = gGATES[num] = 0;
break;
// (touchOSC Control push, toggle)
- } else if ((strncmp(msg[0].address,"/1/push",7)==0) && (num != -1)) {
+ } else if ((strncmp(msg[0].address+(len-1)-4, "push", 4)==0) && (num != -1)) {
if(num > 3) break;
if(absv >= 1 || msg[2].i >= 1) gLEDS[num] = gGATES[num] = 1;
else gLEDS[num] = gGATES[num] = 0;
break;
- } else if ((strncmp(msg[0].address,"/1/toggle",9)==0) && (num != -1)) {
+ } else if ((strncmp(msg[0].address+(len-1)-6, "toggle", 6)==0) && (num != -1)) {
if(num > 3) break;
if(absv >= 1 || msg[2].i >= 1) gLEDS[num] = gGATES[num] = 1;
else gLEDS[num] = gGATES[num] = 0;
@@ -582,34 +624,34 @@
}
// address pattern CV (Type Tag float)
- if((strncmp(msg[0].address,"/1/cv",5)==0) && (num != -1)) {
+ if((strncmp(msg[0].address+(len-1)-2, "cv", 2)==0) && (num != -1)) {
if(num > 7) break;
if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
break;
// (touchOSC Control fader, rotary, xy, multixy, multifader)
- } else if ((strncmp(msg[0].address,"/1/fader",8)==0) && (num != -1)) {
+ } else if ((strncmp(msg[0].address+(len-1)-5, "fader", 5)==0) && (num != -1)) {
if(num > 7) break;
if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
break;
- } else if ((strncmp(msg[0].address,"/1/rotary",9)==0) && (num != -1)) {
+ } else if ((strncmp(msg[0].address+(len-1)-6, "rotary", 6)==0) && (num != -1)) {
if(num > 7) break;
if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
break;
- } else if ((strncmp(msg[0].address,"/1/xy",5)==0) && (num != -1)) {
+ } else if ((strncmp(msg[0].address+(len-1)-2, "xy", 2)==0) && (num != -1)) {
if(num > 7) break;
if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
if(msg[1].typeTag[1] == 'f') gOSC_cv[++num] = msg[3].f * (SCALING_N);
break;
- } else if ((strncmp(msg[0].address,"/1/multixy",10)==0) && (num != -1)) {
+ } else if ((strncmp(msg[0].address+(len-1)-9, "multixy1/", 9)==0) && (num != -1)) {
if(num > 7) break;
if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
if(msg[1].typeTag[1] == 'f') gOSC_cv[++num] = msg[3].f * (SCALING_N);
break;
- } else if ((strncmp(msg[0].address,"/1/multifader",13)==0) && (num != -1)) {
+ } else if ((strncmp(msg[0].address+(len-1)-12, "multifader1/", 12)==0) && (num != -1)) {
if(num > 7) break;
if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
}