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

/media/uploads/casiotone401/tumblr_nsg7y4pkfg1qlle9fo1_540.png

Committer:
casiotone401
Date:
Sat Mar 02 00:14:57 2013 +0000
Revision:
9:1ac3d135d965
Parent:
8:fe50078d6b80
Child:
10:ccfeb687c3f2
bug fix & change quantize data

Who changed what in which revision?

UserRevisionLine numberNew contents of line
casiotone401 0:a4d93cd4c30d 1 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 2 // TI DAC8568 OSC-CV Converter
casiotone401 0:a4d93cd4c30d 3 //
casiotone401 0:a4d93cd4c30d 4 // DAC8568 16bit Octal DAC http://www.ti.com/product/dac8568
casiotone401 0:a4d93cd4c30d 5 //
casiotone401 0:a4d93cd4c30d 6 // referred to
casiotone401 0:a4d93cd4c30d 7 // xshige's OSCReceiver
casiotone401 0:a4d93cd4c30d 8 // http://mbed.org/users/xshige/programs/OSCReceiver/
casiotone401 0:a4d93cd4c30d 9 // radiojunkbox's OSC-CV_Example
casiotone401 0:a4d93cd4c30d 10 // http://mbed.org/users/radiojunkbox/code/KAMUI_OSC-CV_Example/
casiotone401 0:a4d93cd4c30d 11 // Robin Price's Homebrew midi-cv box
casiotone401 0:a4d93cd4c30d 12 // http://crx091081gb.net/?p=69
casiotone401 0:a4d93cd4c30d 13 // Masahiro Hattori's TextLCD Module Functions
casiotone401 0:a4d93cd4c30d 14 // http://www.eleclabo.com/denshi/device/lcd1602/gcram.html
casiotone401 0:a4d93cd4c30d 15 // Dirk-Willem van Gulik's BonjourLib
casiotone401 0:a4d93cd4c30d 16 // http://mbed.org/users/dirkx/code/BonjourLib/file/bb6472f455e8/services/mDNS
casiotone401 0:a4d93cd4c30d 17 //
casiotone401 0:a4d93cd4c30d 18 // Released under the MIT License: http://mbed.org/license/mit
casiotone401 0:a4d93cd4c30d 19 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 20
casiotone401 0:a4d93cd4c30d 21 #pragma O3
casiotone401 0:a4d93cd4c30d 22 #pragma Otime
casiotone401 0:a4d93cd4c30d 23
casiotone401 0:a4d93cd4c30d 24 #include "mbed.h"
casiotone401 0:a4d93cd4c30d 25 #include "TextLCD.h" //edit "writeCommand" "writeData" protected -> public
casiotone401 0:a4d93cd4c30d 26 #include "EthernetNetIf.h"
casiotone401 0:a4d93cd4c30d 27 #include "HTTPServer.h"
casiotone401 0:a4d93cd4c30d 28 #include "mDNSResponder.h" // mDNS response to announce oneselve
casiotone401 0:a4d93cd4c30d 29 #include "UDPSocket.h"
casiotone401 0:a4d93cd4c30d 30 #include "OSCReceiver.h"
casiotone401 0:a4d93cd4c30d 31 #include <stdlib.h>
casiotone401 0:a4d93cd4c30d 32 #include <ctype.h>
casiotone401 1:fd4f70088311 33 #include <math.h>
casiotone401 0:a4d93cd4c30d 34
casiotone401 0:a4d93cd4c30d 35 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 36 // Define
casiotone401 0:a4d93cd4c30d 37
casiotone401 5:e305509d53f3 38 #define MODE_LIN 0 // Linear LinearCV Mode
casiotone401 5:e305509d53f3 39 #define MODE_QChr 1 // Chromatic Quantize Mode
casiotone401 5:e305509d53f3 40 #define MODE_QMaj 2 // Major
casiotone401 5:e305509d53f3 41 #define MODE_QDor 3 // Dorian
casiotone401 5:e305509d53f3 42 #define MODE_Q5th 4 // 5th
casiotone401 5:e305509d53f3 43 #define MODE_QWht 5 // Wholetone
casiotone401 5:e305509d53f3 44 #define MODE_SEQ 6 // Sequencer & Shift Register
casiotone401 5:e305509d53f3 45 #define MODE_Calb 7 // Calibration (for VCO Tuning)
casiotone401 0:a4d93cd4c30d 46
casiotone401 5:e305509d53f3 47 #define MODE_NUM 8 // Modes
casiotone401 5:e305509d53f3 48
casiotone401 9:1ac3d135d965 49 #define QUAN_RES1 115 // Quantize voltage Steps
casiotone401 9:1ac3d135d965 50 #define QUAN_RES2 67
casiotone401 9:1ac3d135d965 51 #define QUAN_RES3 67
casiotone401 3:ca15241dd6b4 52 #define QUAN_RES4 17
casiotone401 9:1ac3d135d965 53 #define QUAN_RES5 57
casiotone401 0:a4d93cd4c30d 54
casiotone401 0:a4d93cd4c30d 55 #define SPI_RATE 40000000 // 40Mbps SPI Clock
casiotone401 0:a4d93cd4c30d 56 #define SCALING_N 38400.0
casiotone401 3:ca15241dd6b4 57 #define INPUT_PORT 12345 // Input Port Number
casiotone401 0:a4d93cd4c30d 58
casiotone401 3:ca15241dd6b4 59 #define POLLING_INTERVAL 20 // Polling Interval (us)
casiotone401 0:a4d93cd4c30d 60
casiotone401 0:a4d93cd4c30d 61 //-------------------------------------------------------------
casiotone401 5:e305509d53f3 62 // DAC8568 Control Bits (See datasheet)
casiotone401 0:a4d93cd4c30d 63
casiotone401 0:a4d93cd4c30d 64 #define WRITE 0x00
casiotone401 0:a4d93cd4c30d 65 #define UPDATE 0x01
casiotone401 5:e305509d53f3 66 #define WRITE_UPDATE_ALL 0x02 // LDAC Write to Selected Update All
casiotone401 5:e305509d53f3 67 #define WRITE_UPDATE_N 0x03 // LDAC Write to Selected Update Respective
casiotone401 0:a4d93cd4c30d 68 #define POWER 0x04
casiotone401 5:e305509d53f3 69 #define CLR 0x05 // Clear Code Register
casiotone401 0:a4d93cd4c30d 70 #define WRITE_LDAC_REG 0x06
casiotone401 5:e305509d53f3 71 #define RESET 0x07 // Software Reset DAC8568
casiotone401 0:a4d93cd4c30d 72 #define SETUP_INTERNAL_REF 0x08
casiotone401 0:a4d93cd4c30d 73
casiotone401 0:a4d93cd4c30d 74 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 75
casiotone401 0:a4d93cd4c30d 76 #define _DISABLE 0
casiotone401 0:a4d93cd4c30d 77 #define _ENABLE 1
casiotone401 0:a4d93cd4c30d 78
casiotone401 5:e305509d53f3 79 #define GATE1 0
casiotone401 5:e305509d53f3 80 #define GATE2 1
casiotone401 5:e305509d53f3 81 #define GATE3 2
casiotone401 5:e305509d53f3 82 #define GATE4 3
casiotone401 5:e305509d53f3 83 #define GATEALL 4
casiotone401 5:e305509d53f3 84
casiotone401 5:e305509d53f3 85 //-------------------------------------------------------------
casiotone401 5:e305509d53f3 86 // Beats (Note values)
casiotone401 5:e305509d53f3 87
casiotone401 5:e305509d53f3 88 #define N1ST 1 // whole
casiotone401 5:e305509d53f3 89 #define N2ND 2 // harf
casiotone401 5:e305509d53f3 90 #define N4TH 4 // quarter
casiotone401 5:e305509d53f3 91 #define N8TH 8
casiotone401 5:e305509d53f3 92 #define N16TH 16
casiotone401 5:e305509d53f3 93 #define N32TH 32
casiotone401 5:e305509d53f3 94 #define N64TH 64
casiotone401 5:e305509d53f3 95 #define NDOT2 3 // dotted
casiotone401 5:e305509d53f3 96 #define NDOT4 7
casiotone401 5:e305509d53f3 97 #define NDOT8 9
casiotone401 5:e305509d53f3 98 #define NDOT16 11
casiotone401 5:e305509d53f3 99 #define NDOT32 13
casiotone401 5:e305509d53f3 100 #define TRIP2 15 // triplets
casiotone401 5:e305509d53f3 101 #define TRIP4 17
casiotone401 5:e305509d53f3 102 #define TRIP8 19
casiotone401 5:e305509d53f3 103 #define TRIP16 21
casiotone401 5:e305509d53f3 104 #define TRIP32 23
casiotone401 5:e305509d53f3 105 #define NRESET 0 // Gate Reset
casiotone401 5:e305509d53f3 106
casiotone401 0:a4d93cd4c30d 107 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 108 // Functions
casiotone401 0:a4d93cd4c30d 109
casiotone401 4:b9f5ae574447 110 inline void NetPoll(void);
casiotone401 0:a4d93cd4c30d 111 void InitOSCCV(void);
casiotone401 4:b9f5ae574447 112 inline void UpdateCV(int, int, const unsigned int*);
casiotone401 5:e305509d53f3 113 int UpdateGate(int, int, int, int, int);
casiotone401 0:a4d93cd4c30d 114 void SetCV(void);
casiotone401 5:e305509d53f3 115 void SeqCV(int);
casiotone401 5:e305509d53f3 116 void CheckModeSW(void);
casiotone401 9:1ac3d135d965 117 inline void CVMeter(int, const unsigned int*);
casiotone401 4:b9f5ae574447 118 void LCD();
casiotone401 0:a4d93cd4c30d 119 void WriteCustomChar(unsigned char, unsigned char*);
casiotone401 0:a4d93cd4c30d 120 int SetupEthNetIf(void);
casiotone401 4:b9f5ae574447 121 inline void onUDPSocketEvent(UDPSocketEvent);
casiotone401 0:a4d93cd4c30d 122
casiotone401 0:a4d93cd4c30d 123 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 124 // Silentway Calibration Data Mapping
casiotone401 0:a4d93cd4c30d 125 // http://www.expert-sleepers.co.uk/silentway.html
casiotone401 0:a4d93cd4c30d 126
casiotone401 0:a4d93cd4c30d 127 // Chromatic Scale
casiotone401 0:a4d93cd4c30d 128 const float calibMap1[QUAN_RES1] = {
casiotone401 9:1ac3d135d965 129 0.00559238, 0.01324014, 0.02088790, 0.02853566, 0.03618342,
casiotone401 9:1ac3d135d965 130 0.04383118, 0.05147894, 0.05912671, 0.06677447, 0.07442223,
casiotone401 9:1ac3d135d965 131 0.08206999, 0.08971775, 0.09736551, 0.10501327, 0.11266103,
casiotone401 9:1ac3d135d965 132 0.12030879, 0.12775089, 0.13486665, 0.14198242, 0.14909819,
casiotone401 9:1ac3d135d965 133 0.15621395, 0.16332972, 0.17044549, 0.17756125, 0.18467702,
casiotone401 9:1ac3d135d965 134 0.19179279, 0.19890857, 0.20602433, 0.21314010, 0.22025587,
casiotone401 9:1ac3d135d965 135 0.22737163, 0.23448740, 0.24160317, 0.24871893, 0.25587305,
casiotone401 9:1ac3d135d965 136 0.26303557, 0.27019811, 0.27736065, 0.28452319, 0.29168573,
casiotone401 9:1ac3d135d965 137 0.29884824, 0.30601078, 0.31317332, 0.32033587, 0.32749838,
casiotone401 9:1ac3d135d965 138 0.33466092, 0.34182346, 0.34898600, 0.35614854, 0.36331105,
casiotone401 9:1ac3d135d965 139 0.37047359, 0.37764084, 0.38481620, 0.39199156, 0.39916691,
casiotone401 9:1ac3d135d965 140 0.40634227, 0.41351759, 0.42069295, 0.42786831, 0.43504366,
casiotone401 9:1ac3d135d965 141 0.44221902, 0.44939438, 0.45656973, 0.46374506, 0.47092041,
casiotone401 9:1ac3d135d965 142 0.47809577, 0.48527113, 0.49244648, 0.49962184, 0.50685716,
casiotone401 9:1ac3d135d965 143 0.51409578, 0.52133441, 0.52857304, 0.53581166, 0.54305035,
casiotone401 9:1ac3d135d965 144 0.55028898, 0.55752760, 0.56476623, 0.57200485, 0.57924354,
casiotone401 9:1ac3d135d965 145 0.58648217, 0.59372079, 0.60095942, 0.60819805, 0.61543667,
casiotone401 9:1ac3d135d965 146 0.62267536, 0.62996829, 0.63728690, 0.64460552, 0.65192413,
casiotone401 9:1ac3d135d965 147 0.65924275, 0.66656137, 0.67387998, 0.68119860, 0.68851727,
casiotone401 9:1ac3d135d965 148 0.69583589, 0.70315450, 0.71047312, 0.71779174, 0.72511035,
casiotone401 9:1ac3d135d965 149 0.73242897, 0.73974758, 0.74706620, 0.75810421, 0.77163076,
casiotone401 9:1ac3d135d965 150 0.78515732, 0.79868382, 0.81221038, 0.82573694, 0.83926344,
casiotone401 9:1ac3d135d965 151 0.85279000, 0.86631656, 0.88188213, 0.90110368, 0.92032516
casiotone401 0:a4d93cd4c30d 152 };
casiotone401 0:a4d93cd4c30d 153
casiotone401 0:a4d93cd4c30d 154 // Major Scale
casiotone401 0:a4d93cd4c30d 155 const float calibMap2[QUAN_RES2] = {
casiotone401 9:1ac3d135d965 156 0.01324014, 0.02853566, 0.03618342, 0.05147894, 0.06677447,
casiotone401 9:1ac3d135d965 157 0.08206999, 0.08971775, 0.10501327, 0.12030879, 0.12775089,
casiotone401 9:1ac3d135d965 158 0.14198242, 0.15621395, 0.17044549, 0.17756125, 0.19179279,
casiotone401 9:1ac3d135d965 159 0.20602433, 0.21314010, 0.22737163, 0.24160317, 0.25587305,
casiotone401 9:1ac3d135d965 160 0.26303557, 0.27736065, 0.29168573, 0.29884824, 0.31317332,
casiotone401 9:1ac3d135d965 161 0.32749838, 0.34182346, 0.34898600, 0.36331105, 0.37764084,
casiotone401 9:1ac3d135d965 162 0.38481620, 0.39916691, 0.41351759, 0.42786831, 0.43504366,
casiotone401 9:1ac3d135d965 163 0.44939438, 0.46374506, 0.47092041, 0.48527113, 0.49962184,
casiotone401 9:1ac3d135d965 164 0.51409578, 0.52133441, 0.53581166, 0.55028898, 0.55752760,
casiotone401 9:1ac3d135d965 165 0.57200485, 0.58648217, 0.60095942, 0.60819805, 0.62267536,
casiotone401 9:1ac3d135d965 166 0.63728690, 0.64460552, 0.65924275, 0.67387998, 0.68851727,
casiotone401 9:1ac3d135d965 167 0.69583589, 0.71047312, 0.72511035, 0.73242897, 0.74706620,
casiotone401 9:1ac3d135d965 168 0.77163076, 0.79868382, 0.81221038, 0.83926344, 0.86631656,
casiotone401 9:1ac3d135d965 169 0.88188213, 0.92032516
casiotone401 0:a4d93cd4c30d 170 };
casiotone401 0:a4d93cd4c30d 171
casiotone401 0:a4d93cd4c30d 172 // Dorian Scale
casiotone401 0:a4d93cd4c30d 173 const float calibMap3[QUAN_RES3] = {
casiotone401 9:1ac3d135d965 174 0.01324014, 0.02853566, 0.04383118, 0.05147894, 0.06677447,
casiotone401 9:1ac3d135d965 175 0.08206999, 0.08971775, 0.10501327, 0.12030879, 0.13486665,
casiotone401 9:1ac3d135d965 176 0.14198242, 0.15621395, 0.17044549, 0.17756125, 0.19179279,
casiotone401 9:1ac3d135d965 177 0.20602433, 0.22025587, 0.22737163, 0.24160317, 0.25587305,
casiotone401 9:1ac3d135d965 178 0.26303557, 0.27736065, 0.29168573, 0.30601078, 0.31317332,
casiotone401 9:1ac3d135d965 179 0.32749838, 0.34182346, 0.34898600, 0.36331105, 0.37764084,
casiotone401 9:1ac3d135d965 180 0.39199156, 0.39916691, 0.41351759, 0.42786831, 0.43504366,
casiotone401 9:1ac3d135d965 181 0.44939438, 0.46374506, 0.47809577, 0.48527113, 0.49962184,
casiotone401 9:1ac3d135d965 182 0.51409578, 0.52133441, 0.53581166, 0.55028898, 0.56476623,
casiotone401 9:1ac3d135d965 183 0.57200485, 0.58648217, 0.60095942, 0.60819805, 0.62267536,
casiotone401 9:1ac3d135d965 184 0.63728690, 0.65192413, 0.65924275, 0.67387998, 0.68851727,
casiotone401 9:1ac3d135d965 185 0.69583589, 0.71047312, 0.72511035, 0.73974758, 0.74706620,
casiotone401 9:1ac3d135d965 186 0.77163076, 0.79868382, 0.81221038, 0.83926344, 0.86631656,
casiotone401 9:1ac3d135d965 187 0.90110368, 0.92032516
casiotone401 0:a4d93cd4c30d 188 };
casiotone401 0:a4d93cd4c30d 189
casiotone401 3:ca15241dd6b4 190 // 5th
casiotone401 0:a4d93cd4c30d 191 const float calibMap4[QUAN_RES4] = {
casiotone401 9:1ac3d135d965 192 0.01324014, 0.06677447, 0.12030879, 0.17044549, 0.22025587,
casiotone401 9:1ac3d135d965 193 0.27019811, 0.32033587, 0.37047359, 0.42069295, 0.47092041,
casiotone401 9:1ac3d135d965 194 0.52133441, 0.57200485, 0.62267536, 0.67387998, 0.72511035,
casiotone401 9:1ac3d135d965 195 0.79868382, 0.90110368
casiotone401 3:ca15241dd6b4 196 };
casiotone401 3:ca15241dd6b4 197
casiotone401 4:b9f5ae574447 198 // Whole tone
casiotone401 3:ca15241dd6b4 199 const float calibMap5[QUAN_RES5] = {
casiotone401 9:1ac3d135d965 200 0.01324014, 0.02853566, 0.04383118, 0.05912671, 0.07442223,
casiotone401 9:1ac3d135d965 201 0.08971775, 0.10501327, 0.12030879, 0.13486665, 0.14909819,
casiotone401 9:1ac3d135d965 202 0.16332972, 0.17756125, 0.19179279, 0.20602433, 0.22025587,
casiotone401 9:1ac3d135d965 203 0.23448740, 0.24871893, 0.26303557, 0.27736065, 0.29168573,
casiotone401 9:1ac3d135d965 204 0.30601078, 0.32033587, 0.33466092, 0.34898600, 0.36331105,
casiotone401 9:1ac3d135d965 205 0.37764084, 0.39199156, 0.40634227, 0.42069295, 0.43504366,
casiotone401 9:1ac3d135d965 206 0.44939438, 0.46374506, 0.47809577, 0.49244648, 0.50685716,
casiotone401 9:1ac3d135d965 207 0.52133441, 0.53581166, 0.55028898, 0.56476623, 0.57924354,
casiotone401 9:1ac3d135d965 208 0.59372079, 0.60819805, 0.62267536, 0.63728690, 0.65192413,
casiotone401 9:1ac3d135d965 209 0.66656137, 0.68119860, 0.69583589, 0.71047312, 0.72511035,
casiotone401 9:1ac3d135d965 210 0.73974758, 0.75810421, 0.78515732, 0.81221038, 0.83926344,
casiotone401 9:1ac3d135d965 211 0.86631656, 0.90110368
casiotone401 0:a4d93cd4c30d 212 };
casiotone401 0:a4d93cd4c30d 213
casiotone401 0:a4d93cd4c30d 214 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 215 // CV Meter Custom Character
casiotone401 0:a4d93cd4c30d 216
casiotone401 0:a4d93cd4c30d 217 unsigned char str1[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F};
casiotone401 0:a4d93cd4c30d 218 unsigned char str2[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F};
casiotone401 0:a4d93cd4c30d 219 unsigned char str3[8] = {0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F};
casiotone401 0:a4d93cd4c30d 220 unsigned char str4[8] = {0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F};
casiotone401 0:a4d93cd4c30d 221 unsigned char str5[8] = {0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F,0x1F};
casiotone401 0:a4d93cd4c30d 222 unsigned char str6[8] = {0x00,0x00,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F};
casiotone401 0:a4d93cd4c30d 223 unsigned char str7[8] = {0x00,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F};
casiotone401 0:a4d93cd4c30d 224 unsigned char str8[8] = {0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F};
casiotone401 0:a4d93cd4c30d 225
casiotone401 0:a4d93cd4c30d 226 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 227 // Global Variables
casiotone401 0:a4d93cd4c30d 228
casiotone401 7:a04f8378662e 229 float gOSC_cv[8];
casiotone401 7:a04f8378662e 230 float gSeq_cv1[8];
casiotone401 7:a04f8378662e 231 float gSeq_cv2[8];
casiotone401 9:1ac3d135d965 232 float gGlide;
casiotone401 8:fe50078d6b80 233 volatile int gMode;
casiotone401 0:a4d93cd4c30d 234
casiotone401 5:e305509d53f3 235 // Variables for Control
casiotone401 5:e305509d53f3 236
casiotone401 9:1ac3d135d965 237 float gCtrl[2];
casiotone401 9:1ac3d135d965 238 volatile int gCtrlSW[4];
casiotone401 5:e305509d53f3 239
casiotone401 0:a4d93cd4c30d 240 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 241 // mbed Functions
casiotone401 0:a4d93cd4c30d 242
casiotone401 0:a4d93cd4c30d 243 TextLCD gLCD(p9, p10, p11, p12, p13, p14); // rs, e, d4-d7
casiotone401 0:a4d93cd4c30d 244
casiotone401 0:a4d93cd4c30d 245 SPI gSPI(p5,p6,p7); // SPI (p6 unconnected)
casiotone401 0:a4d93cd4c30d 246 DigitalOut gSYNCMODE(p15); // SYNC DAC8568
casiotone401 0:a4d93cd4c30d 247 DigitalOut gLDAC(p16); // LDAC DAC8568
casiotone401 0:a4d93cd4c30d 248
casiotone401 9:1ac3d135d965 249 DigitalOut gGATES[4] = {p23, p24, p24, p25}; // GateOut
casiotone401 1:fd4f70088311 250 DigitalOut gLEDS[4] = {p18, p19, p20, p21}; // LED
casiotone401 5:e305509d53f3 251 DigitalOut gCLOCKOUT(p26); // ClockOut
casiotone401 0:a4d93cd4c30d 252
casiotone401 0:a4d93cd4c30d 253 AnalogIn gAIN(p17); // Glide Potentiometer
casiotone401 0:a4d93cd4c30d 254 InterruptIn gSW(p30); // Mode SW
casiotone401 0:a4d93cd4c30d 255
casiotone401 4:b9f5ae574447 256 Timer gTimer; // Timer
casiotone401 0:a4d93cd4c30d 257 Ticker gPoller; // Ticker Polling
casiotone401 0:a4d93cd4c30d 258
casiotone401 0:a4d93cd4c30d 259 // Ethernet
casiotone401 0:a4d93cd4c30d 260 EthernetNetIf gEth;
casiotone401 0:a4d93cd4c30d 261 UDPSocket gUdp;
casiotone401 0:a4d93cd4c30d 262
casiotone401 0:a4d93cd4c30d 263 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 264 // main
casiotone401 0:a4d93cd4c30d 265
casiotone401 0:a4d93cd4c30d 266 int main()
casiotone401 0:a4d93cd4c30d 267 {
casiotone401 7:a04f8378662e 268 float pot, _pot;
casiotone401 5:e305509d53f3 269 int bpm, _bpm;
casiotone401 3:ca15241dd6b4 270
casiotone401 0:a4d93cd4c30d 271 if(SetupEthNetIf() == -1)
casiotone401 0:a4d93cd4c30d 272 {
casiotone401 4:b9f5ae574447 273 for(int i = 0; i < 4; i++)
casiotone401 0:a4d93cd4c30d 274 {
casiotone401 0:a4d93cd4c30d 275 gLEDS[i] = 1;
casiotone401 0:a4d93cd4c30d 276 wait(0.25);
casiotone401 0:a4d93cd4c30d 277 }
casiotone401 5:e305509d53f3 278
casiotone401 0:a4d93cd4c30d 279 return -1;
casiotone401 0:a4d93cd4c30d 280 }
casiotone401 0:a4d93cd4c30d 281
casiotone401 5:e305509d53f3 282 // mdns (Bonjour)
casiotone401 0:a4d93cd4c30d 283 HTTPServer svr;
casiotone401 0:a4d93cd4c30d 284 mDNSResponder mdns;
casiotone401 4:b9f5ae574447 285
casiotone401 0:a4d93cd4c30d 286 svr.addHandler<SimpleHandler>("/");
casiotone401 0:a4d93cd4c30d 287 svr.bind(INPUT_PORT);
casiotone401 0:a4d93cd4c30d 288 IpAddr ip = gEth.getIp();
casiotone401 0:a4d93cd4c30d 289 mdns.announce(ip, "OSCtoCV", "_osc._udp", INPUT_PORT, "mbed(OSCtoCV)", (char *[]) {"path=/",NULL});
casiotone401 0:a4d93cd4c30d 290
casiotone401 0:a4d93cd4c30d 291 InitOSCCV();
casiotone401 0:a4d93cd4c30d 292
casiotone401 4:b9f5ae574447 293 pot = _pot = 0;
casiotone401 4:b9f5ae574447 294 gGlide = gMode = 0;
casiotone401 5:e305509d53f3 295 bpm = _bpm = 120;
casiotone401 4:b9f5ae574447 296
casiotone401 4:b9f5ae574447 297 LCD();
casiotone401 3:ca15241dd6b4 298 gLCD.locate( 0, 1 );
casiotone401 3:ca15241dd6b4 299 gLCD.printf("12345678 G>>%3.2f", gGlide);
casiotone401 3:ca15241dd6b4 300
casiotone401 5:e305509d53f3 301 // loop
casiotone401 0:a4d93cd4c30d 302 while(1)
casiotone401 0:a4d93cd4c30d 303 {
casiotone401 5:e305509d53f3 304 gGlide = pot = gAIN.read(); // Glide Value
casiotone401 0:a4d93cd4c30d 305
casiotone401 4:b9f5ae574447 306 if(abs(pot - _pot) > 0.01f)
casiotone401 0:a4d93cd4c30d 307 {
casiotone401 3:ca15241dd6b4 308 gLCD.locate( 0, 1 );
casiotone401 3:ca15241dd6b4 309 gLCD.printf("12345678 G>>%3.2f", gGlide);
casiotone401 4:b9f5ae574447 310
casiotone401 3:ca15241dd6b4 311 _pot = gAIN.read();
casiotone401 0:a4d93cd4c30d 312 }
casiotone401 3:ca15241dd6b4 313
casiotone401 6:5796b63c70ef 314 switch(gMode)
casiotone401 4:b9f5ae574447 315 {
casiotone401 6:5796b63c70ef 316 case MODE_SEQ:
casiotone401 5:e305509d53f3 317
casiotone401 5:e305509d53f3 318 bpm = (gCtrl[0] * 300 + 10); // Set BPM (gCtrl[0])
casiotone401 5:e305509d53f3 319
casiotone401 6:5796b63c70ef 320 if(abs(bpm - _bpm) > 1)
casiotone401 6:5796b63c70ef 321 {
casiotone401 6:5796b63c70ef 322 UpdateGate(bpm, NRESET, GATEALL, 3, 0); // Reset (if bpm change)
casiotone401 6:5796b63c70ef 323 _bpm = bpm;
casiotone401 6:5796b63c70ef 324
casiotone401 6:5796b63c70ef 325 } else if (gCtrlSW[0] == 1) { // Stop (gCtrlSW[0])
casiotone401 6:5796b63c70ef 326
casiotone401 6:5796b63c70ef 327 bpm = 0;
casiotone401 6:5796b63c70ef 328 }
casiotone401 5:e305509d53f3 329
casiotone401 6:5796b63c70ef 330 if(gCtrlSW[2] == 0 && gCtrlSW[3] == 0) // Sequencer Mode1
casiotone401 6:5796b63c70ef 331 {
casiotone401 8:fe50078d6b80 332 SeqCV((UpdateGate(bpm, N16TH, GATE1, 3, 0))); // Shift Timming 16th note
casiotone401 6:5796b63c70ef 333 UpdateGate(bpm, N8TH, GATE2, 3, 0);
casiotone401 6:5796b63c70ef 334 UpdateGate(bpm, NDOT8, GATE3, 3, 0);
casiotone401 6:5796b63c70ef 335 UpdateGate(bpm, TRIP4, GATE4, 3, 0);
casiotone401 8:fe50078d6b80 336
casiotone401 9:1ac3d135d965 337 break;
casiotone401 5:e305509d53f3 338
casiotone401 6:5796b63c70ef 339 } else if (gCtrlSW[2] == 1 && gCtrlSW[3] == 0) { // Sequencer Mode2 (if gCtrlSW[2] ON)
casiotone401 5:e305509d53f3 340
casiotone401 8:fe50078d6b80 341 SeqCV((UpdateGate(bpm, N16TH, GATE1, 3, 0))); // Do shift ch 1~5
casiotone401 8:fe50078d6b80 342 SeqCV((UpdateGate(bpm, N4TH, GATE2, 3, 0))); // Do shift ch 6
casiotone401 8:fe50078d6b80 343 SeqCV((UpdateGate(bpm, NDOT4, GATE3, 3, 0))); // Do shift ch 7
casiotone401 8:fe50078d6b80 344 SeqCV((UpdateGate(bpm, TRIP8, GATE4, 3, 0))); // Do shift ch 8
casiotone401 8:fe50078d6b80 345
casiotone401 9:1ac3d135d965 346 break;
casiotone401 5:e305509d53f3 347
casiotone401 6:5796b63c70ef 348 } else if (gCtrlSW[3] == 1) { // Sequencer Mode3 (if gCtrlSW[3] ON)
casiotone401 6:5796b63c70ef 349 // (ch6,7,8, short loop)
casiotone401 8:fe50078d6b80 350 SeqCV((UpdateGate(bpm, N16TH, GATE1, 3, 0))); // Do shift ch 1~5
casiotone401 8:fe50078d6b80 351 SeqCV((UpdateGate(bpm, N8TH, GATE2, 3, 0))); // Do shift ch 6
casiotone401 8:fe50078d6b80 352 SeqCV((UpdateGate(bpm, NDOT8, GATE3, 3, 0))); // Do shift ch 7
casiotone401 8:fe50078d6b80 353 SeqCV((UpdateGate(bpm, TRIP4, GATE4, 3, 0))); // Do shift ch 8
casiotone401 8:fe50078d6b80 354
casiotone401 9:1ac3d135d965 355 break;
casiotone401 6:5796b63c70ef 356 }
casiotone401 6:5796b63c70ef 357
casiotone401 6:5796b63c70ef 358 default:
casiotone401 4:b9f5ae574447 359
casiotone401 6:5796b63c70ef 360 SetCV();
casiotone401 9:1ac3d135d965 361 break;
casiotone401 4:b9f5ae574447 362 }
casiotone401 0:a4d93cd4c30d 363 }
casiotone401 0:a4d93cd4c30d 364 }
casiotone401 0:a4d93cd4c30d 365
casiotone401 0:a4d93cd4c30d 366 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 367 // Ethernet Polling
casiotone401 0:a4d93cd4c30d 368
casiotone401 4:b9f5ae574447 369 inline void NetPoll()
casiotone401 0:a4d93cd4c30d 370 {
casiotone401 0:a4d93cd4c30d 371 Net::poll();
casiotone401 0:a4d93cd4c30d 372 }
casiotone401 0:a4d93cd4c30d 373
casiotone401 0:a4d93cd4c30d 374 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 375 // Initialize OSC-CV
casiotone401 0:a4d93cd4c30d 376
casiotone401 0:a4d93cd4c30d 377 void InitOSCCV()
casiotone401 0:a4d93cd4c30d 378 {
casiotone401 5:e305509d53f3 379 // write custom char LCD CGRAM
casiotone401 0:a4d93cd4c30d 380 WriteCustomChar(0x00, str1);
casiotone401 0:a4d93cd4c30d 381 WriteCustomChar(0x01, str2);
casiotone401 0:a4d93cd4c30d 382 WriteCustomChar(0x02, str3);
casiotone401 0:a4d93cd4c30d 383 WriteCustomChar(0x03, str4);
casiotone401 0:a4d93cd4c30d 384 WriteCustomChar(0x04, str5);
casiotone401 0:a4d93cd4c30d 385 WriteCustomChar(0x05, str6);
casiotone401 0:a4d93cd4c30d 386 WriteCustomChar(0x06, str7);
casiotone401 0:a4d93cd4c30d 387 WriteCustomChar(0x07, str8);
casiotone401 0:a4d93cd4c30d 388
casiotone401 5:e305509d53f3 389 // Init. SPI
casiotone401 0:a4d93cd4c30d 390 gLDAC = _ENABLE;
casiotone401 5:e305509d53f3 391 gSPI.format(8,1); // Data word length 8bit, Mode=1
casiotone401 0:a4d93cd4c30d 392 gSPI.frequency(SPI_RATE);
casiotone401 0:a4d93cd4c30d 393
casiotone401 5:e305509d53f3 394 UpdateCV(CLR, 0, 0); // Ignore CLR Pin
casiotone401 0:a4d93cd4c30d 395
casiotone401 5:e305509d53f3 396 gSW.mode(PullUp); // Use internal pullup for ModeSW
casiotone401 0:a4d93cd4c30d 397 wait(.001);
casiotone401 0:a4d93cd4c30d 398
casiotone401 5:e305509d53f3 399 gSW.rise(&CheckModeSW); // InterruptIn rising edge(ModeSW)
casiotone401 0:a4d93cd4c30d 400 gPoller.attach_us(&NetPoll, POLLING_INTERVAL); // Ticker Polling
casiotone401 3:ca15241dd6b4 401
casiotone401 3:ca15241dd6b4 402 wait(0.2);
casiotone401 0:a4d93cd4c30d 403 }
casiotone401 0:a4d93cd4c30d 404
casiotone401 0:a4d93cd4c30d 405 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 406 // SPI Transfer
casiotone401 0:a4d93cd4c30d 407 // DAC8568 data word length 32bit (8bit shift out)
casiotone401 0:a4d93cd4c30d 408
casiotone401 4:b9f5ae574447 409 inline void UpdateCV(int control, int address, const unsigned int *data)
casiotone401 0:a4d93cd4c30d 410 {
casiotone401 0:a4d93cd4c30d 411 __disable_irq();
casiotone401 0:a4d93cd4c30d 412
casiotone401 0:a4d93cd4c30d 413 switch(control)
casiotone401 0:a4d93cd4c30d 414 {
casiotone401 0:a4d93cd4c30d 415 case WRITE_UPDATE_N:
casiotone401 4:b9f5ae574447 416
casiotone401 0:a4d93cd4c30d 417 gSYNCMODE = _DISABLE;
casiotone401 4:b9f5ae574447 418 gSPI.write(00000000|control); // padding at beginning of byte and control bits
casiotone401 4:b9f5ae574447 419 gSPI.write(address << 4 | *data >> 12); // address(ch) bits
casiotone401 4:b9f5ae574447 420 gSPI.write((*data << 4) >> 8); // middle 8 bits of data
casiotone401 4:b9f5ae574447 421 gSPI.write((*data << 12) >> 8 | 00001111);
casiotone401 0:a4d93cd4c30d 422 gSYNCMODE = _ENABLE;
casiotone401 0:a4d93cd4c30d 423 gLDAC = _DISABLE;
casiotone401 0:a4d93cd4c30d 424 gLDAC = _ENABLE;
casiotone401 0:a4d93cd4c30d 425 break;
casiotone401 4:b9f5ae574447 426
casiotone401 0:a4d93cd4c30d 427 case RESET:
casiotone401 4:b9f5ae574447 428
casiotone401 0:a4d93cd4c30d 429 gSYNCMODE = _DISABLE;
casiotone401 4:b9f5ae574447 430 gSPI.write(00000111); // Software RESET
casiotone401 0:a4d93cd4c30d 431 gSPI.write(00000000);
casiotone401 0:a4d93cd4c30d 432 gSPI.write(00000000);
casiotone401 0:a4d93cd4c30d 433 gSPI.write(00000000);
casiotone401 0:a4d93cd4c30d 434 gSYNCMODE = _ENABLE;
casiotone401 0:a4d93cd4c30d 435 break;
casiotone401 4:b9f5ae574447 436
casiotone401 0:a4d93cd4c30d 437 case CLR:
casiotone401 4:b9f5ae574447 438
casiotone401 0:a4d93cd4c30d 439 gSYNCMODE = _DISABLE;
casiotone401 4:b9f5ae574447 440 gSPI.write(00000101); // CLR Register
casiotone401 0:a4d93cd4c30d 441 gSPI.write(00000000);
casiotone401 0:a4d93cd4c30d 442 gSPI.write(00000000);
casiotone401 4:b9f5ae574447 443 gSPI.write(00000011); // Ignore CLR Pin
casiotone401 0:a4d93cd4c30d 444 gSYNCMODE = _ENABLE;
casiotone401 0:a4d93cd4c30d 445 break;
casiotone401 0:a4d93cd4c30d 446 }
casiotone401 0:a4d93cd4c30d 447
casiotone401 0:a4d93cd4c30d 448 __enable_irq();
casiotone401 0:a4d93cd4c30d 449 }
casiotone401 0:a4d93cd4c30d 450
casiotone401 0:a4d93cd4c30d 451 //-------------------------------------------------------------
casiotone401 5:e305509d53f3 452 // GateOutSequence beat(Note values) length(Gate time) invert(invert Gate)
casiotone401 5:e305509d53f3 453
casiotone401 5:e305509d53f3 454 int UpdateGate(int bpm, int beat, int ch, int length, int invert)
casiotone401 5:e305509d53f3 455 {
casiotone401 5:e305509d53f3 456 static int gatetime[4];
casiotone401 5:e305509d53f3 457 static int oldgatetime[4];
casiotone401 5:e305509d53f3 458 static int bar;
casiotone401 5:e305509d53f3 459 static int sync24;
casiotone401 5:e305509d53f3 460 static int oldsynctime;
casiotone401 5:e305509d53f3 461
casiotone401 5:e305509d53f3 462 int time = gTimer.read_us();
casiotone401 5:e305509d53f3 463
casiotone401 5:e305509d53f3 464 bar = (60.0f / bpm) * 4000000;
casiotone401 5:e305509d53f3 465 sync24 = (bar / 4) / 24; // sync24 not tested
casiotone401 5:e305509d53f3 466
casiotone401 5:e305509d53f3 467 switch(beat) // Calculate Note values
casiotone401 5:e305509d53f3 468 {
casiotone401 5:e305509d53f3 469 case NDOT2:
casiotone401 5:e305509d53f3 470
casiotone401 5:e305509d53f3 471 gatetime[ch] = (bar / 4) * 3;
casiotone401 5:e305509d53f3 472 break;
casiotone401 5:e305509d53f3 473
casiotone401 5:e305509d53f3 474 case NDOT4:
casiotone401 5:e305509d53f3 475
casiotone401 5:e305509d53f3 476 gatetime[ch] = (bar / 8) * 3;
casiotone401 5:e305509d53f3 477 break;
casiotone401 5:e305509d53f3 478
casiotone401 5:e305509d53f3 479 case NDOT8:
casiotone401 5:e305509d53f3 480
casiotone401 5:e305509d53f3 481 gatetime[ch] = (bar / 16) * 3;
casiotone401 5:e305509d53f3 482 break;
casiotone401 5:e305509d53f3 483
casiotone401 5:e305509d53f3 484 case NDOT16:
casiotone401 5:e305509d53f3 485
casiotone401 5:e305509d53f3 486 gatetime[ch] = (bar / 32) * 3;
casiotone401 5:e305509d53f3 487 break;
casiotone401 5:e305509d53f3 488
casiotone401 5:e305509d53f3 489 case NDOT32:
casiotone401 5:e305509d53f3 490
casiotone401 5:e305509d53f3 491 gatetime[ch] = (bar / 64) * 3;
casiotone401 5:e305509d53f3 492 break;
casiotone401 5:e305509d53f3 493
casiotone401 5:e305509d53f3 494 case TRIP2:
casiotone401 5:e305509d53f3 495
casiotone401 5:e305509d53f3 496 gatetime[ch] = bar / 3;
casiotone401 5:e305509d53f3 497 break;
casiotone401 5:e305509d53f3 498
casiotone401 5:e305509d53f3 499 case TRIP4:
casiotone401 5:e305509d53f3 500
casiotone401 5:e305509d53f3 501 gatetime[ch] = (bar / 2) / 3;
casiotone401 5:e305509d53f3 502 break;
casiotone401 5:e305509d53f3 503
casiotone401 5:e305509d53f3 504 case TRIP8:
casiotone401 5:e305509d53f3 505
casiotone401 5:e305509d53f3 506 gatetime[ch] = (bar / 4) / 3;
casiotone401 5:e305509d53f3 507 break;
casiotone401 5:e305509d53f3 508
casiotone401 5:e305509d53f3 509 case TRIP16:
casiotone401 5:e305509d53f3 510
casiotone401 5:e305509d53f3 511 gatetime[ch] = (bar / 8) / 3;
casiotone401 5:e305509d53f3 512 break;
casiotone401 5:e305509d53f3 513
casiotone401 5:e305509d53f3 514 case TRIP32:
casiotone401 5:e305509d53f3 515
casiotone401 5:e305509d53f3 516 gatetime[ch] = (bar / 16) / 3;
casiotone401 5:e305509d53f3 517 break;
casiotone401 5:e305509d53f3 518
casiotone401 5:e305509d53f3 519 case NRESET:
casiotone401 5:e305509d53f3 520
casiotone401 5:e305509d53f3 521 for(int i = 0; i < GATEALL; ++i) // Reset
casiotone401 5:e305509d53f3 522 {
casiotone401 5:e305509d53f3 523 gTimer.reset();
casiotone401 5:e305509d53f3 524 oldsynctime = oldgatetime[i] = gatetime[i] = NRESET;
casiotone401 5:e305509d53f3 525 }
casiotone401 5:e305509d53f3 526 break;
casiotone401 5:e305509d53f3 527
casiotone401 5:e305509d53f3 528 default:
casiotone401 5:e305509d53f3 529
casiotone401 5:e305509d53f3 530 gatetime[ch] = bar / beat;
casiotone401 5:e305509d53f3 531 }
casiotone401 5:e305509d53f3 532
casiotone401 5:e305509d53f3 533 if(time > oldsynctime + sync24) // sync24 not tested
casiotone401 5:e305509d53f3 534 {
casiotone401 5:e305509d53f3 535 oldsynctime = time;
casiotone401 5:e305509d53f3 536 gCLOCKOUT = 1;
casiotone401 5:e305509d53f3 537
casiotone401 5:e305509d53f3 538 } else if (time > sync24 - (sync24 - 2)) {
casiotone401 5:e305509d53f3 539
casiotone401 5:e305509d53f3 540 gCLOCKOUT = 0;
casiotone401 5:e305509d53f3 541 }
casiotone401 5:e305509d53f3 542
casiotone401 5:e305509d53f3 543 if (ch == GATEALL)
casiotone401 5:e305509d53f3 544 {
casiotone401 5:e305509d53f3 545 return -1;
casiotone401 5:e305509d53f3 546
casiotone401 5:e305509d53f3 547 } else if (time > oldgatetime[ch] + gatetime[ch] && invert == 0) {
casiotone401 5:e305509d53f3 548
casiotone401 5:e305509d53f3 549 oldgatetime[ch] = time;
casiotone401 5:e305509d53f3 550 gLEDS[ch] = gGATES[ch] = 1;
casiotone401 5:e305509d53f3 551
casiotone401 5:e305509d53f3 552 return ch + 1;
casiotone401 5:e305509d53f3 553
casiotone401 5:e305509d53f3 554 } else if (time > oldgatetime[ch] + gatetime[ch] && invert == 1) {
casiotone401 5:e305509d53f3 555
casiotone401 5:e305509d53f3 556 oldgatetime[ch] = time;
casiotone401 5:e305509d53f3 557 gLEDS[ch] = gGATES[ch] = 0;
casiotone401 5:e305509d53f3 558
casiotone401 5:e305509d53f3 559 return 0;
casiotone401 5:e305509d53f3 560
casiotone401 5:e305509d53f3 561 } else if (time > oldgatetime[ch] + (gatetime[ch] - gatetime[ch] / length) && invert == 0) {
casiotone401 5:e305509d53f3 562
casiotone401 5:e305509d53f3 563 gLEDS[ch] = gGATES[ch] = 0;
casiotone401 5:e305509d53f3 564
casiotone401 5:e305509d53f3 565 return 0;
casiotone401 5:e305509d53f3 566
casiotone401 5:e305509d53f3 567 } else if (time > oldgatetime[ch] + (gatetime[ch] - gatetime[ch] / length) && invert == 1) {
casiotone401 5:e305509d53f3 568
casiotone401 5:e305509d53f3 569 gLEDS[ch] = gGATES[ch] = 1;
casiotone401 5:e305509d53f3 570
casiotone401 5:e305509d53f3 571 return ch + 1;
casiotone401 5:e305509d53f3 572
casiotone401 5:e305509d53f3 573 } else {
casiotone401 5:e305509d53f3 574
casiotone401 5:e305509d53f3 575 return -1;
casiotone401 5:e305509d53f3 576 }
casiotone401 5:e305509d53f3 577 }
casiotone401 5:e305509d53f3 578
casiotone401 5:e305509d53f3 579 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 580 // Calculate CV
casiotone401 0:a4d93cd4c30d 581
casiotone401 0:a4d93cd4c30d 582 void SetCV()
casiotone401 0:a4d93cd4c30d 583 {
casiotone401 4:b9f5ae574447 584 static int ch;
casiotone401 0:a4d93cd4c30d 585 float glidecv[8];
casiotone401 0:a4d93cd4c30d 586 unsigned int cv[8];
casiotone401 0:a4d93cd4c30d 587 static float oldcv[8];
casiotone401 0:a4d93cd4c30d 588 static unsigned int quan;
casiotone401 0:a4d93cd4c30d 589 float qcv;
casiotone401 0:a4d93cd4c30d 590
casiotone401 0:a4d93cd4c30d 591 switch(gMode)
casiotone401 0:a4d93cd4c30d 592 {
casiotone401 0:a4d93cd4c30d 593 case MODE_LIN:
casiotone401 4:b9f5ae574447 594
casiotone401 0:a4d93cd4c30d 595 glidecv[ch] = oldcv[ch] * gGlide + gOSC_cv[ch] * (1.0f - gGlide);
casiotone401 0:a4d93cd4c30d 596 oldcv[ch] = glidecv[ch];
casiotone401 0:a4d93cd4c30d 597 cv[ch] = (unsigned int)glidecv[ch];
casiotone401 0:a4d93cd4c30d 598
casiotone401 4:b9f5ae574447 599 UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]);
casiotone401 0:a4d93cd4c30d 600 break;
casiotone401 0:a4d93cd4c30d 601
casiotone401 0:a4d93cd4c30d 602 case MODE_QChr:
casiotone401 0:a4d93cd4c30d 603
casiotone401 4:b9f5ae574447 604 quan = 40616 / QUAN_RES1;
casiotone401 4:b9f5ae574447 605 qcv = calibMap1[(unsigned int)(gOSC_cv[ch] / quan)];
casiotone401 4:b9f5ae574447 606
casiotone401 4:b9f5ae574447 607 glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 608 oldcv[ch] = glidecv[ch];
casiotone401 4:b9f5ae574447 609 cv[ch] = (unsigned int)glidecv[ch];
casiotone401 4:b9f5ae574447 610
casiotone401 4:b9f5ae574447 611 UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]);
casiotone401 4:b9f5ae574447 612 break;
casiotone401 4:b9f5ae574447 613
casiotone401 4:b9f5ae574447 614 case MODE_QMaj:
casiotone401 4:b9f5ae574447 615
casiotone401 4:b9f5ae574447 616 quan = 40616 / QUAN_RES2;
casiotone401 4:b9f5ae574447 617 qcv = calibMap2[(unsigned int)(gOSC_cv[ch] / quan)];
casiotone401 0:a4d93cd4c30d 618
casiotone401 0:a4d93cd4c30d 619 glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 0:a4d93cd4c30d 620 oldcv[ch] = glidecv[ch];
casiotone401 0:a4d93cd4c30d 621 cv[ch] = (unsigned int)glidecv[ch];
casiotone401 0:a4d93cd4c30d 622
casiotone401 4:b9f5ae574447 623 UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]);
casiotone401 0:a4d93cd4c30d 624 break;
casiotone401 4:b9f5ae574447 625
casiotone401 4:b9f5ae574447 626 case MODE_QDor:
casiotone401 0:a4d93cd4c30d 627
casiotone401 4:b9f5ae574447 628 quan = 40616 / QUAN_RES3;
casiotone401 4:b9f5ae574447 629 qcv = calibMap3[(unsigned int)(gOSC_cv[ch] / quan)];
casiotone401 0:a4d93cd4c30d 630
casiotone401 0:a4d93cd4c30d 631 glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 0:a4d93cd4c30d 632 oldcv[ch] = glidecv[ch];
casiotone401 0:a4d93cd4c30d 633 cv[ch] = (unsigned int)glidecv[ch];
casiotone401 0:a4d93cd4c30d 634
casiotone401 4:b9f5ae574447 635 UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]);
casiotone401 0:a4d93cd4c30d 636 break;
casiotone401 4:b9f5ae574447 637
casiotone401 4:b9f5ae574447 638 case MODE_Q5th:
casiotone401 4:b9f5ae574447 639
casiotone401 4:b9f5ae574447 640 quan = 40616 / QUAN_RES4;
casiotone401 4:b9f5ae574447 641 qcv = calibMap4[(unsigned int)(gOSC_cv[ch] / quan)];
casiotone401 0:a4d93cd4c30d 642
casiotone401 4:b9f5ae574447 643 glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 644 oldcv[ch] = glidecv[ch];
casiotone401 4:b9f5ae574447 645 cv[ch] = (unsigned int)glidecv[ch];
casiotone401 4:b9f5ae574447 646
casiotone401 4:b9f5ae574447 647 UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]);
casiotone401 4:b9f5ae574447 648 break;
casiotone401 0:a4d93cd4c30d 649
casiotone401 4:b9f5ae574447 650 case MODE_QWht:
casiotone401 4:b9f5ae574447 651
casiotone401 4:b9f5ae574447 652 quan = 40616 / QUAN_RES5;
casiotone401 4:b9f5ae574447 653 qcv = calibMap5[(unsigned int)(gOSC_cv[ch] / quan)];
casiotone401 0:a4d93cd4c30d 654
casiotone401 0:a4d93cd4c30d 655 glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 0:a4d93cd4c30d 656 oldcv[ch] = glidecv[ch];
casiotone401 0:a4d93cd4c30d 657 cv[ch] = (unsigned int)glidecv[ch];
casiotone401 0:a4d93cd4c30d 658
casiotone401 4:b9f5ae574447 659 UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]);
casiotone401 0:a4d93cd4c30d 660 break;
casiotone401 3:ca15241dd6b4 661
casiotone401 4:b9f5ae574447 662 case MODE_Calb:
casiotone401 3:ca15241dd6b4 663
casiotone401 9:1ac3d135d965 664 cv[ch] = 19212; // A880.0Hz
casiotone401 5:e305509d53f3 665
casiotone401 5:e305509d53f3 666 gGATES[0] = gGATES[1] = gGATES[2] = gGATES[3] = 1;
casiotone401 5:e305509d53f3 667 gLEDS[0] = gLEDS[1] = gLEDS[2] = gLEDS[3] = 1;
casiotone401 5:e305509d53f3 668
casiotone401 4:b9f5ae574447 669 UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]);
casiotone401 3:ca15241dd6b4 670 break;
casiotone401 0:a4d93cd4c30d 671 }
casiotone401 4:b9f5ae574447 672
casiotone401 4:b9f5ae574447 673 CVMeter(ch, &cv[ch]);
casiotone401 0:a4d93cd4c30d 674
casiotone401 0:a4d93cd4c30d 675 ch++;
casiotone401 0:a4d93cd4c30d 676 ch &= 0x07;
casiotone401 0:a4d93cd4c30d 677 }
casiotone401 0:a4d93cd4c30d 678
casiotone401 0:a4d93cd4c30d 679 //-------------------------------------------------------------
casiotone401 4:b9f5ae574447 680 // Sequence & Shift Out CV
casiotone401 4:b9f5ae574447 681
casiotone401 5:e305509d53f3 682 void SeqCV(int shift)
casiotone401 4:b9f5ae574447 683 {
casiotone401 6:5796b63c70ef 684 int i, j, k;
casiotone401 7:a04f8378662e 685 static int ch, SeqMode;
casiotone401 5:e305509d53f3 686 static int cnt1, cnt2, cnt3;
casiotone401 5:e305509d53f3 687 static int cntloop1, cntloop2, cntloop3;
casiotone401 4:b9f5ae574447 688 static float glidecv[8];
casiotone401 4:b9f5ae574447 689 unsigned int cv[8];
casiotone401 4:b9f5ae574447 690 static float shiftcv[8];
casiotone401 5:e305509d53f3 691 static float buffercv[9];
casiotone401 5:e305509d53f3 692 static float loopcv[3];
casiotone401 7:a04f8378662e 693 int quan;
casiotone401 4:b9f5ae574447 694 float qcv;
casiotone401 4:b9f5ae574447 695
casiotone401 5:e305509d53f3 696 SeqMode = (unsigned int)(gCtrl[1] * (MODE_NUM - 3)); // Sequencer Quantize Mode (gCtrl[1])
casiotone401 4:b9f5ae574447 697
casiotone401 4:b9f5ae574447 698 switch(SeqMode)
casiotone401 4:b9f5ae574447 699 {
casiotone401 4:b9f5ae574447 700 case MODE_LIN:
casiotone401 4:b9f5ae574447 701
casiotone401 4:b9f5ae574447 702 if(ch < 8)
casiotone401 4:b9f5ae574447 703 {
casiotone401 4:b9f5ae574447 704 glidecv[0] = glidecv[0] * gGlide + gSeq_cv1[ch] * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 705
casiotone401 4:b9f5ae574447 706 } else {
casiotone401 4:b9f5ae574447 707
casiotone401 4:b9f5ae574447 708 glidecv[0] = glidecv[0] * gGlide + gSeq_cv2[ch-8] * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 709 }
casiotone401 4:b9f5ae574447 710
casiotone401 4:b9f5ae574447 711 cv[0] = (unsigned int)glidecv[0];
casiotone401 4:b9f5ae574447 712
casiotone401 4:b9f5ae574447 713 UpdateCV(WRITE_UPDATE_N, 0, &cv[0]);
casiotone401 4:b9f5ae574447 714 break;
casiotone401 4:b9f5ae574447 715
casiotone401 4:b9f5ae574447 716 case MODE_QChr:
casiotone401 4:b9f5ae574447 717
casiotone401 4:b9f5ae574447 718 quan = 40616 / QUAN_RES1;
casiotone401 4:b9f5ae574447 719
casiotone401 4:b9f5ae574447 720 if(ch < 8)
casiotone401 4:b9f5ae574447 721 {
casiotone401 4:b9f5ae574447 722 qcv = calibMap1[(unsigned int)(gSeq_cv1[ch] / quan)];
casiotone401 4:b9f5ae574447 723
casiotone401 4:b9f5ae574447 724 } else {
casiotone401 4:b9f5ae574447 725
casiotone401 4:b9f5ae574447 726 qcv = calibMap1[(unsigned int)(gSeq_cv2[ch-8] / quan)];
casiotone401 4:b9f5ae574447 727 }
casiotone401 4:b9f5ae574447 728
casiotone401 4:b9f5ae574447 729 glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 730 cv[0] = (unsigned int)glidecv[0];
casiotone401 4:b9f5ae574447 731
casiotone401 4:b9f5ae574447 732 UpdateCV(WRITE_UPDATE_N, 0, &cv[0]);
casiotone401 4:b9f5ae574447 733 break;
casiotone401 4:b9f5ae574447 734
casiotone401 4:b9f5ae574447 735 case MODE_QMaj:
casiotone401 4:b9f5ae574447 736
casiotone401 4:b9f5ae574447 737 quan = 40616 / QUAN_RES2;
casiotone401 4:b9f5ae574447 738
casiotone401 4:b9f5ae574447 739 if(ch < 8)
casiotone401 4:b9f5ae574447 740 {
casiotone401 4:b9f5ae574447 741 qcv = calibMap2[(unsigned int)(gSeq_cv1[ch] / quan)];
casiotone401 4:b9f5ae574447 742
casiotone401 4:b9f5ae574447 743 } else {
casiotone401 4:b9f5ae574447 744
casiotone401 4:b9f5ae574447 745 qcv = calibMap2[(unsigned int)(gSeq_cv2[ch-8] / quan)];
casiotone401 4:b9f5ae574447 746 }
casiotone401 4:b9f5ae574447 747
casiotone401 4:b9f5ae574447 748 glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 749 cv[0] = (unsigned int)glidecv[0];
casiotone401 4:b9f5ae574447 750
casiotone401 4:b9f5ae574447 751 UpdateCV(WRITE_UPDATE_N, 0, &cv[0]);
casiotone401 4:b9f5ae574447 752 break;
casiotone401 4:b9f5ae574447 753
casiotone401 4:b9f5ae574447 754 case MODE_QDor:
casiotone401 4:b9f5ae574447 755
casiotone401 4:b9f5ae574447 756 quan = 40616 / QUAN_RES3;
casiotone401 4:b9f5ae574447 757
casiotone401 4:b9f5ae574447 758 if(ch < 8)
casiotone401 4:b9f5ae574447 759 {
casiotone401 4:b9f5ae574447 760 qcv = calibMap3[(unsigned int)(gSeq_cv1[ch] / quan)];
casiotone401 4:b9f5ae574447 761
casiotone401 4:b9f5ae574447 762 } else {
casiotone401 4:b9f5ae574447 763
casiotone401 4:b9f5ae574447 764 qcv = calibMap3[(unsigned int)(gSeq_cv2[ch-8] / quan)];
casiotone401 4:b9f5ae574447 765 }
casiotone401 4:b9f5ae574447 766
casiotone401 4:b9f5ae574447 767 glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 768 cv[0] = (unsigned int)glidecv[0];
casiotone401 4:b9f5ae574447 769
casiotone401 4:b9f5ae574447 770 UpdateCV(WRITE_UPDATE_N, 0, &cv[0]);
casiotone401 4:b9f5ae574447 771 break;
casiotone401 4:b9f5ae574447 772
casiotone401 4:b9f5ae574447 773 case MODE_Q5th:
casiotone401 4:b9f5ae574447 774
casiotone401 4:b9f5ae574447 775 quan = 40616 / QUAN_RES4;
casiotone401 4:b9f5ae574447 776
casiotone401 4:b9f5ae574447 777 if(ch < 8)
casiotone401 4:b9f5ae574447 778 {
casiotone401 4:b9f5ae574447 779 qcv = calibMap4[(unsigned int)(gSeq_cv1[ch] / quan)];
casiotone401 4:b9f5ae574447 780
casiotone401 4:b9f5ae574447 781 } else {
casiotone401 4:b9f5ae574447 782
casiotone401 4:b9f5ae574447 783 qcv = calibMap4[(unsigned int)(gSeq_cv2[ch-8] / quan)];
casiotone401 4:b9f5ae574447 784 }
casiotone401 4:b9f5ae574447 785
casiotone401 4:b9f5ae574447 786 glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 787 cv[0] = (unsigned int)glidecv[0];
casiotone401 4:b9f5ae574447 788
casiotone401 4:b9f5ae574447 789 UpdateCV(WRITE_UPDATE_N, 0, &cv[0]);
casiotone401 4:b9f5ae574447 790 break;
casiotone401 4:b9f5ae574447 791
casiotone401 4:b9f5ae574447 792 case MODE_QWht:
casiotone401 4:b9f5ae574447 793
casiotone401 4:b9f5ae574447 794 quan = 40616 / QUAN_RES5;
casiotone401 4:b9f5ae574447 795
casiotone401 4:b9f5ae574447 796 if(ch < 8)
casiotone401 4:b9f5ae574447 797 {
casiotone401 4:b9f5ae574447 798 qcv = calibMap5[(unsigned int)(gSeq_cv1[ch] / quan)];
casiotone401 4:b9f5ae574447 799
casiotone401 4:b9f5ae574447 800 } else {
casiotone401 4:b9f5ae574447 801
casiotone401 4:b9f5ae574447 802 qcv = calibMap5[(unsigned int)(gSeq_cv2[ch-8] / quan)];
casiotone401 4:b9f5ae574447 803 }
casiotone401 4:b9f5ae574447 804
casiotone401 4:b9f5ae574447 805 glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 806 cv[0] = (unsigned int)glidecv[0];
casiotone401 4:b9f5ae574447 807
casiotone401 4:b9f5ae574447 808 UpdateCV(WRITE_UPDATE_N, 0, &cv[0]);
casiotone401 4:b9f5ae574447 809 break;
casiotone401 4:b9f5ae574447 810 }
casiotone401 4:b9f5ae574447 811
casiotone401 8:fe50078d6b80 812 if(gCtrlSW[2] == 0 && gCtrlSW[3] == 0) // Sequencer Mode1
casiotone401 4:b9f5ae574447 813 {
casiotone401 6:5796b63c70ef 814 for(i = 1; i < 8; ++i)
casiotone401 5:e305509d53f3 815 {
casiotone401 5:e305509d53f3 816 glidecv[i] = glidecv[i] * gGlide + shiftcv[i] * (1.0f - gGlide);
casiotone401 5:e305509d53f3 817 cv[i] = (unsigned int)glidecv[i];
casiotone401 5:e305509d53f3 818
casiotone401 5:e305509d53f3 819 UpdateCV(WRITE_UPDATE_N, i, &cv[i]);
casiotone401 8:fe50078d6b80 820 }
casiotone401 8:fe50078d6b80 821
casiotone401 8:fe50078d6b80 822 if(shift == 1) // GATE1
casiotone401 8:fe50078d6b80 823 {
casiotone401 8:fe50078d6b80 824 for(j = 1; j < 8; ++j) // Shift ch2~8
casiotone401 6:5796b63c70ef 825 {
casiotone401 8:fe50078d6b80 826 shiftcv[j] = glidecv[j-1];
casiotone401 6:5796b63c70ef 827 }
casiotone401 6:5796b63c70ef 828
casiotone401 8:fe50078d6b80 829 ch++;
casiotone401 8:fe50078d6b80 830 ch &= 0x0F;
casiotone401 5:e305509d53f3 831 }
casiotone401 8:fe50078d6b80 832
casiotone401 8:fe50078d6b80 833 cnt1 = cnt2 = cnt3 = 0;
casiotone401 4:b9f5ae574447 834
casiotone401 8:fe50078d6b80 835 } else if (gCtrlSW[2] == 1 && gCtrlSW[3] == 0) { // Sequencer Mode2
casiotone401 5:e305509d53f3 836
casiotone401 8:fe50078d6b80 837 for(i = 1; i < 8; ++i)
casiotone401 8:fe50078d6b80 838 {
casiotone401 8:fe50078d6b80 839 glidecv[i] = glidecv[i] * gGlide + shiftcv[i] * (1.0f - gGlide);
casiotone401 8:fe50078d6b80 840 cv[i] = (unsigned int)glidecv[i];
casiotone401 8:fe50078d6b80 841
casiotone401 8:fe50078d6b80 842 UpdateCV(WRITE_UPDATE_N, i, &cv[i]);
casiotone401 8:fe50078d6b80 843 }
casiotone401 8:fe50078d6b80 844
casiotone401 5:e305509d53f3 845 if(shift == 1) // GATE1
casiotone401 5:e305509d53f3 846 {
casiotone401 6:5796b63c70ef 847 for(j = 1; j < 5; ++j)
casiotone401 5:e305509d53f3 848 {
casiotone401 5:e305509d53f3 849 shiftcv[j] = glidecv[j-1]; // Shift ch2~5
casiotone401 5:e305509d53f3 850 }
casiotone401 5:e305509d53f3 851
casiotone401 5:e305509d53f3 852 ch++;
casiotone401 5:e305509d53f3 853 ch &= 0x0F;
casiotone401 5:e305509d53f3 854
casiotone401 5:e305509d53f3 855 } else if (shift == 2) { // GATE2
casiotone401 5:e305509d53f3 856
casiotone401 5:e305509d53f3 857 shiftcv[5] = glidecv[1]; // Shift ch6
casiotone401 5:e305509d53f3 858
casiotone401 5:e305509d53f3 859 } else if (shift == 3) { // GATE3
casiotone401 5:e305509d53f3 860
casiotone401 5:e305509d53f3 861 shiftcv[6] = glidecv[2]; // Shift ch7
casiotone401 5:e305509d53f3 862
casiotone401 5:e305509d53f3 863 } else if (shift == 4) { // GATE4
casiotone401 5:e305509d53f3 864
casiotone401 5:e305509d53f3 865 shiftcv[7] = glidecv[3]; // Shift ch8
casiotone401 8:fe50078d6b80 866 }
casiotone401 8:fe50078d6b80 867
casiotone401 8:fe50078d6b80 868 cnt1 = cnt2 = cnt3 = 0;
casiotone401 6:5796b63c70ef 869
casiotone401 8:fe50078d6b80 870 } else if (gCtrlSW[3] == 1) { // Sequencer Mode3
casiotone401 5:e305509d53f3 871
casiotone401 8:fe50078d6b80 872 for(i = 1; i < 5; ++i)
casiotone401 6:5796b63c70ef 873 {
casiotone401 8:fe50078d6b80 874 glidecv[i] = glidecv[i] * gGlide + shiftcv[i] * (1.0f - gGlide);
casiotone401 8:fe50078d6b80 875 cv[i] = (unsigned int)glidecv[i];
casiotone401 8:fe50078d6b80 876
casiotone401 8:fe50078d6b80 877 UpdateCV(WRITE_UPDATE_N, i, &cv[i]);
casiotone401 8:fe50078d6b80 878 }
casiotone401 8:fe50078d6b80 879
casiotone401 8:fe50078d6b80 880 for(j = 5; j < 8; ++j)
casiotone401 8:fe50078d6b80 881 {
casiotone401 8:fe50078d6b80 882 glidecv[j] = glidecv[j] * gGlide + loopcv[j - 5] * (1.0f - gGlide);
casiotone401 6:5796b63c70ef 883 cv[j] = (unsigned int)glidecv[j];
casiotone401 6:5796b63c70ef 884
casiotone401 6:5796b63c70ef 885 UpdateCV(WRITE_UPDATE_N, j, &cv[j]);
casiotone401 6:5796b63c70ef 886 }
casiotone401 6:5796b63c70ef 887
casiotone401 5:e305509d53f3 888 if(shift == 1) // GATE1
casiotone401 5:e305509d53f3 889 {
casiotone401 8:fe50078d6b80 890 for(k = 1; k < 8; ++k)
casiotone401 5:e305509d53f3 891 {
casiotone401 8:fe50078d6b80 892 shiftcv[k] = glidecv[k-1]; // Shift ch2~5
casiotone401 5:e305509d53f3 893 }
casiotone401 5:e305509d53f3 894
casiotone401 5:e305509d53f3 895 ch++;
casiotone401 5:e305509d53f3 896 ch &= 0x0F;
casiotone401 5:e305509d53f3 897
casiotone401 5:e305509d53f3 898 } else if (shift == 2) { // GATE2
casiotone401 5:e305509d53f3 899
casiotone401 5:e305509d53f3 900 if(cnt1 < 4)
casiotone401 5:e305509d53f3 901 {
casiotone401 5:e305509d53f3 902 loopcv[0] = buffercv[cnt1] = shiftcv[4];
casiotone401 5:e305509d53f3 903
casiotone401 5:e305509d53f3 904 cnt1++;
casiotone401 5:e305509d53f3 905
casiotone401 5:e305509d53f3 906 } else if (cnt1 >= 4) {
casiotone401 5:e305509d53f3 907
casiotone401 5:e305509d53f3 908 loopcv[0] = buffercv[cntloop1];
casiotone401 5:e305509d53f3 909
casiotone401 5:e305509d53f3 910 cntloop1++;
casiotone401 5:e305509d53f3 911 cntloop1 &= 0x03;
casiotone401 5:e305509d53f3 912 }
casiotone401 5:e305509d53f3 913
casiotone401 5:e305509d53f3 914 } else if (shift == 3) { // GATE3
casiotone401 5:e305509d53f3 915
casiotone401 5:e305509d53f3 916 if(cnt2 < 3)
casiotone401 5:e305509d53f3 917 {
casiotone401 5:e305509d53f3 918 loopcv[1] = buffercv[(cnt2 + 4)] = shiftcv[5];
casiotone401 5:e305509d53f3 919
casiotone401 5:e305509d53f3 920 cnt2++;
casiotone401 5:e305509d53f3 921
casiotone401 5:e305509d53f3 922 } else if (cnt2 >= 3) {
casiotone401 5:e305509d53f3 923
casiotone401 5:e305509d53f3 924 loopcv[1] = buffercv[(cntloop2 + 4)];
casiotone401 5:e305509d53f3 925
casiotone401 5:e305509d53f3 926 cntloop2++;
casiotone401 5:e305509d53f3 927 cntloop2 &= 0x03;
casiotone401 5:e305509d53f3 928 }
casiotone401 5:e305509d53f3 929
casiotone401 5:e305509d53f3 930 } else if (shift == 4) { // GATE4
casiotone401 5:e305509d53f3 931
casiotone401 5:e305509d53f3 932 if(cnt3 < 2)
casiotone401 5:e305509d53f3 933 {
casiotone401 5:e305509d53f3 934 loopcv[2] = buffercv[(cnt3 + 7)] = shiftcv[6];
casiotone401 5:e305509d53f3 935
casiotone401 5:e305509d53f3 936 cnt3++;
casiotone401 5:e305509d53f3 937
casiotone401 5:e305509d53f3 938 } else if (cnt3 >= 2) {
casiotone401 5:e305509d53f3 939
casiotone401 5:e305509d53f3 940 loopcv[2] = buffercv[(cntloop3 + 7)];
casiotone401 5:e305509d53f3 941
casiotone401 5:e305509d53f3 942 cntloop3++;
casiotone401 5:e305509d53f3 943 cntloop3 &= 0x01;
casiotone401 5:e305509d53f3 944 }
casiotone401 5:e305509d53f3 945 }
casiotone401 5:e305509d53f3 946
casiotone401 5:e305509d53f3 947 if(gCtrlSW[1] == 1) // Update loop buffer (if gCtrlSW[1] ON)
casiotone401 5:e305509d53f3 948 {
casiotone401 5:e305509d53f3 949 cnt1 = cnt2 = cnt3 = 0;
casiotone401 5:e305509d53f3 950 }
casiotone401 4:b9f5ae574447 951 }
casiotone401 4:b9f5ae574447 952
casiotone401 4:b9f5ae574447 953 if(ch < 8)
casiotone401 4:b9f5ae574447 954 {
casiotone401 4:b9f5ae574447 955 CVMeter(ch, &cv[0]);
casiotone401 4:b9f5ae574447 956
casiotone401 4:b9f5ae574447 957 } else {
casiotone401 4:b9f5ae574447 958
casiotone401 4:b9f5ae574447 959 CVMeter((ch-8), &cv[0]);
casiotone401 4:b9f5ae574447 960 }
casiotone401 4:b9f5ae574447 961 }
casiotone401 4:b9f5ae574447 962
casiotone401 4:b9f5ae574447 963 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 964 // Check SW
casiotone401 0:a4d93cd4c30d 965
casiotone401 5:e305509d53f3 966 void CheckModeSW()
casiotone401 0:a4d93cd4c30d 967 {
casiotone401 7:a04f8378662e 968 wait(0.05);
casiotone401 4:b9f5ae574447 969
casiotone401 3:ca15241dd6b4 970 if(gMode < MODE_NUM - 1)
casiotone401 0:a4d93cd4c30d 971 {
casiotone401 0:a4d93cd4c30d 972 gMode++;
casiotone401 3:ca15241dd6b4 973
casiotone401 0:a4d93cd4c30d 974 } else {
casiotone401 4:b9f5ae574447 975
casiotone401 0:a4d93cd4c30d 976 gMode = 0;
casiotone401 0:a4d93cd4c30d 977 }
casiotone401 3:ca15241dd6b4 978
casiotone401 5:e305509d53f3 979 gCLOCKOUT = gGATES[0] = gGATES[1] = gGATES[2] = gGATES[3] = 0;
casiotone401 5:e305509d53f3 980 gLEDS[0] = gLEDS[1] = gLEDS[2] = gLEDS[3] = 0;
casiotone401 5:e305509d53f3 981
casiotone401 5:e305509d53f3 982 if(gMode == MODE_SEQ)
casiotone401 5:e305509d53f3 983 {
casiotone401 5:e305509d53f3 984 gTimer.start(); // Sequencer Timer Start
casiotone401 5:e305509d53f3 985
casiotone401 5:e305509d53f3 986 } else {
casiotone401 5:e305509d53f3 987
casiotone401 5:e305509d53f3 988 gTimer.stop(); // Sequencer Timer Stop
casiotone401 5:e305509d53f3 989 }
casiotone401 5:e305509d53f3 990
casiotone401 4:b9f5ae574447 991 LCD();
casiotone401 4:b9f5ae574447 992 }
casiotone401 4:b9f5ae574447 993
casiotone401 4:b9f5ae574447 994 //-------------------------------------------------------------
casiotone401 4:b9f5ae574447 995 // CV meter
casiotone401 4:b9f5ae574447 996
casiotone401 9:1ac3d135d965 997 inline void CVMeter(int ch, const unsigned int *level)
casiotone401 4:b9f5ae574447 998 {
casiotone401 7:a04f8378662e 999 unsigned int cvmeter;
casiotone401 4:b9f5ae574447 1000
casiotone401 9:1ac3d135d965 1001 cvmeter = *level / (SCALING_N / 7.9f);
casiotone401 4:b9f5ae574447 1002
casiotone401 4:b9f5ae574447 1003 gLCD.locate ( ch, 0 );
casiotone401 4:b9f5ae574447 1004 gLCD.putc(cvmeter); // put custom char
casiotone401 4:b9f5ae574447 1005 }
casiotone401 4:b9f5ae574447 1006
casiotone401 4:b9f5ae574447 1007 //-------------------------------------------------------------
casiotone401 5:e305509d53f3 1008 // Print LCD Mode Status
casiotone401 4:b9f5ae574447 1009
casiotone401 4:b9f5ae574447 1010 void LCD()
casiotone401 4:b9f5ae574447 1011 {
casiotone401 3:ca15241dd6b4 1012 switch(gMode)
casiotone401 3:ca15241dd6b4 1013 {
casiotone401 3:ca15241dd6b4 1014 case MODE_LIN:
casiotone401 3:ca15241dd6b4 1015 gLCD.locate( 9, 0 );
casiotone401 3:ca15241dd6b4 1016 gLCD.printf("OSC-CV ");
casiotone401 3:ca15241dd6b4 1017 break;
casiotone401 3:ca15241dd6b4 1018
casiotone401 3:ca15241dd6b4 1019 case MODE_QChr:
casiotone401 3:ca15241dd6b4 1020 gLCD.locate( 9, 0 );
casiotone401 3:ca15241dd6b4 1021 gLCD.printf("QUAN_C ");
casiotone401 3:ca15241dd6b4 1022 break;
casiotone401 3:ca15241dd6b4 1023
casiotone401 3:ca15241dd6b4 1024 case MODE_QMaj:
casiotone401 3:ca15241dd6b4 1025 gLCD.locate( 9, 0 );
casiotone401 3:ca15241dd6b4 1026 gLCD.printf("QUAN_M ");
casiotone401 3:ca15241dd6b4 1027 break;
casiotone401 3:ca15241dd6b4 1028
casiotone401 3:ca15241dd6b4 1029 case MODE_QDor:
casiotone401 3:ca15241dd6b4 1030 gLCD.locate( 9, 0 );
casiotone401 3:ca15241dd6b4 1031 gLCD.printf("QUAN_D ");
casiotone401 3:ca15241dd6b4 1032 break;
casiotone401 3:ca15241dd6b4 1033
casiotone401 3:ca15241dd6b4 1034 case MODE_Q5th:
casiotone401 3:ca15241dd6b4 1035 gLCD.locate( 9, 0 );
casiotone401 3:ca15241dd6b4 1036 gLCD.printf("QUAN_5 ");
casiotone401 3:ca15241dd6b4 1037 break;
casiotone401 3:ca15241dd6b4 1038
casiotone401 3:ca15241dd6b4 1039 case MODE_QWht:
casiotone401 3:ca15241dd6b4 1040 gLCD.locate( 9, 0 );
casiotone401 3:ca15241dd6b4 1041 gLCD.printf("QUAN_W ");
casiotone401 3:ca15241dd6b4 1042 break;
casiotone401 4:b9f5ae574447 1043
casiotone401 4:b9f5ae574447 1044 case MODE_SEQ:
casiotone401 4:b9f5ae574447 1045 gLCD.locate( 9, 0 );
casiotone401 4:b9f5ae574447 1046 gLCD.printf("ASRSEQ ");
casiotone401 4:b9f5ae574447 1047 break;
casiotone401 4:b9f5ae574447 1048
casiotone401 4:b9f5ae574447 1049 case MODE_Calb:
casiotone401 4:b9f5ae574447 1050 gLCD.locate( 9, 0 );
casiotone401 4:b9f5ae574447 1051 gLCD.printf("Calibr ");
casiotone401 4:b9f5ae574447 1052 break;
casiotone401 3:ca15241dd6b4 1053 }
casiotone401 0:a4d93cd4c30d 1054 }
casiotone401 0:a4d93cd4c30d 1055
casiotone401 0:a4d93cd4c30d 1056 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 1057 // Write command Custom Char LCD CGRAM(CV Meter)
casiotone401 0:a4d93cd4c30d 1058
casiotone401 0:a4d93cd4c30d 1059 void WriteCustomChar(unsigned char addr, unsigned char *c)
casiotone401 0:a4d93cd4c30d 1060 {
casiotone401 0:a4d93cd4c30d 1061 char cnt = 0;
casiotone401 0:a4d93cd4c30d 1062 addr = ((addr << 3) | 0x40);
casiotone401 0:a4d93cd4c30d 1063
casiotone401 0:a4d93cd4c30d 1064 while(cnt < 0x08)
casiotone401 0:a4d93cd4c30d 1065 {
casiotone401 0:a4d93cd4c30d 1066 gLCD.writeCommand(addr | cnt);
casiotone401 0:a4d93cd4c30d 1067 gLCD.writeData(*c);
casiotone401 4:b9f5ae574447 1068
casiotone401 0:a4d93cd4c30d 1069 cnt++;
casiotone401 0:a4d93cd4c30d 1070 c++;
casiotone401 0:a4d93cd4c30d 1071 }
casiotone401 0:a4d93cd4c30d 1072 }
casiotone401 0:a4d93cd4c30d 1073
casiotone401 0:a4d93cd4c30d 1074 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 1075 // Setup Ethernet port
casiotone401 0:a4d93cd4c30d 1076
casiotone401 0:a4d93cd4c30d 1077 int SetupEthNetIf()
casiotone401 0:a4d93cd4c30d 1078 {
casiotone401 0:a4d93cd4c30d 1079 gLCD.locate( 0, 1 );
casiotone401 0:a4d93cd4c30d 1080 gLCD.printf("Setting up... ");
casiotone401 0:a4d93cd4c30d 1081 // printf("Setting up...\r\n");
casiotone401 0:a4d93cd4c30d 1082 EthernetErr ethErr = gEth.setup();
casiotone401 0:a4d93cd4c30d 1083
casiotone401 0:a4d93cd4c30d 1084 if(ethErr)
casiotone401 0:a4d93cd4c30d 1085 {
casiotone401 0:a4d93cd4c30d 1086 gLCD.locate( 0, 1 );
casiotone401 0:a4d93cd4c30d 1087 gLCD.printf("Error in setup.");
casiotone401 0:a4d93cd4c30d 1088 // printf("Error %d in setup.\r\n", ethErr);
casiotone401 0:a4d93cd4c30d 1089 return -1;
casiotone401 0:a4d93cd4c30d 1090 }
casiotone401 0:a4d93cd4c30d 1091 // printf("Setup OK\r\n");
casiotone401 0:a4d93cd4c30d 1092
casiotone401 0:a4d93cd4c30d 1093 // printf("IP address %d.%d.%d.%d\r\n", gEth.getIp()[0], gEth.getIp()[1], gEth.getIp()[2], gEth.getIp()[3]);
casiotone401 0:a4d93cd4c30d 1094 Host broadcast(IpAddr(gEth.getIp()[0], gEth.getIp()[1], gEth.getIp()[2], 255), INPUT_PORT, NULL);
casiotone401 0:a4d93cd4c30d 1095 gUdp.setOnEvent(&onUDPSocketEvent);
casiotone401 0:a4d93cd4c30d 1096 gUdp.bind(broadcast);
casiotone401 4:b9f5ae574447 1097
casiotone401 0:a4d93cd4c30d 1098 gLCD.locate( 0, 1 );
casiotone401 0:a4d93cd4c30d 1099 gLCD.printf("%03d.%03d.%03d.%03d", gEth.getIp()[0], gEth.getIp()[1], gEth.getIp()[2], gEth.getIp()[3]);
casiotone401 4:b9f5ae574447 1100 wait(1.0);
casiotone401 0:a4d93cd4c30d 1101
casiotone401 0:a4d93cd4c30d 1102 return 0;
casiotone401 0:a4d93cd4c30d 1103 }
casiotone401 0:a4d93cd4c30d 1104
casiotone401 0:a4d93cd4c30d 1105 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 1106 // Handller receive UDP Packet
casiotone401 0:a4d93cd4c30d 1107
casiotone401 4:b9f5ae574447 1108 inline void onUDPSocketEvent(UDPSocketEvent e)
casiotone401 0:a4d93cd4c30d 1109 {
casiotone401 0:a4d93cd4c30d 1110 union OSCarg msg[10];
casiotone401 7:a04f8378662e 1111 int num;
casiotone401 6:5796b63c70ef 1112 unsigned int absv;
casiotone401 6:5796b63c70ef 1113
casiotone401 0:a4d93cd4c30d 1114 switch(e)
casiotone401 0:a4d93cd4c30d 1115 {
casiotone401 4:b9f5ae574447 1116 case UDPSOCKET_READABLE: // The only event for now
casiotone401 0:a4d93cd4c30d 1117 char buf[256] = {0};
casiotone401 0:a4d93cd4c30d 1118 Host host;
casiotone401 0:a4d93cd4c30d 1119
casiotone401 0:a4d93cd4c30d 1120 while( int len = gUdp.recvfrom( buf, 256, &host ))
casiotone401 0:a4d93cd4c30d 1121 {
casiotone401 0:a4d93cd4c30d 1122 if(len <= 0) break;
casiotone401 0:a4d93cd4c30d 1123 // printf("\r\nFrom %d.%d.%d.%d:\r\n",
casiotone401 0:a4d93cd4c30d 1124 // host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3]);
casiotone401 0:a4d93cd4c30d 1125
casiotone401 0:a4d93cd4c30d 1126 getOSCmsg(buf,msg);
casiotone401 0:a4d93cd4c30d 1127 // printf("OSCmsg: %s %s %f %i\r\n",
casiotone401 0:a4d93cd4c30d 1128 // msg[0].address, msg[1].typeTag, msg[2].f, msg[2].i);
casiotone401 0:a4d93cd4c30d 1129
casiotone401 0:a4d93cd4c30d 1130 len = strlen(msg[0].address);
casiotone401 4:b9f5ae574447 1131
casiotone401 4:b9f5ae574447 1132 if(isdigit(msg[0].address[len-1]))
casiotone401 4:b9f5ae574447 1133
casiotone401 4:b9f5ae574447 1134 num = msg[0].address[len-1] - '0' - 1;
casiotone401 4:b9f5ae574447 1135 else
casiotone401 4:b9f5ae574447 1136 num = -1;
casiotone401 4:b9f5ae574447 1137
casiotone401 6:5796b63c70ef 1138 absv = msg[2].f + 0; //convert -0 to 0
casiotone401 0:a4d93cd4c30d 1139
casiotone401 5:e305509d53f3 1140 // address pattern SYNC & GATE (Type Tag int, float)
casiotone401 6:5796b63c70ef 1141 if(strncmp(msg[0].address+(len-1)-4, "sync", 4)==0) {
casiotone401 0:a4d93cd4c30d 1142 if(absv >= 1 || msg[2].i >= 1) gCLOCKOUT = 1;
casiotone401 0:a4d93cd4c30d 1143 else gCLOCKOUT = 0;
casiotone401 0:a4d93cd4c30d 1144 break;
casiotone401 0:a4d93cd4c30d 1145
casiotone401 3:ca15241dd6b4 1146 } else if ((strncmp(msg[0].address+(len-1)-4, "gate", 4)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1147 if(num > 3) break;
casiotone401 0:a4d93cd4c30d 1148 if(absv >= 1 || msg[2].i >= 1) gLEDS[num] = gGATES[num] = 1;
casiotone401 0:a4d93cd4c30d 1149 else gLEDS[num] = gGATES[num] = 0;
casiotone401 0:a4d93cd4c30d 1150 break;
casiotone401 5:e305509d53f3 1151 // (touchOSC Control push, toggle)
casiotone401 3:ca15241dd6b4 1152 } else if ((strncmp(msg[0].address+(len-1)-4, "push", 4)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1153 if(num > 3) break;
casiotone401 0:a4d93cd4c30d 1154 if(absv >= 1 || msg[2].i >= 1) gLEDS[num] = gGATES[num] = 1;
casiotone401 0:a4d93cd4c30d 1155 else gLEDS[num] = gGATES[num] = 0;
casiotone401 0:a4d93cd4c30d 1156 break;
casiotone401 0:a4d93cd4c30d 1157
casiotone401 3:ca15241dd6b4 1158 } else if ((strncmp(msg[0].address+(len-1)-6, "toggle", 6)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1159 if(num > 3) break;
casiotone401 0:a4d93cd4c30d 1160 if(absv >= 1 || msg[2].i >= 1) gLEDS[num] = gGATES[num] = 1;
casiotone401 0:a4d93cd4c30d 1161 else gLEDS[num] = gGATES[num] = 0;
casiotone401 0:a4d93cd4c30d 1162 break;
casiotone401 4:b9f5ae574447 1163
casiotone401 0:a4d93cd4c30d 1164 }
casiotone401 0:a4d93cd4c30d 1165
casiotone401 0:a4d93cd4c30d 1166 // address pattern CV (Type Tag float)
casiotone401 3:ca15241dd6b4 1167 if((strncmp(msg[0].address+(len-1)-2, "cv", 2)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1168 if(num > 7) break;
casiotone401 0:a4d93cd4c30d 1169 if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
casiotone401 0:a4d93cd4c30d 1170 break;
casiotone401 0:a4d93cd4c30d 1171 // (touchOSC Control fader, rotary, xy, multixy, multifader)
casiotone401 3:ca15241dd6b4 1172 } else if ((strncmp(msg[0].address+(len-1)-5, "fader", 5)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1173 if(num > 7) break;
casiotone401 0:a4d93cd4c30d 1174 if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
casiotone401 0:a4d93cd4c30d 1175 break;
casiotone401 0:a4d93cd4c30d 1176
casiotone401 3:ca15241dd6b4 1177 } else if ((strncmp(msg[0].address+(len-1)-6, "rotary", 6)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1178 if(num > 7) break;
casiotone401 0:a4d93cd4c30d 1179 if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
casiotone401 0:a4d93cd4c30d 1180 break;
casiotone401 0:a4d93cd4c30d 1181
casiotone401 3:ca15241dd6b4 1182 } else if ((strncmp(msg[0].address+(len-1)-2, "xy", 2)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1183 if(num > 7) break;
casiotone401 0:a4d93cd4c30d 1184 if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
casiotone401 0:a4d93cd4c30d 1185 if(msg[1].typeTag[1] == 'f') gOSC_cv[++num] = msg[3].f * (SCALING_N);
casiotone401 0:a4d93cd4c30d 1186 break;
casiotone401 0:a4d93cd4c30d 1187
casiotone401 3:ca15241dd6b4 1188 } else if ((strncmp(msg[0].address+(len-1)-9, "multixy1/", 9)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1189 if(num > 7) break;
casiotone401 0:a4d93cd4c30d 1190 if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
casiotone401 0:a4d93cd4c30d 1191 if(msg[1].typeTag[1] == 'f') gOSC_cv[++num] = msg[3].f * (SCALING_N);
casiotone401 0:a4d93cd4c30d 1192 break;
casiotone401 0:a4d93cd4c30d 1193
casiotone401 3:ca15241dd6b4 1194 } else if ((strncmp(msg[0].address+(len-1)-12, "multifader1/", 12)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1195 if(num > 7) break;
casiotone401 0:a4d93cd4c30d 1196 if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
casiotone401 4:b9f5ae574447 1197 break;
casiotone401 5:e305509d53f3 1198 // (touchOSC multifader for Sequencer Mode)
casiotone401 4:b9f5ae574447 1199 } else if ((strncmp(msg[0].address+(len-1)-11, "sequencer1/", 11)==0) && (num != -1)) {
casiotone401 4:b9f5ae574447 1200 if(num > 7) break;
casiotone401 4:b9f5ae574447 1201 if(msg[1].typeTag[1] == 'f') gSeq_cv1[num] = msg[2].f * (SCALING_N);
casiotone401 4:b9f5ae574447 1202 break;
casiotone401 5:e305509d53f3 1203
casiotone401 4:b9f5ae574447 1204 } else if ((strncmp(msg[0].address+(len-1)-11, "sequencer2/", 11)==0) && (num != -1)) {
casiotone401 4:b9f5ae574447 1205 if(num > 7) break;
casiotone401 4:b9f5ae574447 1206 if(msg[1].typeTag[1] == 'f') gSeq_cv2[num] = msg[2].f * (SCALING_N);
casiotone401 4:b9f5ae574447 1207 break;
casiotone401 4:b9f5ae574447 1208 }
casiotone401 4:b9f5ae574447 1209
casiotone401 5:e305509d53f3 1210 // address pattern for control
casiotone401 4:b9f5ae574447 1211 if ((strncmp(msg[0].address+(len-1)-6, "ctrlsw", 6)==0) && (num != -1)) {
casiotone401 5:e305509d53f3 1212 if(num > 4) break;
casiotone401 4:b9f5ae574447 1213 if(absv >= 1 || msg[2].i >= 1) gCtrlSW[num] = 1;
casiotone401 4:b9f5ae574447 1214 else gCtrlSW[num] = 0;
casiotone401 4:b9f5ae574447 1215 break;
casiotone401 4:b9f5ae574447 1216
casiotone401 4:b9f5ae574447 1217 } else if ((strncmp(msg[0].address+(len-1)-4, "ctrl", 4)==0) && (num != -1)) {
casiotone401 4:b9f5ae574447 1218 if(num > 2) break;
casiotone401 4:b9f5ae574447 1219 if(msg[1].typeTag[1] == 'f') gCtrl[num] = msg[2].f;
casiotone401 4:b9f5ae574447 1220 break;
casiotone401 4:b9f5ae574447 1221 }
casiotone401 4:b9f5ae574447 1222 }
casiotone401 4:b9f5ae574447 1223 }
casiotone401 0:a4d93cd4c30d 1224 }