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 23 11:24:13 2013 +0000
Revision:
10:ccfeb687c3f2
Parent:
9:1ac3d135d965
Child:
11:ef7610cd7ebe
minor update

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 10:ccfeb687c3f2 113 int UpdateGate(int, int, int, int, bool);
casiotone401 10:ccfeb687c3f2 114 inline 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 10:ccfeb687c3f2 238 volatile bool gCtrlSW[4] = {false};
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 10:ccfeb687c3f2 325 } else if (gCtrlSW[0]) { // Stop (gCtrlSW[0])
casiotone401 6:5796b63c70ef 326
casiotone401 6:5796b63c70ef 327 bpm = 0;
casiotone401 6:5796b63c70ef 328 }
casiotone401 5:e305509d53f3 329
casiotone401 10:ccfeb687c3f2 330 if(!gCtrlSW[2] && !gCtrlSW[3]) // 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 10:ccfeb687c3f2 339 } else if (gCtrlSW[2] && !gCtrlSW[3]) { // 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 10:ccfeb687c3f2 348 } else if (gCtrlSW[3]) { // 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 10:ccfeb687c3f2 454 int UpdateGate(int bpm, int beat, int ch, int length, bool invert)
casiotone401 5:e305509d53f3 455 {
casiotone401 10:ccfeb687c3f2 456 int i;
casiotone401 10:ccfeb687c3f2 457 static int gatetime[4], oldgatetime[4];
casiotone401 10:ccfeb687c3f2 458 static int bar, sync24, oldsynctime;
casiotone401 5:e305509d53f3 459
casiotone401 5:e305509d53f3 460 int time = gTimer.read_us();
casiotone401 5:e305509d53f3 461
casiotone401 5:e305509d53f3 462 bar = (60.0f / bpm) * 4000000;
casiotone401 5:e305509d53f3 463 sync24 = (bar / 4) / 24; // sync24 not tested
casiotone401 5:e305509d53f3 464
casiotone401 5:e305509d53f3 465 switch(beat) // Calculate Note values
casiotone401 5:e305509d53f3 466 {
casiotone401 5:e305509d53f3 467 case NDOT2:
casiotone401 5:e305509d53f3 468
casiotone401 5:e305509d53f3 469 gatetime[ch] = (bar / 4) * 3;
casiotone401 5:e305509d53f3 470 break;
casiotone401 5:e305509d53f3 471
casiotone401 5:e305509d53f3 472 case NDOT4:
casiotone401 5:e305509d53f3 473
casiotone401 5:e305509d53f3 474 gatetime[ch] = (bar / 8) * 3;
casiotone401 5:e305509d53f3 475 break;
casiotone401 5:e305509d53f3 476
casiotone401 5:e305509d53f3 477 case NDOT8:
casiotone401 5:e305509d53f3 478
casiotone401 5:e305509d53f3 479 gatetime[ch] = (bar / 16) * 3;
casiotone401 5:e305509d53f3 480 break;
casiotone401 5:e305509d53f3 481
casiotone401 5:e305509d53f3 482 case NDOT16:
casiotone401 5:e305509d53f3 483
casiotone401 5:e305509d53f3 484 gatetime[ch] = (bar / 32) * 3;
casiotone401 5:e305509d53f3 485 break;
casiotone401 5:e305509d53f3 486
casiotone401 5:e305509d53f3 487 case NDOT32:
casiotone401 5:e305509d53f3 488
casiotone401 5:e305509d53f3 489 gatetime[ch] = (bar / 64) * 3;
casiotone401 5:e305509d53f3 490 break;
casiotone401 5:e305509d53f3 491
casiotone401 5:e305509d53f3 492 case TRIP2:
casiotone401 5:e305509d53f3 493
casiotone401 5:e305509d53f3 494 gatetime[ch] = bar / 3;
casiotone401 5:e305509d53f3 495 break;
casiotone401 5:e305509d53f3 496
casiotone401 5:e305509d53f3 497 case TRIP4:
casiotone401 5:e305509d53f3 498
casiotone401 5:e305509d53f3 499 gatetime[ch] = (bar / 2) / 3;
casiotone401 5:e305509d53f3 500 break;
casiotone401 5:e305509d53f3 501
casiotone401 5:e305509d53f3 502 case TRIP8:
casiotone401 5:e305509d53f3 503
casiotone401 5:e305509d53f3 504 gatetime[ch] = (bar / 4) / 3;
casiotone401 5:e305509d53f3 505 break;
casiotone401 5:e305509d53f3 506
casiotone401 5:e305509d53f3 507 case TRIP16:
casiotone401 5:e305509d53f3 508
casiotone401 5:e305509d53f3 509 gatetime[ch] = (bar / 8) / 3;
casiotone401 5:e305509d53f3 510 break;
casiotone401 5:e305509d53f3 511
casiotone401 5:e305509d53f3 512 case TRIP32:
casiotone401 5:e305509d53f3 513
casiotone401 5:e305509d53f3 514 gatetime[ch] = (bar / 16) / 3;
casiotone401 5:e305509d53f3 515 break;
casiotone401 5:e305509d53f3 516
casiotone401 5:e305509d53f3 517 case NRESET:
casiotone401 5:e305509d53f3 518
casiotone401 10:ccfeb687c3f2 519 for(i = 0; i < GATEALL; ++i) // Reset
casiotone401 5:e305509d53f3 520 {
casiotone401 5:e305509d53f3 521 gTimer.reset();
casiotone401 5:e305509d53f3 522 oldsynctime = oldgatetime[i] = gatetime[i] = NRESET;
casiotone401 5:e305509d53f3 523 }
casiotone401 5:e305509d53f3 524 break;
casiotone401 5:e305509d53f3 525
casiotone401 5:e305509d53f3 526 default:
casiotone401 5:e305509d53f3 527
casiotone401 5:e305509d53f3 528 gatetime[ch] = bar / beat;
casiotone401 5:e305509d53f3 529 }
casiotone401 5:e305509d53f3 530
casiotone401 5:e305509d53f3 531 if(time > oldsynctime + sync24) // sync24 not tested
casiotone401 5:e305509d53f3 532 {
casiotone401 5:e305509d53f3 533 oldsynctime = time;
casiotone401 5:e305509d53f3 534 gCLOCKOUT = 1;
casiotone401 5:e305509d53f3 535
casiotone401 5:e305509d53f3 536 } else if (time > sync24 - (sync24 - 2)) {
casiotone401 5:e305509d53f3 537
casiotone401 5:e305509d53f3 538 gCLOCKOUT = 0;
casiotone401 5:e305509d53f3 539 }
casiotone401 5:e305509d53f3 540
casiotone401 5:e305509d53f3 541 if (ch == GATEALL)
casiotone401 5:e305509d53f3 542 {
casiotone401 5:e305509d53f3 543 return -1;
casiotone401 5:e305509d53f3 544
casiotone401 10:ccfeb687c3f2 545 } else if (time > oldgatetime[ch] + gatetime[ch] && !invert) {
casiotone401 5:e305509d53f3 546
casiotone401 5:e305509d53f3 547 oldgatetime[ch] = time;
casiotone401 5:e305509d53f3 548 gLEDS[ch] = gGATES[ch] = 1;
casiotone401 5:e305509d53f3 549
casiotone401 5:e305509d53f3 550 return ch + 1;
casiotone401 5:e305509d53f3 551
casiotone401 10:ccfeb687c3f2 552 } else if (time > oldgatetime[ch] + gatetime[ch] && invert) {
casiotone401 5:e305509d53f3 553
casiotone401 5:e305509d53f3 554 oldgatetime[ch] = time;
casiotone401 5:e305509d53f3 555 gLEDS[ch] = gGATES[ch] = 0;
casiotone401 5:e305509d53f3 556
casiotone401 5:e305509d53f3 557 return 0;
casiotone401 5:e305509d53f3 558
casiotone401 10:ccfeb687c3f2 559 } else if (time > oldgatetime[ch] + (gatetime[ch] - gatetime[ch] / length) && !invert) {
casiotone401 5:e305509d53f3 560
casiotone401 5:e305509d53f3 561 gLEDS[ch] = gGATES[ch] = 0;
casiotone401 5:e305509d53f3 562
casiotone401 5:e305509d53f3 563 return 0;
casiotone401 5:e305509d53f3 564
casiotone401 10:ccfeb687c3f2 565 } else if (time > oldgatetime[ch] + (gatetime[ch] - gatetime[ch] / length) && invert) {
casiotone401 5:e305509d53f3 566
casiotone401 5:e305509d53f3 567 gLEDS[ch] = gGATES[ch] = 1;
casiotone401 5:e305509d53f3 568
casiotone401 5:e305509d53f3 569 return ch + 1;
casiotone401 5:e305509d53f3 570
casiotone401 5:e305509d53f3 571 } else {
casiotone401 5:e305509d53f3 572
casiotone401 5:e305509d53f3 573 return -1;
casiotone401 5:e305509d53f3 574 }
casiotone401 5:e305509d53f3 575 }
casiotone401 5:e305509d53f3 576
casiotone401 5:e305509d53f3 577 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 578 // Calculate CV
casiotone401 0:a4d93cd4c30d 579
casiotone401 10:ccfeb687c3f2 580 inline void SetCV()
casiotone401 0:a4d93cd4c30d 581 {
casiotone401 10:ccfeb687c3f2 582 static int ch, quan;
casiotone401 10:ccfeb687c3f2 583 float glidecv[8], oldcv[8];
casiotone401 0:a4d93cd4c30d 584 unsigned int cv[8];
casiotone401 0:a4d93cd4c30d 585 float qcv;
casiotone401 0:a4d93cd4c30d 586
casiotone401 0:a4d93cd4c30d 587 switch(gMode)
casiotone401 0:a4d93cd4c30d 588 {
casiotone401 0:a4d93cd4c30d 589 case MODE_LIN:
casiotone401 4:b9f5ae574447 590
casiotone401 0:a4d93cd4c30d 591 glidecv[ch] = oldcv[ch] * gGlide + gOSC_cv[ch] * (1.0f - gGlide);
casiotone401 0:a4d93cd4c30d 592 oldcv[ch] = glidecv[ch];
casiotone401 0:a4d93cd4c30d 593 cv[ch] = (unsigned int)glidecv[ch];
casiotone401 0:a4d93cd4c30d 594
casiotone401 4:b9f5ae574447 595 UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]);
casiotone401 0:a4d93cd4c30d 596 break;
casiotone401 0:a4d93cd4c30d 597
casiotone401 0:a4d93cd4c30d 598 case MODE_QChr:
casiotone401 0:a4d93cd4c30d 599
casiotone401 4:b9f5ae574447 600 quan = 40616 / QUAN_RES1;
casiotone401 4:b9f5ae574447 601 qcv = calibMap1[(unsigned int)(gOSC_cv[ch] / quan)];
casiotone401 4:b9f5ae574447 602
casiotone401 4:b9f5ae574447 603 glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 604 oldcv[ch] = glidecv[ch];
casiotone401 4:b9f5ae574447 605 cv[ch] = (unsigned int)glidecv[ch];
casiotone401 4:b9f5ae574447 606
casiotone401 4:b9f5ae574447 607 UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]);
casiotone401 4:b9f5ae574447 608 break;
casiotone401 4:b9f5ae574447 609
casiotone401 4:b9f5ae574447 610 case MODE_QMaj:
casiotone401 4:b9f5ae574447 611
casiotone401 4:b9f5ae574447 612 quan = 40616 / QUAN_RES2;
casiotone401 4:b9f5ae574447 613 qcv = calibMap2[(unsigned int)(gOSC_cv[ch] / quan)];
casiotone401 0:a4d93cd4c30d 614
casiotone401 0:a4d93cd4c30d 615 glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 0:a4d93cd4c30d 616 oldcv[ch] = glidecv[ch];
casiotone401 0:a4d93cd4c30d 617 cv[ch] = (unsigned int)glidecv[ch];
casiotone401 0:a4d93cd4c30d 618
casiotone401 4:b9f5ae574447 619 UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]);
casiotone401 0:a4d93cd4c30d 620 break;
casiotone401 4:b9f5ae574447 621
casiotone401 4:b9f5ae574447 622 case MODE_QDor:
casiotone401 0:a4d93cd4c30d 623
casiotone401 4:b9f5ae574447 624 quan = 40616 / QUAN_RES3;
casiotone401 4:b9f5ae574447 625 qcv = calibMap3[(unsigned int)(gOSC_cv[ch] / quan)];
casiotone401 0:a4d93cd4c30d 626
casiotone401 0:a4d93cd4c30d 627 glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 0:a4d93cd4c30d 628 oldcv[ch] = glidecv[ch];
casiotone401 0:a4d93cd4c30d 629 cv[ch] = (unsigned int)glidecv[ch];
casiotone401 0:a4d93cd4c30d 630
casiotone401 4:b9f5ae574447 631 UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]);
casiotone401 0:a4d93cd4c30d 632 break;
casiotone401 4:b9f5ae574447 633
casiotone401 4:b9f5ae574447 634 case MODE_Q5th:
casiotone401 4:b9f5ae574447 635
casiotone401 4:b9f5ae574447 636 quan = 40616 / QUAN_RES4;
casiotone401 4:b9f5ae574447 637 qcv = calibMap4[(unsigned int)(gOSC_cv[ch] / quan)];
casiotone401 0:a4d93cd4c30d 638
casiotone401 4:b9f5ae574447 639 glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 640 oldcv[ch] = glidecv[ch];
casiotone401 4:b9f5ae574447 641 cv[ch] = (unsigned int)glidecv[ch];
casiotone401 4:b9f5ae574447 642
casiotone401 4:b9f5ae574447 643 UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]);
casiotone401 4:b9f5ae574447 644 break;
casiotone401 0:a4d93cd4c30d 645
casiotone401 4:b9f5ae574447 646 case MODE_QWht:
casiotone401 4:b9f5ae574447 647
casiotone401 4:b9f5ae574447 648 quan = 40616 / QUAN_RES5;
casiotone401 4:b9f5ae574447 649 qcv = calibMap5[(unsigned int)(gOSC_cv[ch] / quan)];
casiotone401 0:a4d93cd4c30d 650
casiotone401 0:a4d93cd4c30d 651 glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 0:a4d93cd4c30d 652 oldcv[ch] = glidecv[ch];
casiotone401 0:a4d93cd4c30d 653 cv[ch] = (unsigned int)glidecv[ch];
casiotone401 0:a4d93cd4c30d 654
casiotone401 4:b9f5ae574447 655 UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]);
casiotone401 0:a4d93cd4c30d 656 break;
casiotone401 3:ca15241dd6b4 657
casiotone401 4:b9f5ae574447 658 case MODE_Calb:
casiotone401 3:ca15241dd6b4 659
casiotone401 9:1ac3d135d965 660 cv[ch] = 19212; // A880.0Hz
casiotone401 5:e305509d53f3 661
casiotone401 5:e305509d53f3 662 gGATES[0] = gGATES[1] = gGATES[2] = gGATES[3] = 1;
casiotone401 5:e305509d53f3 663 gLEDS[0] = gLEDS[1] = gLEDS[2] = gLEDS[3] = 1;
casiotone401 5:e305509d53f3 664
casiotone401 4:b9f5ae574447 665 UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]);
casiotone401 3:ca15241dd6b4 666 break;
casiotone401 0:a4d93cd4c30d 667 }
casiotone401 4:b9f5ae574447 668
casiotone401 4:b9f5ae574447 669 CVMeter(ch, &cv[ch]);
casiotone401 0:a4d93cd4c30d 670
casiotone401 0:a4d93cd4c30d 671 ch++;
casiotone401 0:a4d93cd4c30d 672 ch &= 0x07;
casiotone401 0:a4d93cd4c30d 673 }
casiotone401 0:a4d93cd4c30d 674
casiotone401 0:a4d93cd4c30d 675 //-------------------------------------------------------------
casiotone401 4:b9f5ae574447 676 // Sequence & Shift Out CV
casiotone401 4:b9f5ae574447 677
casiotone401 5:e305509d53f3 678 void SeqCV(int shift)
casiotone401 4:b9f5ae574447 679 {
casiotone401 6:5796b63c70ef 680 int i, j, k;
casiotone401 10:ccfeb687c3f2 681 static int ch, quan, SeqMode;
casiotone401 5:e305509d53f3 682 static int cnt1, cnt2, cnt3;
casiotone401 5:e305509d53f3 683 static int cntloop1, cntloop2, cntloop3;
casiotone401 10:ccfeb687c3f2 684 static float glidecv[8], shiftcv[8];
casiotone401 10:ccfeb687c3f2 685 static float buffercv[9], loopcv[3];
casiotone401 4:b9f5ae574447 686 unsigned int cv[8];
casiotone401 4:b9f5ae574447 687 float qcv;
casiotone401 4:b9f5ae574447 688
casiotone401 10:ccfeb687c3f2 689 SeqMode = gCtrl[1] * (MODE_NUM - 3); // Sequencer Quantize Mode (gCtrl[1])
casiotone401 4:b9f5ae574447 690
casiotone401 4:b9f5ae574447 691 switch(SeqMode)
casiotone401 4:b9f5ae574447 692 {
casiotone401 4:b9f5ae574447 693 case MODE_LIN:
casiotone401 4:b9f5ae574447 694
casiotone401 4:b9f5ae574447 695 if(ch < 8)
casiotone401 4:b9f5ae574447 696 {
casiotone401 4:b9f5ae574447 697 glidecv[0] = glidecv[0] * gGlide + gSeq_cv1[ch] * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 698
casiotone401 4:b9f5ae574447 699 } else {
casiotone401 4:b9f5ae574447 700
casiotone401 4:b9f5ae574447 701 glidecv[0] = glidecv[0] * gGlide + gSeq_cv2[ch-8] * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 702 }
casiotone401 4:b9f5ae574447 703
casiotone401 4:b9f5ae574447 704 cv[0] = (unsigned int)glidecv[0];
casiotone401 4:b9f5ae574447 705
casiotone401 4:b9f5ae574447 706 UpdateCV(WRITE_UPDATE_N, 0, &cv[0]);
casiotone401 4:b9f5ae574447 707 break;
casiotone401 4:b9f5ae574447 708
casiotone401 4:b9f5ae574447 709 case MODE_QChr:
casiotone401 4:b9f5ae574447 710
casiotone401 4:b9f5ae574447 711 quan = 40616 / QUAN_RES1;
casiotone401 4:b9f5ae574447 712
casiotone401 4:b9f5ae574447 713 if(ch < 8)
casiotone401 4:b9f5ae574447 714 {
casiotone401 4:b9f5ae574447 715 qcv = calibMap1[(unsigned int)(gSeq_cv1[ch] / quan)];
casiotone401 4:b9f5ae574447 716
casiotone401 4:b9f5ae574447 717 } else {
casiotone401 4:b9f5ae574447 718
casiotone401 4:b9f5ae574447 719 qcv = calibMap1[(unsigned int)(gSeq_cv2[ch-8] / quan)];
casiotone401 4:b9f5ae574447 720 }
casiotone401 4:b9f5ae574447 721
casiotone401 4:b9f5ae574447 722 glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 723 cv[0] = (unsigned int)glidecv[0];
casiotone401 4:b9f5ae574447 724
casiotone401 4:b9f5ae574447 725 UpdateCV(WRITE_UPDATE_N, 0, &cv[0]);
casiotone401 4:b9f5ae574447 726 break;
casiotone401 4:b9f5ae574447 727
casiotone401 4:b9f5ae574447 728 case MODE_QMaj:
casiotone401 4:b9f5ae574447 729
casiotone401 4:b9f5ae574447 730 quan = 40616 / QUAN_RES2;
casiotone401 4:b9f5ae574447 731
casiotone401 4:b9f5ae574447 732 if(ch < 8)
casiotone401 4:b9f5ae574447 733 {
casiotone401 4:b9f5ae574447 734 qcv = calibMap2[(unsigned int)(gSeq_cv1[ch] / quan)];
casiotone401 4:b9f5ae574447 735
casiotone401 4:b9f5ae574447 736 } else {
casiotone401 4:b9f5ae574447 737
casiotone401 4:b9f5ae574447 738 qcv = calibMap2[(unsigned int)(gSeq_cv2[ch-8] / quan)];
casiotone401 4:b9f5ae574447 739 }
casiotone401 4:b9f5ae574447 740
casiotone401 4:b9f5ae574447 741 glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 742 cv[0] = (unsigned int)glidecv[0];
casiotone401 4:b9f5ae574447 743
casiotone401 4:b9f5ae574447 744 UpdateCV(WRITE_UPDATE_N, 0, &cv[0]);
casiotone401 4:b9f5ae574447 745 break;
casiotone401 4:b9f5ae574447 746
casiotone401 4:b9f5ae574447 747 case MODE_QDor:
casiotone401 4:b9f5ae574447 748
casiotone401 4:b9f5ae574447 749 quan = 40616 / QUAN_RES3;
casiotone401 4:b9f5ae574447 750
casiotone401 4:b9f5ae574447 751 if(ch < 8)
casiotone401 4:b9f5ae574447 752 {
casiotone401 4:b9f5ae574447 753 qcv = calibMap3[(unsigned int)(gSeq_cv1[ch] / quan)];
casiotone401 4:b9f5ae574447 754
casiotone401 4:b9f5ae574447 755 } else {
casiotone401 4:b9f5ae574447 756
casiotone401 4:b9f5ae574447 757 qcv = calibMap3[(unsigned int)(gSeq_cv2[ch-8] / quan)];
casiotone401 4:b9f5ae574447 758 }
casiotone401 4:b9f5ae574447 759
casiotone401 4:b9f5ae574447 760 glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 761 cv[0] = (unsigned int)glidecv[0];
casiotone401 4:b9f5ae574447 762
casiotone401 4:b9f5ae574447 763 UpdateCV(WRITE_UPDATE_N, 0, &cv[0]);
casiotone401 4:b9f5ae574447 764 break;
casiotone401 4:b9f5ae574447 765
casiotone401 4:b9f5ae574447 766 case MODE_Q5th:
casiotone401 4:b9f5ae574447 767
casiotone401 4:b9f5ae574447 768 quan = 40616 / QUAN_RES4;
casiotone401 4:b9f5ae574447 769
casiotone401 4:b9f5ae574447 770 if(ch < 8)
casiotone401 4:b9f5ae574447 771 {
casiotone401 4:b9f5ae574447 772 qcv = calibMap4[(unsigned int)(gSeq_cv1[ch] / quan)];
casiotone401 4:b9f5ae574447 773
casiotone401 4:b9f5ae574447 774 } else {
casiotone401 4:b9f5ae574447 775
casiotone401 4:b9f5ae574447 776 qcv = calibMap4[(unsigned int)(gSeq_cv2[ch-8] / quan)];
casiotone401 4:b9f5ae574447 777 }
casiotone401 4:b9f5ae574447 778
casiotone401 4:b9f5ae574447 779 glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 780 cv[0] = (unsigned int)glidecv[0];
casiotone401 4:b9f5ae574447 781
casiotone401 4:b9f5ae574447 782 UpdateCV(WRITE_UPDATE_N, 0, &cv[0]);
casiotone401 4:b9f5ae574447 783 break;
casiotone401 4:b9f5ae574447 784
casiotone401 4:b9f5ae574447 785 case MODE_QWht:
casiotone401 4:b9f5ae574447 786
casiotone401 4:b9f5ae574447 787 quan = 40616 / QUAN_RES5;
casiotone401 4:b9f5ae574447 788
casiotone401 4:b9f5ae574447 789 if(ch < 8)
casiotone401 4:b9f5ae574447 790 {
casiotone401 4:b9f5ae574447 791 qcv = calibMap5[(unsigned int)(gSeq_cv1[ch] / quan)];
casiotone401 4:b9f5ae574447 792
casiotone401 4:b9f5ae574447 793 } else {
casiotone401 4:b9f5ae574447 794
casiotone401 4:b9f5ae574447 795 qcv = calibMap5[(unsigned int)(gSeq_cv2[ch-8] / quan)];
casiotone401 4:b9f5ae574447 796 }
casiotone401 4:b9f5ae574447 797
casiotone401 4:b9f5ae574447 798 glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 799 cv[0] = (unsigned int)glidecv[0];
casiotone401 4:b9f5ae574447 800
casiotone401 4:b9f5ae574447 801 UpdateCV(WRITE_UPDATE_N, 0, &cv[0]);
casiotone401 4:b9f5ae574447 802 break;
casiotone401 4:b9f5ae574447 803 }
casiotone401 4:b9f5ae574447 804
casiotone401 10:ccfeb687c3f2 805 if(!gCtrlSW[2] && !gCtrlSW[3]) // Sequencer Mode1
casiotone401 4:b9f5ae574447 806 {
casiotone401 6:5796b63c70ef 807 for(i = 1; i < 8; ++i)
casiotone401 5:e305509d53f3 808 {
casiotone401 5:e305509d53f3 809 glidecv[i] = glidecv[i] * gGlide + shiftcv[i] * (1.0f - gGlide);
casiotone401 5:e305509d53f3 810 cv[i] = (unsigned int)glidecv[i];
casiotone401 5:e305509d53f3 811
casiotone401 5:e305509d53f3 812 UpdateCV(WRITE_UPDATE_N, i, &cv[i]);
casiotone401 8:fe50078d6b80 813 }
casiotone401 8:fe50078d6b80 814
casiotone401 8:fe50078d6b80 815 if(shift == 1) // GATE1
casiotone401 8:fe50078d6b80 816 {
casiotone401 8:fe50078d6b80 817 for(j = 1; j < 8; ++j) // Shift ch2~8
casiotone401 6:5796b63c70ef 818 {
casiotone401 8:fe50078d6b80 819 shiftcv[j] = glidecv[j-1];
casiotone401 6:5796b63c70ef 820 }
casiotone401 6:5796b63c70ef 821
casiotone401 8:fe50078d6b80 822 ch++;
casiotone401 8:fe50078d6b80 823 ch &= 0x0F;
casiotone401 5:e305509d53f3 824 }
casiotone401 8:fe50078d6b80 825
casiotone401 8:fe50078d6b80 826 cnt1 = cnt2 = cnt3 = 0;
casiotone401 4:b9f5ae574447 827
casiotone401 10:ccfeb687c3f2 828 } else if (gCtrlSW[2] && !gCtrlSW[3]) { // Sequencer Mode2
casiotone401 5:e305509d53f3 829
casiotone401 8:fe50078d6b80 830 for(i = 1; i < 8; ++i)
casiotone401 8:fe50078d6b80 831 {
casiotone401 8:fe50078d6b80 832 glidecv[i] = glidecv[i] * gGlide + shiftcv[i] * (1.0f - gGlide);
casiotone401 8:fe50078d6b80 833 cv[i] = (unsigned int)glidecv[i];
casiotone401 8:fe50078d6b80 834
casiotone401 8:fe50078d6b80 835 UpdateCV(WRITE_UPDATE_N, i, &cv[i]);
casiotone401 8:fe50078d6b80 836 }
casiotone401 8:fe50078d6b80 837
casiotone401 5:e305509d53f3 838 if(shift == 1) // GATE1
casiotone401 5:e305509d53f3 839 {
casiotone401 6:5796b63c70ef 840 for(j = 1; j < 5; ++j)
casiotone401 5:e305509d53f3 841 {
casiotone401 5:e305509d53f3 842 shiftcv[j] = glidecv[j-1]; // Shift ch2~5
casiotone401 5:e305509d53f3 843 }
casiotone401 5:e305509d53f3 844
casiotone401 5:e305509d53f3 845 ch++;
casiotone401 5:e305509d53f3 846 ch &= 0x0F;
casiotone401 5:e305509d53f3 847
casiotone401 5:e305509d53f3 848 } else if (shift == 2) { // GATE2
casiotone401 5:e305509d53f3 849
casiotone401 5:e305509d53f3 850 shiftcv[5] = glidecv[1]; // Shift ch6
casiotone401 5:e305509d53f3 851
casiotone401 5:e305509d53f3 852 } else if (shift == 3) { // GATE3
casiotone401 5:e305509d53f3 853
casiotone401 5:e305509d53f3 854 shiftcv[6] = glidecv[2]; // Shift ch7
casiotone401 5:e305509d53f3 855
casiotone401 5:e305509d53f3 856 } else if (shift == 4) { // GATE4
casiotone401 5:e305509d53f3 857
casiotone401 5:e305509d53f3 858 shiftcv[7] = glidecv[3]; // Shift ch8
casiotone401 8:fe50078d6b80 859 }
casiotone401 8:fe50078d6b80 860
casiotone401 8:fe50078d6b80 861 cnt1 = cnt2 = cnt3 = 0;
casiotone401 6:5796b63c70ef 862
casiotone401 10:ccfeb687c3f2 863 } else if (gCtrlSW[3]) { // Sequencer Mode3
casiotone401 5:e305509d53f3 864
casiotone401 8:fe50078d6b80 865 for(i = 1; i < 5; ++i)
casiotone401 6:5796b63c70ef 866 {
casiotone401 8:fe50078d6b80 867 glidecv[i] = glidecv[i] * gGlide + shiftcv[i] * (1.0f - gGlide);
casiotone401 8:fe50078d6b80 868 cv[i] = (unsigned int)glidecv[i];
casiotone401 8:fe50078d6b80 869
casiotone401 8:fe50078d6b80 870 UpdateCV(WRITE_UPDATE_N, i, &cv[i]);
casiotone401 8:fe50078d6b80 871 }
casiotone401 8:fe50078d6b80 872
casiotone401 8:fe50078d6b80 873 for(j = 5; j < 8; ++j)
casiotone401 8:fe50078d6b80 874 {
casiotone401 8:fe50078d6b80 875 glidecv[j] = glidecv[j] * gGlide + loopcv[j - 5] * (1.0f - gGlide);
casiotone401 6:5796b63c70ef 876 cv[j] = (unsigned int)glidecv[j];
casiotone401 6:5796b63c70ef 877
casiotone401 6:5796b63c70ef 878 UpdateCV(WRITE_UPDATE_N, j, &cv[j]);
casiotone401 6:5796b63c70ef 879 }
casiotone401 6:5796b63c70ef 880
casiotone401 5:e305509d53f3 881 if(shift == 1) // GATE1
casiotone401 5:e305509d53f3 882 {
casiotone401 8:fe50078d6b80 883 for(k = 1; k < 8; ++k)
casiotone401 5:e305509d53f3 884 {
casiotone401 8:fe50078d6b80 885 shiftcv[k] = glidecv[k-1]; // Shift ch2~5
casiotone401 5:e305509d53f3 886 }
casiotone401 5:e305509d53f3 887
casiotone401 5:e305509d53f3 888 ch++;
casiotone401 5:e305509d53f3 889 ch &= 0x0F;
casiotone401 5:e305509d53f3 890
casiotone401 5:e305509d53f3 891 } else if (shift == 2) { // GATE2
casiotone401 5:e305509d53f3 892
casiotone401 5:e305509d53f3 893 if(cnt1 < 4)
casiotone401 5:e305509d53f3 894 {
casiotone401 5:e305509d53f3 895 loopcv[0] = buffercv[cnt1] = shiftcv[4];
casiotone401 5:e305509d53f3 896
casiotone401 5:e305509d53f3 897 cnt1++;
casiotone401 5:e305509d53f3 898
casiotone401 5:e305509d53f3 899 } else if (cnt1 >= 4) {
casiotone401 5:e305509d53f3 900
casiotone401 5:e305509d53f3 901 loopcv[0] = buffercv[cntloop1];
casiotone401 5:e305509d53f3 902
casiotone401 5:e305509d53f3 903 cntloop1++;
casiotone401 5:e305509d53f3 904 cntloop1 &= 0x03;
casiotone401 5:e305509d53f3 905 }
casiotone401 5:e305509d53f3 906
casiotone401 5:e305509d53f3 907 } else if (shift == 3) { // GATE3
casiotone401 5:e305509d53f3 908
casiotone401 5:e305509d53f3 909 if(cnt2 < 3)
casiotone401 5:e305509d53f3 910 {
casiotone401 5:e305509d53f3 911 loopcv[1] = buffercv[(cnt2 + 4)] = shiftcv[5];
casiotone401 5:e305509d53f3 912
casiotone401 5:e305509d53f3 913 cnt2++;
casiotone401 5:e305509d53f3 914
casiotone401 5:e305509d53f3 915 } else if (cnt2 >= 3) {
casiotone401 5:e305509d53f3 916
casiotone401 5:e305509d53f3 917 loopcv[1] = buffercv[(cntloop2 + 4)];
casiotone401 5:e305509d53f3 918
casiotone401 5:e305509d53f3 919 cntloop2++;
casiotone401 5:e305509d53f3 920 cntloop2 &= 0x03;
casiotone401 5:e305509d53f3 921 }
casiotone401 5:e305509d53f3 922
casiotone401 5:e305509d53f3 923 } else if (shift == 4) { // GATE4
casiotone401 5:e305509d53f3 924
casiotone401 5:e305509d53f3 925 if(cnt3 < 2)
casiotone401 5:e305509d53f3 926 {
casiotone401 5:e305509d53f3 927 loopcv[2] = buffercv[(cnt3 + 7)] = shiftcv[6];
casiotone401 5:e305509d53f3 928
casiotone401 5:e305509d53f3 929 cnt3++;
casiotone401 5:e305509d53f3 930
casiotone401 5:e305509d53f3 931 } else if (cnt3 >= 2) {
casiotone401 5:e305509d53f3 932
casiotone401 5:e305509d53f3 933 loopcv[2] = buffercv[(cntloop3 + 7)];
casiotone401 5:e305509d53f3 934
casiotone401 5:e305509d53f3 935 cntloop3++;
casiotone401 5:e305509d53f3 936 cntloop3 &= 0x01;
casiotone401 5:e305509d53f3 937 }
casiotone401 5:e305509d53f3 938 }
casiotone401 5:e305509d53f3 939
casiotone401 10:ccfeb687c3f2 940 if(gCtrlSW[1]) // Update loop buffer (if gCtrlSW[1] ON)
casiotone401 5:e305509d53f3 941 {
casiotone401 5:e305509d53f3 942 cnt1 = cnt2 = cnt3 = 0;
casiotone401 5:e305509d53f3 943 }
casiotone401 4:b9f5ae574447 944 }
casiotone401 4:b9f5ae574447 945
casiotone401 4:b9f5ae574447 946 if(ch < 8)
casiotone401 4:b9f5ae574447 947 {
casiotone401 4:b9f5ae574447 948 CVMeter(ch, &cv[0]);
casiotone401 4:b9f5ae574447 949
casiotone401 4:b9f5ae574447 950 } else {
casiotone401 4:b9f5ae574447 951
casiotone401 4:b9f5ae574447 952 CVMeter((ch-8), &cv[0]);
casiotone401 4:b9f5ae574447 953 }
casiotone401 4:b9f5ae574447 954 }
casiotone401 4:b9f5ae574447 955
casiotone401 4:b9f5ae574447 956 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 957 // Check SW
casiotone401 0:a4d93cd4c30d 958
casiotone401 5:e305509d53f3 959 void CheckModeSW()
casiotone401 0:a4d93cd4c30d 960 {
casiotone401 7:a04f8378662e 961 wait(0.05);
casiotone401 4:b9f5ae574447 962
casiotone401 3:ca15241dd6b4 963 if(gMode < MODE_NUM - 1)
casiotone401 0:a4d93cd4c30d 964 {
casiotone401 0:a4d93cd4c30d 965 gMode++;
casiotone401 3:ca15241dd6b4 966
casiotone401 0:a4d93cd4c30d 967 } else {
casiotone401 4:b9f5ae574447 968
casiotone401 0:a4d93cd4c30d 969 gMode = 0;
casiotone401 0:a4d93cd4c30d 970 }
casiotone401 3:ca15241dd6b4 971
casiotone401 5:e305509d53f3 972 gCLOCKOUT = gGATES[0] = gGATES[1] = gGATES[2] = gGATES[3] = 0;
casiotone401 5:e305509d53f3 973 gLEDS[0] = gLEDS[1] = gLEDS[2] = gLEDS[3] = 0;
casiotone401 5:e305509d53f3 974
casiotone401 5:e305509d53f3 975 if(gMode == MODE_SEQ)
casiotone401 5:e305509d53f3 976 {
casiotone401 5:e305509d53f3 977 gTimer.start(); // Sequencer Timer Start
casiotone401 5:e305509d53f3 978
casiotone401 5:e305509d53f3 979 } else {
casiotone401 5:e305509d53f3 980
casiotone401 5:e305509d53f3 981 gTimer.stop(); // Sequencer Timer Stop
casiotone401 5:e305509d53f3 982 }
casiotone401 5:e305509d53f3 983
casiotone401 4:b9f5ae574447 984 LCD();
casiotone401 4:b9f5ae574447 985 }
casiotone401 4:b9f5ae574447 986
casiotone401 4:b9f5ae574447 987 //-------------------------------------------------------------
casiotone401 4:b9f5ae574447 988 // CV meter
casiotone401 4:b9f5ae574447 989
casiotone401 9:1ac3d135d965 990 inline void CVMeter(int ch, const unsigned int *level)
casiotone401 4:b9f5ae574447 991 {
casiotone401 10:ccfeb687c3f2 992 int cvmeter;
casiotone401 4:b9f5ae574447 993
casiotone401 9:1ac3d135d965 994 cvmeter = *level / (SCALING_N / 7.9f);
casiotone401 4:b9f5ae574447 995
casiotone401 4:b9f5ae574447 996 gLCD.locate ( ch, 0 );
casiotone401 4:b9f5ae574447 997 gLCD.putc(cvmeter); // put custom char
casiotone401 4:b9f5ae574447 998 }
casiotone401 4:b9f5ae574447 999
casiotone401 4:b9f5ae574447 1000 //-------------------------------------------------------------
casiotone401 5:e305509d53f3 1001 // Print LCD Mode Status
casiotone401 4:b9f5ae574447 1002
casiotone401 4:b9f5ae574447 1003 void LCD()
casiotone401 4:b9f5ae574447 1004 {
casiotone401 3:ca15241dd6b4 1005 switch(gMode)
casiotone401 3:ca15241dd6b4 1006 {
casiotone401 3:ca15241dd6b4 1007 case MODE_LIN:
casiotone401 3:ca15241dd6b4 1008 gLCD.locate( 9, 0 );
casiotone401 3:ca15241dd6b4 1009 gLCD.printf("OSC-CV ");
casiotone401 3:ca15241dd6b4 1010 break;
casiotone401 3:ca15241dd6b4 1011
casiotone401 3:ca15241dd6b4 1012 case MODE_QChr:
casiotone401 3:ca15241dd6b4 1013 gLCD.locate( 9, 0 );
casiotone401 3:ca15241dd6b4 1014 gLCD.printf("QUAN_C ");
casiotone401 3:ca15241dd6b4 1015 break;
casiotone401 3:ca15241dd6b4 1016
casiotone401 3:ca15241dd6b4 1017 case MODE_QMaj:
casiotone401 3:ca15241dd6b4 1018 gLCD.locate( 9, 0 );
casiotone401 3:ca15241dd6b4 1019 gLCD.printf("QUAN_M ");
casiotone401 3:ca15241dd6b4 1020 break;
casiotone401 3:ca15241dd6b4 1021
casiotone401 3:ca15241dd6b4 1022 case MODE_QDor:
casiotone401 3:ca15241dd6b4 1023 gLCD.locate( 9, 0 );
casiotone401 3:ca15241dd6b4 1024 gLCD.printf("QUAN_D ");
casiotone401 3:ca15241dd6b4 1025 break;
casiotone401 3:ca15241dd6b4 1026
casiotone401 3:ca15241dd6b4 1027 case MODE_Q5th:
casiotone401 3:ca15241dd6b4 1028 gLCD.locate( 9, 0 );
casiotone401 3:ca15241dd6b4 1029 gLCD.printf("QUAN_5 ");
casiotone401 3:ca15241dd6b4 1030 break;
casiotone401 3:ca15241dd6b4 1031
casiotone401 3:ca15241dd6b4 1032 case MODE_QWht:
casiotone401 3:ca15241dd6b4 1033 gLCD.locate( 9, 0 );
casiotone401 3:ca15241dd6b4 1034 gLCD.printf("QUAN_W ");
casiotone401 3:ca15241dd6b4 1035 break;
casiotone401 4:b9f5ae574447 1036
casiotone401 4:b9f5ae574447 1037 case MODE_SEQ:
casiotone401 4:b9f5ae574447 1038 gLCD.locate( 9, 0 );
casiotone401 4:b9f5ae574447 1039 gLCD.printf("ASRSEQ ");
casiotone401 4:b9f5ae574447 1040 break;
casiotone401 4:b9f5ae574447 1041
casiotone401 4:b9f5ae574447 1042 case MODE_Calb:
casiotone401 4:b9f5ae574447 1043 gLCD.locate( 9, 0 );
casiotone401 4:b9f5ae574447 1044 gLCD.printf("Calibr ");
casiotone401 4:b9f5ae574447 1045 break;
casiotone401 3:ca15241dd6b4 1046 }
casiotone401 0:a4d93cd4c30d 1047 }
casiotone401 0:a4d93cd4c30d 1048
casiotone401 0:a4d93cd4c30d 1049 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 1050 // Write command Custom Char LCD CGRAM(CV Meter)
casiotone401 0:a4d93cd4c30d 1051
casiotone401 0:a4d93cd4c30d 1052 void WriteCustomChar(unsigned char addr, unsigned char *c)
casiotone401 0:a4d93cd4c30d 1053 {
casiotone401 0:a4d93cd4c30d 1054 char cnt = 0;
casiotone401 0:a4d93cd4c30d 1055 addr = ((addr << 3) | 0x40);
casiotone401 0:a4d93cd4c30d 1056
casiotone401 0:a4d93cd4c30d 1057 while(cnt < 0x08)
casiotone401 0:a4d93cd4c30d 1058 {
casiotone401 0:a4d93cd4c30d 1059 gLCD.writeCommand(addr | cnt);
casiotone401 0:a4d93cd4c30d 1060 gLCD.writeData(*c);
casiotone401 4:b9f5ae574447 1061
casiotone401 0:a4d93cd4c30d 1062 cnt++;
casiotone401 0:a4d93cd4c30d 1063 c++;
casiotone401 0:a4d93cd4c30d 1064 }
casiotone401 0:a4d93cd4c30d 1065 }
casiotone401 0:a4d93cd4c30d 1066
casiotone401 0:a4d93cd4c30d 1067 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 1068 // Setup Ethernet port
casiotone401 0:a4d93cd4c30d 1069
casiotone401 0:a4d93cd4c30d 1070 int SetupEthNetIf()
casiotone401 0:a4d93cd4c30d 1071 {
casiotone401 0:a4d93cd4c30d 1072 gLCD.locate( 0, 1 );
casiotone401 0:a4d93cd4c30d 1073 gLCD.printf("Setting up... ");
casiotone401 0:a4d93cd4c30d 1074 // printf("Setting up...\r\n");
casiotone401 0:a4d93cd4c30d 1075 EthernetErr ethErr = gEth.setup();
casiotone401 0:a4d93cd4c30d 1076
casiotone401 0:a4d93cd4c30d 1077 if(ethErr)
casiotone401 0:a4d93cd4c30d 1078 {
casiotone401 0:a4d93cd4c30d 1079 gLCD.locate( 0, 1 );
casiotone401 0:a4d93cd4c30d 1080 gLCD.printf("Error in setup.");
casiotone401 0:a4d93cd4c30d 1081 // printf("Error %d in setup.\r\n", ethErr);
casiotone401 0:a4d93cd4c30d 1082 return -1;
casiotone401 0:a4d93cd4c30d 1083 }
casiotone401 0:a4d93cd4c30d 1084 // printf("Setup OK\r\n");
casiotone401 0:a4d93cd4c30d 1085
casiotone401 0:a4d93cd4c30d 1086 // printf("IP address %d.%d.%d.%d\r\n", gEth.getIp()[0], gEth.getIp()[1], gEth.getIp()[2], gEth.getIp()[3]);
casiotone401 0:a4d93cd4c30d 1087 Host broadcast(IpAddr(gEth.getIp()[0], gEth.getIp()[1], gEth.getIp()[2], 255), INPUT_PORT, NULL);
casiotone401 0:a4d93cd4c30d 1088 gUdp.setOnEvent(&onUDPSocketEvent);
casiotone401 0:a4d93cd4c30d 1089 gUdp.bind(broadcast);
casiotone401 4:b9f5ae574447 1090
casiotone401 0:a4d93cd4c30d 1091 gLCD.locate( 0, 1 );
casiotone401 0:a4d93cd4c30d 1092 gLCD.printf("%03d.%03d.%03d.%03d", gEth.getIp()[0], gEth.getIp()[1], gEth.getIp()[2], gEth.getIp()[3]);
casiotone401 4:b9f5ae574447 1093 wait(1.0);
casiotone401 0:a4d93cd4c30d 1094
casiotone401 0:a4d93cd4c30d 1095 return 0;
casiotone401 0:a4d93cd4c30d 1096 }
casiotone401 0:a4d93cd4c30d 1097
casiotone401 0:a4d93cd4c30d 1098 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 1099 // Handller receive UDP Packet
casiotone401 0:a4d93cd4c30d 1100
casiotone401 10:ccfeb687c3f2 1101 //-------------------------------------------------------------
casiotone401 10:ccfeb687c3f2 1102 // Handller receive UDP Packet
casiotone401 10:ccfeb687c3f2 1103
casiotone401 4:b9f5ae574447 1104 inline void onUDPSocketEvent(UDPSocketEvent e)
casiotone401 0:a4d93cd4c30d 1105 {
casiotone401 0:a4d93cd4c30d 1106 union OSCarg msg[10];
casiotone401 10:ccfeb687c3f2 1107 char buf[768] = {0};
casiotone401 10:ccfeb687c3f2 1108 int num, recvlen, len;
casiotone401 6:5796b63c70ef 1109 unsigned int absv;
casiotone401 10:ccfeb687c3f2 1110 int messagepos = 0;
casiotone401 10:ccfeb687c3f2 1111 bool bundleflag = false;
casiotone401 10:ccfeb687c3f2 1112
casiotone401 10:ccfeb687c3f2 1113 Host host;
casiotone401 10:ccfeb687c3f2 1114
casiotone401 10:ccfeb687c3f2 1115 recvlen = gUdp.recvfrom(buf, 768, &host); // packet length
casiotone401 10:ccfeb687c3f2 1116
casiotone401 0:a4d93cd4c30d 1117 switch(e)
casiotone401 0:a4d93cd4c30d 1118 {
casiotone401 4:b9f5ae574447 1119 case UDPSOCKET_READABLE: // The only event for now
casiotone401 0:a4d93cd4c30d 1120
casiotone401 10:ccfeb687c3f2 1121 if(recvlen <= 0) break;
casiotone401 10:ccfeb687c3f2 1122
casiotone401 10:ccfeb687c3f2 1123 if(!strncmp(buf, "#", 1)) // #bundle
casiotone401 0:a4d93cd4c30d 1124 {
casiotone401 10:ccfeb687c3f2 1125 messagepos += 16; // skip #bundle & timetag
casiotone401 10:ccfeb687c3f2 1126 recvlen -= 16;
casiotone401 0:a4d93cd4c30d 1127
casiotone401 10:ccfeb687c3f2 1128 bundleflag = true;
casiotone401 10:ccfeb687c3f2 1129 }
casiotone401 10:ccfeb687c3f2 1130
casiotone401 10:ccfeb687c3f2 1131 do {
casiotone401 10:ccfeb687c3f2 1132 if(bundleflag)
casiotone401 10:ccfeb687c3f2 1133 {
casiotone401 10:ccfeb687c3f2 1134 messagepos += 4;
casiotone401 10:ccfeb687c3f2 1135 recvlen -= 4;
casiotone401 0:a4d93cd4c30d 1136
casiotone401 10:ccfeb687c3f2 1137 if(recvlen <= 0)
casiotone401 10:ccfeb687c3f2 1138 {
casiotone401 10:ccfeb687c3f2 1139 bundleflag = false;
casiotone401 10:ccfeb687c3f2 1140 break;
casiotone401 10:ccfeb687c3f2 1141 }
casiotone401 10:ccfeb687c3f2 1142 }
casiotone401 10:ccfeb687c3f2 1143
casiotone401 10:ccfeb687c3f2 1144 if(getOSCmsg(buf + messagepos, msg) == -1) continue;
casiotone401 4:b9f5ae574447 1145
casiotone401 10:ccfeb687c3f2 1146 len = strlen(msg[0].address);
casiotone401 10:ccfeb687c3f2 1147
casiotone401 10:ccfeb687c3f2 1148 if(isdigit(msg[0].address[len-1]))
casiotone401 10:ccfeb687c3f2 1149 {
casiotone401 10:ccfeb687c3f2 1150 num = msg[0].address[len-1] - '0' - 1;
casiotone401 4:b9f5ae574447 1151
casiotone401 10:ccfeb687c3f2 1152 } else {
casiotone401 0:a4d93cd4c30d 1153
casiotone401 10:ccfeb687c3f2 1154 num = -1;
casiotone401 10:ccfeb687c3f2 1155 }
casiotone401 10:ccfeb687c3f2 1156
casiotone401 10:ccfeb687c3f2 1157 absv = msg[2].f + 0; //convert -0 to 0
casiotone401 10:ccfeb687c3f2 1158
casiotone401 10:ccfeb687c3f2 1159 // address pattern SYNC & GATE (Type Tag int, float)
casiotone401 10:ccfeb687c3f2 1160 if(!strncmp(msg[0].address+(len-1)-4, "sync", 4))
casiotone401 10:ccfeb687c3f2 1161 {
casiotone401 10:ccfeb687c3f2 1162 if(absv >= 1 || msg[2].i >= 1) gCLOCKOUT = 1;
casiotone401 10:ccfeb687c3f2 1163 else gCLOCKOUT = 0;
casiotone401 10:ccfeb687c3f2 1164 continue;
casiotone401 10:ccfeb687c3f2 1165
casiotone401 10:ccfeb687c3f2 1166 } else if (!strncmp(msg[0].address+(len-1)-4, "gate", 4) && (num != -1)) {
casiotone401 10:ccfeb687c3f2 1167 if(num > 4) continue;
casiotone401 10:ccfeb687c3f2 1168 if(absv >= 1 || msg[2].i >= 1) gLEDS[num] = gGATES[num] = 1;
casiotone401 10:ccfeb687c3f2 1169 else gLEDS[num] = gGATES[num] = 0;
casiotone401 10:ccfeb687c3f2 1170 continue;
casiotone401 10:ccfeb687c3f2 1171 // (touchOSC Control push, toggle)
casiotone401 10:ccfeb687c3f2 1172 } else if (!strncmp(msg[0].address+(len-1)-4, "push", 4) && (num != -1)) {
casiotone401 10:ccfeb687c3f2 1173 if(num > 4) continue;
casiotone401 10:ccfeb687c3f2 1174 if(absv >= 1 || msg[2].i >= 1) gLEDS[num] = gGATES[num] = 1;
casiotone401 10:ccfeb687c3f2 1175 else gLEDS[num] = gGATES[num] = 0;
casiotone401 10:ccfeb687c3f2 1176 continue;
casiotone401 10:ccfeb687c3f2 1177
casiotone401 10:ccfeb687c3f2 1178 } else if (!strncmp(msg[0].address+(len-1)-6, "toggle", 6) && (num != -1)) {
casiotone401 10:ccfeb687c3f2 1179 if(num > 4) continue;
casiotone401 0:a4d93cd4c30d 1180 if(absv >= 1 || msg[2].i >= 1) gLEDS[num] = gGATES[num] = 1;
casiotone401 0:a4d93cd4c30d 1181 else gLEDS[num] = gGATES[num] = 0;
casiotone401 10:ccfeb687c3f2 1182 continue;
casiotone401 10:ccfeb687c3f2 1183
casiotone401 10:ccfeb687c3f2 1184 } else if (!strncmp(msg[0].address,"/1/multipush",12) && (num != -1)) {
casiotone401 10:ccfeb687c3f2 1185 if(num > 4) continue;
casiotone401 10:ccfeb687c3f2 1186 if(absv >= 1 || msg[2].i >= 1) gLEDS[num] = gGATES[num] = 1;
casiotone401 10:ccfeb687c3f2 1187 else gLEDS[num] = gGATES[num] = 0;
casiotone401 10:ccfeb687c3f2 1188 continue;
casiotone401 10:ccfeb687c3f2 1189 // address pattern CV (Type Tag float)
casiotone401 10:ccfeb687c3f2 1190 } else if(!strncmp(msg[0].address+(len-1)-2, "cv", 2) && (num != -1)) {
casiotone401 10:ccfeb687c3f2 1191 if(num > 7) continue;
casiotone401 10:ccfeb687c3f2 1192 if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
casiotone401 10:ccfeb687c3f2 1193 continue;
casiotone401 10:ccfeb687c3f2 1194 // (touchOSC Control fader, rotary, xy, multixy, multifader)
casiotone401 10:ccfeb687c3f2 1195 } else if (!strncmp(msg[0].address+(len-1)-5, "fader", 5) && (num != -1)) {
casiotone401 10:ccfeb687c3f2 1196 if(num > 7) continue;
casiotone401 10:ccfeb687c3f2 1197 if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
casiotone401 10:ccfeb687c3f2 1198 continue;
casiotone401 0:a4d93cd4c30d 1199
casiotone401 10:ccfeb687c3f2 1200 } else if (!strncmp(msg[0].address+(len-1)-6, "rotary", 6) && (num != -1)) {
casiotone401 10:ccfeb687c3f2 1201 if(num > 7) continue;
casiotone401 10:ccfeb687c3f2 1202 if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
casiotone401 10:ccfeb687c3f2 1203 continue;
casiotone401 10:ccfeb687c3f2 1204
casiotone401 10:ccfeb687c3f2 1205 } else if (!strncmp(msg[0].address+(len-1)-2, "xy", 2) && (num != -1)) {
casiotone401 10:ccfeb687c3f2 1206 if(num > 7) continue;
casiotone401 10:ccfeb687c3f2 1207 if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
casiotone401 10:ccfeb687c3f2 1208 if(msg[1].typeTag[1] == 'f') gOSC_cv[++num] = msg[3].f * (SCALING_N);
casiotone401 10:ccfeb687c3f2 1209 continue;
casiotone401 10:ccfeb687c3f2 1210
casiotone401 10:ccfeb687c3f2 1211 } else if (!strncmp(msg[0].address+(len-1)-9, "multixy1/", 9) && (num != -1)) {
casiotone401 10:ccfeb687c3f2 1212 if(num > 7) continue;
casiotone401 10:ccfeb687c3f2 1213 if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
casiotone401 10:ccfeb687c3f2 1214 if(msg[1].typeTag[1] == 'f') gOSC_cv[++num] = msg[3].f * (SCALING_N);
casiotone401 10:ccfeb687c3f2 1215 continue;
casiotone401 10:ccfeb687c3f2 1216
casiotone401 10:ccfeb687c3f2 1217 } else if (!strncmp(msg[0].address+(len-1)-12, "multifader1/", 12) && (num != -1)) {
casiotone401 10:ccfeb687c3f2 1218 if(num > 7) continue;
casiotone401 10:ccfeb687c3f2 1219 if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
casiotone401 10:ccfeb687c3f2 1220 continue;
casiotone401 10:ccfeb687c3f2 1221 // (touchOSC multifader for Sequencer Mode)
casiotone401 10:ccfeb687c3f2 1222 } else if (!strncmp(msg[0].address+(len-1)-11, "sequencer1/", 11) && (num != -1)) {
casiotone401 10:ccfeb687c3f2 1223 if(num > 7) continue;
casiotone401 10:ccfeb687c3f2 1224 if(msg[1].typeTag[1] == 'f') gSeq_cv1[num] = msg[2].f * (SCALING_N);
casiotone401 10:ccfeb687c3f2 1225 continue;
casiotone401 0:a4d93cd4c30d 1226
casiotone401 10:ccfeb687c3f2 1227 } else if (!strncmp(msg[0].address+(len-1)-11, "sequencer2/", 11) && (num != -1)) {
casiotone401 10:ccfeb687c3f2 1228 if(num > 7) continue;
casiotone401 10:ccfeb687c3f2 1229 if(msg[1].typeTag[1] == 'f') gSeq_cv2[num] = msg[2].f * (SCALING_N);
casiotone401 10:ccfeb687c3f2 1230 continue;
casiotone401 10:ccfeb687c3f2 1231 // address pattern for control
casiotone401 10:ccfeb687c3f2 1232 } else if (!strncmp(msg[0].address+(len-1)-6, "ctrlsw", 6) && (num != -1)) {
casiotone401 10:ccfeb687c3f2 1233 if(num > 4) continue;
casiotone401 10:ccfeb687c3f2 1234 if(absv >= 1 || msg[2].i >= 1) gCtrlSW[num] = true;
casiotone401 10:ccfeb687c3f2 1235 else gCtrlSW[num] = false;
casiotone401 10:ccfeb687c3f2 1236 continue;
casiotone401 4:b9f5ae574447 1237
casiotone401 10:ccfeb687c3f2 1238 } else if (!strncmp(msg[0].address+(len-1)-4, "ctrl", 4) && (num != -1)) {
casiotone401 10:ccfeb687c3f2 1239 if(num > 3) continue;
casiotone401 10:ccfeb687c3f2 1240 if(msg[1].typeTag[1] == 'f') gCtrl[num] = msg[2].f;
casiotone401 10:ccfeb687c3f2 1241 continue;
casiotone401 10:ccfeb687c3f2 1242 }
casiotone401 10:ccfeb687c3f2 1243
casiotone401 10:ccfeb687c3f2 1244 } while(bundleflag);
casiotone401 10:ccfeb687c3f2 1245
casiotone401 10:ccfeb687c3f2 1246 }
casiotone401 10:ccfeb687c3f2 1247 }