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:
Mon Jan 28 12:30:15 2013 +0000
Revision:
6:5796b63c70ef
Parent:
5:e305509d53f3
Child:
7:a04f8378662e
bug fix

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 4:b9f5ae574447 232 static float gOSC_cv[8];
casiotone401 4:b9f5ae574447 233 static float gSeq_cv1[8];
casiotone401 4:b9f5ae574447 234 static float gSeq_cv2[8];
casiotone401 4:b9f5ae574447 235 static 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 6:5796b63c70ef 271 static 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 4:b9f5ae574447 699 static int ch;
casiotone401 5:e305509d53f3 700 static int cnt1, cnt2, cnt3;
casiotone401 5:e305509d53f3 701 static int cntloop1, cntloop2, cntloop3;
casiotone401 6:5796b63c70ef 702 static int SeqMode;
casiotone401 4:b9f5ae574447 703 static float glidecv[8];
casiotone401 4:b9f5ae574447 704 unsigned int cv[8];
casiotone401 4:b9f5ae574447 705 static float shiftcv[8];
casiotone401 5:e305509d53f3 706 static float buffercv[9];
casiotone401 5:e305509d53f3 707 static float loopcv[3];
casiotone401 4:b9f5ae574447 708 static unsigned int quan;
casiotone401 4:b9f5ae574447 709 float qcv;
casiotone401 4:b9f5ae574447 710
casiotone401 5:e305509d53f3 711 SeqMode = (unsigned int)(gCtrl[1] * (MODE_NUM - 3)); // Sequencer Quantize Mode (gCtrl[1])
casiotone401 4:b9f5ae574447 712
casiotone401 4:b9f5ae574447 713 switch(SeqMode)
casiotone401 4:b9f5ae574447 714 {
casiotone401 4:b9f5ae574447 715 case MODE_LIN:
casiotone401 4:b9f5ae574447 716
casiotone401 4:b9f5ae574447 717 if(ch < 8)
casiotone401 4:b9f5ae574447 718 {
casiotone401 4:b9f5ae574447 719 glidecv[0] = glidecv[0] * gGlide + gSeq_cv1[ch] * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 720
casiotone401 4:b9f5ae574447 721 } else {
casiotone401 4:b9f5ae574447 722
casiotone401 4:b9f5ae574447 723 glidecv[0] = glidecv[0] * gGlide + gSeq_cv2[ch-8] * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 724 }
casiotone401 4:b9f5ae574447 725
casiotone401 4:b9f5ae574447 726 cv[0] = (unsigned int)glidecv[0];
casiotone401 4:b9f5ae574447 727
casiotone401 4:b9f5ae574447 728 UpdateCV(WRITE_UPDATE_N, 0, &cv[0]);
casiotone401 4:b9f5ae574447 729 break;
casiotone401 4:b9f5ae574447 730
casiotone401 4:b9f5ae574447 731 case MODE_QChr:
casiotone401 4:b9f5ae574447 732
casiotone401 4:b9f5ae574447 733 quan = 40616 / QUAN_RES1;
casiotone401 4:b9f5ae574447 734
casiotone401 4:b9f5ae574447 735 if(ch < 8)
casiotone401 4:b9f5ae574447 736 {
casiotone401 4:b9f5ae574447 737 qcv = calibMap1[(unsigned int)(gSeq_cv1[ch] / quan)];
casiotone401 4:b9f5ae574447 738
casiotone401 4:b9f5ae574447 739 } else {
casiotone401 4:b9f5ae574447 740
casiotone401 4:b9f5ae574447 741 qcv = calibMap1[(unsigned int)(gSeq_cv2[ch-8] / quan)];
casiotone401 4:b9f5ae574447 742 }
casiotone401 4:b9f5ae574447 743
casiotone401 4:b9f5ae574447 744 glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 745 cv[0] = (unsigned int)glidecv[0];
casiotone401 4:b9f5ae574447 746
casiotone401 4:b9f5ae574447 747 UpdateCV(WRITE_UPDATE_N, 0, &cv[0]);
casiotone401 4:b9f5ae574447 748 break;
casiotone401 4:b9f5ae574447 749
casiotone401 4:b9f5ae574447 750 case MODE_QMaj:
casiotone401 4:b9f5ae574447 751
casiotone401 4:b9f5ae574447 752 quan = 40616 / QUAN_RES2;
casiotone401 4:b9f5ae574447 753
casiotone401 4:b9f5ae574447 754 if(ch < 8)
casiotone401 4:b9f5ae574447 755 {
casiotone401 4:b9f5ae574447 756 qcv = calibMap2[(unsigned int)(gSeq_cv1[ch] / quan)];
casiotone401 4:b9f5ae574447 757
casiotone401 4:b9f5ae574447 758 } else {
casiotone401 4:b9f5ae574447 759
casiotone401 4:b9f5ae574447 760 qcv = calibMap2[(unsigned int)(gSeq_cv2[ch-8] / quan)];
casiotone401 4:b9f5ae574447 761 }
casiotone401 4:b9f5ae574447 762
casiotone401 4:b9f5ae574447 763 glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 764 cv[0] = (unsigned int)glidecv[0];
casiotone401 4:b9f5ae574447 765
casiotone401 4:b9f5ae574447 766 UpdateCV(WRITE_UPDATE_N, 0, &cv[0]);
casiotone401 4:b9f5ae574447 767 break;
casiotone401 4:b9f5ae574447 768
casiotone401 4:b9f5ae574447 769 case MODE_QDor:
casiotone401 4:b9f5ae574447 770
casiotone401 4:b9f5ae574447 771 quan = 40616 / QUAN_RES3;
casiotone401 4:b9f5ae574447 772
casiotone401 4:b9f5ae574447 773 if(ch < 8)
casiotone401 4:b9f5ae574447 774 {
casiotone401 4:b9f5ae574447 775 qcv = calibMap3[(unsigned int)(gSeq_cv1[ch] / quan)];
casiotone401 4:b9f5ae574447 776
casiotone401 4:b9f5ae574447 777 } else {
casiotone401 4:b9f5ae574447 778
casiotone401 4:b9f5ae574447 779 qcv = calibMap3[(unsigned int)(gSeq_cv2[ch-8] / quan)];
casiotone401 4:b9f5ae574447 780 }
casiotone401 4:b9f5ae574447 781
casiotone401 4:b9f5ae574447 782 glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 783 cv[0] = (unsigned int)glidecv[0];
casiotone401 4:b9f5ae574447 784
casiotone401 4:b9f5ae574447 785 UpdateCV(WRITE_UPDATE_N, 0, &cv[0]);
casiotone401 4:b9f5ae574447 786 break;
casiotone401 4:b9f5ae574447 787
casiotone401 4:b9f5ae574447 788 case MODE_Q5th:
casiotone401 4:b9f5ae574447 789
casiotone401 4:b9f5ae574447 790 quan = 40616 / QUAN_RES4;
casiotone401 4:b9f5ae574447 791
casiotone401 4:b9f5ae574447 792 if(ch < 8)
casiotone401 4:b9f5ae574447 793 {
casiotone401 4:b9f5ae574447 794 qcv = calibMap4[(unsigned int)(gSeq_cv1[ch] / quan)];
casiotone401 4:b9f5ae574447 795
casiotone401 4:b9f5ae574447 796 } else {
casiotone401 4:b9f5ae574447 797
casiotone401 4:b9f5ae574447 798 qcv = calibMap4[(unsigned int)(gSeq_cv2[ch-8] / quan)];
casiotone401 4:b9f5ae574447 799 }
casiotone401 4:b9f5ae574447 800
casiotone401 4:b9f5ae574447 801 glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 802 cv[0] = (unsigned int)glidecv[0];
casiotone401 4:b9f5ae574447 803
casiotone401 4:b9f5ae574447 804 UpdateCV(WRITE_UPDATE_N, 0, &cv[0]);
casiotone401 4:b9f5ae574447 805 break;
casiotone401 4:b9f5ae574447 806
casiotone401 4:b9f5ae574447 807 case MODE_QWht:
casiotone401 4:b9f5ae574447 808
casiotone401 4:b9f5ae574447 809 quan = 40616 / QUAN_RES5;
casiotone401 4:b9f5ae574447 810
casiotone401 4:b9f5ae574447 811 if(ch < 8)
casiotone401 4:b9f5ae574447 812 {
casiotone401 4:b9f5ae574447 813 qcv = calibMap5[(unsigned int)(gSeq_cv1[ch] / quan)];
casiotone401 4:b9f5ae574447 814
casiotone401 4:b9f5ae574447 815 } else {
casiotone401 4:b9f5ae574447 816
casiotone401 4:b9f5ae574447 817 qcv = calibMap5[(unsigned int)(gSeq_cv2[ch-8] / quan)];
casiotone401 4:b9f5ae574447 818 }
casiotone401 4:b9f5ae574447 819
casiotone401 4:b9f5ae574447 820 glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide);
casiotone401 4:b9f5ae574447 821 cv[0] = (unsigned int)glidecv[0];
casiotone401 4:b9f5ae574447 822
casiotone401 4:b9f5ae574447 823 UpdateCV(WRITE_UPDATE_N, 0, &cv[0]);
casiotone401 4:b9f5ae574447 824 break;
casiotone401 4:b9f5ae574447 825 }
casiotone401 4:b9f5ae574447 826
casiotone401 6:5796b63c70ef 827 if((gCtrlSW[2] == 0 || gCtrlSW[2] == 1) && gCtrlSW[3] == 0)// Sequencer Mode1
casiotone401 4:b9f5ae574447 828 {
casiotone401 6:5796b63c70ef 829 for(i = 1; i < 8; ++i)
casiotone401 5:e305509d53f3 830 {
casiotone401 5:e305509d53f3 831 glidecv[i] = glidecv[i] * gGlide + shiftcv[i] * (1.0f - gGlide);
casiotone401 5:e305509d53f3 832 cv[i] = (unsigned int)glidecv[i];
casiotone401 5:e305509d53f3 833
casiotone401 5:e305509d53f3 834 UpdateCV(WRITE_UPDATE_N, i, &cv[i]);
casiotone401 6:5796b63c70ef 835
casiotone401 6:5796b63c70ef 836 if(shift == 1) // GATE1
casiotone401 6:5796b63c70ef 837 {
casiotone401 6:5796b63c70ef 838 for(i = 1; i < 8; ++i) // Shift ch2~8
casiotone401 6:5796b63c70ef 839 {
casiotone401 6:5796b63c70ef 840 shiftcv[i] = glidecv[i-1];
casiotone401 6:5796b63c70ef 841 }
casiotone401 6:5796b63c70ef 842
casiotone401 6:5796b63c70ef 843 ch++;
casiotone401 6:5796b63c70ef 844 ch &= 0x0F;
casiotone401 6:5796b63c70ef 845 }
casiotone401 6:5796b63c70ef 846
casiotone401 6:5796b63c70ef 847 cnt1 = cnt2 = cnt3 = 0;
casiotone401 5:e305509d53f3 848 }
casiotone401 4:b9f5ae574447 849
casiotone401 5:e305509d53f3 850 } else if (gCtrlSW[2] == 1 && gCtrlSW[3] == 0) { // Sequencer Mode2
casiotone401 5:e305509d53f3 851
casiotone401 5:e305509d53f3 852 if(shift == 1) // GATE1
casiotone401 5:e305509d53f3 853 {
casiotone401 6:5796b63c70ef 854 for(j = 1; j < 5; ++j)
casiotone401 5:e305509d53f3 855 {
casiotone401 5:e305509d53f3 856 shiftcv[j] = glidecv[j-1]; // Shift ch2~5
casiotone401 5:e305509d53f3 857 }
casiotone401 5:e305509d53f3 858
casiotone401 5:e305509d53f3 859 ch++;
casiotone401 5:e305509d53f3 860 ch &= 0x0F;
casiotone401 5:e305509d53f3 861
casiotone401 5:e305509d53f3 862 } else if (shift == 2) { // GATE2
casiotone401 5:e305509d53f3 863
casiotone401 5:e305509d53f3 864 shiftcv[5] = glidecv[1]; // Shift ch6
casiotone401 5:e305509d53f3 865
casiotone401 5:e305509d53f3 866 } else if (shift == 3) { // GATE3
casiotone401 5:e305509d53f3 867
casiotone401 5:e305509d53f3 868 shiftcv[6] = glidecv[2]; // Shift ch7
casiotone401 5:e305509d53f3 869
casiotone401 5:e305509d53f3 870 } else if (shift == 4) { // GATE4
casiotone401 5:e305509d53f3 871
casiotone401 5:e305509d53f3 872 shiftcv[7] = glidecv[3]; // Shift ch8
casiotone401 6:5796b63c70ef 873 }
casiotone401 6:5796b63c70ef 874
casiotone401 5:e305509d53f3 875 } else if (gCtrlSW[3] == 1) { // Sequencer Mode3
casiotone401 5:e305509d53f3 876
casiotone401 6:5796b63c70ef 877 for(j = 1; j < 5; ++j)
casiotone401 6:5796b63c70ef 878 {
casiotone401 6:5796b63c70ef 879 glidecv[j] = glidecv[j] * gGlide + shiftcv[j] * (1.0f - gGlide);
casiotone401 6:5796b63c70ef 880 cv[j] = (unsigned int)glidecv[j];
casiotone401 6:5796b63c70ef 881
casiotone401 6:5796b63c70ef 882 UpdateCV(WRITE_UPDATE_N, j, &cv[j]);
casiotone401 6:5796b63c70ef 883 }
casiotone401 6:5796b63c70ef 884
casiotone401 6:5796b63c70ef 885 for(k = 5; k < 8; ++k)
casiotone401 6:5796b63c70ef 886 {
casiotone401 6:5796b63c70ef 887 glidecv[k] = glidecv[k] * gGlide + loopcv[k - 5] * (1.0f - gGlide);
casiotone401 6:5796b63c70ef 888 cv[k] = (unsigned int)glidecv[k];
casiotone401 6:5796b63c70ef 889
casiotone401 6:5796b63c70ef 890 UpdateCV(WRITE_UPDATE_N, k, &cv[k]);
casiotone401 6:5796b63c70ef 891 }
casiotone401 6:5796b63c70ef 892
casiotone401 5:e305509d53f3 893 if(shift == 1) // GATE1
casiotone401 5:e305509d53f3 894 {
casiotone401 6:5796b63c70ef 895 for(i = 1; i < 8; ++i)
casiotone401 5:e305509d53f3 896 {
casiotone401 5:e305509d53f3 897 shiftcv[i] = glidecv[i-1]; // Shift ch2~5
casiotone401 5:e305509d53f3 898 }
casiotone401 5:e305509d53f3 899
casiotone401 5:e305509d53f3 900 ch++;
casiotone401 5:e305509d53f3 901 ch &= 0x0F;
casiotone401 5:e305509d53f3 902
casiotone401 5:e305509d53f3 903 } else if (shift == 2) { // GATE2
casiotone401 5:e305509d53f3 904
casiotone401 5:e305509d53f3 905 if(cnt1 < 4)
casiotone401 5:e305509d53f3 906 {
casiotone401 5:e305509d53f3 907 loopcv[0] = buffercv[cnt1] = shiftcv[4];
casiotone401 5:e305509d53f3 908
casiotone401 5:e305509d53f3 909 cnt1++;
casiotone401 5:e305509d53f3 910
casiotone401 5:e305509d53f3 911 } else if (cnt1 >= 4) {
casiotone401 5:e305509d53f3 912
casiotone401 5:e305509d53f3 913 loopcv[0] = buffercv[cntloop1];
casiotone401 5:e305509d53f3 914
casiotone401 5:e305509d53f3 915 cntloop1++;
casiotone401 5:e305509d53f3 916 cntloop1 &= 0x03;
casiotone401 5:e305509d53f3 917 }
casiotone401 5:e305509d53f3 918
casiotone401 5:e305509d53f3 919 } else if (shift == 3) { // GATE3
casiotone401 5:e305509d53f3 920
casiotone401 5:e305509d53f3 921 if(cnt2 < 3)
casiotone401 5:e305509d53f3 922 {
casiotone401 5:e305509d53f3 923 loopcv[1] = buffercv[(cnt2 + 4)] = shiftcv[5];
casiotone401 5:e305509d53f3 924
casiotone401 5:e305509d53f3 925 cnt2++;
casiotone401 5:e305509d53f3 926
casiotone401 5:e305509d53f3 927 } else if (cnt2 >= 3) {
casiotone401 5:e305509d53f3 928
casiotone401 5:e305509d53f3 929 loopcv[1] = buffercv[(cntloop2 + 4)];
casiotone401 5:e305509d53f3 930
casiotone401 5:e305509d53f3 931 cntloop2++;
casiotone401 5:e305509d53f3 932 cntloop2 &= 0x03;
casiotone401 5:e305509d53f3 933 }
casiotone401 5:e305509d53f3 934
casiotone401 5:e305509d53f3 935 } else if (shift == 4) { // GATE4
casiotone401 5:e305509d53f3 936
casiotone401 5:e305509d53f3 937 if(cnt3 < 2)
casiotone401 5:e305509d53f3 938 {
casiotone401 5:e305509d53f3 939 loopcv[2] = buffercv[(cnt3 + 7)] = shiftcv[6];
casiotone401 5:e305509d53f3 940
casiotone401 5:e305509d53f3 941 cnt3++;
casiotone401 5:e305509d53f3 942
casiotone401 5:e305509d53f3 943 } else if (cnt3 >= 2) {
casiotone401 5:e305509d53f3 944
casiotone401 5:e305509d53f3 945 loopcv[2] = buffercv[(cntloop3 + 7)];
casiotone401 5:e305509d53f3 946
casiotone401 5:e305509d53f3 947 cntloop3++;
casiotone401 5:e305509d53f3 948 cntloop3 &= 0x01;
casiotone401 5:e305509d53f3 949 }
casiotone401 5:e305509d53f3 950 }
casiotone401 5:e305509d53f3 951
casiotone401 5:e305509d53f3 952 if(gCtrlSW[1] == 1) // Update loop buffer (if gCtrlSW[1] ON)
casiotone401 5:e305509d53f3 953 {
casiotone401 5:e305509d53f3 954 cnt1 = cnt2 = cnt3 = 0;
casiotone401 5:e305509d53f3 955 }
casiotone401 4:b9f5ae574447 956 }
casiotone401 4:b9f5ae574447 957
casiotone401 4:b9f5ae574447 958 if(ch < 8)
casiotone401 4:b9f5ae574447 959 {
casiotone401 4:b9f5ae574447 960 CVMeter(ch, &cv[0]);
casiotone401 4:b9f5ae574447 961
casiotone401 4:b9f5ae574447 962 } else {
casiotone401 4:b9f5ae574447 963
casiotone401 4:b9f5ae574447 964 CVMeter((ch-8), &cv[0]);
casiotone401 4:b9f5ae574447 965 }
casiotone401 4:b9f5ae574447 966 }
casiotone401 4:b9f5ae574447 967
casiotone401 4:b9f5ae574447 968 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 969 // Check SW
casiotone401 0:a4d93cd4c30d 970
casiotone401 5:e305509d53f3 971 void CheckModeSW()
casiotone401 0:a4d93cd4c30d 972 {
casiotone401 5:e305509d53f3 973 wait(0.02);
casiotone401 4:b9f5ae574447 974
casiotone401 3:ca15241dd6b4 975 if(gMode < MODE_NUM - 1)
casiotone401 0:a4d93cd4c30d 976 {
casiotone401 0:a4d93cd4c30d 977 gMode++;
casiotone401 3:ca15241dd6b4 978
casiotone401 0:a4d93cd4c30d 979 } else {
casiotone401 4:b9f5ae574447 980
casiotone401 0:a4d93cd4c30d 981 gMode = 0;
casiotone401 0:a4d93cd4c30d 982 }
casiotone401 3:ca15241dd6b4 983
casiotone401 5:e305509d53f3 984 gCLOCKOUT = gGATES[0] = gGATES[1] = gGATES[2] = gGATES[3] = 0;
casiotone401 5:e305509d53f3 985 gLEDS[0] = gLEDS[1] = gLEDS[2] = gLEDS[3] = 0;
casiotone401 5:e305509d53f3 986
casiotone401 5:e305509d53f3 987 if(gMode == MODE_SEQ)
casiotone401 5:e305509d53f3 988 {
casiotone401 5:e305509d53f3 989 gTimer.start(); // Sequencer Timer Start
casiotone401 5:e305509d53f3 990
casiotone401 5:e305509d53f3 991 } else {
casiotone401 5:e305509d53f3 992
casiotone401 5:e305509d53f3 993 gTimer.stop(); // Sequencer Timer Stop
casiotone401 5:e305509d53f3 994 }
casiotone401 5:e305509d53f3 995
casiotone401 4:b9f5ae574447 996 LCD();
casiotone401 4:b9f5ae574447 997 }
casiotone401 4:b9f5ae574447 998
casiotone401 4:b9f5ae574447 999 //-------------------------------------------------------------
casiotone401 4:b9f5ae574447 1000 // CV meter
casiotone401 4:b9f5ae574447 1001
casiotone401 4:b9f5ae574447 1002 void CVMeter(int ch, const unsigned int *level)
casiotone401 4:b9f5ae574447 1003 {
casiotone401 6:5796b63c70ef 1004 static unsigned int cvmeter;
casiotone401 4:b9f5ae574447 1005
casiotone401 5:e305509d53f3 1006 cvmeter = *level / (SCALING_N / 7.9);
casiotone401 4:b9f5ae574447 1007
casiotone401 4:b9f5ae574447 1008 gLCD.locate ( ch, 0 );
casiotone401 4:b9f5ae574447 1009 gLCD.putc(cvmeter); // put custom char
casiotone401 4:b9f5ae574447 1010 }
casiotone401 4:b9f5ae574447 1011
casiotone401 4:b9f5ae574447 1012 //-------------------------------------------------------------
casiotone401 5:e305509d53f3 1013 // Print LCD Mode Status
casiotone401 4:b9f5ae574447 1014
casiotone401 4:b9f5ae574447 1015 void LCD()
casiotone401 4:b9f5ae574447 1016 {
casiotone401 3:ca15241dd6b4 1017 switch(gMode)
casiotone401 3:ca15241dd6b4 1018 {
casiotone401 3:ca15241dd6b4 1019 case MODE_LIN:
casiotone401 3:ca15241dd6b4 1020 gLCD.locate( 9, 0 );
casiotone401 3:ca15241dd6b4 1021 gLCD.printf("OSC-CV ");
casiotone401 3:ca15241dd6b4 1022 break;
casiotone401 3:ca15241dd6b4 1023
casiotone401 3:ca15241dd6b4 1024 case MODE_QChr:
casiotone401 3:ca15241dd6b4 1025 gLCD.locate( 9, 0 );
casiotone401 3:ca15241dd6b4 1026 gLCD.printf("QUAN_C ");
casiotone401 3:ca15241dd6b4 1027 break;
casiotone401 3:ca15241dd6b4 1028
casiotone401 3:ca15241dd6b4 1029 case MODE_QMaj:
casiotone401 3:ca15241dd6b4 1030 gLCD.locate( 9, 0 );
casiotone401 3:ca15241dd6b4 1031 gLCD.printf("QUAN_M ");
casiotone401 3:ca15241dd6b4 1032 break;
casiotone401 3:ca15241dd6b4 1033
casiotone401 3:ca15241dd6b4 1034 case MODE_QDor:
casiotone401 3:ca15241dd6b4 1035 gLCD.locate( 9, 0 );
casiotone401 3:ca15241dd6b4 1036 gLCD.printf("QUAN_D ");
casiotone401 3:ca15241dd6b4 1037 break;
casiotone401 3:ca15241dd6b4 1038
casiotone401 3:ca15241dd6b4 1039 case MODE_Q5th:
casiotone401 3:ca15241dd6b4 1040 gLCD.locate( 9, 0 );
casiotone401 3:ca15241dd6b4 1041 gLCD.printf("QUAN_5 ");
casiotone401 3:ca15241dd6b4 1042 break;
casiotone401 3:ca15241dd6b4 1043
casiotone401 3:ca15241dd6b4 1044 case MODE_QWht:
casiotone401 3:ca15241dd6b4 1045 gLCD.locate( 9, 0 );
casiotone401 3:ca15241dd6b4 1046 gLCD.printf("QUAN_W ");
casiotone401 3:ca15241dd6b4 1047 break;
casiotone401 4:b9f5ae574447 1048
casiotone401 4:b9f5ae574447 1049 case MODE_SEQ:
casiotone401 4:b9f5ae574447 1050 gLCD.locate( 9, 0 );
casiotone401 4:b9f5ae574447 1051 gLCD.printf("ASRSEQ ");
casiotone401 4:b9f5ae574447 1052 break;
casiotone401 4:b9f5ae574447 1053
casiotone401 4:b9f5ae574447 1054 case MODE_Calb:
casiotone401 4:b9f5ae574447 1055 gLCD.locate( 9, 0 );
casiotone401 4:b9f5ae574447 1056 gLCD.printf("Calibr ");
casiotone401 4:b9f5ae574447 1057 break;
casiotone401 3:ca15241dd6b4 1058 }
casiotone401 0:a4d93cd4c30d 1059 }
casiotone401 0:a4d93cd4c30d 1060
casiotone401 0:a4d93cd4c30d 1061 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 1062 // Write command Custom Char LCD CGRAM(CV Meter)
casiotone401 0:a4d93cd4c30d 1063
casiotone401 0:a4d93cd4c30d 1064 void WriteCustomChar(unsigned char addr, unsigned char *c)
casiotone401 0:a4d93cd4c30d 1065 {
casiotone401 0:a4d93cd4c30d 1066 char cnt = 0;
casiotone401 0:a4d93cd4c30d 1067 addr = ((addr << 3) | 0x40);
casiotone401 0:a4d93cd4c30d 1068
casiotone401 0:a4d93cd4c30d 1069 while(cnt < 0x08)
casiotone401 0:a4d93cd4c30d 1070 {
casiotone401 0:a4d93cd4c30d 1071 gLCD.writeCommand(addr | cnt);
casiotone401 0:a4d93cd4c30d 1072 gLCD.writeData(*c);
casiotone401 4:b9f5ae574447 1073
casiotone401 0:a4d93cd4c30d 1074 cnt++;
casiotone401 0:a4d93cd4c30d 1075 c++;
casiotone401 0:a4d93cd4c30d 1076 }
casiotone401 0:a4d93cd4c30d 1077 }
casiotone401 0:a4d93cd4c30d 1078
casiotone401 0:a4d93cd4c30d 1079 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 1080 // Setup Ethernet port
casiotone401 0:a4d93cd4c30d 1081
casiotone401 0:a4d93cd4c30d 1082 int SetupEthNetIf()
casiotone401 0:a4d93cd4c30d 1083 {
casiotone401 0:a4d93cd4c30d 1084 gLCD.locate( 0, 1 );
casiotone401 0:a4d93cd4c30d 1085 gLCD.printf("Setting up... ");
casiotone401 0:a4d93cd4c30d 1086 // printf("Setting up...\r\n");
casiotone401 0:a4d93cd4c30d 1087 EthernetErr ethErr = gEth.setup();
casiotone401 0:a4d93cd4c30d 1088
casiotone401 0:a4d93cd4c30d 1089 if(ethErr)
casiotone401 0:a4d93cd4c30d 1090 {
casiotone401 0:a4d93cd4c30d 1091 gLCD.locate( 0, 1 );
casiotone401 0:a4d93cd4c30d 1092 gLCD.printf("Error in setup.");
casiotone401 0:a4d93cd4c30d 1093 // printf("Error %d in setup.\r\n", ethErr);
casiotone401 0:a4d93cd4c30d 1094 return -1;
casiotone401 0:a4d93cd4c30d 1095 }
casiotone401 0:a4d93cd4c30d 1096 // printf("Setup OK\r\n");
casiotone401 0:a4d93cd4c30d 1097
casiotone401 0:a4d93cd4c30d 1098 // printf("IP address %d.%d.%d.%d\r\n", gEth.getIp()[0], gEth.getIp()[1], gEth.getIp()[2], gEth.getIp()[3]);
casiotone401 0:a4d93cd4c30d 1099 Host broadcast(IpAddr(gEth.getIp()[0], gEth.getIp()[1], gEth.getIp()[2], 255), INPUT_PORT, NULL);
casiotone401 0:a4d93cd4c30d 1100 gUdp.setOnEvent(&onUDPSocketEvent);
casiotone401 0:a4d93cd4c30d 1101 gUdp.bind(broadcast);
casiotone401 4:b9f5ae574447 1102
casiotone401 0:a4d93cd4c30d 1103 gLCD.locate( 0, 1 );
casiotone401 0:a4d93cd4c30d 1104 gLCD.printf("%03d.%03d.%03d.%03d", gEth.getIp()[0], gEth.getIp()[1], gEth.getIp()[2], gEth.getIp()[3]);
casiotone401 4:b9f5ae574447 1105 wait(1.0);
casiotone401 0:a4d93cd4c30d 1106
casiotone401 0:a4d93cd4c30d 1107 return 0;
casiotone401 0:a4d93cd4c30d 1108 }
casiotone401 0:a4d93cd4c30d 1109
casiotone401 0:a4d93cd4c30d 1110 //-------------------------------------------------------------
casiotone401 0:a4d93cd4c30d 1111 // Handller receive UDP Packet
casiotone401 0:a4d93cd4c30d 1112
casiotone401 4:b9f5ae574447 1113 inline void onUDPSocketEvent(UDPSocketEvent e)
casiotone401 0:a4d93cd4c30d 1114 {
casiotone401 0:a4d93cd4c30d 1115 union OSCarg msg[10];
casiotone401 0:a4d93cd4c30d 1116 static int num;
casiotone401 6:5796b63c70ef 1117 unsigned int absv;
casiotone401 6:5796b63c70ef 1118
casiotone401 0:a4d93cd4c30d 1119 switch(e)
casiotone401 0:a4d93cd4c30d 1120 {
casiotone401 4:b9f5ae574447 1121 case UDPSOCKET_READABLE: // The only event for now
casiotone401 0:a4d93cd4c30d 1122 char buf[256] = {0};
casiotone401 0:a4d93cd4c30d 1123 Host host;
casiotone401 0:a4d93cd4c30d 1124
casiotone401 0:a4d93cd4c30d 1125 while( int len = gUdp.recvfrom( buf, 256, &host ))
casiotone401 0:a4d93cd4c30d 1126 {
casiotone401 0:a4d93cd4c30d 1127 if(len <= 0) break;
casiotone401 0:a4d93cd4c30d 1128 // printf("\r\nFrom %d.%d.%d.%d:\r\n",
casiotone401 0:a4d93cd4c30d 1129 // host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3]);
casiotone401 0:a4d93cd4c30d 1130
casiotone401 0:a4d93cd4c30d 1131 getOSCmsg(buf,msg);
casiotone401 0:a4d93cd4c30d 1132 // printf("OSCmsg: %s %s %f %i\r\n",
casiotone401 0:a4d93cd4c30d 1133 // msg[0].address, msg[1].typeTag, msg[2].f, msg[2].i);
casiotone401 0:a4d93cd4c30d 1134
casiotone401 0:a4d93cd4c30d 1135 len = strlen(msg[0].address);
casiotone401 4:b9f5ae574447 1136
casiotone401 4:b9f5ae574447 1137 if(isdigit(msg[0].address[len-1]))
casiotone401 4:b9f5ae574447 1138
casiotone401 4:b9f5ae574447 1139 num = msg[0].address[len-1] - '0' - 1;
casiotone401 4:b9f5ae574447 1140 else
casiotone401 4:b9f5ae574447 1141 num = -1;
casiotone401 4:b9f5ae574447 1142
casiotone401 6:5796b63c70ef 1143 absv = msg[2].f + 0; //convert -0 to 0
casiotone401 0:a4d93cd4c30d 1144
casiotone401 5:e305509d53f3 1145 // address pattern SYNC & GATE (Type Tag int, float)
casiotone401 6:5796b63c70ef 1146 if(strncmp(msg[0].address+(len-1)-4, "sync", 4)==0) {
casiotone401 0:a4d93cd4c30d 1147 if(absv >= 1 || msg[2].i >= 1) gCLOCKOUT = 1;
casiotone401 0:a4d93cd4c30d 1148 else gCLOCKOUT = 0;
casiotone401 0:a4d93cd4c30d 1149 break;
casiotone401 0:a4d93cd4c30d 1150
casiotone401 3:ca15241dd6b4 1151 } else if ((strncmp(msg[0].address+(len-1)-4, "gate", 4)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1152 if(num > 3) break;
casiotone401 0:a4d93cd4c30d 1153 if(absv >= 1 || msg[2].i >= 1) gLEDS[num] = gGATES[num] = 1;
casiotone401 0:a4d93cd4c30d 1154 else gLEDS[num] = gGATES[num] = 0;
casiotone401 0:a4d93cd4c30d 1155 break;
casiotone401 5:e305509d53f3 1156 // (touchOSC Control push, toggle)
casiotone401 3:ca15241dd6b4 1157 } else if ((strncmp(msg[0].address+(len-1)-4, "push", 4)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1158 if(num > 3) break;
casiotone401 0:a4d93cd4c30d 1159 if(absv >= 1 || msg[2].i >= 1) gLEDS[num] = gGATES[num] = 1;
casiotone401 0:a4d93cd4c30d 1160 else gLEDS[num] = gGATES[num] = 0;
casiotone401 0:a4d93cd4c30d 1161 break;
casiotone401 0:a4d93cd4c30d 1162
casiotone401 3:ca15241dd6b4 1163 } else if ((strncmp(msg[0].address+(len-1)-6, "toggle", 6)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1164 if(num > 3) break;
casiotone401 0:a4d93cd4c30d 1165 if(absv >= 1 || msg[2].i >= 1) gLEDS[num] = gGATES[num] = 1;
casiotone401 0:a4d93cd4c30d 1166 else gLEDS[num] = gGATES[num] = 0;
casiotone401 0:a4d93cd4c30d 1167 break;
casiotone401 4:b9f5ae574447 1168
casiotone401 0:a4d93cd4c30d 1169 } else if ((strncmp(msg[0].address,"/1/multipush",12)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1170 if(num > 3) break;
casiotone401 0:a4d93cd4c30d 1171 if(absv >= 1 || msg[2].i >= 1) gLEDS[num] = gGATES[num] = 1;
casiotone401 0:a4d93cd4c30d 1172 else gLEDS[num] = gGATES[num] = 0;
casiotone401 0:a4d93cd4c30d 1173 break;
casiotone401 0:a4d93cd4c30d 1174 }
casiotone401 0:a4d93cd4c30d 1175
casiotone401 0:a4d93cd4c30d 1176 // address pattern CV (Type Tag float)
casiotone401 3:ca15241dd6b4 1177 if((strncmp(msg[0].address+(len-1)-2, "cv", 2)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1178 if(num > 7) break;
casiotone401 0:a4d93cd4c30d 1179 if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
casiotone401 0:a4d93cd4c30d 1180 break;
casiotone401 0:a4d93cd4c30d 1181 // (touchOSC Control fader, rotary, xy, multixy, multifader)
casiotone401 3:ca15241dd6b4 1182 } else if ((strncmp(msg[0].address+(len-1)-5, "fader", 5)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1183 if(num > 7) break;
casiotone401 0:a4d93cd4c30d 1184 if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
casiotone401 0:a4d93cd4c30d 1185 break;
casiotone401 0:a4d93cd4c30d 1186
casiotone401 3:ca15241dd6b4 1187 } else if ((strncmp(msg[0].address+(len-1)-6, "rotary", 6)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1188 if(num > 7) break;
casiotone401 0:a4d93cd4c30d 1189 if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
casiotone401 0:a4d93cd4c30d 1190 break;
casiotone401 0:a4d93cd4c30d 1191
casiotone401 3:ca15241dd6b4 1192 } else if ((strncmp(msg[0].address+(len-1)-2, "xy", 2)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1193 if(num > 7) break;
casiotone401 0:a4d93cd4c30d 1194 if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
casiotone401 0:a4d93cd4c30d 1195 if(msg[1].typeTag[1] == 'f') gOSC_cv[++num] = msg[3].f * (SCALING_N);
casiotone401 0:a4d93cd4c30d 1196 break;
casiotone401 0:a4d93cd4c30d 1197
casiotone401 3:ca15241dd6b4 1198 } else if ((strncmp(msg[0].address+(len-1)-9, "multixy1/", 9)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1199 if(num > 7) break;
casiotone401 0:a4d93cd4c30d 1200 if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
casiotone401 0:a4d93cd4c30d 1201 if(msg[1].typeTag[1] == 'f') gOSC_cv[++num] = msg[3].f * (SCALING_N);
casiotone401 0:a4d93cd4c30d 1202 break;
casiotone401 0:a4d93cd4c30d 1203
casiotone401 3:ca15241dd6b4 1204 } else if ((strncmp(msg[0].address+(len-1)-12, "multifader1/", 12)==0) && (num != -1)) {
casiotone401 0:a4d93cd4c30d 1205 if(num > 7) break;
casiotone401 0:a4d93cd4c30d 1206 if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N);
casiotone401 4:b9f5ae574447 1207 break;
casiotone401 5:e305509d53f3 1208 // (touchOSC multifader for Sequencer Mode)
casiotone401 4:b9f5ae574447 1209 } else if ((strncmp(msg[0].address+(len-1)-11, "sequencer1/", 11)==0) && (num != -1)) {
casiotone401 4:b9f5ae574447 1210 if(num > 7) break;
casiotone401 4:b9f5ae574447 1211 if(msg[1].typeTag[1] == 'f') gSeq_cv1[num] = msg[2].f * (SCALING_N);
casiotone401 4:b9f5ae574447 1212 break;
casiotone401 5:e305509d53f3 1213
casiotone401 4:b9f5ae574447 1214 } else if ((strncmp(msg[0].address+(len-1)-11, "sequencer2/", 11)==0) && (num != -1)) {
casiotone401 4:b9f5ae574447 1215 if(num > 7) break;
casiotone401 4:b9f5ae574447 1216 if(msg[1].typeTag[1] == 'f') gSeq_cv2[num] = msg[2].f * (SCALING_N);
casiotone401 4:b9f5ae574447 1217 break;
casiotone401 4:b9f5ae574447 1218 }
casiotone401 4:b9f5ae574447 1219
casiotone401 5:e305509d53f3 1220 // address pattern for control
casiotone401 4:b9f5ae574447 1221 if ((strncmp(msg[0].address+(len-1)-6, "ctrlsw", 6)==0) && (num != -1)) {
casiotone401 5:e305509d53f3 1222 if(num > 4) break;
casiotone401 4:b9f5ae574447 1223 if(absv >= 1 || msg[2].i >= 1) gCtrlSW[num] = 1;
casiotone401 4:b9f5ae574447 1224 else gCtrlSW[num] = 0;
casiotone401 4:b9f5ae574447 1225 break;
casiotone401 4:b9f5ae574447 1226
casiotone401 4:b9f5ae574447 1227 } else if ((strncmp(msg[0].address+(len-1)-4, "ctrl", 4)==0) && (num != -1)) {
casiotone401 4:b9f5ae574447 1228 if(num > 2) break;
casiotone401 4:b9f5ae574447 1229 if(msg[1].typeTag[1] == 'f') gCtrl[num] = msg[2].f;
casiotone401 4:b9f5ae574447 1230 break;
casiotone401 4:b9f5ae574447 1231 }
casiotone401 4:b9f5ae574447 1232 }
casiotone401 4:b9f5ae574447 1233 }
casiotone401 0:a4d93cd4c30d 1234 }