Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Bonjour OSCReceiver TextLCD mbed mbed-rpc BurstSPI DebouncedInterrupt FastIO MIDI OSC OSCtoCV ClockControl
main.cpp@14:977f3c5a4b4e, 2014-10-16 (annotated)
- Committer:
- casiotone401
- Date:
- Thu Oct 16 14:14:25 2014 +0000
- Revision:
- 14:977f3c5a4b4e
- Parent:
- 13:3f42e451a8d3
- Child:
- 15:3e4bc47d6a39
improved performance & minor change
Who changed what in which revision?
User | Revision | Line number | New 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 | 14:977f3c5a4b4e | 38 | #define MODE_Calb 0 // Calibration (for VCO Tuning) |
casiotone401 | 14:977f3c5a4b4e | 39 | #define MODE_LIN 1 // Linear LinearCV |
casiotone401 | 14:977f3c5a4b4e | 40 | #define MODE_SEQ 2 // Mode Shift |
casiotone401 | 14:977f3c5a4b4e | 41 | |
casiotone401 | 14:977f3c5a4b4e | 42 | #define MODE_NUM 3 // Modes |
casiotone401 | 0:a4d93cd4c30d | 43 | |
casiotone401 | 14:977f3c5a4b4e | 44 | #define Lin 0 // Linear LinearCV |
casiotone401 | 14:977f3c5a4b4e | 45 | #define Chr 1 // Chromatic |
casiotone401 | 14:977f3c5a4b4e | 46 | #define Maj 2 // Major |
casiotone401 | 14:977f3c5a4b4e | 47 | #define M7 3 // Major7 |
casiotone401 | 14:977f3c5a4b4e | 48 | #define Min7 4 // Minor7 |
casiotone401 | 14:977f3c5a4b4e | 49 | #define Dor 5 // Dorian |
casiotone401 | 14:977f3c5a4b4e | 50 | #define Min 6 // Minor |
casiotone401 | 14:977f3c5a4b4e | 51 | #define S5th 7 // 5th |
casiotone401 | 14:977f3c5a4b4e | 52 | #define Wht 8 // Wholetone |
casiotone401 | 5:e305509d53f3 | 53 | |
casiotone401 | 9:1ac3d135d965 | 54 | #define QUAN_RES1 115 // Quantize voltage Steps |
casiotone401 | 9:1ac3d135d965 | 55 | #define QUAN_RES2 67 |
casiotone401 | 14:977f3c5a4b4e | 56 | #define QUAN_RES3 39 |
casiotone401 | 14:977f3c5a4b4e | 57 | #define QUAN_RES4 48 |
casiotone401 | 14:977f3c5a4b4e | 58 | #define QUAN_RES5 67 |
casiotone401 | 14:977f3c5a4b4e | 59 | #define QUAN_RES6 67 |
casiotone401 | 14:977f3c5a4b4e | 60 | #define QUAN_RES7 17 |
casiotone401 | 14:977f3c5a4b4e | 61 | #define QUAN_RES8 57 |
casiotone401 | 0:a4d93cd4c30d | 62 | |
casiotone401 | 14:977f3c5a4b4e | 63 | #define SPI_RATE 20000000 // 20Mbps SPI Clock |
casiotone401 | 0:a4d93cd4c30d | 64 | #define SCALING_N 38400.0 |
casiotone401 | 3:ca15241dd6b4 | 65 | #define INPUT_PORT 12345 // Input Port Number |
casiotone401 | 0:a4d93cd4c30d | 66 | |
casiotone401 | 3:ca15241dd6b4 | 67 | #define POLLING_INTERVAL 20 // Polling Interval (us) |
casiotone401 | 0:a4d93cd4c30d | 68 | |
casiotone401 | 0:a4d93cd4c30d | 69 | //------------------------------------------------------------- |
casiotone401 | 5:e305509d53f3 | 70 | // DAC8568 Control Bits (See datasheet) |
casiotone401 | 0:a4d93cd4c30d | 71 | |
casiotone401 | 0:a4d93cd4c30d | 72 | #define WRITE 0x00 |
casiotone401 | 0:a4d93cd4c30d | 73 | #define UPDATE 0x01 |
casiotone401 | 5:e305509d53f3 | 74 | #define WRITE_UPDATE_ALL 0x02 // LDAC Write to Selected Update All |
casiotone401 | 5:e305509d53f3 | 75 | #define WRITE_UPDATE_N 0x03 // LDAC Write to Selected Update Respective |
casiotone401 | 0:a4d93cd4c30d | 76 | #define POWER 0x04 |
casiotone401 | 5:e305509d53f3 | 77 | #define CLR 0x05 // Clear Code Register |
casiotone401 | 0:a4d93cd4c30d | 78 | #define WRITE_LDAC_REG 0x06 |
casiotone401 | 5:e305509d53f3 | 79 | #define RESET 0x07 // Software Reset DAC8568 |
casiotone401 | 0:a4d93cd4c30d | 80 | #define SETUP_INTERNAL_REF 0x08 |
casiotone401 | 0:a4d93cd4c30d | 81 | |
casiotone401 | 0:a4d93cd4c30d | 82 | //------------------------------------------------------------- |
casiotone401 | 0:a4d93cd4c30d | 83 | |
casiotone401 | 0:a4d93cd4c30d | 84 | #define _DISABLE 0 |
casiotone401 | 0:a4d93cd4c30d | 85 | #define _ENABLE 1 |
casiotone401 | 0:a4d93cd4c30d | 86 | |
casiotone401 | 5:e305509d53f3 | 87 | #define GATE1 0 |
casiotone401 | 5:e305509d53f3 | 88 | #define GATE2 1 |
casiotone401 | 5:e305509d53f3 | 89 | #define GATE3 2 |
casiotone401 | 5:e305509d53f3 | 90 | #define GATE4 3 |
casiotone401 | 5:e305509d53f3 | 91 | #define GATEALL 4 |
casiotone401 | 5:e305509d53f3 | 92 | |
casiotone401 | 5:e305509d53f3 | 93 | //------------------------------------------------------------- |
casiotone401 | 5:e305509d53f3 | 94 | // Beats (Note values) |
casiotone401 | 5:e305509d53f3 | 95 | |
casiotone401 | 5:e305509d53f3 | 96 | #define N1ST 1 // whole |
casiotone401 | 5:e305509d53f3 | 97 | #define N2ND 2 // harf |
casiotone401 | 5:e305509d53f3 | 98 | #define N4TH 4 // quarter |
casiotone401 | 5:e305509d53f3 | 99 | #define N8TH 8 |
casiotone401 | 5:e305509d53f3 | 100 | #define N16TH 16 |
casiotone401 | 5:e305509d53f3 | 101 | #define N32TH 32 |
casiotone401 | 5:e305509d53f3 | 102 | #define N64TH 64 |
casiotone401 | 5:e305509d53f3 | 103 | #define NDOT2 3 // dotted |
casiotone401 | 5:e305509d53f3 | 104 | #define NDOT4 7 |
casiotone401 | 5:e305509d53f3 | 105 | #define NDOT8 9 |
casiotone401 | 5:e305509d53f3 | 106 | #define NDOT16 11 |
casiotone401 | 5:e305509d53f3 | 107 | #define NDOT32 13 |
casiotone401 | 5:e305509d53f3 | 108 | #define TRIP2 15 // triplets |
casiotone401 | 5:e305509d53f3 | 109 | #define TRIP4 17 |
casiotone401 | 5:e305509d53f3 | 110 | #define TRIP8 19 |
casiotone401 | 5:e305509d53f3 | 111 | #define TRIP16 21 |
casiotone401 | 5:e305509d53f3 | 112 | #define TRIP32 23 |
casiotone401 | 5:e305509d53f3 | 113 | #define NRESET 0 // Gate Reset |
casiotone401 | 5:e305509d53f3 | 114 | |
casiotone401 | 0:a4d93cd4c30d | 115 | //------------------------------------------------------------- |
casiotone401 | 0:a4d93cd4c30d | 116 | // Functions |
casiotone401 | 0:a4d93cd4c30d | 117 | |
casiotone401 | 4:b9f5ae574447 | 118 | inline void NetPoll(void); |
casiotone401 | 0:a4d93cd4c30d | 119 | void InitOSCCV(void); |
casiotone401 | 4:b9f5ae574447 | 120 | inline void UpdateCV(int, int, const unsigned int*); |
casiotone401 | 14:977f3c5a4b4e | 121 | inline void CalibCV(void); |
casiotone401 | 14:977f3c5a4b4e | 122 | inline void SetSCV(void); |
casiotone401 | 14:977f3c5a4b4e | 123 | inline void SeqCV(int); |
casiotone401 | 14:977f3c5a4b4e | 124 | inline void Seq(void); |
casiotone401 | 14:977f3c5a4b4e | 125 | inline int UpdateGate(int, int, int, int, bool); |
casiotone401 | 14:977f3c5a4b4e | 126 | inline void UpdateSync(int, int, bool); |
casiotone401 | 5:e305509d53f3 | 127 | void CheckModeSW(void); |
casiotone401 | 9:1ac3d135d965 | 128 | inline void CVMeter(int, const unsigned int*); |
casiotone401 | 4:b9f5ae574447 | 129 | void LCD(); |
casiotone401 | 0:a4d93cd4c30d | 130 | void WriteCustomChar(unsigned char, unsigned char*); |
casiotone401 | 0:a4d93cd4c30d | 131 | int SetupEthNetIf(void); |
casiotone401 | 14:977f3c5a4b4e | 132 | inline size_t strlength(const char *); |
casiotone401 | 4:b9f5ae574447 | 133 | inline void onUDPSocketEvent(UDPSocketEvent); |
casiotone401 | 0:a4d93cd4c30d | 134 | |
casiotone401 | 0:a4d93cd4c30d | 135 | //------------------------------------------------------------- |
casiotone401 | 0:a4d93cd4c30d | 136 | // Silentway Calibration Data Mapping |
casiotone401 | 0:a4d93cd4c30d | 137 | // http://www.expert-sleepers.co.uk/silentway.html |
casiotone401 | 0:a4d93cd4c30d | 138 | |
casiotone401 | 13:3f42e451a8d3 | 139 | // Chromatic Scale |
casiotone401 | 0:a4d93cd4c30d | 140 | const float calibMap1[QUAN_RES1] = { |
casiotone401 | 14:977f3c5a4b4e | 141 | 0.00331362, 0.01097947, 0.01864531, 0.02631116, 0.03397701, |
casiotone401 | 14:977f3c5a4b4e | 142 | 0.04164285, 0.04930869, 0.05697454, 0.06464039, 0.07230624, |
casiotone401 | 14:977f3c5a4b4e | 143 | 0.07997208, 0.08763793, 0.09530377, 0.10296962, 0.11063547, |
casiotone401 | 14:977f3c5a4b4e | 144 | 0.11830132, 0.12590303, 0.13306051, 0.14021800, 0.14737549, |
casiotone401 | 14:977f3c5a4b4e | 145 | 0.15453300, 0.16169049, 0.16884798, 0.17600547, 0.18316296, |
casiotone401 | 14:977f3c5a4b4e | 146 | 0.19032045, 0.19747795, 0.20463544, 0.21179293, 0.21895042, |
casiotone401 | 14:977f3c5a4b4e | 147 | 0.22610791, 0.23326540, 0.24042290, 0.24758039, 0.25476459, |
casiotone401 | 14:977f3c5a4b4e | 148 | 0.26196238, 0.26916021, 0.27635801, 0.28355584, 0.29075363, |
casiotone401 | 14:977f3c5a4b4e | 149 | 0.29795146, 0.30514926, 0.31234708, 0.31954488, 0.32674271, |
casiotone401 | 14:977f3c5a4b4e | 150 | 0.33394051, 0.34113833, 0.34833613, 0.35553396, 0.36273175, |
casiotone401 | 14:977f3c5a4b4e | 151 | 0.36992958, 0.37713069, 0.38433966, 0.39154866, 0.39875764, |
casiotone401 | 14:977f3c5a4b4e | 152 | 0.40596664, 0.41317561, 0.42038459, 0.42759359, 0.43480256, |
casiotone401 | 14:977f3c5a4b4e | 153 | 0.44201156, 0.44922054, 0.45642951, 0.46363851, 0.47084749, |
casiotone401 | 14:977f3c5a4b4e | 154 | 0.47805649, 0.48526546, 0.49247447, 0.49968344, 0.50694764, |
casiotone401 | 14:977f3c5a4b4e | 155 | 0.51421440, 0.52148110, 0.52874786, 0.53601462, 0.54328132, |
casiotone401 | 14:977f3c5a4b4e | 156 | 0.55054808, 0.55781484, 0.56508154, 0.57234830, 0.57961506, |
casiotone401 | 14:977f3c5a4b4e | 157 | 0.58688176, 0.59414852, 0.60141528, 0.60868198, 0.61594874, |
casiotone401 | 14:977f3c5a4b4e | 158 | 0.62321550, 0.63052768, 0.63785475, 0.64518178, 0.65250880, |
casiotone401 | 14:977f3c5a4b4e | 159 | 0.65983582, 0.66716284, 0.67448992, 0.68181694, 0.68914396, |
casiotone401 | 14:977f3c5a4b4e | 160 | 0.69647098, 0.70379800, 0.71112502, 0.71845210, 0.72577912, |
casiotone401 | 14:977f3c5a4b4e | 161 | 0.73310614, 0.74043316, 0.74776018, 0.75861782, 0.77102989, |
casiotone401 | 14:977f3c5a4b4e | 162 | 0.78344196, 0.79585397, 0.80826604, 0.82067811, 0.83309019, |
casiotone401 | 14:977f3c5a4b4e | 163 | 0.84550226, 0.85791427, 0.87032634, 0.90296346, 0.94781560 |
casiotone401 | 14:977f3c5a4b4e | 164 | }; |
casiotone401 | 14:977f3c5a4b4e | 165 | |
casiotone401 | 14:977f3c5a4b4e | 166 | // Major Scale |
casiotone401 | 14:977f3c5a4b4e | 167 | const float calibMap2[QUAN_RES2] = { |
casiotone401 | 14:977f3c5a4b4e | 168 | 0.01097947, 0.02631116, 0.03397701, 0.04930869, 0.06464039, |
casiotone401 | 14:977f3c5a4b4e | 169 | 0.07997208, 0.08763793, 0.10296962, 0.11830132, 0.12590303, |
casiotone401 | 14:977f3c5a4b4e | 170 | 0.14021800, 0.15453300, 0.16884798, 0.17600547, 0.19032045, |
casiotone401 | 14:977f3c5a4b4e | 171 | 0.20463544, 0.21179293, 0.22610791, 0.24042290, 0.25476459, |
casiotone401 | 14:977f3c5a4b4e | 172 | 0.26196238, 0.27635801, 0.29075363, 0.29795146, 0.31234708, |
casiotone401 | 14:977f3c5a4b4e | 173 | 0.32674271, 0.34113833, 0.34833613, 0.36273175, 0.37713069, |
casiotone401 | 14:977f3c5a4b4e | 174 | 0.38433966, 0.39875764, 0.41317561, 0.42759359, 0.43480256, |
casiotone401 | 14:977f3c5a4b4e | 175 | 0.44922054, 0.46363851, 0.47084749, 0.48526546, 0.49968344, |
casiotone401 | 14:977f3c5a4b4e | 176 | 0.51421440, 0.52148110, 0.53601462, 0.55054808, 0.55781484, |
casiotone401 | 14:977f3c5a4b4e | 177 | 0.57234830, 0.58688176, 0.60141528, 0.60868198, 0.62321550, |
casiotone401 | 14:977f3c5a4b4e | 178 | 0.63785475, 0.64518178, 0.65983582, 0.67448992, 0.68914396, |
casiotone401 | 14:977f3c5a4b4e | 179 | 0.69647098, 0.71112502, 0.72577912, 0.73310614, 0.74776018, |
casiotone401 | 14:977f3c5a4b4e | 180 | 0.77102989, 0.79585397, 0.80826604, 0.83309019, 0.85791427, |
casiotone401 | 14:977f3c5a4b4e | 181 | 0.87032634, 0.94781560 |
casiotone401 | 14:977f3c5a4b4e | 182 | }; |
casiotone401 | 14:977f3c5a4b4e | 183 | |
casiotone401 | 14:977f3c5a4b4e | 184 | // M7(9) |
casiotone401 | 14:977f3c5a4b4e | 185 | const float calibMap3[QUAN_RES3] = { |
casiotone401 | 14:977f3c5a4b4e | 186 | 0.02631116, 0.04930869, 0.07997208, 0.08763793, 0.11830132, |
casiotone401 | 14:977f3c5a4b4e | 187 | 0.14021800, 0.16884798, 0.17600547, 0.20463544, 0.22610791, |
casiotone401 | 14:977f3c5a4b4e | 188 | 0.25476459, 0.26196238, 0.29075363, 0.31234708, 0.34113833, |
casiotone401 | 14:977f3c5a4b4e | 189 | 0.34833613, 0.37713069, 0.39875764, 0.42759359, 0.43480256, |
casiotone401 | 14:977f3c5a4b4e | 190 | 0.44922054, 0.46363851, 0.48526546, 0.51421440, 0.52148110, |
casiotone401 | 14:977f3c5a4b4e | 191 | 0.55054808, 0.57234830, 0.60141528, 0.60868198, 0.62321550, |
casiotone401 | 14:977f3c5a4b4e | 192 | 0.63785475, 0.65983582, 0.68914396, 0.69647098, 0.72577912, |
casiotone401 | 14:977f3c5a4b4e | 193 | 0.74776018, 0.79585397, 0.85791427, 0.94781560 |
casiotone401 | 0:a4d93cd4c30d | 194 | }; |
casiotone401 | 0:a4d93cd4c30d | 195 | |
casiotone401 | 14:977f3c5a4b4e | 196 | // m7(9) |
casiotone401 | 14:977f3c5a4b4e | 197 | const float calibMap4[QUAN_RES4] = { |
casiotone401 | 14:977f3c5a4b4e | 198 | 0.01097947, 0.01864531, 0.03397701, 0.04930869, 0.07230624, |
casiotone401 | 14:977f3c5a4b4e | 199 | 0.08763793, 0.11063547, 0.14021800, 0.16169049, 0.17600547, |
casiotone401 | 14:977f3c5a4b4e | 200 | 0.19747795, 0.22610791, 0.24042290, 0.24758039, 0.26196238, |
casiotone401 | 14:977f3c5a4b4e | 201 | 0.29075363, 0.31234708, 0.33394051, 0.34833613, 0.36273175, |
casiotone401 | 14:977f3c5a4b4e | 202 | 0.36992958, 0.38433966, 0.39875764, 0.41317561, 0.42038459, |
casiotone401 | 14:977f3c5a4b4e | 203 | 0.43480256, 0.45642951, 0.48526546, 0.50694764, 0.52148110, |
casiotone401 | 14:977f3c5a4b4e | 204 | 0.53601462, 0.55781484, 0.57234830, 0.59414852, 0.62321550, |
casiotone401 | 14:977f3c5a4b4e | 205 | 0.63052768, 0.64518178, 0.65983582, 0.68181694, 0.69647098, |
casiotone401 | 14:977f3c5a4b4e | 206 | 0.71845210, 0.74776018, 0.77102989, 0.78344196, 0.80826604, |
casiotone401 | 14:977f3c5a4b4e | 207 | 0.83309019, 0.84550226, 0.94781560 |
casiotone401 | 14:977f3c5a4b4e | 208 | }; |
casiotone401 | 14:977f3c5a4b4e | 209 | |
casiotone401 | 14:977f3c5a4b4e | 210 | // Dorian Scale |
casiotone401 | 14:977f3c5a4b4e | 211 | const float calibMap5[QUAN_RES5] = { |
casiotone401 | 14:977f3c5a4b4e | 212 | 0.01097947, 0.02631116, 0.04164285, 0.04930869, 0.06464039, |
casiotone401 | 14:977f3c5a4b4e | 213 | 0.07997208, 0.08763793, 0.10296962, 0.11830132, 0.13306051, |
casiotone401 | 14:977f3c5a4b4e | 214 | 0.14021800, 0.15453300, 0.16884798, 0.17600547, 0.19032045, |
casiotone401 | 14:977f3c5a4b4e | 215 | 0.20463544, 0.21895042, 0.22610791, 0.24042290, 0.25476459, |
casiotone401 | 14:977f3c5a4b4e | 216 | 0.26196238, 0.27635801, 0.29075363, 0.30514926, 0.31234708, |
casiotone401 | 14:977f3c5a4b4e | 217 | 0.32674271, 0.34113833, 0.34833613, 0.36273175, 0.37713069, |
casiotone401 | 14:977f3c5a4b4e | 218 | 0.39154866, 0.39875764, 0.41317561, 0.42759359, 0.43480256, |
casiotone401 | 14:977f3c5a4b4e | 219 | 0.44922054, 0.46363851, 0.47805649, 0.48526546, 0.49968344, |
casiotone401 | 14:977f3c5a4b4e | 220 | 0.51421440, 0.52148110, 0.53601462, 0.55054808, 0.56508154, |
casiotone401 | 14:977f3c5a4b4e | 221 | 0.57234830, 0.58688176, 0.60141528, 0.60868198, 0.62321550, |
casiotone401 | 14:977f3c5a4b4e | 222 | 0.63785475, 0.65250880, 0.65983582, 0.67448992, 0.68914396, |
casiotone401 | 14:977f3c5a4b4e | 223 | 0.69647098, 0.71112502, 0.72577912, 0.74043316, 0.74776018, |
casiotone401 | 14:977f3c5a4b4e | 224 | 0.77102989, 0.79585397, 0.80826604, 0.83309019, 0.85791427, |
casiotone401 | 14:977f3c5a4b4e | 225 | 0.90296346, 0.94781560 |
casiotone401 | 0:a4d93cd4c30d | 226 | }; |
casiotone401 | 0:a4d93cd4c30d | 227 | |
casiotone401 | 14:977f3c5a4b4e | 228 | // Minor Scale |
casiotone401 | 14:977f3c5a4b4e | 229 | const float calibMap6[QUAN_RES6] = { |
casiotone401 | 14:977f3c5a4b4e | 230 | 0.01097947, 0.01864531, 0.03397701, 0.04930869, 0.05697454, |
casiotone401 | 14:977f3c5a4b4e | 231 | 0.07230624, 0.08763793, 0.10296962, 0.11063547, 0.12590303, |
casiotone401 | 14:977f3c5a4b4e | 232 | 0.14021800, 0.14737549, 0.16169049, 0.17600547, 0.19032045, |
casiotone401 | 14:977f3c5a4b4e | 233 | 0.19747795, 0.21179293, 0.22610791, 0.23326540, 0.24758039, |
casiotone401 | 14:977f3c5a4b4e | 234 | 0.26196238, 0.27635801, 0.28355584, 0.29795146, 0.31234708, |
casiotone401 | 14:977f3c5a4b4e | 235 | 0.31954488, 0.33394051, 0.34833613, 0.36273175, 0.36992958, |
casiotone401 | 14:977f3c5a4b4e | 236 | 0.38433966, 0.39875764, 0.40596664, 0.42038459, 0.43480256, |
casiotone401 | 14:977f3c5a4b4e | 237 | 0.44922054, 0.45642951, 0.47084749, 0.48526546, 0.49247447, |
casiotone401 | 14:977f3c5a4b4e | 238 | 0.50694764, 0.52148110, 0.53601462, 0.54328132, 0.55781484, |
casiotone401 | 14:977f3c5a4b4e | 239 | 0.57234830, 0.57961506, 0.59414852, 0.60868198, 0.62321550, |
casiotone401 | 14:977f3c5a4b4e | 240 | 0.63052768, 0.64518178, 0.65983582, 0.66716284, 0.68181694, |
casiotone401 | 14:977f3c5a4b4e | 241 | 0.69647098, 0.71112502, 0.71845210, 0.73310614, 0.74776018, |
casiotone401 | 14:977f3c5a4b4e | 242 | 0.75861782, 0.78344196, 0.80826604, 0.83309019, 0.84550226, |
casiotone401 | 14:977f3c5a4b4e | 243 | 0.87032634, 0.94781560 |
casiotone401 | 0:a4d93cd4c30d | 244 | }; |
casiotone401 | 0:a4d93cd4c30d | 245 | |
casiotone401 | 14:977f3c5a4b4e | 246 | // 5th |
casiotone401 | 14:977f3c5a4b4e | 247 | const float calibMap7[QUAN_RES7] = { |
casiotone401 | 14:977f3c5a4b4e | 248 | 0.01097947, 0.06464039, 0.11830132, 0.16884798, 0.21895042, |
casiotone401 | 14:977f3c5a4b4e | 249 | 0.26916021, 0.31954488, 0.36992958, 0.42038459, 0.47084749, |
casiotone401 | 14:977f3c5a4b4e | 250 | 0.52148110, 0.57234830, 0.62321550, 0.67448992, 0.72577912, |
casiotone401 | 14:977f3c5a4b4e | 251 | 0.79585397, 0.90296346 |
casiotone401 | 3:ca15241dd6b4 | 252 | }; |
casiotone401 | 3:ca15241dd6b4 | 253 | |
casiotone401 | 14:977f3c5a4b4e | 254 | // Whole tone |
casiotone401 | 14:977f3c5a4b4e | 255 | const float calibMap8[QUAN_RES8] = { |
casiotone401 | 14:977f3c5a4b4e | 256 | 0.01097947, 0.02631116, 0.04164285, 0.05697454, 0.07230624, |
casiotone401 | 14:977f3c5a4b4e | 257 | 0.08763793, 0.10296962, 0.11830132, 0.13306051, 0.14737549, |
casiotone401 | 14:977f3c5a4b4e | 258 | 0.16169049, 0.17600547, 0.19032045, 0.20463544, 0.21895042, |
casiotone401 | 14:977f3c5a4b4e | 259 | 0.23326540, 0.24758039, 0.26196238, 0.27635801, 0.29075363, |
casiotone401 | 14:977f3c5a4b4e | 260 | 0.30514926, 0.31954488, 0.33394051, 0.34833613, 0.36273175, |
casiotone401 | 14:977f3c5a4b4e | 261 | 0.37713069, 0.39154866, 0.40596664, 0.42038459, 0.43480256, |
casiotone401 | 14:977f3c5a4b4e | 262 | 0.44922054, 0.46363851, 0.47805649, 0.49247447, 0.50694764, |
casiotone401 | 14:977f3c5a4b4e | 263 | 0.52148110, 0.53601462, 0.55054808, 0.56508154, 0.57961506, |
casiotone401 | 14:977f3c5a4b4e | 264 | 0.59414852, 0.60868198, 0.62321550, 0.63785475, 0.65250880, |
casiotone401 | 14:977f3c5a4b4e | 265 | 0.66716284, 0.68181694, 0.69647098, 0.71112502, 0.72577912, |
casiotone401 | 14:977f3c5a4b4e | 266 | 0.74043316, 0.75861782, 0.78344196, 0.80826604, 0.83309019, |
casiotone401 | 14:977f3c5a4b4e | 267 | 0.85791427, 0.90296346 |
casiotone401 | 0:a4d93cd4c30d | 268 | }; |
casiotone401 | 0:a4d93cd4c30d | 269 | |
casiotone401 | 0:a4d93cd4c30d | 270 | //------------------------------------------------------------- |
casiotone401 | 0:a4d93cd4c30d | 271 | // CV Meter Custom Character |
casiotone401 | 0:a4d93cd4c30d | 272 | |
casiotone401 | 0:a4d93cd4c30d | 273 | unsigned char str1[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F}; |
casiotone401 | 0:a4d93cd4c30d | 274 | unsigned char str2[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F}; |
casiotone401 | 0:a4d93cd4c30d | 275 | unsigned char str3[8] = {0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F}; |
casiotone401 | 0:a4d93cd4c30d | 276 | unsigned char str4[8] = {0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F}; |
casiotone401 | 0:a4d93cd4c30d | 277 | unsigned char str5[8] = {0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F,0x1F}; |
casiotone401 | 0:a4d93cd4c30d | 278 | unsigned char str6[8] = {0x00,0x00,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}; |
casiotone401 | 0:a4d93cd4c30d | 279 | unsigned char str7[8] = {0x00,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}; |
casiotone401 | 0:a4d93cd4c30d | 280 | unsigned char str8[8] = {0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}; |
casiotone401 | 0:a4d93cd4c30d | 281 | |
casiotone401 | 0:a4d93cd4c30d | 282 | //------------------------------------------------------------- |
casiotone401 | 0:a4d93cd4c30d | 283 | // Global Variables |
casiotone401 | 0:a4d93cd4c30d | 284 | |
casiotone401 | 7:a04f8378662e | 285 | float gOSC_cv[8]; |
casiotone401 | 14:977f3c5a4b4e | 286 | float gSeq_cv1[8], gSeq_cv2[8]; |
casiotone401 | 9:1ac3d135d965 | 287 | float gGlide; |
casiotone401 | 14:977f3c5a4b4e | 288 | int gMode; |
casiotone401 | 0:a4d93cd4c30d | 289 | |
casiotone401 | 5:e305509d53f3 | 290 | // Variables for Control |
casiotone401 | 5:e305509d53f3 | 291 | |
casiotone401 | 14:977f3c5a4b4e | 292 | float gCtrl[6]; |
casiotone401 | 14:977f3c5a4b4e | 293 | bool gCtrlSW[6] = {false}; |
casiotone401 | 5:e305509d53f3 | 294 | |
casiotone401 | 0:a4d93cd4c30d | 295 | //------------------------------------------------------------- |
casiotone401 | 0:a4d93cd4c30d | 296 | // mbed Functions |
casiotone401 | 0:a4d93cd4c30d | 297 | |
casiotone401 | 0:a4d93cd4c30d | 298 | TextLCD gLCD(p9, p10, p11, p12, p13, p14); // rs, e, d4-d7 |
casiotone401 | 0:a4d93cd4c30d | 299 | |
casiotone401 | 0:a4d93cd4c30d | 300 | SPI gSPI(p5,p6,p7); // SPI (p6 unconnected) |
casiotone401 | 0:a4d93cd4c30d | 301 | DigitalOut gSYNCMODE(p15); // SYNC DAC8568 |
casiotone401 | 0:a4d93cd4c30d | 302 | DigitalOut gLDAC(p16); // LDAC DAC8568 |
casiotone401 | 0:a4d93cd4c30d | 303 | |
casiotone401 | 9:1ac3d135d965 | 304 | DigitalOut gGATES[4] = {p23, p24, p24, p25}; // GateOut |
casiotone401 | 1:fd4f70088311 | 305 | DigitalOut gLEDS[4] = {p18, p19, p20, p21}; // LED |
casiotone401 | 5:e305509d53f3 | 306 | DigitalOut gCLOCKOUT(p26); // ClockOut |
casiotone401 | 0:a4d93cd4c30d | 307 | |
casiotone401 | 0:a4d93cd4c30d | 308 | AnalogIn gAIN(p17); // Glide Potentiometer |
casiotone401 | 0:a4d93cd4c30d | 309 | InterruptIn gSW(p30); // Mode SW |
casiotone401 | 0:a4d93cd4c30d | 310 | |
casiotone401 | 4:b9f5ae574447 | 311 | Timer gTimer; // Timer |
casiotone401 | 0:a4d93cd4c30d | 312 | Ticker gPoller; // Ticker Polling |
casiotone401 | 0:a4d93cd4c30d | 313 | |
casiotone401 | 0:a4d93cd4c30d | 314 | // Ethernet |
casiotone401 | 0:a4d93cd4c30d | 315 | EthernetNetIf gEth; |
casiotone401 | 0:a4d93cd4c30d | 316 | UDPSocket gUdp; |
casiotone401 | 0:a4d93cd4c30d | 317 | |
casiotone401 | 0:a4d93cd4c30d | 318 | //------------------------------------------------------------- |
casiotone401 | 0:a4d93cd4c30d | 319 | // main |
casiotone401 | 0:a4d93cd4c30d | 320 | |
casiotone401 | 0:a4d93cd4c30d | 321 | int main() |
casiotone401 | 0:a4d93cd4c30d | 322 | { |
casiotone401 | 7:a04f8378662e | 323 | float pot, _pot; |
casiotone401 | 14:977f3c5a4b4e | 324 | |
casiotone401 | 14:977f3c5a4b4e | 325 | //Clock Up 110Mhz ------------------------------------------------------------- |
casiotone401 | 14:977f3c5a4b4e | 326 | LPC_SC->PLL0CON = 0x00; /* PLL0 Disable */ |
casiotone401 | 14:977f3c5a4b4e | 327 | LPC_SC->PLL0FEED = 0xAA; |
casiotone401 | 14:977f3c5a4b4e | 328 | LPC_SC->PLL0FEED = 0x55; |
casiotone401 | 14:977f3c5a4b4e | 329 | |
casiotone401 | 14:977f3c5a4b4e | 330 | LPC_SC->CCLKCFG = 0x00000003; /* Select Clock Divisor = 4 */ |
casiotone401 | 14:977f3c5a4b4e | 331 | LPC_SC->PLL0CFG = 0x00020037; /* configure PLL0 */ |
casiotone401 | 14:977f3c5a4b4e | 332 | LPC_SC->PLL0FEED = 0xAA; /* divide by 3 then multiply by 50 */ |
casiotone401 | 14:977f3c5a4b4e | 333 | LPC_SC->PLL0FEED = 0x55; /* PLL0 frequency = 400,000,000 */ |
casiotone401 | 14:977f3c5a4b4e | 334 | |
casiotone401 | 14:977f3c5a4b4e | 335 | LPC_SC->PLL0CON = 0x01; /* PLL0 Enable */ |
casiotone401 | 14:977f3c5a4b4e | 336 | LPC_SC->PLL0FEED = 0xAA; |
casiotone401 | 14:977f3c5a4b4e | 337 | LPC_SC->PLL0FEED = 0x55; |
casiotone401 | 14:977f3c5a4b4e | 338 | while (!(LPC_SC->PLL0STAT & (1<<26)));/* Wait for PLOCK0 */ |
casiotone401 | 14:977f3c5a4b4e | 339 | |
casiotone401 | 14:977f3c5a4b4e | 340 | LPC_SC->PLL0CON = 0x03; /* PLL0 Enable & Connect */ |
casiotone401 | 14:977f3c5a4b4e | 341 | LPC_SC->PLL0FEED = 0xAA; |
casiotone401 | 14:977f3c5a4b4e | 342 | LPC_SC->PLL0FEED = 0x55; |
casiotone401 | 14:977f3c5a4b4e | 343 | while (!(LPC_SC->PLL0STAT & ((1<<25) | (1<<24))));/* Wait for PLLC0_STAT & PLLE0_STAT */ |
casiotone401 | 14:977f3c5a4b4e | 344 | |
casiotone401 | 14:977f3c5a4b4e | 345 | SystemCoreClockUpdate(); |
casiotone401 | 14:977f3c5a4b4e | 346 | //----------------------------------------------------------------------------- |
casiotone401 | 3:ca15241dd6b4 | 347 | |
casiotone401 | 0:a4d93cd4c30d | 348 | if(SetupEthNetIf() == -1) |
casiotone401 | 0:a4d93cd4c30d | 349 | { |
casiotone401 | 4:b9f5ae574447 | 350 | for(int i = 0; i < 4; i++) |
casiotone401 | 0:a4d93cd4c30d | 351 | { |
casiotone401 | 0:a4d93cd4c30d | 352 | gLEDS[i] = 1; |
casiotone401 | 0:a4d93cd4c30d | 353 | wait(0.25); |
casiotone401 | 0:a4d93cd4c30d | 354 | } |
casiotone401 | 5:e305509d53f3 | 355 | |
casiotone401 | 0:a4d93cd4c30d | 356 | return -1; |
casiotone401 | 0:a4d93cd4c30d | 357 | } |
casiotone401 | 0:a4d93cd4c30d | 358 | |
casiotone401 | 5:e305509d53f3 | 359 | // mdns (Bonjour) |
casiotone401 | 0:a4d93cd4c30d | 360 | HTTPServer svr; |
casiotone401 | 0:a4d93cd4c30d | 361 | mDNSResponder mdns; |
casiotone401 | 4:b9f5ae574447 | 362 | |
casiotone401 | 0:a4d93cd4c30d | 363 | svr.addHandler<SimpleHandler>("/"); |
casiotone401 | 0:a4d93cd4c30d | 364 | svr.bind(INPUT_PORT); |
casiotone401 | 0:a4d93cd4c30d | 365 | IpAddr ip = gEth.getIp(); |
casiotone401 | 0:a4d93cd4c30d | 366 | mdns.announce(ip, "OSCtoCV", "_osc._udp", INPUT_PORT, "mbed(OSCtoCV)", (char *[]) {"path=/",NULL}); |
casiotone401 | 0:a4d93cd4c30d | 367 | |
casiotone401 | 0:a4d93cd4c30d | 368 | InitOSCCV(); |
casiotone401 | 0:a4d93cd4c30d | 369 | |
casiotone401 | 14:977f3c5a4b4e | 370 | _pot = pot = gMode = 0; |
casiotone401 | 14:977f3c5a4b4e | 371 | gGlide = gCtrl[3] = gAIN.read(); |
casiotone401 | 4:b9f5ae574447 | 372 | |
casiotone401 | 4:b9f5ae574447 | 373 | LCD(); |
casiotone401 | 3:ca15241dd6b4 | 374 | gLCD.locate( 0, 1 ); |
casiotone401 | 3:ca15241dd6b4 | 375 | gLCD.printf("12345678 G>>%3.2f", gGlide); |
casiotone401 | 3:ca15241dd6b4 | 376 | |
casiotone401 | 5:e305509d53f3 | 377 | // loop |
casiotone401 | 0:a4d93cd4c30d | 378 | while(1) |
casiotone401 | 0:a4d93cd4c30d | 379 | { |
casiotone401 | 14:977f3c5a4b4e | 380 | pot = gAIN.read(); // Glide Value |
casiotone401 | 0:a4d93cd4c30d | 381 | |
casiotone401 | 14:977f3c5a4b4e | 382 | if(pot == 0) |
casiotone401 | 0:a4d93cd4c30d | 383 | { |
casiotone401 | 14:977f3c5a4b4e | 384 | if(abs(gCtrl[3] - _pot) > 0.01f) |
casiotone401 | 14:977f3c5a4b4e | 385 | { |
casiotone401 | 14:977f3c5a4b4e | 386 | _pot = gGlide = gCtrl[3]; |
casiotone401 | 14:977f3c5a4b4e | 387 | |
casiotone401 | 14:977f3c5a4b4e | 388 | gLCD.locate( 0, 1 ); |
casiotone401 | 14:977f3c5a4b4e | 389 | gLCD.printf("12345678 G>>%3.2f", gGlide); |
casiotone401 | 14:977f3c5a4b4e | 390 | } |
casiotone401 | 14:977f3c5a4b4e | 391 | |
casiotone401 | 14:977f3c5a4b4e | 392 | } else if (abs(pot - _pot) > 0.01f) { |
casiotone401 | 14:977f3c5a4b4e | 393 | |
casiotone401 | 14:977f3c5a4b4e | 394 | gGlide = _pot = gAIN.read(); |
casiotone401 | 14:977f3c5a4b4e | 395 | |
casiotone401 | 3:ca15241dd6b4 | 396 | gLCD.locate( 0, 1 ); |
casiotone401 | 3:ca15241dd6b4 | 397 | gLCD.printf("12345678 G>>%3.2f", gGlide); |
casiotone401 | 0:a4d93cd4c30d | 398 | } |
casiotone401 | 3:ca15241dd6b4 | 399 | |
casiotone401 | 6:5796b63c70ef | 400 | switch(gMode) |
casiotone401 | 14:977f3c5a4b4e | 401 | { |
casiotone401 | 14:977f3c5a4b4e | 402 | case MODE_LIN: |
casiotone401 | 5:e305509d53f3 | 403 | |
casiotone401 | 14:977f3c5a4b4e | 404 | SetSCV(); |
casiotone401 | 14:977f3c5a4b4e | 405 | break; |
casiotone401 | 5:e305509d53f3 | 406 | |
casiotone401 | 14:977f3c5a4b4e | 407 | case MODE_SEQ: |
casiotone401 | 14:977f3c5a4b4e | 408 | |
casiotone401 | 14:977f3c5a4b4e | 409 | Seq(); |
casiotone401 | 14:977f3c5a4b4e | 410 | break; |
casiotone401 | 6:5796b63c70ef | 411 | |
casiotone401 | 6:5796b63c70ef | 412 | default: |
casiotone401 | 14:977f3c5a4b4e | 413 | |
casiotone401 | 14:977f3c5a4b4e | 414 | CalibCV(); |
casiotone401 | 9:1ac3d135d965 | 415 | break; |
casiotone401 | 4:b9f5ae574447 | 416 | } |
casiotone401 | 0:a4d93cd4c30d | 417 | } |
casiotone401 | 0:a4d93cd4c30d | 418 | } |
casiotone401 | 0:a4d93cd4c30d | 419 | |
casiotone401 | 0:a4d93cd4c30d | 420 | //------------------------------------------------------------- |
casiotone401 | 0:a4d93cd4c30d | 421 | // Ethernet Polling |
casiotone401 | 0:a4d93cd4c30d | 422 | |
casiotone401 | 4:b9f5ae574447 | 423 | inline void NetPoll() |
casiotone401 | 0:a4d93cd4c30d | 424 | { |
casiotone401 | 0:a4d93cd4c30d | 425 | Net::poll(); |
casiotone401 | 0:a4d93cd4c30d | 426 | } |
casiotone401 | 0:a4d93cd4c30d | 427 | |
casiotone401 | 0:a4d93cd4c30d | 428 | //------------------------------------------------------------- |
casiotone401 | 0:a4d93cd4c30d | 429 | // Initialize OSC-CV |
casiotone401 | 0:a4d93cd4c30d | 430 | |
casiotone401 | 0:a4d93cd4c30d | 431 | void InitOSCCV() |
casiotone401 | 0:a4d93cd4c30d | 432 | { |
casiotone401 | 5:e305509d53f3 | 433 | // write custom char LCD CGRAM |
casiotone401 | 0:a4d93cd4c30d | 434 | WriteCustomChar(0x00, str1); |
casiotone401 | 0:a4d93cd4c30d | 435 | WriteCustomChar(0x01, str2); |
casiotone401 | 0:a4d93cd4c30d | 436 | WriteCustomChar(0x02, str3); |
casiotone401 | 0:a4d93cd4c30d | 437 | WriteCustomChar(0x03, str4); |
casiotone401 | 0:a4d93cd4c30d | 438 | WriteCustomChar(0x04, str5); |
casiotone401 | 0:a4d93cd4c30d | 439 | WriteCustomChar(0x05, str6); |
casiotone401 | 0:a4d93cd4c30d | 440 | WriteCustomChar(0x06, str7); |
casiotone401 | 0:a4d93cd4c30d | 441 | WriteCustomChar(0x07, str8); |
casiotone401 | 0:a4d93cd4c30d | 442 | |
casiotone401 | 5:e305509d53f3 | 443 | // Init. SPI |
casiotone401 | 0:a4d93cd4c30d | 444 | gLDAC = _ENABLE; |
casiotone401 | 5:e305509d53f3 | 445 | gSPI.format(8,1); // Data word length 8bit, Mode=1 |
casiotone401 | 0:a4d93cd4c30d | 446 | gSPI.frequency(SPI_RATE); |
casiotone401 | 0:a4d93cd4c30d | 447 | |
casiotone401 | 5:e305509d53f3 | 448 | UpdateCV(CLR, 0, 0); // Ignore CLR Pin |
casiotone401 | 0:a4d93cd4c30d | 449 | |
casiotone401 | 5:e305509d53f3 | 450 | gSW.mode(PullUp); // Use internal pullup for ModeSW |
casiotone401 | 0:a4d93cd4c30d | 451 | wait(.001); |
casiotone401 | 0:a4d93cd4c30d | 452 | |
casiotone401 | 5:e305509d53f3 | 453 | gSW.rise(&CheckModeSW); // InterruptIn rising edge(ModeSW) |
casiotone401 | 0:a4d93cd4c30d | 454 | gPoller.attach_us(&NetPoll, POLLING_INTERVAL); // Ticker Polling |
casiotone401 | 3:ca15241dd6b4 | 455 | |
casiotone401 | 3:ca15241dd6b4 | 456 | wait(0.2); |
casiotone401 | 0:a4d93cd4c30d | 457 | } |
casiotone401 | 0:a4d93cd4c30d | 458 | |
casiotone401 | 0:a4d93cd4c30d | 459 | //------------------------------------------------------------- |
casiotone401 | 0:a4d93cd4c30d | 460 | // SPI Transfer |
casiotone401 | 0:a4d93cd4c30d | 461 | // DAC8568 data word length 32bit (8bit shift out) |
casiotone401 | 0:a4d93cd4c30d | 462 | |
casiotone401 | 4:b9f5ae574447 | 463 | inline void UpdateCV(int control, int address, const unsigned int *data) |
casiotone401 | 0:a4d93cd4c30d | 464 | { |
casiotone401 | 0:a4d93cd4c30d | 465 | __disable_irq(); |
casiotone401 | 0:a4d93cd4c30d | 466 | |
casiotone401 | 0:a4d93cd4c30d | 467 | switch(control) |
casiotone401 | 0:a4d93cd4c30d | 468 | { |
casiotone401 | 0:a4d93cd4c30d | 469 | case WRITE_UPDATE_N: |
casiotone401 | 4:b9f5ae574447 | 470 | |
casiotone401 | 0:a4d93cd4c30d | 471 | gSYNCMODE = _DISABLE; |
casiotone401 | 4:b9f5ae574447 | 472 | gSPI.write(00000000|control); // padding at beginning of byte and control bits |
casiotone401 | 4:b9f5ae574447 | 473 | gSPI.write(address << 4 | *data >> 12); // address(ch) bits |
casiotone401 | 4:b9f5ae574447 | 474 | gSPI.write((*data << 4) >> 8); // middle 8 bits of data |
casiotone401 | 4:b9f5ae574447 | 475 | gSPI.write((*data << 12) >> 8 | 00001111); |
casiotone401 | 0:a4d93cd4c30d | 476 | gSYNCMODE = _ENABLE; |
casiotone401 | 0:a4d93cd4c30d | 477 | gLDAC = _DISABLE; |
casiotone401 | 0:a4d93cd4c30d | 478 | gLDAC = _ENABLE; |
casiotone401 | 0:a4d93cd4c30d | 479 | break; |
casiotone401 | 4:b9f5ae574447 | 480 | |
casiotone401 | 0:a4d93cd4c30d | 481 | case RESET: |
casiotone401 | 4:b9f5ae574447 | 482 | |
casiotone401 | 0:a4d93cd4c30d | 483 | gSYNCMODE = _DISABLE; |
casiotone401 | 4:b9f5ae574447 | 484 | gSPI.write(00000111); // Software RESET |
casiotone401 | 0:a4d93cd4c30d | 485 | gSPI.write(00000000); |
casiotone401 | 0:a4d93cd4c30d | 486 | gSPI.write(00000000); |
casiotone401 | 0:a4d93cd4c30d | 487 | gSPI.write(00000000); |
casiotone401 | 0:a4d93cd4c30d | 488 | gSYNCMODE = _ENABLE; |
casiotone401 | 0:a4d93cd4c30d | 489 | break; |
casiotone401 | 4:b9f5ae574447 | 490 | |
casiotone401 | 0:a4d93cd4c30d | 491 | case CLR: |
casiotone401 | 4:b9f5ae574447 | 492 | |
casiotone401 | 0:a4d93cd4c30d | 493 | gSYNCMODE = _DISABLE; |
casiotone401 | 4:b9f5ae574447 | 494 | gSPI.write(00000101); // CLR Register |
casiotone401 | 0:a4d93cd4c30d | 495 | gSPI.write(00000000); |
casiotone401 | 0:a4d93cd4c30d | 496 | gSPI.write(00000000); |
casiotone401 | 4:b9f5ae574447 | 497 | gSPI.write(00000011); // Ignore CLR Pin |
casiotone401 | 0:a4d93cd4c30d | 498 | gSYNCMODE = _ENABLE; |
casiotone401 | 0:a4d93cd4c30d | 499 | break; |
casiotone401 | 0:a4d93cd4c30d | 500 | } |
casiotone401 | 0:a4d93cd4c30d | 501 | |
casiotone401 | 0:a4d93cd4c30d | 502 | __enable_irq(); |
casiotone401 | 0:a4d93cd4c30d | 503 | } |
casiotone401 | 0:a4d93cd4c30d | 504 | |
casiotone401 | 0:a4d93cd4c30d | 505 | //------------------------------------------------------------- |
casiotone401 | 14:977f3c5a4b4e | 506 | // Calibrate Mode |
casiotone401 | 14:977f3c5a4b4e | 507 | |
casiotone401 | 14:977f3c5a4b4e | 508 | inline void CalibCV() |
casiotone401 | 14:977f3c5a4b4e | 509 | { |
casiotone401 | 14:977f3c5a4b4e | 510 | static int ch; |
casiotone401 | 14:977f3c5a4b4e | 511 | unsigned int cv; |
casiotone401 | 14:977f3c5a4b4e | 512 | |
casiotone401 | 14:977f3c5a4b4e | 513 | switch(gMode) |
casiotone401 | 14:977f3c5a4b4e | 514 | { |
casiotone401 | 14:977f3c5a4b4e | 515 | case MODE_Calb: |
casiotone401 | 14:977f3c5a4b4e | 516 | |
casiotone401 | 14:977f3c5a4b4e | 517 | cv = (unsigned int)((calibMap1[68] + 0.0007) * SCALING_N); // A880.0Hz |
casiotone401 | 14:977f3c5a4b4e | 518 | |
casiotone401 | 14:977f3c5a4b4e | 519 | gGATES[0] = gGATES[1] = gGATES[2] = gGATES[3] = 1; |
casiotone401 | 14:977f3c5a4b4e | 520 | gLEDS[0] = gLEDS[1] = gLEDS[2] = gLEDS[3] = 1; |
casiotone401 | 14:977f3c5a4b4e | 521 | |
casiotone401 | 14:977f3c5a4b4e | 522 | UpdateCV(WRITE_UPDATE_N, ch, &cv); |
casiotone401 | 14:977f3c5a4b4e | 523 | break; |
casiotone401 | 14:977f3c5a4b4e | 524 | } |
casiotone401 | 14:977f3c5a4b4e | 525 | |
casiotone401 | 14:977f3c5a4b4e | 526 | CVMeter(ch, &cv); |
casiotone401 | 14:977f3c5a4b4e | 527 | |
casiotone401 | 14:977f3c5a4b4e | 528 | ch++; |
casiotone401 | 14:977f3c5a4b4e | 529 | ch &= 0x07; |
casiotone401 | 14:977f3c5a4b4e | 530 | } |
casiotone401 | 14:977f3c5a4b4e | 531 | |
casiotone401 | 14:977f3c5a4b4e | 532 | //------------------------------------------------------------- |
casiotone401 | 14:977f3c5a4b4e | 533 | // Calculate CV |
casiotone401 | 14:977f3c5a4b4e | 534 | |
casiotone401 | 14:977f3c5a4b4e | 535 | inline void SetSCV() |
casiotone401 | 14:977f3c5a4b4e | 536 | { |
casiotone401 | 14:977f3c5a4b4e | 537 | static int ch, quan, mode, mcount; |
casiotone401 | 14:977f3c5a4b4e | 538 | static float glidecv[8]; |
casiotone401 | 14:977f3c5a4b4e | 539 | unsigned int cv; |
casiotone401 | 14:977f3c5a4b4e | 540 | static float qcv; |
casiotone401 | 14:977f3c5a4b4e | 541 | |
casiotone401 | 14:977f3c5a4b4e | 542 | mode = (gCtrl[1] * 8); |
casiotone401 | 14:977f3c5a4b4e | 543 | |
casiotone401 | 14:977f3c5a4b4e | 544 | switch(mode) |
casiotone401 | 14:977f3c5a4b4e | 545 | { |
casiotone401 | 14:977f3c5a4b4e | 546 | case Lin: |
casiotone401 | 14:977f3c5a4b4e | 547 | |
casiotone401 | 14:977f3c5a4b4e | 548 | glidecv[ch] = glidecv[ch] * gGlide + gOSC_cv[ch] * (1.0f - gGlide); |
casiotone401 | 14:977f3c5a4b4e | 549 | cv = (unsigned int)glidecv[ch]; |
casiotone401 | 14:977f3c5a4b4e | 550 | |
casiotone401 | 14:977f3c5a4b4e | 551 | UpdateCV(WRITE_UPDATE_N, ch, &cv); |
casiotone401 | 14:977f3c5a4b4e | 552 | break; |
casiotone401 | 14:977f3c5a4b4e | 553 | |
casiotone401 | 14:977f3c5a4b4e | 554 | case Chr: |
casiotone401 | 14:977f3c5a4b4e | 555 | |
casiotone401 | 14:977f3c5a4b4e | 556 | quan = (40616 / QUAN_RES1); |
casiotone401 | 14:977f3c5a4b4e | 557 | qcv = calibMap1[(unsigned int)(gOSC_cv[ch] / quan)]; |
casiotone401 | 14:977f3c5a4b4e | 558 | |
casiotone401 | 14:977f3c5a4b4e | 559 | glidecv[ch] = glidecv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
casiotone401 | 14:977f3c5a4b4e | 560 | cv = (unsigned int)glidecv[ch]; |
casiotone401 | 14:977f3c5a4b4e | 561 | |
casiotone401 | 14:977f3c5a4b4e | 562 | UpdateCV(WRITE_UPDATE_N, ch, &cv); |
casiotone401 | 14:977f3c5a4b4e | 563 | break; |
casiotone401 | 14:977f3c5a4b4e | 564 | |
casiotone401 | 14:977f3c5a4b4e | 565 | case Maj: |
casiotone401 | 14:977f3c5a4b4e | 566 | |
casiotone401 | 14:977f3c5a4b4e | 567 | quan = (40616 / QUAN_RES2); |
casiotone401 | 14:977f3c5a4b4e | 568 | qcv = calibMap2[(unsigned int)(gOSC_cv[ch] / quan)]; |
casiotone401 | 14:977f3c5a4b4e | 569 | |
casiotone401 | 14:977f3c5a4b4e | 570 | glidecv[ch] = glidecv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
casiotone401 | 14:977f3c5a4b4e | 571 | cv = (unsigned int)glidecv[ch]; |
casiotone401 | 14:977f3c5a4b4e | 572 | |
casiotone401 | 14:977f3c5a4b4e | 573 | UpdateCV(WRITE_UPDATE_N, ch, &cv); |
casiotone401 | 14:977f3c5a4b4e | 574 | break; |
casiotone401 | 14:977f3c5a4b4e | 575 | |
casiotone401 | 14:977f3c5a4b4e | 576 | case M7: |
casiotone401 | 14:977f3c5a4b4e | 577 | |
casiotone401 | 14:977f3c5a4b4e | 578 | quan = (40616 / QUAN_RES3); |
casiotone401 | 14:977f3c5a4b4e | 579 | qcv = calibMap3[(unsigned int)(gOSC_cv[ch] / quan)]; |
casiotone401 | 14:977f3c5a4b4e | 580 | |
casiotone401 | 14:977f3c5a4b4e | 581 | glidecv[ch] = glidecv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
casiotone401 | 14:977f3c5a4b4e | 582 | cv = (unsigned int)glidecv[ch]; |
casiotone401 | 14:977f3c5a4b4e | 583 | |
casiotone401 | 14:977f3c5a4b4e | 584 | UpdateCV(WRITE_UPDATE_N, ch, &cv); |
casiotone401 | 14:977f3c5a4b4e | 585 | break; |
casiotone401 | 14:977f3c5a4b4e | 586 | |
casiotone401 | 14:977f3c5a4b4e | 587 | case Min7: |
casiotone401 | 14:977f3c5a4b4e | 588 | |
casiotone401 | 14:977f3c5a4b4e | 589 | quan = (40616 / QUAN_RES4); |
casiotone401 | 14:977f3c5a4b4e | 590 | qcv = calibMap4[(unsigned int)(gOSC_cv[ch] / quan)]; |
casiotone401 | 14:977f3c5a4b4e | 591 | |
casiotone401 | 14:977f3c5a4b4e | 592 | glidecv[ch] = glidecv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
casiotone401 | 14:977f3c5a4b4e | 593 | cv = (unsigned int)glidecv[ch]; |
casiotone401 | 14:977f3c5a4b4e | 594 | |
casiotone401 | 14:977f3c5a4b4e | 595 | UpdateCV(WRITE_UPDATE_N, ch, &cv); |
casiotone401 | 14:977f3c5a4b4e | 596 | break; |
casiotone401 | 14:977f3c5a4b4e | 597 | |
casiotone401 | 14:977f3c5a4b4e | 598 | case Dor: |
casiotone401 | 14:977f3c5a4b4e | 599 | |
casiotone401 | 14:977f3c5a4b4e | 600 | quan = (40616 / QUAN_RES5); |
casiotone401 | 14:977f3c5a4b4e | 601 | qcv = calibMap5[(unsigned int)(gOSC_cv[ch] / quan)]; |
casiotone401 | 14:977f3c5a4b4e | 602 | |
casiotone401 | 14:977f3c5a4b4e | 603 | glidecv[ch] = glidecv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
casiotone401 | 14:977f3c5a4b4e | 604 | cv = (unsigned int)glidecv[ch]; |
casiotone401 | 14:977f3c5a4b4e | 605 | |
casiotone401 | 14:977f3c5a4b4e | 606 | UpdateCV(WRITE_UPDATE_N, ch, &cv); |
casiotone401 | 14:977f3c5a4b4e | 607 | break; |
casiotone401 | 14:977f3c5a4b4e | 608 | |
casiotone401 | 14:977f3c5a4b4e | 609 | case Min: |
casiotone401 | 14:977f3c5a4b4e | 610 | |
casiotone401 | 14:977f3c5a4b4e | 611 | quan = (40616 / QUAN_RES6); |
casiotone401 | 14:977f3c5a4b4e | 612 | qcv = calibMap6[(unsigned int)(gOSC_cv[ch] / quan)]; |
casiotone401 | 14:977f3c5a4b4e | 613 | |
casiotone401 | 14:977f3c5a4b4e | 614 | glidecv[ch] = glidecv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
casiotone401 | 14:977f3c5a4b4e | 615 | cv = (unsigned int)glidecv[ch]; |
casiotone401 | 14:977f3c5a4b4e | 616 | |
casiotone401 | 14:977f3c5a4b4e | 617 | UpdateCV(WRITE_UPDATE_N, ch, &cv); |
casiotone401 | 14:977f3c5a4b4e | 618 | break; |
casiotone401 | 14:977f3c5a4b4e | 619 | |
casiotone401 | 14:977f3c5a4b4e | 620 | case S5th: |
casiotone401 | 14:977f3c5a4b4e | 621 | |
casiotone401 | 14:977f3c5a4b4e | 622 | quan = (40616 / QUAN_RES7); |
casiotone401 | 14:977f3c5a4b4e | 623 | qcv = calibMap7[(unsigned int)(gOSC_cv[ch] / quan)]; |
casiotone401 | 14:977f3c5a4b4e | 624 | |
casiotone401 | 14:977f3c5a4b4e | 625 | glidecv[ch] = glidecv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
casiotone401 | 14:977f3c5a4b4e | 626 | cv = (unsigned int)glidecv[ch]; |
casiotone401 | 14:977f3c5a4b4e | 627 | |
casiotone401 | 14:977f3c5a4b4e | 628 | UpdateCV(WRITE_UPDATE_N, ch, &cv); |
casiotone401 | 14:977f3c5a4b4e | 629 | break; |
casiotone401 | 14:977f3c5a4b4e | 630 | |
casiotone401 | 14:977f3c5a4b4e | 631 | case Wht: |
casiotone401 | 14:977f3c5a4b4e | 632 | |
casiotone401 | 14:977f3c5a4b4e | 633 | quan = (40616 / QUAN_RES8); |
casiotone401 | 14:977f3c5a4b4e | 634 | qcv = calibMap8[(unsigned int)(gOSC_cv[ch] / quan)]; |
casiotone401 | 14:977f3c5a4b4e | 635 | |
casiotone401 | 14:977f3c5a4b4e | 636 | glidecv[ch] = glidecv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
casiotone401 | 14:977f3c5a4b4e | 637 | cv = (unsigned int)glidecv[ch]; |
casiotone401 | 14:977f3c5a4b4e | 638 | |
casiotone401 | 14:977f3c5a4b4e | 639 | UpdateCV(WRITE_UPDATE_N, ch, &cv); |
casiotone401 | 14:977f3c5a4b4e | 640 | break; |
casiotone401 | 14:977f3c5a4b4e | 641 | } |
casiotone401 | 14:977f3c5a4b4e | 642 | |
casiotone401 | 14:977f3c5a4b4e | 643 | if(mcount % 16 == 0) |
casiotone401 | 14:977f3c5a4b4e | 644 | { |
casiotone401 | 14:977f3c5a4b4e | 645 | CVMeter(ch, &cv); |
casiotone401 | 14:977f3c5a4b4e | 646 | } |
casiotone401 | 14:977f3c5a4b4e | 647 | |
casiotone401 | 14:977f3c5a4b4e | 648 | ch++; |
casiotone401 | 14:977f3c5a4b4e | 649 | |
casiotone401 | 14:977f3c5a4b4e | 650 | if(ch &= 0x07) |
casiotone401 | 14:977f3c5a4b4e | 651 | { |
casiotone401 | 14:977f3c5a4b4e | 652 | mcount ++; |
casiotone401 | 14:977f3c5a4b4e | 653 | mcount &= 0x3F; |
casiotone401 | 14:977f3c5a4b4e | 654 | } |
casiotone401 | 14:977f3c5a4b4e | 655 | |
casiotone401 | 14:977f3c5a4b4e | 656 | } |
casiotone401 | 14:977f3c5a4b4e | 657 | |
casiotone401 | 14:977f3c5a4b4e | 658 | //------------------------------------------------------------- |
casiotone401 | 14:977f3c5a4b4e | 659 | // Sequence & Shift Out CV |
casiotone401 | 14:977f3c5a4b4e | 660 | |
casiotone401 | 14:977f3c5a4b4e | 661 | inline void SeqCV(int shift) |
casiotone401 | 14:977f3c5a4b4e | 662 | { |
casiotone401 | 14:977f3c5a4b4e | 663 | int i, j; |
casiotone401 | 14:977f3c5a4b4e | 664 | static int ch, quan, mode; |
casiotone401 | 14:977f3c5a4b4e | 665 | static float glidecv[8], shiftcv[8]; |
casiotone401 | 14:977f3c5a4b4e | 666 | unsigned int cv; |
casiotone401 | 14:977f3c5a4b4e | 667 | static float qcv; |
casiotone401 | 14:977f3c5a4b4e | 668 | |
casiotone401 | 14:977f3c5a4b4e | 669 | mode = (gCtrl[1] * 8); // Sequencer Quantize Mode (gCtrl[1]) |
casiotone401 | 14:977f3c5a4b4e | 670 | |
casiotone401 | 14:977f3c5a4b4e | 671 | switch(mode) |
casiotone401 | 14:977f3c5a4b4e | 672 | { |
casiotone401 | 14:977f3c5a4b4e | 673 | case Lin: |
casiotone401 | 14:977f3c5a4b4e | 674 | |
casiotone401 | 14:977f3c5a4b4e | 675 | if(ch < 8) |
casiotone401 | 14:977f3c5a4b4e | 676 | { |
casiotone401 | 14:977f3c5a4b4e | 677 | glidecv[0] = glidecv[0] * gGlide + gSeq_cv1[ch] * (1.0f - gGlide); |
casiotone401 | 14:977f3c5a4b4e | 678 | |
casiotone401 | 14:977f3c5a4b4e | 679 | } else { |
casiotone401 | 14:977f3c5a4b4e | 680 | |
casiotone401 | 14:977f3c5a4b4e | 681 | glidecv[0] = glidecv[0] * gGlide + gSeq_cv2[ch-8] * (1.0f - gGlide); |
casiotone401 | 14:977f3c5a4b4e | 682 | } |
casiotone401 | 14:977f3c5a4b4e | 683 | |
casiotone401 | 14:977f3c5a4b4e | 684 | cv = (unsigned int)glidecv[0]; |
casiotone401 | 14:977f3c5a4b4e | 685 | |
casiotone401 | 14:977f3c5a4b4e | 686 | UpdateCV(WRITE_UPDATE_N, 0, &cv); |
casiotone401 | 14:977f3c5a4b4e | 687 | break; |
casiotone401 | 14:977f3c5a4b4e | 688 | |
casiotone401 | 14:977f3c5a4b4e | 689 | case Chr: |
casiotone401 | 14:977f3c5a4b4e | 690 | |
casiotone401 | 14:977f3c5a4b4e | 691 | quan = 40616 / QUAN_RES1; |
casiotone401 | 14:977f3c5a4b4e | 692 | |
casiotone401 | 14:977f3c5a4b4e | 693 | if(ch < 8) |
casiotone401 | 14:977f3c5a4b4e | 694 | { |
casiotone401 | 14:977f3c5a4b4e | 695 | qcv = calibMap1[(unsigned int)(gSeq_cv1[ch] / quan)]; |
casiotone401 | 14:977f3c5a4b4e | 696 | |
casiotone401 | 14:977f3c5a4b4e | 697 | } else { |
casiotone401 | 14:977f3c5a4b4e | 698 | |
casiotone401 | 14:977f3c5a4b4e | 699 | qcv = calibMap1[(unsigned int)(gSeq_cv2[ch-8] / quan)]; |
casiotone401 | 14:977f3c5a4b4e | 700 | } |
casiotone401 | 14:977f3c5a4b4e | 701 | |
casiotone401 | 14:977f3c5a4b4e | 702 | glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
casiotone401 | 14:977f3c5a4b4e | 703 | cv = (unsigned int)glidecv[0]; |
casiotone401 | 14:977f3c5a4b4e | 704 | |
casiotone401 | 14:977f3c5a4b4e | 705 | UpdateCV(WRITE_UPDATE_N, 0, &cv); |
casiotone401 | 14:977f3c5a4b4e | 706 | break; |
casiotone401 | 14:977f3c5a4b4e | 707 | |
casiotone401 | 14:977f3c5a4b4e | 708 | case Maj: |
casiotone401 | 14:977f3c5a4b4e | 709 | |
casiotone401 | 14:977f3c5a4b4e | 710 | quan = 40616 / QUAN_RES2; |
casiotone401 | 14:977f3c5a4b4e | 711 | |
casiotone401 | 14:977f3c5a4b4e | 712 | if(ch < 8) |
casiotone401 | 14:977f3c5a4b4e | 713 | { |
casiotone401 | 14:977f3c5a4b4e | 714 | qcv = calibMap2[(unsigned int)(gSeq_cv1[ch] / quan)]; |
casiotone401 | 14:977f3c5a4b4e | 715 | |
casiotone401 | 14:977f3c5a4b4e | 716 | } else { |
casiotone401 | 14:977f3c5a4b4e | 717 | |
casiotone401 | 14:977f3c5a4b4e | 718 | qcv = calibMap2[(unsigned int)(gSeq_cv2[ch-8] / quan)]; |
casiotone401 | 14:977f3c5a4b4e | 719 | } |
casiotone401 | 14:977f3c5a4b4e | 720 | |
casiotone401 | 14:977f3c5a4b4e | 721 | glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
casiotone401 | 14:977f3c5a4b4e | 722 | cv = (unsigned int)glidecv[0]; |
casiotone401 | 14:977f3c5a4b4e | 723 | |
casiotone401 | 14:977f3c5a4b4e | 724 | UpdateCV(WRITE_UPDATE_N, 0, &cv); |
casiotone401 | 14:977f3c5a4b4e | 725 | break; |
casiotone401 | 14:977f3c5a4b4e | 726 | |
casiotone401 | 14:977f3c5a4b4e | 727 | case M7: |
casiotone401 | 14:977f3c5a4b4e | 728 | |
casiotone401 | 14:977f3c5a4b4e | 729 | quan = 40616 / QUAN_RES3; |
casiotone401 | 14:977f3c5a4b4e | 730 | |
casiotone401 | 14:977f3c5a4b4e | 731 | if(ch < 8) |
casiotone401 | 14:977f3c5a4b4e | 732 | { |
casiotone401 | 14:977f3c5a4b4e | 733 | qcv = calibMap3[(unsigned int)(gSeq_cv1[ch] / quan)]; |
casiotone401 | 14:977f3c5a4b4e | 734 | |
casiotone401 | 14:977f3c5a4b4e | 735 | } else { |
casiotone401 | 14:977f3c5a4b4e | 736 | |
casiotone401 | 14:977f3c5a4b4e | 737 | qcv = calibMap3[(unsigned int)(gSeq_cv2[ch-8] / quan)]; |
casiotone401 | 14:977f3c5a4b4e | 738 | } |
casiotone401 | 14:977f3c5a4b4e | 739 | |
casiotone401 | 14:977f3c5a4b4e | 740 | glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
casiotone401 | 14:977f3c5a4b4e | 741 | cv = (unsigned int)glidecv[0]; |
casiotone401 | 14:977f3c5a4b4e | 742 | |
casiotone401 | 14:977f3c5a4b4e | 743 | UpdateCV(WRITE_UPDATE_N, 0, &cv); |
casiotone401 | 14:977f3c5a4b4e | 744 | break; |
casiotone401 | 14:977f3c5a4b4e | 745 | |
casiotone401 | 14:977f3c5a4b4e | 746 | case Min7: |
casiotone401 | 14:977f3c5a4b4e | 747 | |
casiotone401 | 14:977f3c5a4b4e | 748 | quan = 40616 / QUAN_RES4; |
casiotone401 | 14:977f3c5a4b4e | 749 | |
casiotone401 | 14:977f3c5a4b4e | 750 | if(ch < 8) |
casiotone401 | 14:977f3c5a4b4e | 751 | { |
casiotone401 | 14:977f3c5a4b4e | 752 | qcv = calibMap4[(unsigned int)(gSeq_cv1[ch] / quan)]; |
casiotone401 | 14:977f3c5a4b4e | 753 | |
casiotone401 | 14:977f3c5a4b4e | 754 | } else { |
casiotone401 | 14:977f3c5a4b4e | 755 | |
casiotone401 | 14:977f3c5a4b4e | 756 | qcv = calibMap4[(unsigned int)(gSeq_cv2[ch-8] / quan)]; |
casiotone401 | 14:977f3c5a4b4e | 757 | } |
casiotone401 | 14:977f3c5a4b4e | 758 | |
casiotone401 | 14:977f3c5a4b4e | 759 | glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
casiotone401 | 14:977f3c5a4b4e | 760 | cv = (unsigned int)glidecv[0]; |
casiotone401 | 14:977f3c5a4b4e | 761 | |
casiotone401 | 14:977f3c5a4b4e | 762 | UpdateCV(WRITE_UPDATE_N, 0, &cv); |
casiotone401 | 14:977f3c5a4b4e | 763 | break; |
casiotone401 | 14:977f3c5a4b4e | 764 | |
casiotone401 | 14:977f3c5a4b4e | 765 | case Dor: |
casiotone401 | 14:977f3c5a4b4e | 766 | |
casiotone401 | 14:977f3c5a4b4e | 767 | quan = 40616 / QUAN_RES5; |
casiotone401 | 14:977f3c5a4b4e | 768 | |
casiotone401 | 14:977f3c5a4b4e | 769 | if(ch < 8) |
casiotone401 | 14:977f3c5a4b4e | 770 | { |
casiotone401 | 14:977f3c5a4b4e | 771 | qcv = calibMap5[(unsigned int)(gSeq_cv1[ch] / quan)]; |
casiotone401 | 14:977f3c5a4b4e | 772 | |
casiotone401 | 14:977f3c5a4b4e | 773 | } else { |
casiotone401 | 14:977f3c5a4b4e | 774 | |
casiotone401 | 14:977f3c5a4b4e | 775 | qcv = calibMap5[(unsigned int)(gSeq_cv2[ch-8] / quan)]; |
casiotone401 | 14:977f3c5a4b4e | 776 | } |
casiotone401 | 14:977f3c5a4b4e | 777 | |
casiotone401 | 14:977f3c5a4b4e | 778 | glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
casiotone401 | 14:977f3c5a4b4e | 779 | cv = (unsigned int)glidecv[0]; |
casiotone401 | 14:977f3c5a4b4e | 780 | |
casiotone401 | 14:977f3c5a4b4e | 781 | UpdateCV(WRITE_UPDATE_N, 0, &cv); |
casiotone401 | 14:977f3c5a4b4e | 782 | break; |
casiotone401 | 14:977f3c5a4b4e | 783 | |
casiotone401 | 14:977f3c5a4b4e | 784 | case Min: |
casiotone401 | 14:977f3c5a4b4e | 785 | |
casiotone401 | 14:977f3c5a4b4e | 786 | quan = 40616 / QUAN_RES6; |
casiotone401 | 14:977f3c5a4b4e | 787 | |
casiotone401 | 14:977f3c5a4b4e | 788 | if(ch < 8) |
casiotone401 | 14:977f3c5a4b4e | 789 | { |
casiotone401 | 14:977f3c5a4b4e | 790 | qcv = calibMap6[(unsigned int)(gSeq_cv1[ch] / quan)]; |
casiotone401 | 14:977f3c5a4b4e | 791 | |
casiotone401 | 14:977f3c5a4b4e | 792 | } else { |
casiotone401 | 14:977f3c5a4b4e | 793 | |
casiotone401 | 14:977f3c5a4b4e | 794 | qcv = calibMap6[(unsigned int)(gSeq_cv2[ch-8] / quan)]; |
casiotone401 | 14:977f3c5a4b4e | 795 | } |
casiotone401 | 14:977f3c5a4b4e | 796 | |
casiotone401 | 14:977f3c5a4b4e | 797 | glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
casiotone401 | 14:977f3c5a4b4e | 798 | cv = (unsigned int)glidecv[0]; |
casiotone401 | 14:977f3c5a4b4e | 799 | |
casiotone401 | 14:977f3c5a4b4e | 800 | UpdateCV(WRITE_UPDATE_N, 0, &cv); |
casiotone401 | 14:977f3c5a4b4e | 801 | break; |
casiotone401 | 14:977f3c5a4b4e | 802 | |
casiotone401 | 14:977f3c5a4b4e | 803 | case S5th: |
casiotone401 | 14:977f3c5a4b4e | 804 | |
casiotone401 | 14:977f3c5a4b4e | 805 | quan = 40616 / QUAN_RES7; |
casiotone401 | 14:977f3c5a4b4e | 806 | |
casiotone401 | 14:977f3c5a4b4e | 807 | if(ch < 8) |
casiotone401 | 14:977f3c5a4b4e | 808 | { |
casiotone401 | 14:977f3c5a4b4e | 809 | qcv = calibMap7[(unsigned int)(gSeq_cv1[ch] / quan)]; |
casiotone401 | 14:977f3c5a4b4e | 810 | |
casiotone401 | 14:977f3c5a4b4e | 811 | } else { |
casiotone401 | 14:977f3c5a4b4e | 812 | |
casiotone401 | 14:977f3c5a4b4e | 813 | qcv = calibMap7[(unsigned int)(gSeq_cv2[ch-8] / quan)]; |
casiotone401 | 14:977f3c5a4b4e | 814 | } |
casiotone401 | 14:977f3c5a4b4e | 815 | |
casiotone401 | 14:977f3c5a4b4e | 816 | glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
casiotone401 | 14:977f3c5a4b4e | 817 | cv = (unsigned int)glidecv[0]; |
casiotone401 | 14:977f3c5a4b4e | 818 | |
casiotone401 | 14:977f3c5a4b4e | 819 | UpdateCV(WRITE_UPDATE_N, 0, &cv); |
casiotone401 | 14:977f3c5a4b4e | 820 | break; |
casiotone401 | 14:977f3c5a4b4e | 821 | |
casiotone401 | 14:977f3c5a4b4e | 822 | case Wht: |
casiotone401 | 14:977f3c5a4b4e | 823 | |
casiotone401 | 14:977f3c5a4b4e | 824 | quan = 40616 / QUAN_RES8; |
casiotone401 | 14:977f3c5a4b4e | 825 | |
casiotone401 | 14:977f3c5a4b4e | 826 | if(ch < 8) |
casiotone401 | 14:977f3c5a4b4e | 827 | { |
casiotone401 | 14:977f3c5a4b4e | 828 | qcv = calibMap8[(unsigned int)(gSeq_cv1[ch] / quan)]; |
casiotone401 | 14:977f3c5a4b4e | 829 | |
casiotone401 | 14:977f3c5a4b4e | 830 | } else { |
casiotone401 | 14:977f3c5a4b4e | 831 | |
casiotone401 | 14:977f3c5a4b4e | 832 | qcv = calibMap8[(unsigned int)(gSeq_cv2[ch-8] / quan)]; |
casiotone401 | 14:977f3c5a4b4e | 833 | } |
casiotone401 | 14:977f3c5a4b4e | 834 | |
casiotone401 | 14:977f3c5a4b4e | 835 | glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
casiotone401 | 14:977f3c5a4b4e | 836 | cv = (unsigned int)glidecv[0]; |
casiotone401 | 14:977f3c5a4b4e | 837 | |
casiotone401 | 14:977f3c5a4b4e | 838 | UpdateCV(WRITE_UPDATE_N, 0, &cv); |
casiotone401 | 14:977f3c5a4b4e | 839 | break; |
casiotone401 | 14:977f3c5a4b4e | 840 | } |
casiotone401 | 14:977f3c5a4b4e | 841 | |
casiotone401 | 14:977f3c5a4b4e | 842 | for(i = 1; i < 8; ++i) |
casiotone401 | 14:977f3c5a4b4e | 843 | { |
casiotone401 | 14:977f3c5a4b4e | 844 | glidecv[i] = glidecv[i] * gGlide + shiftcv[i] * (1.0f - gGlide); |
casiotone401 | 14:977f3c5a4b4e | 845 | cv = (unsigned int)glidecv[i]; |
casiotone401 | 14:977f3c5a4b4e | 846 | |
casiotone401 | 14:977f3c5a4b4e | 847 | UpdateCV(WRITE_UPDATE_N, i, &cv); |
casiotone401 | 14:977f3c5a4b4e | 848 | } |
casiotone401 | 14:977f3c5a4b4e | 849 | |
casiotone401 | 14:977f3c5a4b4e | 850 | if(shift == 1) // GATE1 |
casiotone401 | 14:977f3c5a4b4e | 851 | { |
casiotone401 | 14:977f3c5a4b4e | 852 | for(j = 1; j < 8; ++j) // Shift ch2~8 |
casiotone401 | 14:977f3c5a4b4e | 853 | { |
casiotone401 | 14:977f3c5a4b4e | 854 | shiftcv[j] = glidecv[j-1]; |
casiotone401 | 14:977f3c5a4b4e | 855 | } |
casiotone401 | 14:977f3c5a4b4e | 856 | |
casiotone401 | 14:977f3c5a4b4e | 857 | ch++; |
casiotone401 | 14:977f3c5a4b4e | 858 | ch &= 0x0F; |
casiotone401 | 14:977f3c5a4b4e | 859 | } |
casiotone401 | 14:977f3c5a4b4e | 860 | |
casiotone401 | 14:977f3c5a4b4e | 861 | |
casiotone401 | 14:977f3c5a4b4e | 862 | if(ch < 8) |
casiotone401 | 14:977f3c5a4b4e | 863 | { |
casiotone401 | 14:977f3c5a4b4e | 864 | CVMeter(ch, &cv); |
casiotone401 | 14:977f3c5a4b4e | 865 | |
casiotone401 | 14:977f3c5a4b4e | 866 | } else { |
casiotone401 | 14:977f3c5a4b4e | 867 | |
casiotone401 | 14:977f3c5a4b4e | 868 | CVMeter((ch-8), &cv); |
casiotone401 | 14:977f3c5a4b4e | 869 | } |
casiotone401 | 14:977f3c5a4b4e | 870 | |
casiotone401 | 14:977f3c5a4b4e | 871 | } |
casiotone401 | 14:977f3c5a4b4e | 872 | |
casiotone401 | 14:977f3c5a4b4e | 873 | //------------------------------------------------------------- |
casiotone401 | 14:977f3c5a4b4e | 874 | // Sequencer Mode |
casiotone401 | 14:977f3c5a4b4e | 875 | |
casiotone401 | 14:977f3c5a4b4e | 876 | inline void Seq() |
casiotone401 | 14:977f3c5a4b4e | 877 | { |
casiotone401 | 14:977f3c5a4b4e | 878 | static int bpm, _bpm; |
casiotone401 | 14:977f3c5a4b4e | 879 | |
casiotone401 | 14:977f3c5a4b4e | 880 | bpm = (gCtrl[0] * 300 + 10); // Set BPM (gCtrl[0]) |
casiotone401 | 14:977f3c5a4b4e | 881 | |
casiotone401 | 14:977f3c5a4b4e | 882 | if(abs(bpm - _bpm) > 1) |
casiotone401 | 14:977f3c5a4b4e | 883 | { |
casiotone401 | 14:977f3c5a4b4e | 884 | UpdateGate(bpm, NRESET, GATEALL, 3, false); // Reset (if bpm change) |
casiotone401 | 14:977f3c5a4b4e | 885 | _bpm = bpm; |
casiotone401 | 14:977f3c5a4b4e | 886 | |
casiotone401 | 14:977f3c5a4b4e | 887 | } else if (gCtrlSW[0]) { // Stop (gCtrlSW[0]) |
casiotone401 | 14:977f3c5a4b4e | 888 | |
casiotone401 | 14:977f3c5a4b4e | 889 | bpm = 0; |
casiotone401 | 14:977f3c5a4b4e | 890 | } |
casiotone401 | 14:977f3c5a4b4e | 891 | |
casiotone401 | 14:977f3c5a4b4e | 892 | if(!gCtrlSW[2] && !gCtrlSW[3]) // Sequencer Mode1 |
casiotone401 | 14:977f3c5a4b4e | 893 | { |
casiotone401 | 14:977f3c5a4b4e | 894 | SeqCV((UpdateGate(bpm, N16TH, GATE1, 3, false))); // Shift Timming 16th note |
casiotone401 | 14:977f3c5a4b4e | 895 | UpdateGate(bpm, N8TH, GATE2, 3, 0); |
casiotone401 | 14:977f3c5a4b4e | 896 | UpdateGate(bpm, NDOT8, GATE3, 3, 0); |
casiotone401 | 14:977f3c5a4b4e | 897 | UpdateGate(bpm, TRIP4, GATE4, 3, 0); |
casiotone401 | 14:977f3c5a4b4e | 898 | } |
casiotone401 | 14:977f3c5a4b4e | 899 | |
casiotone401 | 14:977f3c5a4b4e | 900 | } |
casiotone401 | 14:977f3c5a4b4e | 901 | |
casiotone401 | 14:977f3c5a4b4e | 902 | //------------------------------------------------------------- |
casiotone401 | 14:977f3c5a4b4e | 903 | // Check SW |
casiotone401 | 14:977f3c5a4b4e | 904 | |
casiotone401 | 14:977f3c5a4b4e | 905 | void CheckModeSW() |
casiotone401 | 14:977f3c5a4b4e | 906 | { |
casiotone401 | 14:977f3c5a4b4e | 907 | wait(0.05); |
casiotone401 | 14:977f3c5a4b4e | 908 | |
casiotone401 | 14:977f3c5a4b4e | 909 | if(gMode < MODE_NUM - 1) |
casiotone401 | 14:977f3c5a4b4e | 910 | { |
casiotone401 | 14:977f3c5a4b4e | 911 | gMode++; |
casiotone401 | 14:977f3c5a4b4e | 912 | |
casiotone401 | 14:977f3c5a4b4e | 913 | } else { |
casiotone401 | 14:977f3c5a4b4e | 914 | |
casiotone401 | 14:977f3c5a4b4e | 915 | gMode = 0; |
casiotone401 | 14:977f3c5a4b4e | 916 | } |
casiotone401 | 14:977f3c5a4b4e | 917 | |
casiotone401 | 14:977f3c5a4b4e | 918 | gCLOCKOUT = gGATES[0] = gGATES[1] = gGATES[2] = gGATES[3] = 0; |
casiotone401 | 14:977f3c5a4b4e | 919 | gLEDS[0] = gLEDS[1] = gLEDS[2] = gLEDS[3] = 0; |
casiotone401 | 14:977f3c5a4b4e | 920 | |
casiotone401 | 14:977f3c5a4b4e | 921 | if(gMode == MODE_SEQ) |
casiotone401 | 14:977f3c5a4b4e | 922 | { |
casiotone401 | 14:977f3c5a4b4e | 923 | gTimer.start(); // Sequencer Timer Start |
casiotone401 | 14:977f3c5a4b4e | 924 | |
casiotone401 | 14:977f3c5a4b4e | 925 | } else { |
casiotone401 | 14:977f3c5a4b4e | 926 | |
casiotone401 | 14:977f3c5a4b4e | 927 | gTimer.stop(); // Sequencer Timer Stop |
casiotone401 | 14:977f3c5a4b4e | 928 | } |
casiotone401 | 14:977f3c5a4b4e | 929 | |
casiotone401 | 14:977f3c5a4b4e | 930 | LCD(); |
casiotone401 | 14:977f3c5a4b4e | 931 | } |
casiotone401 | 14:977f3c5a4b4e | 932 | |
casiotone401 | 14:977f3c5a4b4e | 933 | //------------------------------------------------------------- |
casiotone401 | 5:e305509d53f3 | 934 | // GateOutSequence beat(Note values) length(Gate time) invert(invert Gate) |
casiotone401 | 5:e305509d53f3 | 935 | |
casiotone401 | 14:977f3c5a4b4e | 936 | inline int UpdateGate(int bpm, int beat, int ch, int length, bool invert) |
casiotone401 | 5:e305509d53f3 | 937 | { |
casiotone401 | 10:ccfeb687c3f2 | 938 | int i; |
casiotone401 | 10:ccfeb687c3f2 | 939 | static int gatetime[4], oldgatetime[4]; |
casiotone401 | 10:ccfeb687c3f2 | 940 | static int bar, sync24, oldsynctime; |
casiotone401 | 5:e305509d53f3 | 941 | |
casiotone401 | 5:e305509d53f3 | 942 | int time = gTimer.read_us(); |
casiotone401 | 5:e305509d53f3 | 943 | |
casiotone401 | 5:e305509d53f3 | 944 | bar = (60.0f / bpm) * 4000000; |
casiotone401 | 14:977f3c5a4b4e | 945 | sync24 = (bar / 4) / 24; // sync24 not tested |
casiotone401 | 5:e305509d53f3 | 946 | |
casiotone401 | 14:977f3c5a4b4e | 947 | switch(beat) // Calculate Note values |
casiotone401 | 5:e305509d53f3 | 948 | { |
casiotone401 | 5:e305509d53f3 | 949 | case NDOT2: |
casiotone401 | 5:e305509d53f3 | 950 | |
casiotone401 | 5:e305509d53f3 | 951 | gatetime[ch] = (bar / 4) * 3; |
casiotone401 | 5:e305509d53f3 | 952 | break; |
casiotone401 | 5:e305509d53f3 | 953 | |
casiotone401 | 5:e305509d53f3 | 954 | case NDOT4: |
casiotone401 | 5:e305509d53f3 | 955 | |
casiotone401 | 5:e305509d53f3 | 956 | gatetime[ch] = (bar / 8) * 3; |
casiotone401 | 5:e305509d53f3 | 957 | break; |
casiotone401 | 5:e305509d53f3 | 958 | |
casiotone401 | 5:e305509d53f3 | 959 | case NDOT8: |
casiotone401 | 5:e305509d53f3 | 960 | |
casiotone401 | 5:e305509d53f3 | 961 | gatetime[ch] = (bar / 16) * 3; |
casiotone401 | 5:e305509d53f3 | 962 | break; |
casiotone401 | 5:e305509d53f3 | 963 | |
casiotone401 | 5:e305509d53f3 | 964 | case NDOT16: |
casiotone401 | 5:e305509d53f3 | 965 | |
casiotone401 | 5:e305509d53f3 | 966 | gatetime[ch] = (bar / 32) * 3; |
casiotone401 | 5:e305509d53f3 | 967 | break; |
casiotone401 | 5:e305509d53f3 | 968 | |
casiotone401 | 5:e305509d53f3 | 969 | case NDOT32: |
casiotone401 | 5:e305509d53f3 | 970 | |
casiotone401 | 5:e305509d53f3 | 971 | gatetime[ch] = (bar / 64) * 3; |
casiotone401 | 5:e305509d53f3 | 972 | break; |
casiotone401 | 5:e305509d53f3 | 973 | |
casiotone401 | 5:e305509d53f3 | 974 | case NRESET: |
casiotone401 | 5:e305509d53f3 | 975 | |
casiotone401 | 10:ccfeb687c3f2 | 976 | for(i = 0; i < GATEALL; ++i) // Reset |
casiotone401 | 5:e305509d53f3 | 977 | { |
casiotone401 | 5:e305509d53f3 | 978 | gTimer.reset(); |
casiotone401 | 5:e305509d53f3 | 979 | oldsynctime = oldgatetime[i] = gatetime[i] = NRESET; |
casiotone401 | 5:e305509d53f3 | 980 | } |
casiotone401 | 5:e305509d53f3 | 981 | break; |
casiotone401 | 5:e305509d53f3 | 982 | |
casiotone401 | 5:e305509d53f3 | 983 | default: |
casiotone401 | 5:e305509d53f3 | 984 | |
casiotone401 | 5:e305509d53f3 | 985 | gatetime[ch] = bar / beat; |
casiotone401 | 5:e305509d53f3 | 986 | } |
casiotone401 | 5:e305509d53f3 | 987 | |
casiotone401 | 5:e305509d53f3 | 988 | if(time > oldsynctime + sync24) // sync24 not tested |
casiotone401 | 5:e305509d53f3 | 989 | { |
casiotone401 | 5:e305509d53f3 | 990 | oldsynctime = time; |
casiotone401 | 5:e305509d53f3 | 991 | gCLOCKOUT = 1; |
casiotone401 | 5:e305509d53f3 | 992 | |
casiotone401 | 5:e305509d53f3 | 993 | } else if (time > sync24 - (sync24 - 2)) { |
casiotone401 | 5:e305509d53f3 | 994 | |
casiotone401 | 5:e305509d53f3 | 995 | gCLOCKOUT = 0; |
casiotone401 | 5:e305509d53f3 | 996 | } |
casiotone401 | 5:e305509d53f3 | 997 | |
casiotone401 | 5:e305509d53f3 | 998 | if (ch == GATEALL) |
casiotone401 | 5:e305509d53f3 | 999 | { |
casiotone401 | 5:e305509d53f3 | 1000 | return -1; |
casiotone401 | 5:e305509d53f3 | 1001 | |
casiotone401 | 10:ccfeb687c3f2 | 1002 | } else if (time > oldgatetime[ch] + gatetime[ch] && !invert) { |
casiotone401 | 5:e305509d53f3 | 1003 | |
casiotone401 | 5:e305509d53f3 | 1004 | oldgatetime[ch] = time; |
casiotone401 | 5:e305509d53f3 | 1005 | gLEDS[ch] = gGATES[ch] = 1; |
casiotone401 | 5:e305509d53f3 | 1006 | |
casiotone401 | 5:e305509d53f3 | 1007 | return ch + 1; |
casiotone401 | 5:e305509d53f3 | 1008 | |
casiotone401 | 10:ccfeb687c3f2 | 1009 | } else if (time > oldgatetime[ch] + gatetime[ch] && invert) { |
casiotone401 | 5:e305509d53f3 | 1010 | |
casiotone401 | 5:e305509d53f3 | 1011 | oldgatetime[ch] = time; |
casiotone401 | 5:e305509d53f3 | 1012 | gLEDS[ch] = gGATES[ch] = 0; |
casiotone401 | 5:e305509d53f3 | 1013 | |
casiotone401 | 5:e305509d53f3 | 1014 | return 0; |
casiotone401 | 5:e305509d53f3 | 1015 | |
casiotone401 | 10:ccfeb687c3f2 | 1016 | } else if (time > oldgatetime[ch] + (gatetime[ch] - gatetime[ch] / length) && !invert) { |
casiotone401 | 5:e305509d53f3 | 1017 | |
casiotone401 | 5:e305509d53f3 | 1018 | gLEDS[ch] = gGATES[ch] = 0; |
casiotone401 | 5:e305509d53f3 | 1019 | |
casiotone401 | 5:e305509d53f3 | 1020 | return 0; |
casiotone401 | 5:e305509d53f3 | 1021 | |
casiotone401 | 10:ccfeb687c3f2 | 1022 | } else if (time > oldgatetime[ch] + (gatetime[ch] - gatetime[ch] / length) && invert) { |
casiotone401 | 5:e305509d53f3 | 1023 | |
casiotone401 | 5:e305509d53f3 | 1024 | gLEDS[ch] = gGATES[ch] = 1; |
casiotone401 | 5:e305509d53f3 | 1025 | |
casiotone401 | 5:e305509d53f3 | 1026 | return ch + 1; |
casiotone401 | 5:e305509d53f3 | 1027 | |
casiotone401 | 5:e305509d53f3 | 1028 | } else { |
casiotone401 | 5:e305509d53f3 | 1029 | |
casiotone401 | 5:e305509d53f3 | 1030 | return -1; |
casiotone401 | 5:e305509d53f3 | 1031 | } |
casiotone401 | 5:e305509d53f3 | 1032 | } |
casiotone401 | 5:e305509d53f3 | 1033 | |
casiotone401 | 5:e305509d53f3 | 1034 | //------------------------------------------------------------- |
casiotone401 | 14:977f3c5a4b4e | 1035 | // SyncOut Sequence beat(Note values) invert(invert Gate) |
casiotone401 | 0:a4d93cd4c30d | 1036 | |
casiotone401 | 14:977f3c5a4b4e | 1037 | inline void UpdateSync(int bpm, int beat, bool invert) |
casiotone401 | 4:b9f5ae574447 | 1038 | { |
casiotone401 | 14:977f3c5a4b4e | 1039 | static int bar, synctime, oldsynctime; |
casiotone401 | 14:977f3c5a4b4e | 1040 | |
casiotone401 | 14:977f3c5a4b4e | 1041 | int time = gTimer.read_us(); |
casiotone401 | 4:b9f5ae574447 | 1042 | |
casiotone401 | 14:977f3c5a4b4e | 1043 | bar = (60.0f / bpm) * 4000000; |
casiotone401 | 4:b9f5ae574447 | 1044 | |
casiotone401 | 14:977f3c5a4b4e | 1045 | synctime = bar / beat; |
casiotone401 | 4:b9f5ae574447 | 1046 | |
casiotone401 | 14:977f3c5a4b4e | 1047 | if(beat == NRESET) |
casiotone401 | 14:977f3c5a4b4e | 1048 | { |
casiotone401 | 14:977f3c5a4b4e | 1049 | bar = synctime = oldsynctime = gCLOCKOUT = 0; |
casiotone401 | 0:a4d93cd4c30d | 1050 | } |
casiotone401 | 3:ca15241dd6b4 | 1051 | |
casiotone401 | 14:977f3c5a4b4e | 1052 | if((time > oldsynctime + synctime) && !invert) |
casiotone401 | 5:e305509d53f3 | 1053 | { |
casiotone401 | 14:977f3c5a4b4e | 1054 | oldsynctime = time; |
casiotone401 | 14:977f3c5a4b4e | 1055 | gCLOCKOUT = 1; |
casiotone401 | 14:977f3c5a4b4e | 1056 | |
casiotone401 | 14:977f3c5a4b4e | 1057 | } else if ((time > synctime - (synctime / 2)) && !invert) { |
casiotone401 | 14:977f3c5a4b4e | 1058 | |
casiotone401 | 14:977f3c5a4b4e | 1059 | gCLOCKOUT = 0; |
casiotone401 | 5:e305509d53f3 | 1060 | |
casiotone401 | 14:977f3c5a4b4e | 1061 | } else if((time > oldsynctime + synctime) && invert) { |
casiotone401 | 14:977f3c5a4b4e | 1062 | |
casiotone401 | 14:977f3c5a4b4e | 1063 | oldsynctime = time; |
casiotone401 | 14:977f3c5a4b4e | 1064 | gCLOCKOUT = 0; |
casiotone401 | 14:977f3c5a4b4e | 1065 | |
casiotone401 | 14:977f3c5a4b4e | 1066 | } else if ((time > synctime - (synctime / 2)) && invert) { |
casiotone401 | 14:977f3c5a4b4e | 1067 | |
casiotone401 | 14:977f3c5a4b4e | 1068 | gCLOCKOUT = 1; |
casiotone401 | 5:e305509d53f3 | 1069 | } |
casiotone401 | 5:e305509d53f3 | 1070 | |
casiotone401 | 4:b9f5ae574447 | 1071 | } |
casiotone401 | 4:b9f5ae574447 | 1072 | |
casiotone401 | 4:b9f5ae574447 | 1073 | //------------------------------------------------------------- |
casiotone401 | 4:b9f5ae574447 | 1074 | // CV meter |
casiotone401 | 4:b9f5ae574447 | 1075 | |
casiotone401 | 9:1ac3d135d965 | 1076 | inline void CVMeter(int ch, const unsigned int *level) |
casiotone401 | 14:977f3c5a4b4e | 1077 | { |
casiotone401 | 4:b9f5ae574447 | 1078 | gLCD.locate ( ch, 0 ); |
casiotone401 | 14:977f3c5a4b4e | 1079 | gLCD.putc(*level * 0.000205729); // put custom char |
casiotone401 | 4:b9f5ae574447 | 1080 | } |
casiotone401 | 4:b9f5ae574447 | 1081 | |
casiotone401 | 4:b9f5ae574447 | 1082 | //------------------------------------------------------------- |
casiotone401 | 5:e305509d53f3 | 1083 | // Print LCD Mode Status |
casiotone401 | 4:b9f5ae574447 | 1084 | |
casiotone401 | 4:b9f5ae574447 | 1085 | void LCD() |
casiotone401 | 4:b9f5ae574447 | 1086 | { |
casiotone401 | 3:ca15241dd6b4 | 1087 | switch(gMode) |
casiotone401 | 3:ca15241dd6b4 | 1088 | { |
casiotone401 | 14:977f3c5a4b4e | 1089 | case MODE_Calb: |
casiotone401 | 14:977f3c5a4b4e | 1090 | gLCD.locate( 9, 0 ); |
casiotone401 | 14:977f3c5a4b4e | 1091 | gLCD.printf("Calibr "); |
casiotone401 | 14:977f3c5a4b4e | 1092 | break; |
casiotone401 | 14:977f3c5a4b4e | 1093 | |
casiotone401 | 3:ca15241dd6b4 | 1094 | case MODE_LIN: |
casiotone401 | 3:ca15241dd6b4 | 1095 | gLCD.locate( 9, 0 ); |
casiotone401 | 3:ca15241dd6b4 | 1096 | gLCD.printf("OSC-CV "); |
casiotone401 | 3:ca15241dd6b4 | 1097 | break; |
casiotone401 | 14:977f3c5a4b4e | 1098 | |
casiotone401 | 4:b9f5ae574447 | 1099 | case MODE_SEQ: |
casiotone401 | 4:b9f5ae574447 | 1100 | gLCD.locate( 9, 0 ); |
casiotone401 | 14:977f3c5a4b4e | 1101 | gLCD.printf("SHIFTCV"); |
casiotone401 | 4:b9f5ae574447 | 1102 | break; |
casiotone401 | 3:ca15241dd6b4 | 1103 | } |
casiotone401 | 0:a4d93cd4c30d | 1104 | } |
casiotone401 | 0:a4d93cd4c30d | 1105 | |
casiotone401 | 0:a4d93cd4c30d | 1106 | //------------------------------------------------------------- |
casiotone401 | 0:a4d93cd4c30d | 1107 | // Write command Custom Char LCD CGRAM(CV Meter) |
casiotone401 | 0:a4d93cd4c30d | 1108 | |
casiotone401 | 0:a4d93cd4c30d | 1109 | void WriteCustomChar(unsigned char addr, unsigned char *c) |
casiotone401 | 0:a4d93cd4c30d | 1110 | { |
casiotone401 | 0:a4d93cd4c30d | 1111 | char cnt = 0; |
casiotone401 | 0:a4d93cd4c30d | 1112 | addr = ((addr << 3) | 0x40); |
casiotone401 | 0:a4d93cd4c30d | 1113 | |
casiotone401 | 0:a4d93cd4c30d | 1114 | while(cnt < 0x08) |
casiotone401 | 0:a4d93cd4c30d | 1115 | { |
casiotone401 | 0:a4d93cd4c30d | 1116 | gLCD.writeCommand(addr | cnt); |
casiotone401 | 0:a4d93cd4c30d | 1117 | gLCD.writeData(*c); |
casiotone401 | 4:b9f5ae574447 | 1118 | |
casiotone401 | 0:a4d93cd4c30d | 1119 | cnt++; |
casiotone401 | 0:a4d93cd4c30d | 1120 | c++; |
casiotone401 | 0:a4d93cd4c30d | 1121 | } |
casiotone401 | 0:a4d93cd4c30d | 1122 | } |
casiotone401 | 0:a4d93cd4c30d | 1123 | |
casiotone401 | 0:a4d93cd4c30d | 1124 | //------------------------------------------------------------- |
casiotone401 | 0:a4d93cd4c30d | 1125 | // Setup Ethernet port |
casiotone401 | 0:a4d93cd4c30d | 1126 | |
casiotone401 | 0:a4d93cd4c30d | 1127 | int SetupEthNetIf() |
casiotone401 | 0:a4d93cd4c30d | 1128 | { |
casiotone401 | 0:a4d93cd4c30d | 1129 | gLCD.locate( 0, 1 ); |
casiotone401 | 0:a4d93cd4c30d | 1130 | gLCD.printf("Setting up... "); |
casiotone401 | 0:a4d93cd4c30d | 1131 | // printf("Setting up...\r\n"); |
casiotone401 | 0:a4d93cd4c30d | 1132 | EthernetErr ethErr = gEth.setup(); |
casiotone401 | 0:a4d93cd4c30d | 1133 | |
casiotone401 | 0:a4d93cd4c30d | 1134 | if(ethErr) |
casiotone401 | 0:a4d93cd4c30d | 1135 | { |
casiotone401 | 0:a4d93cd4c30d | 1136 | gLCD.locate( 0, 1 ); |
casiotone401 | 0:a4d93cd4c30d | 1137 | gLCD.printf("Error in setup."); |
casiotone401 | 0:a4d93cd4c30d | 1138 | // printf("Error %d in setup.\r\n", ethErr); |
casiotone401 | 0:a4d93cd4c30d | 1139 | return -1; |
casiotone401 | 0:a4d93cd4c30d | 1140 | } |
casiotone401 | 0:a4d93cd4c30d | 1141 | // printf("Setup OK\r\n"); |
casiotone401 | 0:a4d93cd4c30d | 1142 | |
casiotone401 | 0:a4d93cd4c30d | 1143 | // printf("IP address %d.%d.%d.%d\r\n", gEth.getIp()[0], gEth.getIp()[1], gEth.getIp()[2], gEth.getIp()[3]); |
casiotone401 | 0:a4d93cd4c30d | 1144 | Host broadcast(IpAddr(gEth.getIp()[0], gEth.getIp()[1], gEth.getIp()[2], 255), INPUT_PORT, NULL); |
casiotone401 | 0:a4d93cd4c30d | 1145 | gUdp.setOnEvent(&onUDPSocketEvent); |
casiotone401 | 0:a4d93cd4c30d | 1146 | gUdp.bind(broadcast); |
casiotone401 | 4:b9f5ae574447 | 1147 | |
casiotone401 | 0:a4d93cd4c30d | 1148 | gLCD.locate( 0, 1 ); |
casiotone401 | 0:a4d93cd4c30d | 1149 | gLCD.printf("%03d.%03d.%03d.%03d", gEth.getIp()[0], gEth.getIp()[1], gEth.getIp()[2], gEth.getIp()[3]); |
casiotone401 | 4:b9f5ae574447 | 1150 | wait(1.0); |
casiotone401 | 0:a4d93cd4c30d | 1151 | |
casiotone401 | 0:a4d93cd4c30d | 1152 | return 0; |
casiotone401 | 0:a4d93cd4c30d | 1153 | } |
casiotone401 | 0:a4d93cd4c30d | 1154 | |
casiotone401 | 0:a4d93cd4c30d | 1155 | //------------------------------------------------------------- |
casiotone401 | 14:977f3c5a4b4e | 1156 | // Fast strlen function http://www.strchr.com/optimized_strlen_function |
casiotone401 | 14:977f3c5a4b4e | 1157 | |
casiotone401 | 14:977f3c5a4b4e | 1158 | size_t strlength(const char *s) |
casiotone401 | 14:977f3c5a4b4e | 1159 | { |
casiotone401 | 14:977f3c5a4b4e | 1160 | size_t len = 0; |
casiotone401 | 14:977f3c5a4b4e | 1161 | |
casiotone401 | 14:977f3c5a4b4e | 1162 | for(;;) |
casiotone401 | 14:977f3c5a4b4e | 1163 | { |
casiotone401 | 14:977f3c5a4b4e | 1164 | unsigned x = *(unsigned*)s; |
casiotone401 | 14:977f3c5a4b4e | 1165 | if((x & 0xFF) == 0) return len; |
casiotone401 | 14:977f3c5a4b4e | 1166 | if((x & 0xFF00) == 0) return len + 1; |
casiotone401 | 14:977f3c5a4b4e | 1167 | if((x & 0xFF0000) == 0) return len + 2; |
casiotone401 | 14:977f3c5a4b4e | 1168 | if((x & 0xFF000000) == 0) return len + 3; |
casiotone401 | 14:977f3c5a4b4e | 1169 | s += 4, len += 4; |
casiotone401 | 14:977f3c5a4b4e | 1170 | } |
casiotone401 | 14:977f3c5a4b4e | 1171 | } |
casiotone401 | 14:977f3c5a4b4e | 1172 | |
casiotone401 | 14:977f3c5a4b4e | 1173 | //------------------------------------------------------------- |
casiotone401 | 0:a4d93cd4c30d | 1174 | // Handller receive UDP Packet |
casiotone401 | 0:a4d93cd4c30d | 1175 | |
casiotone401 | 4:b9f5ae574447 | 1176 | inline void onUDPSocketEvent(UDPSocketEvent e) |
casiotone401 | 0:a4d93cd4c30d | 1177 | { |
casiotone401 | 0:a4d93cd4c30d | 1178 | union OSCarg msg[10]; |
casiotone401 | 10:ccfeb687c3f2 | 1179 | char buf[768] = {0}; |
casiotone401 | 13:3f42e451a8d3 | 1180 | int num, len; |
casiotone401 | 14:977f3c5a4b4e | 1181 | int recvlen; |
casiotone401 | 14:977f3c5a4b4e | 1182 | int messagepos = 0; |
casiotone401 | 14:977f3c5a4b4e | 1183 | bool bundleflag = false; |
casiotone401 | 10:ccfeb687c3f2 | 1184 | |
casiotone401 | 10:ccfeb687c3f2 | 1185 | Host host; |
casiotone401 | 10:ccfeb687c3f2 | 1186 | |
casiotone401 | 10:ccfeb687c3f2 | 1187 | recvlen = gUdp.recvfrom(buf, 768, &host); // packet length |
casiotone401 | 10:ccfeb687c3f2 | 1188 | |
casiotone401 | 0:a4d93cd4c30d | 1189 | switch(e) |
casiotone401 | 0:a4d93cd4c30d | 1190 | { |
casiotone401 | 4:b9f5ae574447 | 1191 | case UDPSOCKET_READABLE: // The only event for now |
casiotone401 | 0:a4d93cd4c30d | 1192 | |
casiotone401 | 10:ccfeb687c3f2 | 1193 | if(recvlen <= 0) break; |
casiotone401 | 10:ccfeb687c3f2 | 1194 | |
casiotone401 | 11:ef7610cd7ebe | 1195 | if(buf[0] == '#') // #bundle |
casiotone401 | 0:a4d93cd4c30d | 1196 | { |
casiotone401 | 10:ccfeb687c3f2 | 1197 | messagepos += 16; // skip #bundle & timetag |
casiotone401 | 10:ccfeb687c3f2 | 1198 | recvlen -= 16; |
casiotone401 | 0:a4d93cd4c30d | 1199 | |
casiotone401 | 10:ccfeb687c3f2 | 1200 | bundleflag = true; |
casiotone401 | 10:ccfeb687c3f2 | 1201 | } |
casiotone401 | 10:ccfeb687c3f2 | 1202 | |
casiotone401 | 10:ccfeb687c3f2 | 1203 | do { |
casiotone401 | 10:ccfeb687c3f2 | 1204 | if(bundleflag) |
casiotone401 | 10:ccfeb687c3f2 | 1205 | { |
casiotone401 | 10:ccfeb687c3f2 | 1206 | messagepos += 4; |
casiotone401 | 10:ccfeb687c3f2 | 1207 | recvlen -= 4; |
casiotone401 | 0:a4d93cd4c30d | 1208 | |
casiotone401 | 10:ccfeb687c3f2 | 1209 | if(recvlen <= 0) |
casiotone401 | 10:ccfeb687c3f2 | 1210 | { |
casiotone401 | 10:ccfeb687c3f2 | 1211 | bundleflag = false; |
casiotone401 | 10:ccfeb687c3f2 | 1212 | break; |
casiotone401 | 10:ccfeb687c3f2 | 1213 | } |
casiotone401 | 10:ccfeb687c3f2 | 1214 | } |
casiotone401 | 10:ccfeb687c3f2 | 1215 | |
casiotone401 | 10:ccfeb687c3f2 | 1216 | if(getOSCmsg(buf + messagepos, msg) == -1) continue; |
casiotone401 | 4:b9f5ae574447 | 1217 | |
casiotone401 | 10:ccfeb687c3f2 | 1218 | len = strlen(msg[0].address); |
casiotone401 | 10:ccfeb687c3f2 | 1219 | |
casiotone401 | 10:ccfeb687c3f2 | 1220 | if(isdigit(msg[0].address[len-1])) |
casiotone401 | 10:ccfeb687c3f2 | 1221 | { |
casiotone401 | 10:ccfeb687c3f2 | 1222 | num = msg[0].address[len-1] - '0' - 1; |
casiotone401 | 4:b9f5ae574447 | 1223 | |
casiotone401 | 10:ccfeb687c3f2 | 1224 | } else { |
casiotone401 | 0:a4d93cd4c30d | 1225 | |
casiotone401 | 10:ccfeb687c3f2 | 1226 | num = -1; |
casiotone401 | 10:ccfeb687c3f2 | 1227 | } |
casiotone401 | 10:ccfeb687c3f2 | 1228 | |
casiotone401 | 10:ccfeb687c3f2 | 1229 | // address pattern SYNC & GATE (Type Tag int, float) |
casiotone401 | 10:ccfeb687c3f2 | 1230 | if(!strncmp(msg[0].address+(len-1)-4, "sync", 4)) |
casiotone401 | 10:ccfeb687c3f2 | 1231 | { |
casiotone401 | 14:977f3c5a4b4e | 1232 | if(msg[2].i != 0) gCLOCKOUT = 1; |
casiotone401 | 14:977f3c5a4b4e | 1233 | else gCLOCKOUT = 0; |
casiotone401 | 10:ccfeb687c3f2 | 1234 | continue; |
casiotone401 | 10:ccfeb687c3f2 | 1235 | |
casiotone401 | 10:ccfeb687c3f2 | 1236 | } else if (!strncmp(msg[0].address+(len-1)-4, "gate", 4) && (num != -1)) { |
casiotone401 | 14:977f3c5a4b4e | 1237 | if(num > 3) continue; |
casiotone401 | 14:977f3c5a4b4e | 1238 | if(msg[2].i != 0) gLEDS[num] = gGATES[num] = 1; |
casiotone401 | 14:977f3c5a4b4e | 1239 | else gLEDS[num] = gGATES[num] = 0; |
casiotone401 | 10:ccfeb687c3f2 | 1240 | continue; |
casiotone401 | 10:ccfeb687c3f2 | 1241 | // (touchOSC Control push, toggle) |
casiotone401 | 10:ccfeb687c3f2 | 1242 | } else if (!strncmp(msg[0].address+(len-1)-4, "push", 4) && (num != -1)) { |
casiotone401 | 10:ccfeb687c3f2 | 1243 | if(num > 4) continue; |
casiotone401 | 14:977f3c5a4b4e | 1244 | if(msg[2].i != 0) gLEDS[num] = gGATES[num] = 1; |
casiotone401 | 14:977f3c5a4b4e | 1245 | else gLEDS[num] = gGATES[num] = 0; |
casiotone401 | 10:ccfeb687c3f2 | 1246 | continue; |
casiotone401 | 10:ccfeb687c3f2 | 1247 | |
casiotone401 | 10:ccfeb687c3f2 | 1248 | } else if (!strncmp(msg[0].address+(len-1)-6, "toggle", 6) && (num != -1)) { |
casiotone401 | 10:ccfeb687c3f2 | 1249 | if(num > 4) continue; |
casiotone401 | 14:977f3c5a4b4e | 1250 | if(msg[2].i != 0) gLEDS[num] = gGATES[num] = 1; |
casiotone401 | 14:977f3c5a4b4e | 1251 | else gLEDS[num] = gGATES[num] = 0; |
casiotone401 | 10:ccfeb687c3f2 | 1252 | continue; |
casiotone401 | 10:ccfeb687c3f2 | 1253 | |
casiotone401 | 10:ccfeb687c3f2 | 1254 | } else if (!strncmp(msg[0].address,"/1/multipush",12) && (num != -1)) { |
casiotone401 | 10:ccfeb687c3f2 | 1255 | if(num > 4) continue; |
casiotone401 | 14:977f3c5a4b4e | 1256 | if(msg[2].i != 0) gLEDS[num] = gGATES[num] = 1; |
casiotone401 | 14:977f3c5a4b4e | 1257 | else gLEDS[num] = gGATES[num] = 0; |
casiotone401 | 10:ccfeb687c3f2 | 1258 | continue; |
casiotone401 | 10:ccfeb687c3f2 | 1259 | // address pattern CV (Type Tag float) |
casiotone401 | 10:ccfeb687c3f2 | 1260 | } else if(!strncmp(msg[0].address+(len-1)-2, "cv", 2) && (num != -1)) { |
casiotone401 | 10:ccfeb687c3f2 | 1261 | if(num > 7) continue; |
casiotone401 | 10:ccfeb687c3f2 | 1262 | if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N); |
casiotone401 | 10:ccfeb687c3f2 | 1263 | continue; |
casiotone401 | 10:ccfeb687c3f2 | 1264 | // (touchOSC Control fader, rotary, xy, multixy, multifader) |
casiotone401 | 10:ccfeb687c3f2 | 1265 | } else if (!strncmp(msg[0].address+(len-1)-5, "fader", 5) && (num != -1)) { |
casiotone401 | 10:ccfeb687c3f2 | 1266 | if(num > 7) continue; |
casiotone401 | 10:ccfeb687c3f2 | 1267 | if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N); |
casiotone401 | 10:ccfeb687c3f2 | 1268 | continue; |
casiotone401 | 0:a4d93cd4c30d | 1269 | |
casiotone401 | 10:ccfeb687c3f2 | 1270 | } else if (!strncmp(msg[0].address+(len-1)-6, "rotary", 6) && (num != -1)) { |
casiotone401 | 10:ccfeb687c3f2 | 1271 | if(num > 7) continue; |
casiotone401 | 10:ccfeb687c3f2 | 1272 | if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N); |
casiotone401 | 10:ccfeb687c3f2 | 1273 | continue; |
casiotone401 | 10:ccfeb687c3f2 | 1274 | |
casiotone401 | 10:ccfeb687c3f2 | 1275 | } else if (!strncmp(msg[0].address+(len-1)-2, "xy", 2) && (num != -1)) { |
casiotone401 | 10:ccfeb687c3f2 | 1276 | if(num > 7) continue; |
casiotone401 | 10:ccfeb687c3f2 | 1277 | if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N); |
casiotone401 | 10:ccfeb687c3f2 | 1278 | if(msg[1].typeTag[1] == 'f') gOSC_cv[++num] = msg[3].f * (SCALING_N); |
casiotone401 | 10:ccfeb687c3f2 | 1279 | continue; |
casiotone401 | 10:ccfeb687c3f2 | 1280 | |
casiotone401 | 10:ccfeb687c3f2 | 1281 | } else if (!strncmp(msg[0].address+(len-1)-9, "multixy1/", 9) && (num != -1)) { |
casiotone401 | 10:ccfeb687c3f2 | 1282 | if(num > 7) continue; |
casiotone401 | 10:ccfeb687c3f2 | 1283 | if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N); |
casiotone401 | 10:ccfeb687c3f2 | 1284 | if(msg[1].typeTag[1] == 'f') gOSC_cv[++num] = msg[3].f * (SCALING_N); |
casiotone401 | 10:ccfeb687c3f2 | 1285 | continue; |
casiotone401 | 10:ccfeb687c3f2 | 1286 | |
casiotone401 | 10:ccfeb687c3f2 | 1287 | } else if (!strncmp(msg[0].address+(len-1)-12, "multifader1/", 12) && (num != -1)) { |
casiotone401 | 10:ccfeb687c3f2 | 1288 | if(num > 7) continue; |
casiotone401 | 10:ccfeb687c3f2 | 1289 | if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N); |
casiotone401 | 10:ccfeb687c3f2 | 1290 | continue; |
casiotone401 | 10:ccfeb687c3f2 | 1291 | // (touchOSC multifader for Sequencer Mode) |
casiotone401 | 10:ccfeb687c3f2 | 1292 | } else if (!strncmp(msg[0].address+(len-1)-11, "sequencer1/", 11) && (num != -1)) { |
casiotone401 | 10:ccfeb687c3f2 | 1293 | if(num > 7) continue; |
casiotone401 | 10:ccfeb687c3f2 | 1294 | if(msg[1].typeTag[1] == 'f') gSeq_cv1[num] = msg[2].f * (SCALING_N); |
casiotone401 | 10:ccfeb687c3f2 | 1295 | continue; |
casiotone401 | 0:a4d93cd4c30d | 1296 | |
casiotone401 | 10:ccfeb687c3f2 | 1297 | } else if (!strncmp(msg[0].address+(len-1)-11, "sequencer2/", 11) && (num != -1)) { |
casiotone401 | 10:ccfeb687c3f2 | 1298 | if(num > 7) continue; |
casiotone401 | 10:ccfeb687c3f2 | 1299 | if(msg[1].typeTag[1] == 'f') gSeq_cv2[num] = msg[2].f * (SCALING_N); |
casiotone401 | 10:ccfeb687c3f2 | 1300 | continue; |
casiotone401 | 10:ccfeb687c3f2 | 1301 | // address pattern for control |
casiotone401 | 10:ccfeb687c3f2 | 1302 | } else if (!strncmp(msg[0].address+(len-1)-6, "ctrlsw", 6) && (num != -1)) { |
casiotone401 | 14:977f3c5a4b4e | 1303 | if(num > 5) continue; |
casiotone401 | 14:977f3c5a4b4e | 1304 | if(msg[2].i != 0) gCtrlSW[num] = true; |
casiotone401 | 14:977f3c5a4b4e | 1305 | else gCtrlSW[num] = false; |
casiotone401 | 10:ccfeb687c3f2 | 1306 | continue; |
casiotone401 | 4:b9f5ae574447 | 1307 | |
casiotone401 | 10:ccfeb687c3f2 | 1308 | } else if (!strncmp(msg[0].address+(len-1)-4, "ctrl", 4) && (num != -1)) { |
casiotone401 | 14:977f3c5a4b4e | 1309 | if(num > 5) continue; |
casiotone401 | 10:ccfeb687c3f2 | 1310 | if(msg[1].typeTag[1] == 'f') gCtrl[num] = msg[2].f; |
casiotone401 | 10:ccfeb687c3f2 | 1311 | continue; |
casiotone401 | 10:ccfeb687c3f2 | 1312 | } |
casiotone401 | 10:ccfeb687c3f2 | 1313 | |
casiotone401 | 10:ccfeb687c3f2 | 1314 | } while(bundleflag); |
casiotone401 | 10:ccfeb687c3f2 | 1315 | |
casiotone401 | 10:ccfeb687c3f2 | 1316 | } |
casiotone401 | 10:ccfeb687c3f2 | 1317 | } |