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 Feb 09 04:23:17 2013 +0000
Revision:
7:a04f8378662e
Parent:
6:5796b63c70ef
Child:
8:fe50078d6b80
performance improvement

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 5:e305509d53f3 49 #define QUAN_RES1 116 // Quantize voltage Steps
casiotone401 0:a4d93cd4c30d 50 #define QUAN_RES2 69
casiotone401 0:a4d93cd4c30d 51 #define QUAN_RES3 68
casiotone401 3:ca15241dd6b4 52 #define QUAN_RES4 17
casiotone401 3:ca15241dd6b4 53 #define QUAN_RES5 58
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 4:b9f5ae574447 117 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 0:a4d93cd4c30d 129 0.00663080, 0.01433030, 0.02202980, 0.02972930, 0.03742880,
casiotone401 0:a4d93cd4c30d 130 0.04512830, 0.05282781, 0.06052731, 0.06822681, 0.07592630,
casiotone401 0:a4d93cd4c30d 131 0.08362581, 0.09132531, 0.09902481, 0.10672431, 0.11442380,
casiotone401 0:a4d93cd4c30d 132 0.12212331, 0.12951356, 0.13671936, 0.14392516, 0.15113096,
casiotone401 0:a4d93cd4c30d 133 0.15833676, 0.16554256, 0.17274836, 0.17995416, 0.18715996,
casiotone401 0:a4d93cd4c30d 134 0.19436575, 0.20157155, 0.20877735, 0.21598317, 0.22318897,
casiotone401 0:a4d93cd4c30d 135 0.23039477, 0.23760056, 0.24480636, 0.25202271, 0.25926629,
casiotone401 0:a4d93cd4c30d 136 0.26650983, 0.27375340, 0.28099698, 0.28824055, 0.29548413,
casiotone401 0:a4d93cd4c30d 137 0.30272770, 0.30997124, 0.31721482, 0.32445839, 0.33170196,
casiotone401 0:a4d93cd4c30d 138 0.33894554, 0.34618911, 0.35343266, 0.36067623, 0.36791980,
casiotone401 0:a4d93cd4c30d 139 0.37516347, 0.38241133, 0.38965923, 0.39690709, 0.40415496,
casiotone401 0:a4d93cd4c30d 140 0.41140282, 0.41865072, 0.42589858, 0.43314645, 0.44039431,
casiotone401 0:a4d93cd4c30d 141 0.44764221, 0.45489007, 0.46213794, 0.46938580, 0.47663370,
casiotone401 0:a4d93cd4c30d 142 0.48388156, 0.49112943, 0.49837729, 0.50566339, 0.51296055,
casiotone401 0:a4d93cd4c30d 143 0.52025765, 0.52755481, 0.53485191, 0.54214907, 0.54944617,
casiotone401 0:a4d93cd4c30d 144 0.55674326, 0.56404042, 0.57133752, 0.57863468, 0.58593178,
casiotone401 0:a4d93cd4c30d 145 0.59322894, 0.60052603, 0.60782319, 0.61512029, 0.62241745,
casiotone401 0:a4d93cd4c30d 146 0.62976688, 0.63714498, 0.64452308, 0.65190119, 0.65927929,
casiotone401 0:a4d93cd4c30d 147 0.66665739, 0.67403549, 0.68141359, 0.68879169, 0.69616979,
casiotone401 0:a4d93cd4c30d 148 0.70354789, 0.71092600, 0.71830410, 0.72568226, 0.73306036,
casiotone401 0:a4d93cd4c30d 149 0.74043846, 0.74781656, 0.75820577, 0.76986063, 0.78151548,
casiotone401 0:a4d93cd4c30d 150 0.79317033, 0.80482519, 0.81648004, 0.82813489, 0.83978975,
casiotone401 0:a4d93cd4c30d 151 0.85144460, 0.86309946, 0.87475431, 0.90686423, 0.93941462,
casiotone401 0:a4d93cd4c30d 152 0.97196496
casiotone401 0:a4d93cd4c30d 153 };
casiotone401 0:a4d93cd4c30d 154
casiotone401 0:a4d93cd4c30d 155 // Major Scale
casiotone401 0:a4d93cd4c30d 156 const float calibMap2[QUAN_RES2] = {
casiotone401 0:a4d93cd4c30d 157 0.00663080, 0.01433030, 0.02972930, 0.04512830, 0.05282781,
casiotone401 0:a4d93cd4c30d 158 0.06822681, 0.08362581, 0.09902481, 0.10672431, 0.12212331,
casiotone401 0:a4d93cd4c30d 159 0.13671936, 0.14392516, 0.15833676, 0.17274836, 0.18715996,
casiotone401 0:a4d93cd4c30d 160 0.19436575, 0.20877735, 0.22318897, 0.23039477, 0.24480636,
casiotone401 0:a4d93cd4c30d 161 0.25926629, 0.27375340, 0.28099698, 0.29548413, 0.30997124,
casiotone401 0:a4d93cd4c30d 162 0.31721482, 0.33170196, 0.34618911, 0.36067623, 0.36791980,
casiotone401 0:a4d93cd4c30d 163 0.38241133, 0.39690709, 0.40415496, 0.41865072, 0.43314645,
casiotone401 0:a4d93cd4c30d 164 0.44764221, 0.45489007, 0.46938580, 0.48388156, 0.49112943,
casiotone401 0:a4d93cd4c30d 165 0.50566339, 0.52025765, 0.53485191, 0.54214907, 0.55674326,
casiotone401 0:a4d93cd4c30d 166 0.57133752, 0.57863468, 0.59322894, 0.60782319, 0.62241745,
casiotone401 0:a4d93cd4c30d 167 0.62976688, 0.64452308, 0.65927929, 0.66665739, 0.68141359,
casiotone401 0:a4d93cd4c30d 168 0.69616979, 0.71092600, 0.71830410, 0.73306036, 0.74781656,
casiotone401 0:a4d93cd4c30d 169 0.75820577, 0.78151548, 0.80482519, 0.82813489, 0.83978975,
casiotone401 0:a4d93cd4c30d 170 0.86309946, 0.90686423, 0.93941462
casiotone401 0:a4d93cd4c30d 171 };
casiotone401 0:a4d93cd4c30d 172
casiotone401 0:a4d93cd4c30d 173 // Dorian Scale
casiotone401 0:a4d93cd4c30d 174 const float calibMap3[QUAN_RES3] = {
casiotone401 0:a4d93cd4c30d 175 0.00663080, 0.01433030, 0.02972930, 0.04512830, 0.06052731,
casiotone401 0:a4d93cd4c30d 176 0.06822681, 0.08362581, 0.09902481, 0.10672431, 0.12212331,
casiotone401 0:a4d93cd4c30d 177 0.13671936, 0.15113096, 0.15833676, 0.17274836, 0.18715996,
casiotone401 0:a4d93cd4c30d 178 0.19436575, 0.20877735, 0.22318897, 0.23760056, 0.24480636,
casiotone401 0:a4d93cd4c30d 179 0.25926629, 0.27375340, 0.28099698, 0.29548413, 0.30997124,
casiotone401 0:a4d93cd4c30d 180 0.32445839, 0.33170196, 0.34618911, 0.36067623, 0.36791980,
casiotone401 0:a4d93cd4c30d 181 0.38241133, 0.39690709, 0.41140282, 0.41865072, 0.43314645,
casiotone401 0:a4d93cd4c30d 182 0.44764221, 0.45489007, 0.46938580, 0.48388156, 0.49837729,
casiotone401 0:a4d93cd4c30d 183 0.50566339, 0.52025765, 0.53485191, 0.54214907, 0.55674326,
casiotone401 0:a4d93cd4c30d 184 0.57133752, 0.58593178, 0.59322894, 0.60782319, 0.62241745,
casiotone401 0:a4d93cd4c30d 185 0.62976688, 0.64452308, 0.65927929, 0.67403549, 0.68141359,
casiotone401 0:a4d93cd4c30d 186 0.69616979, 0.71092600, 0.71830410, 0.73306036, 0.74781656,
casiotone401 0:a4d93cd4c30d 187 0.76986063, 0.78151548, 0.80482519, 0.82813489, 0.83978975,
casiotone401 0:a4d93cd4c30d 188 0.86309946, 0.90686423, 0.97196496
casiotone401 0:a4d93cd4c30d 189 };
casiotone401 0:a4d93cd4c30d 190
casiotone401 3:ca15241dd6b4 191 // 5th
casiotone401 0:a4d93cd4c30d 192 const float calibMap4[QUAN_RES4] = {
casiotone401 5:e305509d53f3 193 0.00663080, 0.06052731, 0.11442380, 0.16554256, 0.21598317,
casiotone401 5:e305509d53f3 194 0.26650983, 0.31721482, 0.36791980, 0.41865072, 0.46938580,
casiotone401 5:e305509d53f3 195 0.52025765, 0.57133752, 0.62241745, 0.67403549, 0.72568226,
casiotone401 3:ca15241dd6b4 196 0.79317033, 0.87475431
casiotone401 3:ca15241dd6b4 197
casiotone401 3:ca15241dd6b4 198 };
casiotone401 3:ca15241dd6b4 199
casiotone401 4:b9f5ae574447 200 // Whole tone
casiotone401 3:ca15241dd6b4 201 const float calibMap5[QUAN_RES5] = {
casiotone401 5:e305509d53f3 202 0.00663080, 0.02202980, 0.03742880, 0.05282781, 0.06822681,
casiotone401 5:e305509d53f3 203 0.08362581, 0.09902481, 0.11442380, 0.12951356, 0.14392516,
casiotone401 5:e305509d53f3 204 0.15833676, 0.17274836, 0.18715996, 0.20157155, 0.21598317,
casiotone401 5:e305509d53f3 205 0.23039477, 0.24480636, 0.25926629, 0.27375340, 0.28824055,
casiotone401 5:e305509d53f3 206 0.30272770, 0.31721482, 0.33170196, 0.34618911, 0.36067623,
casiotone401 5:e305509d53f3 207 0.37516347, 0.38965923, 0.40415496, 0.41865072, 0.43314645,
casiotone401 5:e305509d53f3 208 0.44764221, 0.46213794, 0.47663370, 0.49112943, 0.50566339,
casiotone401 5:e305509d53f3 209 0.52025765, 0.53485191, 0.54944617, 0.56404042, 0.57863468,
casiotone401 5:e305509d53f3 210 0.59322894, 0.60782319, 0.62241745, 0.63714498, 0.65190119,
casiotone401 5:e305509d53f3 211 0.66665739, 0.68141359, 0.69616979, 0.71092600, 0.72568226,
casiotone401 5:e305509d53f3 212 0.74043846, 0.75820577, 0.78151548, 0.80482519, 0.82813489,
casiotone401 5:e305509d53f3 213 0.85144460, 0.87475431, 0.93941462
casiotone401 3:ca15241dd6b4 214
casiotone401 0:a4d93cd4c30d 215 };
casiotone401 0:a4d93cd4c30d 216
casiotone401 0:a4d93cd4c30d 217 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 218 // CV Meter Custom Character
casiotone401 0:a4d93cd4c30d 219
casiotone401 0:a4d93cd4c30d 220 unsigned char str1[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F};
casiotone401 0:a4d93cd4c30d 221 unsigned char str2[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F};
casiotone401 0:a4d93cd4c30d 222 unsigned char str3[8] = {0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F};
casiotone401 0:a4d93cd4c30d 223 unsigned char str4[8] = {0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F};
casiotone401 0:a4d93cd4c30d 224 unsigned char str5[8] = {0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F,0x1F};
casiotone401 0:a4d93cd4c30d 225 unsigned char str6[8] = {0x00,0x00,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F};
casiotone401 0:a4d93cd4c30d 226 unsigned char str7[8] = {0x00,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F};
casiotone401 0:a4d93cd4c30d 227 unsigned char str8[8] = {0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F};
casiotone401 0:a4d93cd4c30d 228
casiotone401 0:a4d93cd4c30d 229 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 230 // Global Variables
casiotone401 0:a4d93cd4c30d 231
casiotone401 7:a04f8378662e 232 float gOSC_cv[8];
casiotone401 7:a04f8378662e 233 float gSeq_cv1[8];
casiotone401 7:a04f8378662e 234 float gSeq_cv2[8];
casiotone401 7:a04f8378662e 235 float gGlide;
casiotone401 6:5796b63c70ef 236 volatile static int gMode;
casiotone401 0:a4d93cd4c30d 237
casiotone401 5:e305509d53f3 238 // Variables for Control
casiotone401 5:e305509d53f3 239
casiotone401 5:e305509d53f3 240 float gCtrl[2];
casiotone401 6:5796b63c70ef 241 volatile int gCtrlSW[4];
casiotone401 5:e305509d53f3 242
casiotone401 0:a4d93cd4c30d 243 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 244 // mbed Functions
casiotone401 0:a4d93cd4c30d 245
casiotone401 0:a4d93cd4c30d 246 TextLCD gLCD(p9, p10, p11, p12, p13, p14); // rs, e, d4-d7
casiotone401 0:a4d93cd4c30d 247
casiotone401 0:a4d93cd4c30d 248 SPI gSPI(p5,p6,p7); // SPI (p6 unconnected)
casiotone401 0:a4d93cd4c30d 249 DigitalOut gSYNCMODE(p15); // SYNC DAC8568
casiotone401 0:a4d93cd4c30d 250 DigitalOut gLDAC(p16); // LDAC DAC8568
casiotone401 0:a4d93cd4c30d 251
casiotone401 1:fd4f70088311 252 DigitalOut gGATES[4] = {p22, p23, p24, p25}; // GateOut
casiotone401 1:fd4f70088311 253 DigitalOut gLEDS[4] = {p18, p19, p20, p21}; // LED
casiotone401 5:e305509d53f3 254 DigitalOut gCLOCKOUT(p26); // ClockOut
casiotone401 0:a4d93cd4c30d 255
casiotone401 0:a4d93cd4c30d 256 AnalogIn gAIN(p17); // Glide Potentiometer
casiotone401 0:a4d93cd4c30d 257 InterruptIn gSW(p30); // Mode SW
casiotone401 0:a4d93cd4c30d 258
casiotone401 4:b9f5ae574447 259 Timer gTimer; // Timer
casiotone401 0:a4d93cd4c30d 260 Ticker gPoller; // Ticker Polling
casiotone401 0:a4d93cd4c30d 261
casiotone401 0:a4d93cd4c30d 262 // Ethernet
casiotone401 0:a4d93cd4c30d 263 EthernetNetIf gEth;
casiotone401 0:a4d93cd4c30d 264 UDPSocket gUdp;
casiotone401 0:a4d93cd4c30d 265
casiotone401 0:a4d93cd4c30d 266 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 267 // main
casiotone401 0:a4d93cd4c30d 268
casiotone401 0:a4d93cd4c30d 269 int main()
casiotone401 0:a4d93cd4c30d 270 {
casiotone401 7:a04f8378662e 271 float pot, _pot;
casiotone401 5:e305509d53f3 272 int bpm, _bpm;
casiotone401 5:e305509d53f3 273 int shift1, shift2, shift3, shift4;
casiotone401 3:ca15241dd6b4 274
casiotone401 0:a4d93cd4c30d 275 if(SetupEthNetIf() == -1)
casiotone401 0:a4d93cd4c30d 276 {
casiotone401 4:b9f5ae574447 277 for(int i = 0; i < 4; i++)
casiotone401 0:a4d93cd4c30d 278 {
casiotone401 0:a4d93cd4c30d 279 gLEDS[i] = 1;
casiotone401 0:a4d93cd4c30d 280 wait(0.25);
casiotone401 0:a4d93cd4c30d 281 }
casiotone401 5:e305509d53f3 282
casiotone401 0:a4d93cd4c30d 283 return -1;
casiotone401 0:a4d93cd4c30d 284 }
casiotone401 0:a4d93cd4c30d 285
casiotone401 5:e305509d53f3 286 // mdns (Bonjour)
casiotone401 0:a4d93cd4c30d 287 HTTPServer svr;
casiotone401 0:a4d93cd4c30d 288 mDNSResponder mdns;
casiotone401 4:b9f5ae574447 289
casiotone401 0:a4d93cd4c30d 290 svr.addHandler<SimpleHandler>("/");
casiotone401 0:a4d93cd4c30d 291 svr.bind(INPUT_PORT);
casiotone401 0:a4d93cd4c30d 292 IpAddr ip = gEth.getIp();
casiotone401 0:a4d93cd4c30d 293 mdns.announce(ip, "OSCtoCV", "_osc._udp", INPUT_PORT, "mbed(OSCtoCV)", (char *[]) {"path=/",NULL});
casiotone401 0:a4d93cd4c30d 294
casiotone401 0:a4d93cd4c30d 295 InitOSCCV();
casiotone401 0:a4d93cd4c30d 296
casiotone401 4:b9f5ae574447 297 pot = _pot = 0;
casiotone401 4:b9f5ae574447 298 gGlide = gMode = 0;
casiotone401 5:e305509d53f3 299 bpm = _bpm = 120;
casiotone401 4:b9f5ae574447 300
casiotone401 4:b9f5ae574447 301 LCD();
casiotone401 3:ca15241dd6b4 302 gLCD.locate( 0, 1 );
casiotone401 3:ca15241dd6b4 303 gLCD.printf("12345678 G>>%3.2f", gGlide);
casiotone401 3:ca15241dd6b4 304
casiotone401 5:e305509d53f3 305 // loop
casiotone401 0:a4d93cd4c30d 306 while(1)
casiotone401 0:a4d93cd4c30d 307 {
casiotone401 5:e305509d53f3 308 gGlide = pot = gAIN.read(); // Glide Value
casiotone401 0:a4d93cd4c30d 309
casiotone401 4:b9f5ae574447 310 if(abs(pot - _pot) > 0.01f)
casiotone401 0:a4d93cd4c30d 311 {
casiotone401 3:ca15241dd6b4 312 gLCD.locate( 0, 1 );
casiotone401 3:ca15241dd6b4 313 gLCD.printf("12345678 G>>%3.2f", gGlide);
casiotone401 4:b9f5ae574447 314
casiotone401 3:ca15241dd6b4 315 _pot = gAIN.read();
casiotone401 0:a4d93cd4c30d 316 }
casiotone401 3:ca15241dd6b4 317
casiotone401 6:5796b63c70ef 318 switch(gMode)
casiotone401 4:b9f5ae574447 319 {
casiotone401 6:5796b63c70ef 320 case MODE_SEQ:
casiotone401 5:e305509d53f3 321
casiotone401 5:e305509d53f3 322 bpm = (gCtrl[0] * 300 + 10); // Set BPM (gCtrl[0])
casiotone401 5:e305509d53f3 323
casiotone401 6:5796b63c70ef 324 if(abs(bpm - _bpm) > 1)
casiotone401 6:5796b63c70ef 325 {
casiotone401 6:5796b63c70ef 326 UpdateGate(bpm, NRESET, GATEALL, 3, 0); // Reset (if bpm change)
casiotone401 6:5796b63c70ef 327 _bpm = bpm;
casiotone401 6:5796b63c70ef 328
casiotone401 6:5796b63c70ef 329 } else if (gCtrlSW[0] == 1) { // Stop (gCtrlSW[0])
casiotone401 6:5796b63c70ef 330
casiotone401 6:5796b63c70ef 331 bpm = 0;
casiotone401 6:5796b63c70ef 332 }
casiotone401 5:e305509d53f3 333
casiotone401 6:5796b63c70ef 334 if(gCtrlSW[2] == 0 && gCtrlSW[3] == 0) // Sequencer Mode1
casiotone401 6:5796b63c70ef 335 {
casiotone401 6:5796b63c70ef 336 shift1 = UpdateGate(bpm, N16TH, GATE1, 3, 0); // Shift Timming 16th note
casiotone401 5:e305509d53f3 337
casiotone401 6:5796b63c70ef 338 UpdateGate(bpm, N8TH, GATE2, 3, 0);
casiotone401 6:5796b63c70ef 339 UpdateGate(bpm, NDOT8, GATE3, 3, 0);
casiotone401 6:5796b63c70ef 340 UpdateGate(bpm, TRIP4, GATE4, 3, 0);
casiotone401 5:e305509d53f3 341
casiotone401 6:5796b63c70ef 342 SeqCV(shift1); // Do shift ch all
casiotone401 6:5796b63c70ef 343 continue;
casiotone401 5:e305509d53f3 344
casiotone401 6:5796b63c70ef 345 } else if (gCtrlSW[2] == 1 && gCtrlSW[3] == 0) { // Sequencer Mode2 (if gCtrlSW[2] ON)
casiotone401 5:e305509d53f3 346
casiotone401 6:5796b63c70ef 347 shift1 = UpdateGate(bpm, N16TH, GATE1, 3, 0);
casiotone401 6:5796b63c70ef 348 shift2 = UpdateGate(bpm, N8TH, GATE2, 3, 0);
casiotone401 6:5796b63c70ef 349 shift3 = UpdateGate(bpm, NDOT4, GATE3, 3, 0);
casiotone401 6:5796b63c70ef 350 shift4 = UpdateGate(bpm, TRIP8, GATE4, 3, 0);
casiotone401 5:e305509d53f3 351
casiotone401 6:5796b63c70ef 352 SeqCV(shift1); // Do shift ch 1~5
casiotone401 6:5796b63c70ef 353 SeqCV(shift2); // Do shift ch 6
casiotone401 6:5796b63c70ef 354 SeqCV(shift3); // Do shift ch 7
casiotone401 6:5796b63c70ef 355 SeqCV(shift4); // Do shift ch 8
casiotone401 6:5796b63c70ef 356 continue;
casiotone401 5:e305509d53f3 357
casiotone401 6:5796b63c70ef 358 } else if (gCtrlSW[3] == 1) { // Sequencer Mode3 (if gCtrlSW[3] ON)
casiotone401 6:5796b63c70ef 359 // (ch6,7,8, short loop)
casiotone401 6:5796b63c70ef 360 shift1 = UpdateGate(bpm, N16TH, GATE1, 3, 0);
casiotone401 6:5796b63c70ef 361 shift2 = UpdateGate(bpm, N8TH, GATE2, 3, 0);
casiotone401 6:5796b63c70ef 362 shift3 = UpdateGate(bpm, NDOT8, GATE3, 3, 0);
casiotone401 6:5796b63c70ef 363 shift4 = UpdateGate(bpm, TRIP4, GATE4, 3, 0);
casiotone401 5:e305509d53f3 364
casiotone401 6:5796b63c70ef 365 SeqCV(shift1); // Do shift ch 1~5
casiotone401 6:5796b63c70ef 366 SeqCV(shift2); // Do shift ch 6
casiotone401 6:5796b63c70ef 367 SeqCV(shift3); // Do shift ch 7
casiotone401 6:5796b63c70ef 368 SeqCV(shift4); // Do shift ch 8
casiotone401 6:5796b63c70ef 369 continue;
casiotone401 6:5796b63c70ef 370 }
casiotone401 6:5796b63c70ef 371
casiotone401 6:5796b63c70ef 372 default:
casiotone401 4:b9f5ae574447 373
casiotone401 6:5796b63c70ef 374 SetCV();
casiotone401 6:5796b63c70ef 375 continue;
casiotone401 4:b9f5ae574447 376 }
casiotone401 0:a4d93cd4c30d 377 }
casiotone401 0:a4d93cd4c30d 378 }
casiotone401 0:a4d93cd4c30d 379
casiotone401 0:a4d93cd4c30d 380 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 381 // Ethernet Polling
casiotone401 0:a4d93cd4c30d 382
casiotone401 4:b9f5ae574447 383 inline void NetPoll()
casiotone401 0:a4d93cd4c30d 384 {
casiotone401 0:a4d93cd4c30d 385 Net::poll();
casiotone401 0:a4d93cd4c30d 386 }
casiotone401 0:a4d93cd4c30d 387
casiotone401 0:a4d93cd4c30d 388 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 389 // Initialize OSC-CV
casiotone401 0:a4d93cd4c30d 390
casiotone401 0:a4d93cd4c30d 391 void InitOSCCV()
casiotone401 0:a4d93cd4c30d 392 {
casiotone401 5:e305509d53f3 393 // write custom char LCD CGRAM
casiotone401 0:a4d93cd4c30d 394 WriteCustomChar(0x00, str1);
casiotone401 0:a4d93cd4c30d 395 WriteCustomChar(0x01, str2);
casiotone401 0:a4d93cd4c30d 396 WriteCustomChar(0x02, str3);
casiotone401 0:a4d93cd4c30d 397 WriteCustomChar(0x03, str4);
casiotone401 0:a4d93cd4c30d 398 WriteCustomChar(0x04, str5);
casiotone401 0:a4d93cd4c30d 399 WriteCustomChar(0x05, str6);
casiotone401 0:a4d93cd4c30d 400 WriteCustomChar(0x06, str7);
casiotone401 0:a4d93cd4c30d 401 WriteCustomChar(0x07, str8);
casiotone401 0:a4d93cd4c30d 402
casiotone401 5:e305509d53f3 403 // Init. SPI
casiotone401 0:a4d93cd4c30d 404 gLDAC = _ENABLE;
casiotone401 5:e305509d53f3 405 gSPI.format(8,1); // Data word length 8bit, Mode=1
casiotone401 0:a4d93cd4c30d 406 gSPI.frequency(SPI_RATE);
casiotone401 0:a4d93cd4c30d 407
casiotone401 5:e305509d53f3 408 UpdateCV(CLR, 0, 0); // Ignore CLR Pin
casiotone401 0:a4d93cd4c30d 409
casiotone401 5:e305509d53f3 410 gSW.mode(PullUp); // Use internal pullup for ModeSW
casiotone401 0:a4d93cd4c30d 411 wait(.001);
casiotone401 0:a4d93cd4c30d 412
casiotone401 5:e305509d53f3 413 gSW.rise(&CheckModeSW); // InterruptIn rising edge(ModeSW)
casiotone401 0:a4d93cd4c30d 414 gPoller.attach_us(&NetPoll, POLLING_INTERVAL); // Ticker Polling
casiotone401 3:ca15241dd6b4 415
casiotone401 3:ca15241dd6b4 416 wait(0.2);
casiotone401 0:a4d93cd4c30d 417 }
casiotone401 0:a4d93cd4c30d 418
casiotone401 0:a4d93cd4c30d 419 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 420 // SPI Transfer
casiotone401 0:a4d93cd4c30d 421 // DAC8568 data word length 32bit (8bit shift out)
casiotone401 0:a4d93cd4c30d 422
casiotone401 4:b9f5ae574447 423 inline void UpdateCV(int control, int address, const unsigned int *data)
casiotone401 0:a4d93cd4c30d 424 {
casiotone401 0:a4d93cd4c30d 425 __disable_irq();
casiotone401 0:a4d93cd4c30d 426
casiotone401 0:a4d93cd4c30d 427 switch(control)
casiotone401 0:a4d93cd4c30d 428 {
casiotone401 0:a4d93cd4c30d 429 case WRITE_UPDATE_N:
casiotone401 4:b9f5ae574447 430
casiotone401 0:a4d93cd4c30d 431 gSYNCMODE = _DISABLE;
casiotone401 4:b9f5ae574447 432 gSPI.write(00000000|control); // padding at beginning of byte and control bits
casiotone401 4:b9f5ae574447 433 gSPI.write(address << 4 | *data >> 12); // address(ch) bits
casiotone401 4:b9f5ae574447 434 gSPI.write((*data << 4) >> 8); // middle 8 bits of data
casiotone401 4:b9f5ae574447 435 gSPI.write((*data << 12) >> 8 | 00001111);
casiotone401 0:a4d93cd4c30d 436 gSYNCMODE = _ENABLE;
casiotone401 0:a4d93cd4c30d 437 gLDAC = _DISABLE;
casiotone401 0:a4d93cd4c30d 438 gLDAC = _ENABLE;
casiotone401 0:a4d93cd4c30d 439 break;
casiotone401 4:b9f5ae574447 440
casiotone401 0:a4d93cd4c30d 441 case RESET:
casiotone401 4:b9f5ae574447 442
casiotone401 0:a4d93cd4c30d 443 gSYNCMODE = _DISABLE;
casiotone401 4:b9f5ae574447 444 gSPI.write(00000111); // Software RESET
casiotone401 0:a4d93cd4c30d 445 gSPI.write(00000000);
casiotone401 0:a4d93cd4c30d 446 gSPI.write(00000000);
casiotone401 0:a4d93cd4c30d 447 gSPI.write(00000000);
casiotone401 0:a4d93cd4c30d 448 gSYNCMODE = _ENABLE;
casiotone401 0:a4d93cd4c30d 449 break;
casiotone401 4:b9f5ae574447 450
casiotone401 0:a4d93cd4c30d 451 case CLR:
casiotone401 4:b9f5ae574447 452
casiotone401 0:a4d93cd4c30d 453 gSYNCMODE = _DISABLE;
casiotone401 4:b9f5ae574447 454 gSPI.write(00000101); // CLR Register
casiotone401 0:a4d93cd4c30d 455 gSPI.write(00000000);
casiotone401 0:a4d93cd4c30d 456 gSPI.write(00000000);
casiotone401 4:b9f5ae574447 457 gSPI.write(00000011); // Ignore CLR Pin
casiotone401 0:a4d93cd4c30d 458 gSYNCMODE = _ENABLE;
casiotone401 0:a4d93cd4c30d 459 break;
casiotone401 0:a4d93cd4c30d 460 }
casiotone401 0:a4d93cd4c30d 461
casiotone401 0:a4d93cd4c30d 462 __enable_irq();
casiotone401 0:a4d93cd4c30d 463 }
casiotone401 0:a4d93cd4c30d 464
casiotone401 0:a4d93cd4c30d 465 //-------------------------------------------------------------
casiotone401 5:e305509d53f3 466 // GateOutSequence beat(Note values) length(Gate time) invert(invert Gate)
casiotone401 5:e305509d53f3 467
casiotone401 5:e305509d53f3 468 int UpdateGate(int bpm, int beat, int ch, int length, int invert)
casiotone401 5:e305509d53f3 469 {
casiotone401 5:e305509d53f3 470 static int gatetime[4];
casiotone401 5:e305509d53f3 471 static int oldgatetime[4];
casiotone401 5:e305509d53f3 472 static int bar;
casiotone401 5:e305509d53f3 473 static int sync24;
casiotone401 5:e305509d53f3 474 static int oldsynctime;
casiotone401 5:e305509d53f3 475
casiotone401 5:e305509d53f3 476 int time = gTimer.read_us();
casiotone401 5:e305509d53f3 477
casiotone401 5:e305509d53f3 478 bar = (60.0f / bpm) * 4000000;
casiotone401 5:e305509d53f3 479 sync24 = (bar / 4) / 24; // sync24 not tested
casiotone401 5:e305509d53f3 480
casiotone401 5:e305509d53f3 481 switch(beat) // Calculate Note values
casiotone401 5:e305509d53f3 482 {
casiotone401 5:e305509d53f3 483 case NDOT2:
casiotone401 5:e305509d53f3 484
casiotone401 5:e305509d53f3 485 gatetime[ch] = (bar / 4) * 3;
casiotone401 5:e305509d53f3 486 break;
casiotone401 5:e305509d53f3 487
casiotone401 5:e305509d53f3 488 case NDOT4:
casiotone401 5:e305509d53f3 489
casiotone401 5:e305509d53f3 490 gatetime[ch] = (bar / 8) * 3;
casiotone401 5:e305509d53f3 491 break;
casiotone401 5:e305509d53f3 492
casiotone401 5:e305509d53f3 493 case NDOT8:
casiotone401 5:e305509d53f3 494
casiotone401 5:e305509d53f3 495 gatetime[ch] = (bar / 16) * 3;
casiotone401 5:e305509d53f3 496 break;
casiotone401 5:e305509d53f3 497
casiotone401 5:e305509d53f3 498 case NDOT16:
casiotone401 5:e305509d53f3 499
casiotone401 5:e305509d53f3 500 gatetime[ch] = (bar / 32) * 3;
casiotone401 5:e305509d53f3 501 break;
casiotone401 5:e305509d53f3 502
casiotone401 5:e305509d53f3 503 case NDOT32:
casiotone401 5:e305509d53f3 504
casiotone401 5:e305509d53f3 505 gatetime[ch] = (bar / 64) * 3;
casiotone401 5:e305509d53f3 506 break;
casiotone401 5:e305509d53f3 507
casiotone401 5:e305509d53f3 508 case TRIP2:
casiotone401 5:e305509d53f3 509
casiotone401 5:e305509d53f3 510 gatetime[ch] = bar / 3;
casiotone401 5:e305509d53f3 511 break;
casiotone401 5:e305509d53f3 512
casiotone401 5:e305509d53f3 513 case TRIP4:
casiotone401 5:e305509d53f3 514
casiotone401 5:e305509d53f3 515 gatetime[ch] = (bar / 2) / 3;
casiotone401 5:e305509d53f3 516 break;
casiotone401 5:e305509d53f3 517
casiotone401 5:e305509d53f3 518 case TRIP8:
casiotone401 5:e305509d53f3 519
casiotone401 5:e305509d53f3 520 gatetime[ch] = (bar / 4) / 3;
casiotone401 5:e305509d53f3 521 break;
casiotone401 5:e305509d53f3 522
casiotone401 5:e305509d53f3 523 case TRIP16:
casiotone401 5:e305509d53f3 524
casiotone401 5:e305509d53f3 525 gatetime[ch] = (bar / 8) / 3;
casiotone401 5:e305509d53f3 526 break;
casiotone401 5:e305509d53f3 527
casiotone401 5:e305509d53f3 528 case TRIP32:
casiotone401 5:e305509d53f3 529
casiotone401 5:e305509d53f3 530 gatetime[ch] = (bar / 16) / 3;
casiotone401 5:e305509d53f3 531 break;
casiotone401 5:e305509d53f3 532
casiotone401 5:e305509d53f3 533 case NRESET:
casiotone401 5:e305509d53f3 534
casiotone401 5:e305509d53f3 535 for(int i = 0; i < GATEALL; ++i) // Reset
casiotone401 5:e305509d53f3 536 {
casiotone401 5:e305509d53f3 537 gTimer.reset();
casiotone401 5:e305509d53f3 538 oldsynctime = oldgatetime[i] = gatetime[i] = NRESET;
casiotone401 5:e305509d53f3 539 }
casiotone401 5:e305509d53f3 540 break;
casiotone401 5:e305509d53f3 541
casiotone401 5:e305509d53f3 542 default:
casiotone401 5:e305509d53f3 543
casiotone401 5:e305509d53f3 544 gatetime[ch] = bar / beat;
casiotone401 5:e305509d53f3 545 }
casiotone401 5:e305509d53f3 546
casiotone401 5:e305509d53f3 547 if(time > oldsynctime + sync24) // sync24 not tested
casiotone401 5:e305509d53f3 548 {
casiotone401 5:e305509d53f3 549 oldsynctime = time;
casiotone401 5:e305509d53f3 550 gCLOCKOUT = 1;
casiotone401 5:e305509d53f3 551
casiotone401 5:e305509d53f3 552 } else if (time > sync24 - (sync24 - 2)) {
casiotone401 5:e305509d53f3 553
casiotone401 5:e305509d53f3 554 gCLOCKOUT = 0;
casiotone401 5:e305509d53f3 555 }
casiotone401 5:e305509d53f3 556
casiotone401 5:e305509d53f3 557 if (ch == GATEALL)
casiotone401 5:e305509d53f3 558 {
casiotone401 5:e305509d53f3 559 return -1;
casiotone401 5:e305509d53f3 560
casiotone401 5:e305509d53f3 561 } else if (time > oldgatetime[ch] + gatetime[ch] && invert == 0) {
casiotone401 5:e305509d53f3 562
casiotone401 5:e305509d53f3 563 oldgatetime[ch] = time;
casiotone401 5:e305509d53f3 564 gLEDS[ch] = gGATES[ch] = 1;
casiotone401 5:e305509d53f3 565
casiotone401 5:e305509d53f3 566 return ch + 1;
casiotone401 5:e305509d53f3 567
casiotone401 5:e305509d53f3 568 } else if (time > oldgatetime[ch] + gatetime[ch] && invert == 1) {
casiotone401 5:e305509d53f3 569
casiotone401 5:e305509d53f3 570 oldgatetime[ch] = time;
casiotone401 5:e305509d53f3 571 gLEDS[ch] = gGATES[ch] = 0;
casiotone401 5:e305509d53f3 572
casiotone401 5:e305509d53f3 573 return 0;
casiotone401 5:e305509d53f3 574
casiotone401 5:e305509d53f3 575 } else if (time > oldgatetime[ch] + (gatetime[ch] - gatetime[ch] / length) && invert == 0) {
casiotone401 5:e305509d53f3 576
casiotone401 5:e305509d53f3 577 gLEDS[ch] = gGATES[ch] = 0;
casiotone401 5:e305509d53f3 578
casiotone401 5:e305509d53f3 579 return 0;
casiotone401 5:e305509d53f3 580
casiotone401 5:e305509d53f3 581 } else if (time > oldgatetime[ch] + (gatetime[ch] - gatetime[ch] / length) && invert == 1) {
casiotone401 5:e305509d53f3 582
casiotone401 5:e305509d53f3 583 gLEDS[ch] = gGATES[ch] = 1;
casiotone401 5:e305509d53f3 584
casiotone401 5:e305509d53f3 585 return ch + 1;
casiotone401 5:e305509d53f3 586
casiotone401 5:e305509d53f3 587 } else {
casiotone401 5:e305509d53f3 588
casiotone401 5:e305509d53f3 589 return -1;
casiotone401 5:e305509d53f3 590 }
casiotone401 5:e305509d53f3 591 }
casiotone401 5:e305509d53f3 592
casiotone401 5:e305509d53f3 593 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 594 // Calculate CV
casiotone401 0:a4d93cd4c30d 595
casiotone401 0:a4d93cd4c30d 596 void SetCV()
casiotone401 0:a4d93cd4c30d 597 {
casiotone401 4:b9f5ae574447 598 static int ch;
casiotone401 0:a4d93cd4c30d 599 float glidecv[8];
casiotone401 0:a4d93cd4c30d 600 unsigned int cv[8];
casiotone401 0:a4d93cd4c30d 601 static float oldcv[8];
casiotone401 0:a4d93cd4c30d 602 static unsigned int quan;
casiotone401 0:a4d93cd4c30d 603 float qcv;
casiotone401 0:a4d93cd4c30d 604
casiotone401 0:a4d93cd4c30d 605 switch(gMode)
casiotone401 0:a4d93cd4c30d 606 {
casiotone401 0:a4d93cd4c30d 607 case MODE_LIN:
casiotone401 4:b9f5ae574447 608
casiotone401 0:a4d93cd4c30d 609 glidecv[ch] = oldcv[ch] * gGlide + gOSC_cv[ch] * (1.0f - gGlide);
casiotone401 0:a4d93cd4c30d 610 oldcv[ch] = glidecv[ch];
casiotone401 0:a4d93cd4c30d 611 cv[ch] = (unsigned int)glidecv[ch];
casiotone401 0:a4d93cd4c30d 612
casiotone401 4:b9f5ae574447 613 UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]);
casiotone401 0:a4d93cd4c30d 614 break;
casiotone401 0:a4d93cd4c30d 615
casiotone401 0:a4d93cd4c30d 616 case MODE_QChr:
casiotone401 0:a4d93cd4c30d 617
casiotone401 4:b9f5ae574447 618 quan = 40616 / QUAN_RES1;
casiotone401 4:b9f5ae574447 619 qcv = calibMap1[(unsigned int)(gOSC_cv[ch] / quan)];
casiotone401 4:b9f5ae574447 620
casiotone401 4:b9f5ae574447 621 glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 622 oldcv[ch] = glidecv[ch];
casiotone401 4:b9f5ae574447 623 cv[ch] = (unsigned int)glidecv[ch];
casiotone401 4:b9f5ae574447 624
casiotone401 4:b9f5ae574447 625 UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]);
casiotone401 4:b9f5ae574447 626 break;
casiotone401 4:b9f5ae574447 627
casiotone401 4:b9f5ae574447 628 case MODE_QMaj:
casiotone401 4:b9f5ae574447 629
casiotone401 4:b9f5ae574447 630 quan = 40616 / QUAN_RES2;
casiotone401 4:b9f5ae574447 631 qcv = calibMap2[(unsigned int)(gOSC_cv[ch] / quan)];
casiotone401 0:a4d93cd4c30d 632
casiotone401 0:a4d93cd4c30d 633 glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 0:a4d93cd4c30d 634 oldcv[ch] = glidecv[ch];
casiotone401 0:a4d93cd4c30d 635 cv[ch] = (unsigned int)glidecv[ch];
casiotone401 0:a4d93cd4c30d 636
casiotone401 4:b9f5ae574447 637 UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]);
casiotone401 0:a4d93cd4c30d 638 break;
casiotone401 4:b9f5ae574447 639
casiotone401 4:b9f5ae574447 640 case MODE_QDor:
casiotone401 0:a4d93cd4c30d 641
casiotone401 4:b9f5ae574447 642 quan = 40616 / QUAN_RES3;
casiotone401 4:b9f5ae574447 643 qcv = calibMap3[(unsigned int)(gOSC_cv[ch] / quan)];
casiotone401 0:a4d93cd4c30d 644
casiotone401 0:a4d93cd4c30d 645 glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 0:a4d93cd4c30d 646 oldcv[ch] = glidecv[ch];
casiotone401 0:a4d93cd4c30d 647 cv[ch] = (unsigned int)glidecv[ch];
casiotone401 0:a4d93cd4c30d 648
casiotone401 4:b9f5ae574447 649 UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]);
casiotone401 0:a4d93cd4c30d 650 break;
casiotone401 4:b9f5ae574447 651
casiotone401 4:b9f5ae574447 652 case MODE_Q5th:
casiotone401 4:b9f5ae574447 653
casiotone401 4:b9f5ae574447 654 quan = 40616 / QUAN_RES4;
casiotone401 4:b9f5ae574447 655 qcv = calibMap4[(unsigned int)(gOSC_cv[ch] / quan)];
casiotone401 0:a4d93cd4c30d 656
casiotone401 4:b9f5ae574447 657 glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 658 oldcv[ch] = glidecv[ch];
casiotone401 4:b9f5ae574447 659 cv[ch] = (unsigned int)glidecv[ch];
casiotone401 4:b9f5ae574447 660
casiotone401 4:b9f5ae574447 661 UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]);
casiotone401 4:b9f5ae574447 662 break;
casiotone401 0:a4d93cd4c30d 663
casiotone401 4:b9f5ae574447 664 case MODE_QWht:
casiotone401 4:b9f5ae574447 665
casiotone401 4:b9f5ae574447 666 quan = 40616 / QUAN_RES5;
casiotone401 4:b9f5ae574447 667 qcv = calibMap5[(unsigned int)(gOSC_cv[ch] / quan)];
casiotone401 0:a4d93cd4c30d 668
casiotone401 0:a4d93cd4c30d 669 glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 0:a4d93cd4c30d 670 oldcv[ch] = glidecv[ch];
casiotone401 0:a4d93cd4c30d 671 cv[ch] = (unsigned int)glidecv[ch];
casiotone401 0:a4d93cd4c30d 672
casiotone401 4:b9f5ae574447 673 UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]);
casiotone401 0:a4d93cd4c30d 674 break;
casiotone401 3:ca15241dd6b4 675
casiotone401 4:b9f5ae574447 676 case MODE_Calb:
casiotone401 3:ca15241dd6b4 677
casiotone401 4:b9f5ae574447 678 cv[ch] = 19212; // A440.0Hz
casiotone401 5:e305509d53f3 679
casiotone401 5:e305509d53f3 680 gGATES[0] = gGATES[1] = gGATES[2] = gGATES[3] = 1;
casiotone401 5:e305509d53f3 681 gLEDS[0] = gLEDS[1] = gLEDS[2] = gLEDS[3] = 1;
casiotone401 5:e305509d53f3 682
casiotone401 4:b9f5ae574447 683 UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]);
casiotone401 3:ca15241dd6b4 684 break;
casiotone401 0:a4d93cd4c30d 685 }
casiotone401 4:b9f5ae574447 686
casiotone401 4:b9f5ae574447 687 CVMeter(ch, &cv[ch]);
casiotone401 0:a4d93cd4c30d 688
casiotone401 0:a4d93cd4c30d 689 ch++;
casiotone401 0:a4d93cd4c30d 690 ch &= 0x07;
casiotone401 0:a4d93cd4c30d 691 }
casiotone401 0:a4d93cd4c30d 692
casiotone401 0:a4d93cd4c30d 693 //-------------------------------------------------------------
casiotone401 4:b9f5ae574447 694 // Sequence & Shift Out CV
casiotone401 4:b9f5ae574447 695
casiotone401 5:e305509d53f3 696 void SeqCV(int shift)
casiotone401 4:b9f5ae574447 697 {
casiotone401 6:5796b63c70ef 698 int i, j, k;
casiotone401 7:a04f8378662e 699 static int ch, SeqMode;
casiotone401 5:e305509d53f3 700 static int cnt1, cnt2, cnt3;
casiotone401 5:e305509d53f3 701 static int cntloop1, cntloop2, cntloop3;
casiotone401 4:b9f5ae574447 702 static float glidecv[8];
casiotone401 4:b9f5ae574447 703 unsigned int cv[8];
casiotone401 4:b9f5ae574447 704 static float shiftcv[8];
casiotone401 5:e305509d53f3 705 static float buffercv[9];
casiotone401 5:e305509d53f3 706 static float loopcv[3];
casiotone401 7:a04f8378662e 707 int quan;
casiotone401 4:b9f5ae574447 708 float qcv;
casiotone401 4:b9f5ae574447 709
casiotone401 5:e305509d53f3 710 SeqMode = (unsigned int)(gCtrl[1] * (MODE_NUM - 3)); // Sequencer Quantize Mode (gCtrl[1])
casiotone401 4:b9f5ae574447 711
casiotone401 4:b9f5ae574447 712 switch(SeqMode)
casiotone401 4:b9f5ae574447 713 {
casiotone401 4:b9f5ae574447 714 case MODE_LIN:
casiotone401 4:b9f5ae574447 715
casiotone401 4:b9f5ae574447 716 if(ch < 8)
casiotone401 4:b9f5ae574447 717 {
casiotone401 4:b9f5ae574447 718 glidecv[0] = glidecv[0] * gGlide + gSeq_cv1[ch] * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 719
casiotone401 4:b9f5ae574447 720 } else {
casiotone401 4:b9f5ae574447 721
casiotone401 4:b9f5ae574447 722 glidecv[0] = glidecv[0] * gGlide + gSeq_cv2[ch-8] * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 723 }
casiotone401 4:b9f5ae574447 724
casiotone401 4:b9f5ae574447 725 cv[0] = (unsigned int)glidecv[0];
casiotone401 4:b9f5ae574447 726
casiotone401 4:b9f5ae574447 727 UpdateCV(WRITE_UPDATE_N, 0, &cv[0]);
casiotone401 4:b9f5ae574447 728 break;
casiotone401 4:b9f5ae574447 729
casiotone401 4:b9f5ae574447 730 case MODE_QChr:
casiotone401 4:b9f5ae574447 731
casiotone401 4:b9f5ae574447 732 quan = 40616 / QUAN_RES1;
casiotone401 4:b9f5ae574447 733
casiotone401 4:b9f5ae574447 734 if(ch < 8)
casiotone401 4:b9f5ae574447 735 {
casiotone401 4:b9f5ae574447 736 qcv = calibMap1[(unsigned int)(gSeq_cv1[ch] / quan)];
casiotone401 4:b9f5ae574447 737
casiotone401 4:b9f5ae574447 738 } else {
casiotone401 4:b9f5ae574447 739
casiotone401 4:b9f5ae574447 740 qcv = calibMap1[(unsigned int)(gSeq_cv2[ch-8] / quan)];
casiotone401 4:b9f5ae574447 741 }
casiotone401 4:b9f5ae574447 742
casiotone401 4:b9f5ae574447 743 glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 744 cv[0] = (unsigned int)glidecv[0];
casiotone401 4:b9f5ae574447 745
casiotone401 4:b9f5ae574447 746 UpdateCV(WRITE_UPDATE_N, 0, &cv[0]);
casiotone401 4:b9f5ae574447 747 break;
casiotone401 4:b9f5ae574447 748
casiotone401 4:b9f5ae574447 749 case MODE_QMaj:
casiotone401 4:b9f5ae574447 750
casiotone401 4:b9f5ae574447 751 quan = 40616 / QUAN_RES2;
casiotone401 4:b9f5ae574447 752
casiotone401 4:b9f5ae574447 753 if(ch < 8)
casiotone401 4:b9f5ae574447 754 {
casiotone401 4:b9f5ae574447 755 qcv = calibMap2[(unsigned int)(gSeq_cv1[ch] / quan)];
casiotone401 4:b9f5ae574447 756
casiotone401 4:b9f5ae574447 757 } else {
casiotone401 4:b9f5ae574447 758
casiotone401 4:b9f5ae574447 759 qcv = calibMap2[(unsigned int)(gSeq_cv2[ch-8] / quan)];
casiotone401 4:b9f5ae574447 760 }
casiotone401 4:b9f5ae574447 761
casiotone401 4:b9f5ae574447 762 glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 763 cv[0] = (unsigned int)glidecv[0];
casiotone401 4:b9f5ae574447 764
casiotone401 4:b9f5ae574447 765 UpdateCV(WRITE_UPDATE_N, 0, &cv[0]);
casiotone401 4:b9f5ae574447 766 break;
casiotone401 4:b9f5ae574447 767
casiotone401 4:b9f5ae574447 768 case MODE_QDor:
casiotone401 4:b9f5ae574447 769
casiotone401 4:b9f5ae574447 770 quan = 40616 / QUAN_RES3;
casiotone401 4:b9f5ae574447 771
casiotone401 4:b9f5ae574447 772 if(ch < 8)
casiotone401 4:b9f5ae574447 773 {
casiotone401 4:b9f5ae574447 774 qcv = calibMap3[(unsigned int)(gSeq_cv1[ch] / quan)];
casiotone401 4:b9f5ae574447 775
casiotone401 4:b9f5ae574447 776 } else {
casiotone401 4:b9f5ae574447 777
casiotone401 4:b9f5ae574447 778 qcv = calibMap3[(unsigned int)(gSeq_cv2[ch-8] / quan)];
casiotone401 4:b9f5ae574447 779 }
casiotone401 4:b9f5ae574447 780
casiotone401 4:b9f5ae574447 781 glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 782 cv[0] = (unsigned int)glidecv[0];
casiotone401 4:b9f5ae574447 783
casiotone401 4:b9f5ae574447 784 UpdateCV(WRITE_UPDATE_N, 0, &cv[0]);
casiotone401 4:b9f5ae574447 785 break;
casiotone401 4:b9f5ae574447 786
casiotone401 4:b9f5ae574447 787 case MODE_Q5th:
casiotone401 4:b9f5ae574447 788
casiotone401 4:b9f5ae574447 789 quan = 40616 / QUAN_RES4;
casiotone401 4:b9f5ae574447 790
casiotone401 4:b9f5ae574447 791 if(ch < 8)
casiotone401 4:b9f5ae574447 792 {
casiotone401 4:b9f5ae574447 793 qcv = calibMap4[(unsigned int)(gSeq_cv1[ch] / quan)];
casiotone401 4:b9f5ae574447 794
casiotone401 4:b9f5ae574447 795 } else {
casiotone401 4:b9f5ae574447 796
casiotone401 4:b9f5ae574447 797 qcv = calibMap4[(unsigned int)(gSeq_cv2[ch-8] / quan)];
casiotone401 4:b9f5ae574447 798 }
casiotone401 4:b9f5ae574447 799
casiotone401 4:b9f5ae574447 800 glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 801 cv[0] = (unsigned int)glidecv[0];
casiotone401 4:b9f5ae574447 802
casiotone401 4:b9f5ae574447 803 UpdateCV(WRITE_UPDATE_N, 0, &cv[0]);
casiotone401 4:b9f5ae574447 804 break;
casiotone401 4:b9f5ae574447 805
casiotone401 4:b9f5ae574447 806 case MODE_QWht:
casiotone401 4:b9f5ae574447 807
casiotone401 4:b9f5ae574447 808 quan = 40616 / QUAN_RES5;
casiotone401 4:b9f5ae574447 809
casiotone401 4:b9f5ae574447 810 if(ch < 8)
casiotone401 4:b9f5ae574447 811 {
casiotone401 4:b9f5ae574447 812 qcv = calibMap5[(unsigned int)(gSeq_cv1[ch] / quan)];
casiotone401 4:b9f5ae574447 813
casiotone401 4:b9f5ae574447 814 } else {
casiotone401 4:b9f5ae574447 815
casiotone401 4:b9f5ae574447 816 qcv = calibMap5[(unsigned int)(gSeq_cv2[ch-8] / quan)];
casiotone401 4:b9f5ae574447 817 }
casiotone401 4:b9f5ae574447 818
casiotone401 4:b9f5ae574447 819 glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 820 cv[0] = (unsigned int)glidecv[0];
casiotone401 4:b9f5ae574447 821
casiotone401 4:b9f5ae574447 822 UpdateCV(WRITE_UPDATE_N, 0, &cv[0]);
casiotone401 4:b9f5ae574447 823 break;
casiotone401 4:b9f5ae574447 824 }
casiotone401 4:b9f5ae574447 825
casiotone401 6:5796b63c70ef 826 if((gCtrlSW[2] == 0 || gCtrlSW[2] == 1) && gCtrlSW[3] == 0)// Sequencer Mode1
casiotone401 4:b9f5ae574447 827 {
casiotone401 6:5796b63c70ef 828 for(i = 1; i < 8; ++i)
casiotone401 5:e305509d53f3 829 {
casiotone401 5:e305509d53f3 830 glidecv[i] = glidecv[i] * gGlide + shiftcv[i] * (1.0f - gGlide);
casiotone401 5:e305509d53f3 831 cv[i] = (unsigned int)glidecv[i];
casiotone401 5:e305509d53f3 832
casiotone401 5:e305509d53f3 833 UpdateCV(WRITE_UPDATE_N, i, &cv[i]);
casiotone401 6:5796b63c70ef 834
casiotone401 6:5796b63c70ef 835 if(shift == 1) // GATE1
casiotone401 6:5796b63c70ef 836 {
casiotone401 6:5796b63c70ef 837 for(i = 1; i < 8; ++i) // Shift ch2~8
casiotone401 6:5796b63c70ef 838 {
casiotone401 6:5796b63c70ef 839 shiftcv[i] = glidecv[i-1];
casiotone401 6:5796b63c70ef 840 }
casiotone401 6:5796b63c70ef 841
casiotone401 6:5796b63c70ef 842 ch++;
casiotone401 6:5796b63c70ef 843 ch &= 0x0F;
casiotone401 6:5796b63c70ef 844 }
casiotone401 6:5796b63c70ef 845
casiotone401 6:5796b63c70ef 846 cnt1 = cnt2 = cnt3 = 0;
casiotone401 5:e305509d53f3 847 }
casiotone401 4:b9f5ae574447 848
casiotone401 5:e305509d53f3 849 } else if (gCtrlSW[2] == 1 && gCtrlSW[3] == 0) { // Sequencer Mode2
casiotone401 5:e305509d53f3 850
casiotone401 5:e305509d53f3 851 if(shift == 1) // GATE1
casiotone401 5:e305509d53f3 852 {
casiotone401 6:5796b63c70ef 853 for(j = 1; j < 5; ++j)
casiotone401 5:e305509d53f3 854 {
casiotone401 5:e305509d53f3 855 shiftcv[j] = glidecv[j-1]; // Shift ch2~5
casiotone401 5:e305509d53f3 856 }
casiotone401 5:e305509d53f3 857
casiotone401 5:e305509d53f3 858 ch++;
casiotone401 5:e305509d53f3 859 ch &= 0x0F;
casiotone401 5:e305509d53f3 860
casiotone401 5:e305509d53f3 861 } else if (shift == 2) { // GATE2
casiotone401 5:e305509d53f3 862
casiotone401 5:e305509d53f3 863 shiftcv[5] = glidecv[1]; // Shift ch6
casiotone401 5:e305509d53f3 864
casiotone401 5:e305509d53f3 865 } else if (shift == 3) { // GATE3
casiotone401 5:e305509d53f3 866
casiotone401 5:e305509d53f3 867 shiftcv[6] = glidecv[2]; // Shift ch7
casiotone401 5:e305509d53f3 868
casiotone401 5:e305509d53f3 869 } else if (shift == 4) { // GATE4
casiotone401 5:e305509d53f3 870
casiotone401 5:e305509d53f3 871 shiftcv[7] = glidecv[3]; // Shift ch8
casiotone401 6:5796b63c70ef 872 }
casiotone401 6:5796b63c70ef 873
casiotone401 5:e305509d53f3 874 } else if (gCtrlSW[3] == 1) { // Sequencer Mode3
casiotone401 5:e305509d53f3 875
casiotone401 6:5796b63c70ef 876 for(j = 1; j < 5; ++j)
casiotone401 6:5796b63c70ef 877 {
casiotone401 6:5796b63c70ef 878 glidecv[j] = glidecv[j] * gGlide + shiftcv[j] * (1.0f - gGlide);
casiotone401 6:5796b63c70ef 879 cv[j] = (unsigned int)glidecv[j];
casiotone401 6:5796b63c70ef 880
casiotone401 6:5796b63c70ef 881 UpdateCV(WRITE_UPDATE_N, j, &cv[j]);
casiotone401 6:5796b63c70ef 882 }
casiotone401 6:5796b63c70ef 883
casiotone401 6:5796b63c70ef 884 for(k = 5; k < 8; ++k)
casiotone401 6:5796b63c70ef 885 {
casiotone401 6:5796b63c70ef 886 glidecv[k] = glidecv[k] * gGlide + loopcv[k - 5] * (1.0f - gGlide);
casiotone401 6:5796b63c70ef 887 cv[k] = (unsigned int)glidecv[k];
casiotone401 6:5796b63c70ef 888
casiotone401 6:5796b63c70ef 889 UpdateCV(WRITE_UPDATE_N, k, &cv[k]);
casiotone401 6:5796b63c70ef 890 }
casiotone401 6:5796b63c70ef 891
casiotone401 5:e305509d53f3 892 if(shift == 1) // GATE1
casiotone401 5:e305509d53f3 893 {
casiotone401 6:5796b63c70ef 894 for(i = 1; i < 8; ++i)
casiotone401 5:e305509d53f3 895 {
casiotone401 5:e305509d53f3 896 shiftcv[i] = glidecv[i-1]; // Shift ch2~5
casiotone401 5:e305509d53f3 897 }
casiotone401 5:e305509d53f3 898
casiotone401 5:e305509d53f3 899 ch++;
casiotone401 5:e305509d53f3 900 ch &= 0x0F;
casiotone401 5:e305509d53f3 901
casiotone401 5:e305509d53f3 902 } else if (shift == 2) { // GATE2
casiotone401 5:e305509d53f3 903
casiotone401 5:e305509d53f3 904 if(cnt1 < 4)
casiotone401 5:e305509d53f3 905 {
casiotone401 5:e305509d53f3 906 loopcv[0] = buffercv[cnt1] = shiftcv[4];
casiotone401 5:e305509d53f3 907
casiotone401 5:e305509d53f3 908 cnt1++;
casiotone401 5:e305509d53f3 909
casiotone401 5:e305509d53f3 910 } else if (cnt1 >= 4) {
casiotone401 5:e305509d53f3 911
casiotone401 5:e305509d53f3 912 loopcv[0] = buffercv[cntloop1];
casiotone401 5:e305509d53f3 913
casiotone401 5:e305509d53f3 914 cntloop1++;
casiotone401 5:e305509d53f3 915 cntloop1 &= 0x03;
casiotone401 5:e305509d53f3 916 }
casiotone401 5:e305509d53f3 917
casiotone401 5:e305509d53f3 918 } else if (shift == 3) { // GATE3
casiotone401 5:e305509d53f3 919
casiotone401 5:e305509d53f3 920 if(cnt2 < 3)
casiotone401 5:e305509d53f3 921 {
casiotone401 5:e305509d53f3 922 loopcv[1] = buffercv[(cnt2 + 4)] = shiftcv[5];
casiotone401 5:e305509d53f3 923
casiotone401 5:e305509d53f3 924 cnt2++;
casiotone401 5:e305509d53f3 925
casiotone401 5:e305509d53f3 926 } else if (cnt2 >= 3) {
casiotone401 5:e305509d53f3 927
casiotone401 5:e305509d53f3 928 loopcv[1] = buffercv[(cntloop2 + 4)];
casiotone401 5:e305509d53f3 929
casiotone401 5:e305509d53f3 930 cntloop2++;
casiotone401 5:e305509d53f3 931 cntloop2 &= 0x03;
casiotone401 5:e305509d53f3 932 }
casiotone401 5:e305509d53f3 933
casiotone401 5:e305509d53f3 934 } else if (shift == 4) { // GATE4
casiotone401 5:e305509d53f3 935
casiotone401 5:e305509d53f3 936 if(cnt3 < 2)
casiotone401 5:e305509d53f3 937 {
casiotone401 5:e305509d53f3 938 loopcv[2] = buffercv[(cnt3 + 7)] = shiftcv[6];
casiotone401 5:e305509d53f3 939
casiotone401 5:e305509d53f3 940 cnt3++;
casiotone401 5:e305509d53f3 941
casiotone401 5:e305509d53f3 942 } else if (cnt3 >= 2) {
casiotone401 5:e305509d53f3 943
casiotone401 5:e305509d53f3 944 loopcv[2] = buffercv[(cntloop3 + 7)];
casiotone401 5:e305509d53f3 945
casiotone401 5:e305509d53f3 946 cntloop3++;
casiotone401 5:e305509d53f3 947 cntloop3 &= 0x01;
casiotone401 5:e305509d53f3 948 }
casiotone401 5:e305509d53f3 949 }
casiotone401 5:e305509d53f3 950
casiotone401 5:e305509d53f3 951 if(gCtrlSW[1] == 1) // Update loop buffer (if gCtrlSW[1] ON)
casiotone401 5:e305509d53f3 952 {
casiotone401 5:e305509d53f3 953 cnt1 = cnt2 = cnt3 = 0;
casiotone401 5:e305509d53f3 954 }
casiotone401 4:b9f5ae574447 955 }
casiotone401 4:b9f5ae574447 956
casiotone401 4:b9f5ae574447 957 if(ch < 8)
casiotone401 4:b9f5ae574447 958 {
casiotone401 4:b9f5ae574447 959 CVMeter(ch, &cv[0]);
casiotone401 4:b9f5ae574447 960
casiotone401 4:b9f5ae574447 961 } else {
casiotone401 4:b9f5ae574447 962
casiotone401 4:b9f5ae574447 963 CVMeter((ch-8), &cv[0]);
casiotone401 4:b9f5ae574447 964 }
casiotone401 4:b9f5ae574447 965 }
casiotone401 4:b9f5ae574447 966
casiotone401 4:b9f5ae574447 967 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 968 // Check SW
casiotone401 0:a4d93cd4c30d 969
casiotone401 5:e305509d53f3 970 void CheckModeSW()
casiotone401 0:a4d93cd4c30d 971 {
casiotone401 7:a04f8378662e 972 wait(0.05);
casiotone401 4:b9f5ae574447 973
casiotone401 3:ca15241dd6b4 974 if(gMode < MODE_NUM - 1)
casiotone401 0:a4d93cd4c30d 975 {
casiotone401 0:a4d93cd4c30d 976 gMode++;
casiotone401 3:ca15241dd6b4 977
casiotone401 0:a4d93cd4c30d 978 } else {
casiotone401 4:b9f5ae574447 979
casiotone401 0:a4d93cd4c30d 980 gMode = 0;
casiotone401 0:a4d93cd4c30d 981 }
casiotone401 3:ca15241dd6b4 982
casiotone401 5:e305509d53f3 983 gCLOCKOUT = gGATES[0] = gGATES[1] = gGATES[2] = gGATES[3] = 0;
casiotone401 5:e305509d53f3 984 gLEDS[0] = gLEDS[1] = gLEDS[2] = gLEDS[3] = 0;
casiotone401 5:e305509d53f3 985
casiotone401 5:e305509d53f3 986 if(gMode == MODE_SEQ)
casiotone401 5:e305509d53f3 987 {
casiotone401 5:e305509d53f3 988 gTimer.start(); // Sequencer Timer Start
casiotone401 5:e305509d53f3 989
casiotone401 5:e305509d53f3 990 } else {
casiotone401 5:e305509d53f3 991
casiotone401 5:e305509d53f3 992 gTimer.stop(); // Sequencer Timer Stop
casiotone401 5:e305509d53f3 993 }
casiotone401 5:e305509d53f3 994
casiotone401 4:b9f5ae574447 995 LCD();
casiotone401 4:b9f5ae574447 996 }
casiotone401 4:b9f5ae574447 997
casiotone401 4:b9f5ae574447 998 //-------------------------------------------------------------
casiotone401 4:b9f5ae574447 999 // CV meter
casiotone401 4:b9f5ae574447 1000
casiotone401 4:b9f5ae574447 1001 void CVMeter(int ch, const unsigned int *level)
casiotone401 4:b9f5ae574447 1002 {
casiotone401 7:a04f8378662e 1003 unsigned int cvmeter;
casiotone401 4:b9f5ae574447 1004
casiotone401 5:e305509d53f3 1005 cvmeter = *level / (SCALING_N / 7.9);
casiotone401 4:b9f5ae574447 1006
casiotone401 4:b9f5ae574447 1007 gLCD.locate ( ch, 0 );
casiotone401 4:b9f5ae574447 1008 gLCD.putc(cvmeter); // put custom char
casiotone401 4:b9f5ae574447 1009 }
casiotone401 4:b9f5ae574447 1010
casiotone401 4:b9f5ae574447 1011 //-------------------------------------------------------------
casiotone401 5:e305509d53f3 1012 // Print LCD Mode Status
casiotone401 4:b9f5ae574447 1013
casiotone401 4:b9f5ae574447 1014 void LCD()
casiotone401 4:b9f5ae574447 1015 {
casiotone401 3:ca15241dd6b4 1016 switch(gMode)
casiotone401 3:ca15241dd6b4 1017 {
casiotone401 3:ca15241dd6b4 1018 case MODE_LIN:
casiotone401 3:ca15241dd6b4 1019 gLCD.locate( 9, 0 );
casiotone401 3:ca15241dd6b4 1020 gLCD.printf("OSC-CV ");
casiotone401 3:ca15241dd6b4 1021 break;
casiotone401 3:ca15241dd6b4 1022
casiotone401 3:ca15241dd6b4 1023 case MODE_QChr:
casiotone401 3:ca15241dd6b4 1024 gLCD.locate( 9, 0 );
casiotone401 3:ca15241dd6b4 1025 gLCD.printf("QUAN_C ");
casiotone401 3:ca15241dd6b4 1026 break;
casiotone401 3:ca15241dd6b4 1027
casiotone401 3:ca15241dd6b4 1028 case MODE_QMaj:
casiotone401 3:ca15241dd6b4 1029 gLCD.locate( 9, 0 );
casiotone401 3:ca15241dd6b4 1030 gLCD.printf("QUAN_M ");
casiotone401 3:ca15241dd6b4 1031 break;
casiotone401 3:ca15241dd6b4 1032
casiotone401 3:ca15241dd6b4 1033 case MODE_QDor:
casiotone401 3:ca15241dd6b4 1034 gLCD.locate( 9, 0 );
casiotone401 3:ca15241dd6b4 1035 gLCD.printf("QUAN_D ");
casiotone401 3:ca15241dd6b4 1036 break;
casiotone401 3:ca15241dd6b4 1037
casiotone401 3:ca15241dd6b4 1038 case MODE_Q5th:
casiotone401 3:ca15241dd6b4 1039 gLCD.locate( 9, 0 );
casiotone401 3:ca15241dd6b4 1040 gLCD.printf("QUAN_5 ");
casiotone401 3:ca15241dd6b4 1041 break;
casiotone401 3:ca15241dd6b4 1042
casiotone401 3:ca15241dd6b4 1043 case MODE_QWht:
casiotone401 3:ca15241dd6b4 1044 gLCD.locate( 9, 0 );
casiotone401 3:ca15241dd6b4 1045 gLCD.printf("QUAN_W ");
casiotone401 3:ca15241dd6b4 1046 break;
casiotone401 4:b9f5ae574447 1047
casiotone401 4:b9f5ae574447 1048 case MODE_SEQ:
casiotone401 4:b9f5ae574447 1049 gLCD.locate( 9, 0 );
casiotone401 4:b9f5ae574447 1050 gLCD.printf("ASRSEQ ");
casiotone401 4:b9f5ae574447 1051 break;
casiotone401 4:b9f5ae574447 1052
casiotone401 4:b9f5ae574447 1053 case MODE_Calb:
casiotone401 4:b9f5ae574447 1054 gLCD.locate( 9, 0 );
casiotone401 4:b9f5ae574447 1055 gLCD.printf("Calibr ");
casiotone401 4:b9f5ae574447 1056 break;
casiotone401 3:ca15241dd6b4 1057 }
casiotone401 0:a4d93cd4c30d 1058 }
casiotone401 0:a4d93cd4c30d 1059
casiotone401 0:a4d93cd4c30d 1060 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 1061 // Write command Custom Char LCD CGRAM(CV Meter)
casiotone401 0:a4d93cd4c30d 1062
casiotone401 0:a4d93cd4c30d 1063 void WriteCustomChar(unsigned char addr, unsigned char *c)
casiotone401 0:a4d93cd4c30d 1064 {
casiotone401 0:a4d93cd4c30d 1065 char cnt = 0;
casiotone401 0:a4d93cd4c30d 1066 addr = ((addr << 3) | 0x40);
casiotone401 0:a4d93cd4c30d 1067
casiotone401 0:a4d93cd4c30d 1068 while(cnt < 0x08)
casiotone401 0:a4d93cd4c30d 1069 {
casiotone401 0:a4d93cd4c30d 1070 gLCD.writeCommand(addr | cnt);
casiotone401 0:a4d93cd4c30d 1071 gLCD.writeData(*c);
casiotone401 4:b9f5ae574447 1072
casiotone401 0:a4d93cd4c30d 1073 cnt++;
casiotone401 0:a4d93cd4c30d 1074 c++;
casiotone401 0:a4d93cd4c30d 1075 }
casiotone401 0:a4d93cd4c30d 1076 }
casiotone401 0:a4d93cd4c30d 1077
casiotone401 0:a4d93cd4c30d 1078 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 1079 // Setup Ethernet port
casiotone401 0:a4d93cd4c30d 1080
casiotone401 0:a4d93cd4c30d 1081 int SetupEthNetIf()
casiotone401 0:a4d93cd4c30d 1082 {
casiotone401 0:a4d93cd4c30d 1083 gLCD.locate( 0, 1 );
casiotone401 0:a4d93cd4c30d 1084 gLCD.printf("Setting up... ");
casiotone401 0:a4d93cd4c30d 1085 // printf("Setting up...\r\n");
casiotone401 0:a4d93cd4c30d 1086 EthernetErr ethErr = gEth.setup();
casiotone401 0:a4d93cd4c30d 1087
casiotone401 0:a4d93cd4c30d 1088 if(ethErr)
casiotone401 0:a4d93cd4c30d 1089 {
casiotone401 0:a4d93cd4c30d 1090 gLCD.locate( 0, 1 );
casiotone401 0:a4d93cd4c30d 1091 gLCD.printf("Error in setup.");
casiotone401 0:a4d93cd4c30d 1092 // printf("Error %d in setup.\r\n", ethErr);
casiotone401 0:a4d93cd4c30d 1093 return -1;
casiotone401 0:a4d93cd4c30d 1094 }
casiotone401 0:a4d93cd4c30d 1095 // printf("Setup OK\r\n");
casiotone401 0:a4d93cd4c30d 1096
casiotone401 0:a4d93cd4c30d 1097 // printf("IP address %d.%d.%d.%d\r\n", gEth.getIp()[0], gEth.getIp()[1], gEth.getIp()[2], gEth.getIp()[3]);
casiotone401 0:a4d93cd4c30d 1098 Host broadcast(IpAddr(gEth.getIp()[0], gEth.getIp()[1], gEth.getIp()[2], 255), INPUT_PORT, NULL);
casiotone401 0:a4d93cd4c30d 1099 gUdp.setOnEvent(&onUDPSocketEvent);
casiotone401 0:a4d93cd4c30d 1100 gUdp.bind(broadcast);
casiotone401 4:b9f5ae574447 1101
casiotone401 0:a4d93cd4c30d 1102 gLCD.locate( 0, 1 );
casiotone401 0:a4d93cd4c30d 1103 gLCD.printf("%03d.%03d.%03d.%03d", gEth.getIp()[0], gEth.getIp()[1], gEth.getIp()[2], gEth.getIp()[3]);
casiotone401 4:b9f5ae574447 1104 wait(1.0);
casiotone401 0:a4d93cd4c30d 1105
casiotone401 0:a4d93cd4c30d 1106 return 0;
casiotone401 0:a4d93cd4c30d 1107 }
casiotone401 0:a4d93cd4c30d 1108
casiotone401 0:a4d93cd4c30d 1109 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 1110 // Handller receive UDP Packet
casiotone401 0:a4d93cd4c30d 1111
casiotone401 4:b9f5ae574447 1112 inline void onUDPSocketEvent(UDPSocketEvent e)
casiotone401 0:a4d93cd4c30d 1113 {
casiotone401 0:a4d93cd4c30d 1114 union OSCarg msg[10];
casiotone401 7:a04f8378662e 1115 int num;
casiotone401 6:5796b63c70ef 1116 unsigned int absv;
casiotone401 6:5796b63c70ef 1117
casiotone401 0:a4d93cd4c30d 1118 switch(e)
casiotone401 0:a4d93cd4c30d 1119 {
casiotone401 4:b9f5ae574447 1120 case UDPSOCKET_READABLE: // The only event for now
casiotone401 0:a4d93cd4c30d 1121 char buf[256] = {0};
casiotone401 0:a4d93cd4c30d 1122 Host host;
casiotone401 0:a4d93cd4c30d 1123
casiotone401 0:a4d93cd4c30d 1124 while( int len = gUdp.recvfrom( buf, 256, &host ))
casiotone401 0:a4d93cd4c30d 1125 {
casiotone401 0:a4d93cd4c30d 1126 if(len <= 0) break;
casiotone401 0:a4d93cd4c30d 1127 // printf("\r\nFrom %d.%d.%d.%d:\r\n",
casiotone401 0:a4d93cd4c30d 1128 // host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3]);
casiotone401 0:a4d93cd4c30d 1129
casiotone401 0:a4d93cd4c30d 1130 getOSCmsg(buf,msg);
casiotone401 0:a4d93cd4c30d 1131 // printf("OSCmsg: %s %s %f %i\r\n",
casiotone401 0:a4d93cd4c30d 1132 // msg[0].address, msg[1].typeTag, msg[2].f, msg[2].i);
casiotone401 0:a4d93cd4c30d 1133
casiotone401 0:a4d93cd4c30d 1134 len = strlen(msg[0].address);
casiotone401 4:b9f5ae574447 1135
casiotone401 4:b9f5ae574447 1136 if(isdigit(msg[0].address[len-1]))
casiotone401 4:b9f5ae574447 1137
casiotone401 4:b9f5ae574447 1138 num = msg[0].address[len-1] - '0' - 1;
casiotone401 4:b9f5ae574447 1139 else
casiotone401 4:b9f5ae574447 1140 num = -1;
casiotone401 4:b9f5ae574447 1141
casiotone401 6:5796b63c70ef 1142 absv = msg[2].f + 0; //convert -0 to 0
casiotone401 0:a4d93cd4c30d 1143
casiotone401 5:e305509d53f3 1144 // address pattern SYNC & GATE (Type Tag int, float)
casiotone401 6:5796b63c70ef 1145 if(strncmp(msg[0].address+(len-1)-4, "sync", 4)==0) {
casiotone401 0:a4d93cd4c30d 1146 if(absv >= 1 || msg[2].i >= 1) gCLOCKOUT = 1;
casiotone401 0:a4d93cd4c30d 1147 else gCLOCKOUT = 0;
casiotone401 0:a4d93cd4c30d 1148 break;
casiotone401 0:a4d93cd4c30d 1149
casiotone401 3:ca15241dd6b4 1150 } else if ((strncmp(msg[0].address+(len-1)-4, "gate", 4)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1151 if(num > 3) break;
casiotone401 0:a4d93cd4c30d 1152 if(absv >= 1 || msg[2].i >= 1) gLEDS[num] = gGATES[num] = 1;
casiotone401 0:a4d93cd4c30d 1153 else gLEDS[num] = gGATES[num] = 0;
casiotone401 0:a4d93cd4c30d 1154 break;
casiotone401 5:e305509d53f3 1155 // (touchOSC Control push, toggle)
casiotone401 3:ca15241dd6b4 1156 } else if ((strncmp(msg[0].address+(len-1)-4, "push", 4)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1157 if(num > 3) break;
casiotone401 0:a4d93cd4c30d 1158 if(absv >= 1 || msg[2].i >= 1) gLEDS[num] = gGATES[num] = 1;
casiotone401 0:a4d93cd4c30d 1159 else gLEDS[num] = gGATES[num] = 0;
casiotone401 0:a4d93cd4c30d 1160 break;
casiotone401 0:a4d93cd4c30d 1161
casiotone401 3:ca15241dd6b4 1162 } else if ((strncmp(msg[0].address+(len-1)-6, "toggle", 6)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1163 if(num > 3) break;
casiotone401 0:a4d93cd4c30d 1164 if(absv >= 1 || msg[2].i >= 1) gLEDS[num] = gGATES[num] = 1;
casiotone401 0:a4d93cd4c30d 1165 else gLEDS[num] = gGATES[num] = 0;
casiotone401 0:a4d93cd4c30d 1166 break;
casiotone401 4:b9f5ae574447 1167
casiotone401 0:a4d93cd4c30d 1168 } else if ((strncmp(msg[0].address,"/1/multipush",12)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1169 if(num > 3) break;
casiotone401 0:a4d93cd4c30d 1170 if(absv >= 1 || msg[2].i >= 1) gLEDS[num] = gGATES[num] = 1;
casiotone401 0:a4d93cd4c30d 1171 else gLEDS[num] = gGATES[num] = 0;
casiotone401 0:a4d93cd4c30d 1172 break;
casiotone401 0:a4d93cd4c30d 1173 }
casiotone401 0:a4d93cd4c30d 1174
casiotone401 0:a4d93cd4c30d 1175 // address pattern CV (Type Tag float)
casiotone401 3:ca15241dd6b4 1176 if((strncmp(msg[0].address+(len-1)-2, "cv", 2)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1177 if(num > 7) break;
casiotone401 0:a4d93cd4c30d 1178 if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
casiotone401 0:a4d93cd4c30d 1179 break;
casiotone401 0:a4d93cd4c30d 1180 // (touchOSC Control fader, rotary, xy, multixy, multifader)
casiotone401 3:ca15241dd6b4 1181 } else if ((strncmp(msg[0].address+(len-1)-5, "fader", 5)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1182 if(num > 7) break;
casiotone401 0:a4d93cd4c30d 1183 if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
casiotone401 0:a4d93cd4c30d 1184 break;
casiotone401 0:a4d93cd4c30d 1185
casiotone401 3:ca15241dd6b4 1186 } else if ((strncmp(msg[0].address+(len-1)-6, "rotary", 6)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1187 if(num > 7) break;
casiotone401 0:a4d93cd4c30d 1188 if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
casiotone401 0:a4d93cd4c30d 1189 break;
casiotone401 0:a4d93cd4c30d 1190
casiotone401 3:ca15241dd6b4 1191 } else if ((strncmp(msg[0].address+(len-1)-2, "xy", 2)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1192 if(num > 7) break;
casiotone401 0:a4d93cd4c30d 1193 if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
casiotone401 0:a4d93cd4c30d 1194 if(msg[1].typeTag[1] == 'f') gOSC_cv[++num] = msg[3].f * (SCALING_N);
casiotone401 0:a4d93cd4c30d 1195 break;
casiotone401 0:a4d93cd4c30d 1196
casiotone401 3:ca15241dd6b4 1197 } else if ((strncmp(msg[0].address+(len-1)-9, "multixy1/", 9)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1198 if(num > 7) break;
casiotone401 0:a4d93cd4c30d 1199 if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
casiotone401 0:a4d93cd4c30d 1200 if(msg[1].typeTag[1] == 'f') gOSC_cv[++num] = msg[3].f * (SCALING_N);
casiotone401 0:a4d93cd4c30d 1201 break;
casiotone401 0:a4d93cd4c30d 1202
casiotone401 3:ca15241dd6b4 1203 } else if ((strncmp(msg[0].address+(len-1)-12, "multifader1/", 12)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1204 if(num > 7) break;
casiotone401 0:a4d93cd4c30d 1205 if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
casiotone401 4:b9f5ae574447 1206 break;
casiotone401 5:e305509d53f3 1207 // (touchOSC multifader for Sequencer Mode)
casiotone401 4:b9f5ae574447 1208 } else if ((strncmp(msg[0].address+(len-1)-11, "sequencer1/", 11)==0) && (num != -1)) {
casiotone401 4:b9f5ae574447 1209 if(num > 7) break;
casiotone401 4:b9f5ae574447 1210 if(msg[1].typeTag[1] == 'f') gSeq_cv1[num] = msg[2].f * (SCALING_N);
casiotone401 4:b9f5ae574447 1211 break;
casiotone401 5:e305509d53f3 1212
casiotone401 4:b9f5ae574447 1213 } else if ((strncmp(msg[0].address+(len-1)-11, "sequencer2/", 11)==0) && (num != -1)) {
casiotone401 4:b9f5ae574447 1214 if(num > 7) break;
casiotone401 4:b9f5ae574447 1215 if(msg[1].typeTag[1] == 'f') gSeq_cv2[num] = msg[2].f * (SCALING_N);
casiotone401 4:b9f5ae574447 1216 break;
casiotone401 4:b9f5ae574447 1217 }
casiotone401 4:b9f5ae574447 1218
casiotone401 5:e305509d53f3 1219 // address pattern for control
casiotone401 4:b9f5ae574447 1220 if ((strncmp(msg[0].address+(len-1)-6, "ctrlsw", 6)==0) && (num != -1)) {
casiotone401 5:e305509d53f3 1221 if(num > 4) break;
casiotone401 4:b9f5ae574447 1222 if(absv >= 1 || msg[2].i >= 1) gCtrlSW[num] = 1;
casiotone401 4:b9f5ae574447 1223 else gCtrlSW[num] = 0;
casiotone401 4:b9f5ae574447 1224 break;
casiotone401 4:b9f5ae574447 1225
casiotone401 4:b9f5ae574447 1226 } else if ((strncmp(msg[0].address+(len-1)-4, "ctrl", 4)==0) && (num != -1)) {
casiotone401 4:b9f5ae574447 1227 if(num > 2) break;
casiotone401 4:b9f5ae574447 1228 if(msg[1].typeTag[1] == 'f') gCtrl[num] = msg[2].f;
casiotone401 4:b9f5ae574447 1229 break;
casiotone401 4:b9f5ae574447 1230 }
casiotone401 4:b9f5ae574447 1231 }
casiotone401 4:b9f5ae574447 1232 }
casiotone401 0:a4d93cd4c30d 1233 }