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 29:8b61b87b9676, committed 2016-02-25
- Comitter:
- casiotone401
- Date:
- Thu Feb 25 11:22:24 2016 +0000
- Parent:
- 28:14be965b333e
- Child:
- 30:d82b42321364
- Commit message:
- minor change
Changed in this revision
--- a/OSC.lib Thu Feb 18 13:27:35 2016 +0000 +++ b/OSC.lib Thu Feb 25 11:22:24 2016 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/users/casiotone401/code/OSC/#a47004fb44f5 +http://developer.mbed.org/users/casiotone401/code/OSC/#498455cded21
--- a/OSCReceiver.lib Thu Feb 18 13:27:35 2016 +0000 +++ b/OSCReceiver.lib Thu Feb 25 11:22:24 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/casiotone401/code/OSCReceiver/#6dab18e1eb37 +http://mbed.org/users/casiotone401/code/OSCReceiver/#ff3e4aee583e
--- a/OSCtoCV.lib Thu Feb 18 13:27:35 2016 +0000 +++ b/OSCtoCV.lib Thu Feb 25 11:22:24 2016 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/casiotone401/code/OSCtoCV/#abe335652add +https://developer.mbed.org/users/casiotone401/code/OSCtoCV/#7fb15b1b5459
--- a/main.cpp Thu Feb 18 13:27:35 2016 +0000
+++ b/main.cpp Thu Feb 25 11:22:24 2016 +0000
@@ -41,7 +41,6 @@
#include "OSCtoCV_Random.h"
#include "OSCtoCV_LFO.h"
-
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
@@ -68,8 +67,10 @@
void CalibrationCV(void);
inline void SetCV(void);
inline int CheckBPM(void);
+inline float CheckGlide(void);
+inline float CheckDuration(void);
void CheckModeSW(void);
-inline void LCD();
+inline void UpdateLCD();
void WriteCustomChar(unsigned char, unsigned char*);
int SetupEthNetIf(void);
inline void onUDPSocketEvent(UDPSocketEvent);
@@ -99,17 +100,13 @@
int main()
{
- float pot, _pot;
- float duration, _duration = 0.6;
+ float duration;
int bpm;
- InitOSCCV();
-
- gCtrl[3] = _pot = pot = gMode = 0;
-
+ InitOSCCV();
// Init LCD
- LCD();
+ UpdateLCD();
gLCD.locate( 0, 1 );
gLCD.printf("12345678 G>>%3.2f", gGlide);
@@ -117,41 +114,13 @@
// Main loop
while (1)
{
- LCD(); // Check Text LCD Mode Status
-
- pot = gAIN.read(); // Update glide value
+ UpdateLCD(); // Check Text LCD Mode Status
- if (!pot) // when glide pot value == 0
- { // use gCtrl[3] value (MODE_OSC)
- if (abs(gCtrl[3] - _pot) > 0.01f)
- {
- _pot = gGlide = gCtrl[3];
-
- gLCD.locate( 9, 1 );
- gLCD.printf("G>>%3.2f", gGlide);
- }
-
- } else if (abs(pot - _pot) > 0.01f) {
-
- _pot = gGlide = gAIN.read();
-
- gLCD.locate( 9, 1 );
- gLCD.printf("G>>%3.2f", gGlide);
- }
+ CheckGlide(); // check glide value
bpm = CheckBPM(); // check current BPM
- duration = gCtrl[6];
-
- if (_duration != duration) // check current gate duration
- {
- sendMes.setTopAddress("/ctrl7");
- sendMes.setArgs("f", gCtrl[6]);
-
- osc.sendOsc(&sendMes);
-
- _duration = duration;
- }
+ duration = CheckDuration(); // check current duration(Gate length)
switch (gMode)
{
@@ -166,11 +135,11 @@
if (gCtrlSW[3])
{ // euclid sequencer auto offset
- ShiftCVSeq(EuclideanSeq(GateSeq(bpm, N16TH, SUBGATE, (duration * 12), NON_INVERT, GATESOUT_OFF, SYNC_ON), gCtrlSW[0], GATESOUT_OFF, true), gCtrlSW[0], CV_CHANNEL8);
+ ShiftCVSeq(EuclideanSeq(GateSeq(bpm, N16TH, SUBGATE, (duration * 12.0f), NON_INVERT, GATESOUT_OFF, SYNC_ON), gCtrlSW[0], GATESOUT_OFF, true), gCtrlSW[0], CV_CHANNEL8);
} else {
- ShiftCVSeq(BeatsSeq(GateSeq(bpm, N16TH, SUBGATE, (duration * 8), NON_INVERT, GATESOUT_OFF, SYNC_ON), gCtrlSW[0], GATESOUT_OFF), gCtrlSW[0], CV_CHANNEL8);
+ ShiftCVSeq(BeatsSeq(GateSeq(bpm, N16TH, SUBGATE, (duration * 8.0f), NON_INVERT, GATESOUT_OFF, SYNC_ON), gCtrlSW[0], GATESOUT_OFF), gCtrlSW[0], CV_CHANNEL8);
}
break;
@@ -181,11 +150,11 @@
if (gCtrlSW[3])
{ // euclid sequencer auto offset
- M185Seq(EuclideanSeq(GateSeq(bpm, N16TH, SUBGATE, (duration * 12), NON_INVERT, GATESOUT_OFF, SYNC_ON), gCtrlSW[0], GATESOUT_OFF, true), gCtrlSW[0], CV_CHANNEL8);
+ M185Seq(EuclideanSeq(GateSeq(bpm, N16TH, SUBGATE, (duration * 12.0f), NON_INVERT, GATESOUT_OFF, SYNC_ON), gCtrlSW[0], GATESOUT_OFF, true), gCtrlSW[0], CV_CHANNEL8);
} else {
- M185Seq(BeatsSeq(GateSeq(bpm, N16TH, SUBGATE, (duration * 8), NON_INVERT, GATESOUT_OFF, SYNC_ON), gCtrlSW[0], GATESOUT_OFF), gCtrlSW[0], CV_CHANNEL8);
+ M185Seq(BeatsSeq(GateSeq(bpm, N16TH, SUBGATE, (duration * 8.0f), NON_INVERT, GATESOUT_OFF, SYNC_ON), gCtrlSW[0], GATESOUT_OFF), gCtrlSW[0], CV_CHANNEL8);
}
break;
@@ -195,23 +164,23 @@
if (gCtrlSW[3])
{ // euclid sequencer auto offset
- PolyCVSeq(EuclideanSeq(GateSeq(bpm, N16TH, SUBGATE, (duration * 12), NON_INVERT, GATESOUT_OFF, SYNC_ON), gCtrlSW[0], GATESOUT_OFF, true), gCtrlSW[0]);
+ PolyCVSeq(EuclideanSeq(GateSeq(bpm, N16TH, SUBGATE, (duration * 12.0f), NON_INVERT, GATESOUT_OFF, SYNC_ON), gCtrlSW[0], GATESOUT_OFF, true), gCtrlSW[0]);
} else {
- PolyCVSeq(BeatsSeq(GateSeq(bpm, N16TH, SUBGATE, (duration * 8), NON_INVERT, GATESOUT_OFF, SYNC_ON), gCtrlSW[0], GATESOUT_OFF), gCtrlSW[0]);
+ PolyCVSeq(BeatsSeq(GateSeq(bpm, N16TH, SUBGATE, (duration * 8.0f), NON_INVERT, GATESOUT_OFF, SYNC_ON), gCtrlSW[0], GATESOUT_OFF), gCtrlSW[0]);
}
break;
case MODE_EUC: // Euclidean Sequencer mode
- ShiftCVSeq(GateSeq(bpm, N1ST, SUBGATE, (duration * 5), NON_INVERT, GATESOUT_OFF, SYNC_OFF), gCtrlSW[0], CV_CHANNEL8);
+ ShiftCVSeq(GateSeq(bpm, N1ST, SUBGATE, (duration * 5.0f), NON_INVERT, GATESOUT_OFF, SYNC_OFF), gCtrlSW[0], CV_CHANNEL8);
EuclideanSeq(GateSeq(bpm, N16TH, GATE1, 3, NON_INVERT, GATESOUT_OFF, SYNC_OFF), gCtrlSW[0], GATESOUT_ON, false);
break;
case MODE_RND: // Random CV Generator mode
- RandomCVGenerator(GateSeq(bpm, N32TH, GATE1, (duration * 5), NON_INVERT, GATESOUT_OFF, SYNC_ON));
+ RandomCVGenerator(GateSeq(bpm, N32TH, GATE1, (duration * 5.0f), NON_INVERT, GATESOUT_OFF, SYNC_ON));
break;
case MODE_LFO: // Stepped LFO mode
@@ -241,7 +210,6 @@
void InitOSCCV()
{
- int i;
// Set System Frequency 120Mhz
setSystemFrequency(0x3, 0x1, 15, 1);
@@ -275,39 +243,33 @@
gSPI.frequency(SPI_RATE);
UpdateCV(CLR, 0, 0); // Ignore CLR Pin
-
-// Init BPM
- gCtrl[0] = 0.398f;
-
-// Init Sequencer Data
- for (i = 0; i < 16; ++i)
- {
- gSeq_cv[i] = (calibMap1[69] * SCALING_N);
- }
-
- for (i = 0; i < 8; ++i)
- {
- g185_cv[i] = (calibMap1[69] * SCALING_N);
- gBeatsLevel[i] = gBeatsDecay[i] = 1;
- }
-
-// Init Sequencer Reset Count
- gCtrl[4] = gCtrl[5] = gCtrl[7] = 1;
-
-// Init Sequencer Gate Length
- gCtrl[6] = 0.6;
// Init Euclidean Sequencer
InitEuclideanSeq();
// Init Glide value
gGlide = gAIN.read();
-
+
+// Init Mode
+ gMode = MODE_CLB;
+
+// Init Sequencer Data
+ for (int i = 0; i < 16; ++i)
+ {
+ if (i < 8)
+ {
+ g185_cv[i] = (calibMap1[69] * SCALING_N);
+ gBeatsLevel[i] = gBeatsDecay[i] = 1;
+ }
+
+ gSeq_cv[i] = (calibMap1[69] * SCALING_N);
+ }
+
// Set OSC message for sending
sendMes.setIp(touchOSCAddress);
sendMes.setPort(touchOSCPort);
- gSW.attach(&CheckModeSW,IRQ_RISE, 20); // InterruptIn rising edge(ModeSW)
+ gSW.attach(&CheckModeSW, IRQ_RISE, 20); // InterruptIn rising edge(ModeSW)
wait(0.5);
gPoller.attach_us(&NetPoll, POLLING_INTERVAL); // Ticker Polling
@@ -322,19 +284,11 @@
static int ch;
unsigned int cv;
- switch (gMode)
- {
- case MODE_CLB:
-
- cv = (unsigned int)(calibMap1[69] * SCALING_N); // A880.0Hz
+ cv = (unsigned int)(calibMap1[69] * SCALING_N); // A880.0Hz
- gSUBGATE = gGATES[0] = gGATES[1] = gGATES[2] = gGATES[3] = true;
-
- UpdateCV(WRITE_UPDATE_N, ch, &cv);
-
- break;
- }
-
+ gSUBGATE = gGATES[0] = gGATES[1] = gGATES[2] = gGATES[3] = true;
+
+ UpdateCV(WRITE_UPDATE_N, ch, &cv);
UpdateCVMeter(ch, &cv);
++ch;
@@ -461,7 +415,7 @@
bpm = (gCtrl[0] * 240 + 5);
- if (abs(bpm - _bpm) > 1)
+ if (bpm != _bpm)
{
_bpm = bpm;
@@ -469,11 +423,8 @@
sendMes.setArgs("i", bpm);
osc.sendOsc(&sendMes);
- osc.sendOsc(&sendMes);
-
sendMes.setTopAddress("/ctrl1");
sendMes.setArgs("f", gCtrl[0]);
-
osc.sendOsc(&sendMes);
}
}
@@ -482,6 +433,56 @@
}
//-------------------------------------------------------------
+// Check Glide Value
+
+inline float CheckGlide()
+{
+ static float _pot;
+ float pot = 0;
+
+ pot = gAIN.read(); // Update glide value
+
+ if (!pot) // when (glide pot value == 0) && MODE_OSC
+ { // use gCtrl[3] value
+ if (abs(gCtrl[3] - _pot) > 0.01f)
+ {
+ _pot = gGlide = gCtrl[3];
+
+ gLCD.locate( 9, 1 );
+ gLCD.printf("G>>%3.2f", gGlide);
+ }
+
+ } else if (abs(pot - _pot) > 0.01f) {
+
+ _pot = gGlide = pot;
+
+ gLCD.locate( 9, 1 );
+ gLCD.printf("G>>%3.2f", gGlide);
+ }
+
+ return pot;
+}
+
+//-------------------------------------------------------------
+// Check Duration Value
+
+inline float CheckDuration()
+{
+ static float _duration = 0.6f;
+
+ if (_duration != gCtrl[6]) // check current gate duration
+ {
+ sendMes.setTopAddress("/ctrl7");
+ sendMes.setArgs("f", gCtrl[6]);
+ osc.sendOsc(&sendMes);
+
+ _duration = gCtrl[6];
+ }
+
+ return gCtrl[6];
+}
+
+//-------------------------------------------------------------
// Check Mode SW
void CheckModeSW()
@@ -513,7 +514,7 @@
//-------------------------------------------------------------
// Print LCD Mode Status
-inline void LCD()
+inline void UpdateLCD()
{
static int _mode = -1;
static int _qmode = -1;
@@ -755,8 +756,8 @@
{
static union OSCarg msg[10];
static char buf[1024] = {0};
- static int recvlen;
- static int num, numrow, len, offset;
+ int recvlen;
+ int num, numrow, len, offset;
int messagepos = 0;
bool bundleflag = false;
@@ -816,14 +817,12 @@
// address pattern SYNC & GATE (Type Tag int, float)
if (!strncmp(msg[0].address + (len - offset) - 4, "sync", 4))
{
- if (msg[2].i != 0) gCLOCKOUT = true;
- else gCLOCKOUT = false;
+ gCLOCKOUT = (msg[2].i != 0) ? true: false;
continue;
} else if (!strncmp(msg[0].address + (len - offset) - 4, "gate", 4) && (num != -1)) {
if (num > 3) continue;
- if (msg[2].i != 0) gGATES[num] = true;
- else gGATES[num] = false;
+ gGATES[num] = (msg[2].i != 0) ? true: false;
continue;
// (touchOSC Control push, toggle)
} else if (!strncmp(msg[0].address + (len - offset) - 5, "fader", 5) && (num != -1)) {
@@ -854,8 +853,7 @@
} else if (!strncmp(msg[0].address + (len - offset) - 6, "ctrlsw", 6) && (num != -1)) {
if (num > 7) continue;
- if (msg[2].i != 0) gCtrlSW[num] = true;
- else gCtrlSW[num] = false;
+ gCtrlSW[num] = (msg[2].i != 0) ? true: false;
continue;
} else if (!strncmp(msg[0].address + (len - offset) - 4, "ctrl", 4) && (num != -1)) {
@@ -1007,8 +1005,7 @@
} else if (!strncmp(msg[0].address + (len - offset) - 2, "sw", 2) && (num != -1)) {
if (num > 1) continue;
- if (msg[2].i != 0) gArdSW[num] = true;
- else gArdSW[num] = false;
+ gArdSW[num] = (msg[2].i != 0) ? true: false;
continue;
}