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
example.h@12:33c8f06c2e03, 2013-04-14 (annotated)
- Committer:
- casiotone401
- Date:
- Sun Apr 14 00:54:10 2013 +0000
- Revision:
- 12:33c8f06c2e03
- Child:
- 13:3f42e451a8d3
add example
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| casiotone401 | 12:33c8f06c2e03 | 1 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 2 | // TI DAC8568 OSC-CV Converter |
| casiotone401 | 12:33c8f06c2e03 | 3 | // |
| casiotone401 | 12:33c8f06c2e03 | 4 | // DAC8568 16bit Octal DAC http://www.ti.com/product/dac8568 |
| casiotone401 | 12:33c8f06c2e03 | 5 | // |
| casiotone401 | 12:33c8f06c2e03 | 6 | // referred to |
| casiotone401 | 12:33c8f06c2e03 | 7 | // xshige's OSCReceiver |
| casiotone401 | 12:33c8f06c2e03 | 8 | // http://mbed.org/users/xshige/programs/OSCReceiver/ |
| casiotone401 | 12:33c8f06c2e03 | 9 | // radiojunkbox's OSC-CV_Example |
| casiotone401 | 12:33c8f06c2e03 | 10 | // http://mbed.org/users/radiojunkbox/code/KAMUI_OSC-CV_Example/ |
| casiotone401 | 12:33c8f06c2e03 | 11 | // Robin Price's Homebrew midi-cv box |
| casiotone401 | 12:33c8f06c2e03 | 12 | // http://crx091081gb.net/?p=69 |
| casiotone401 | 12:33c8f06c2e03 | 13 | // Masahiro Hattori's TextLCD Module Functions |
| casiotone401 | 12:33c8f06c2e03 | 14 | // http://www.eleclabo.com/denshi/device/lcd1602/gcram.html |
| casiotone401 | 12:33c8f06c2e03 | 15 | // Dirk-Willem van Gulik's BonjourLib |
| casiotone401 | 12:33c8f06c2e03 | 16 | // http://mbed.org/users/dirkx/code/BonjourLib/file/bb6472f455e8/services/mDNS |
| casiotone401 | 12:33c8f06c2e03 | 17 | // |
| casiotone401 | 12:33c8f06c2e03 | 18 | // Released under the MIT License: http://mbed.org/license/mit |
| casiotone401 | 12:33c8f06c2e03 | 19 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 20 | |
| casiotone401 | 12:33c8f06c2e03 | 21 | #pragma O3 |
| casiotone401 | 12:33c8f06c2e03 | 22 | #pragma Otime |
| casiotone401 | 12:33c8f06c2e03 | 23 | |
| casiotone401 | 12:33c8f06c2e03 | 24 | #include "mbed.h" |
| casiotone401 | 12:33c8f06c2e03 | 25 | #include "TextLCD.h" //edit "writeCommand" "writeData" protected -> public |
| casiotone401 | 12:33c8f06c2e03 | 26 | #include "EthernetNetIf.h" |
| casiotone401 | 12:33c8f06c2e03 | 27 | #include "HTTPServer.h" |
| casiotone401 | 12:33c8f06c2e03 | 28 | #include "mDNSResponder.h" // mDNS response to announce oneselve |
| casiotone401 | 12:33c8f06c2e03 | 29 | #include "UDPSocket.h" |
| casiotone401 | 12:33c8f06c2e03 | 30 | #include "OSCReceiver.h" |
| casiotone401 | 12:33c8f06c2e03 | 31 | #include <stdlib.h> |
| casiotone401 | 12:33c8f06c2e03 | 32 | #include <ctype.h> |
| casiotone401 | 12:33c8f06c2e03 | 33 | #include <math.h> |
| casiotone401 | 12:33c8f06c2e03 | 34 | |
| casiotone401 | 12:33c8f06c2e03 | 35 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 36 | // Define |
| casiotone401 | 12:33c8f06c2e03 | 37 | |
| casiotone401 | 12:33c8f06c2e03 | 38 | #define MODE_Calb 0 // Calibration (for VCO Tuning) |
| casiotone401 | 12:33c8f06c2e03 | 39 | #define MODE_LIN 1 // Linear LinearCV |
| casiotone401 | 12:33c8f06c2e03 | 40 | #define MODE_QChr 2 // Chromatic Quantize Mode |
| casiotone401 | 12:33c8f06c2e03 | 41 | #define MODE_QMaj 3 // Major |
| casiotone401 | 12:33c8f06c2e03 | 42 | #define MODE_QDor 4 // Dorian |
| casiotone401 | 12:33c8f06c2e03 | 43 | #define MODE_Q5th 5 // 5th |
| casiotone401 | 12:33c8f06c2e03 | 44 | #define MODE_QWht 6 // Wholetone |
| casiotone401 | 12:33c8f06c2e03 | 45 | #define MODE_SEQ 7 // Sequencer & Shift Register |
| casiotone401 | 12:33c8f06c2e03 | 46 | #define MODE_SHIF 8 // Mode Shift |
| casiotone401 | 12:33c8f06c2e03 | 47 | |
| casiotone401 | 12:33c8f06c2e03 | 48 | #define MODE_NUM 9 // Modes |
| casiotone401 | 12:33c8f06c2e03 | 49 | |
| casiotone401 | 12:33c8f06c2e03 | 50 | #define Lin 0 // Linear LinearCV |
| casiotone401 | 12:33c8f06c2e03 | 51 | #define Chr 1 // Chromatic |
| casiotone401 | 12:33c8f06c2e03 | 52 | #define Maj 2 // Major |
| casiotone401 | 12:33c8f06c2e03 | 53 | #define M7 3 // Major7 |
| casiotone401 | 12:33c8f06c2e03 | 54 | #define Min7 4 // Minor7 |
| casiotone401 | 12:33c8f06c2e03 | 55 | #define Dor 5 // Dorian |
| casiotone401 | 12:33c8f06c2e03 | 56 | #define Min 6 // Minor |
| casiotone401 | 12:33c8f06c2e03 | 57 | #define S5th 7 // 5th |
| casiotone401 | 12:33c8f06c2e03 | 58 | #define Wht 8 // Wholetone |
| casiotone401 | 12:33c8f06c2e03 | 59 | |
| casiotone401 | 12:33c8f06c2e03 | 60 | #define QUAN_RES1 115 // Quantize voltage Steps |
| casiotone401 | 12:33c8f06c2e03 | 61 | #define QUAN_RES2 67 |
| casiotone401 | 12:33c8f06c2e03 | 62 | #define QUAN_RES3 39 |
| casiotone401 | 12:33c8f06c2e03 | 63 | #define QUAN_RES4 48 |
| casiotone401 | 12:33c8f06c2e03 | 64 | #define QUAN_RES5 67 |
| casiotone401 | 12:33c8f06c2e03 | 65 | #define QUAN_RES6 67 |
| casiotone401 | 12:33c8f06c2e03 | 66 | #define QUAN_RES7 17 |
| casiotone401 | 12:33c8f06c2e03 | 67 | #define QUAN_RES8 57 |
| casiotone401 | 12:33c8f06c2e03 | 68 | |
| casiotone401 | 12:33c8f06c2e03 | 69 | #define SPI_RATE 48000000 // 40Mbps SPI Clock |
| casiotone401 | 12:33c8f06c2e03 | 70 | #define SCALING_N 38400.0 |
| casiotone401 | 12:33c8f06c2e03 | 71 | #define INPUT_PORT 12345 // Input Port Number |
| casiotone401 | 12:33c8f06c2e03 | 72 | |
| casiotone401 | 12:33c8f06c2e03 | 73 | #define POLLING_INTERVAL 20 // Polling Interval (us) |
| casiotone401 | 12:33c8f06c2e03 | 74 | |
| casiotone401 | 12:33c8f06c2e03 | 75 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 76 | // DAC8568 Control Bits (See datasheet) |
| casiotone401 | 12:33c8f06c2e03 | 77 | |
| casiotone401 | 12:33c8f06c2e03 | 78 | #define WRITE 0x00 |
| casiotone401 | 12:33c8f06c2e03 | 79 | #define UPDATE 0x01 |
| casiotone401 | 12:33c8f06c2e03 | 80 | #define WRITE_UPDATE_ALL 0x02 // LDAC Write to Selected Update All |
| casiotone401 | 12:33c8f06c2e03 | 81 | #define WRITE_UPDATE_N 0x03 // LDAC Write to Selected Update Respective |
| casiotone401 | 12:33c8f06c2e03 | 82 | #define POWER 0x04 |
| casiotone401 | 12:33c8f06c2e03 | 83 | #define CLR 0x05 // Clear Code Register |
| casiotone401 | 12:33c8f06c2e03 | 84 | #define WRITE_LDAC_REG 0x06 |
| casiotone401 | 12:33c8f06c2e03 | 85 | #define RESET 0x07 // Software Reset DAC8568 |
| casiotone401 | 12:33c8f06c2e03 | 86 | #define SETUP_INTERNAL_REF 0x08 |
| casiotone401 | 12:33c8f06c2e03 | 87 | |
| casiotone401 | 12:33c8f06c2e03 | 88 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 89 | |
| casiotone401 | 12:33c8f06c2e03 | 90 | #define _DISABLE 0 |
| casiotone401 | 12:33c8f06c2e03 | 91 | #define _ENABLE 1 |
| casiotone401 | 12:33c8f06c2e03 | 92 | |
| casiotone401 | 12:33c8f06c2e03 | 93 | #define GATE1 0 |
| casiotone401 | 12:33c8f06c2e03 | 94 | #define GATE2 1 |
| casiotone401 | 12:33c8f06c2e03 | 95 | #define GATE3 2 |
| casiotone401 | 12:33c8f06c2e03 | 96 | #define GATE4 3 |
| casiotone401 | 12:33c8f06c2e03 | 97 | #define GATEALL 4 |
| casiotone401 | 12:33c8f06c2e03 | 98 | |
| casiotone401 | 12:33c8f06c2e03 | 99 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 100 | // Beats (Note values) |
| casiotone401 | 12:33c8f06c2e03 | 101 | |
| casiotone401 | 12:33c8f06c2e03 | 102 | #define N1ST 1 // whole |
| casiotone401 | 12:33c8f06c2e03 | 103 | #define N2ND 2 // harf |
| casiotone401 | 12:33c8f06c2e03 | 104 | #define N4TH 4 // quarter |
| casiotone401 | 12:33c8f06c2e03 | 105 | #define N8TH 8 |
| casiotone401 | 12:33c8f06c2e03 | 106 | #define N16TH 16 |
| casiotone401 | 12:33c8f06c2e03 | 107 | #define N32TH 32 |
| casiotone401 | 12:33c8f06c2e03 | 108 | #define N64TH 64 |
| casiotone401 | 12:33c8f06c2e03 | 109 | #define NDOT2 3 // dotted |
| casiotone401 | 12:33c8f06c2e03 | 110 | #define NDOT4 7 |
| casiotone401 | 12:33c8f06c2e03 | 111 | #define NDOT8 9 |
| casiotone401 | 12:33c8f06c2e03 | 112 | #define NDOT16 11 |
| casiotone401 | 12:33c8f06c2e03 | 113 | #define NDOT32 13 |
| casiotone401 | 12:33c8f06c2e03 | 114 | #define TRIP2 15 // triplets |
| casiotone401 | 12:33c8f06c2e03 | 115 | #define TRIP4 17 |
| casiotone401 | 12:33c8f06c2e03 | 116 | #define TRIP8 19 |
| casiotone401 | 12:33c8f06c2e03 | 117 | #define TRIP16 21 |
| casiotone401 | 12:33c8f06c2e03 | 118 | #define TRIP32 23 |
| casiotone401 | 12:33c8f06c2e03 | 119 | #define NRESET 0 // Gate Reset |
| casiotone401 | 12:33c8f06c2e03 | 120 | |
| casiotone401 | 12:33c8f06c2e03 | 121 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 122 | // Functions |
| casiotone401 | 12:33c8f06c2e03 | 123 | |
| casiotone401 | 12:33c8f06c2e03 | 124 | inline void NetPoll(void); |
| casiotone401 | 12:33c8f06c2e03 | 125 | void InitOSCCV(void); |
| casiotone401 | 12:33c8f06c2e03 | 126 | inline void Seq(void); |
| casiotone401 | 12:33c8f06c2e03 | 127 | inline void UpdateCV(int, int, const unsigned int*); |
| casiotone401 | 12:33c8f06c2e03 | 128 | inline int UpdateTrigger(volatile bool); |
| casiotone401 | 12:33c8f06c2e03 | 129 | inline int UpdateGate(int, int, int, int, bool); |
| casiotone401 | 12:33c8f06c2e03 | 130 | inline void SetCV(void); |
| casiotone401 | 12:33c8f06c2e03 | 131 | inline void SetSCV(void); |
| casiotone401 | 12:33c8f06c2e03 | 132 | inline void ShiftCV(int); |
| casiotone401 | 12:33c8f06c2e03 | 133 | inline void SeqCV(int); |
| casiotone401 | 12:33c8f06c2e03 | 134 | void CheckModeSW(void); |
| casiotone401 | 12:33c8f06c2e03 | 135 | inline void CVMeter(int, const unsigned int*); |
| casiotone401 | 12:33c8f06c2e03 | 136 | void LCD(); |
| casiotone401 | 12:33c8f06c2e03 | 137 | void WriteCustomChar(unsigned char, unsigned char*); |
| casiotone401 | 12:33c8f06c2e03 | 138 | int SetupEthNetIf(void); |
| casiotone401 | 12:33c8f06c2e03 | 139 | inline void onUDPSocketEvent(UDPSocketEvent); |
| casiotone401 | 12:33c8f06c2e03 | 140 | |
| casiotone401 | 12:33c8f06c2e03 | 141 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 142 | // Silentway Calibration Data Mapping |
| casiotone401 | 12:33c8f06c2e03 | 143 | // http://www.expert-sleepers.co.uk/silentway.html |
| casiotone401 | 12:33c8f06c2e03 | 144 | |
| casiotone401 | 12:33c8f06c2e03 | 145 | // Chromatic Scale |
| casiotone401 | 12:33c8f06c2e03 | 146 | const float calibMap1[QUAN_RES1] = { |
| casiotone401 | 12:33c8f06c2e03 | 147 | 0.00559238, 0.01324014, 0.02088790, 0.02853566, 0.03618342, |
| casiotone401 | 12:33c8f06c2e03 | 148 | 0.04383118, 0.05147894, 0.05912671, 0.06677447, 0.07442223, |
| casiotone401 | 12:33c8f06c2e03 | 149 | 0.08206999, 0.08971775, 0.09736551, 0.10501327, 0.11266103, |
| casiotone401 | 12:33c8f06c2e03 | 150 | 0.12030879, 0.12775089, 0.13486665, 0.14198242, 0.14909819, |
| casiotone401 | 12:33c8f06c2e03 | 151 | 0.15621395, 0.16332972, 0.17044549, 0.17756125, 0.18467702, |
| casiotone401 | 12:33c8f06c2e03 | 152 | 0.19179279, 0.19890857, 0.20602433, 0.21314010, 0.22025587, |
| casiotone401 | 12:33c8f06c2e03 | 153 | 0.22737163, 0.23448740, 0.24160317, 0.24871893, 0.25587305, |
| casiotone401 | 12:33c8f06c2e03 | 154 | 0.26303557, 0.27019811, 0.27736065, 0.28452319, 0.29168573, |
| casiotone401 | 12:33c8f06c2e03 | 155 | 0.29884824, 0.30601078, 0.31317332, 0.32033587, 0.32749838, |
| casiotone401 | 12:33c8f06c2e03 | 156 | 0.33466092, 0.34182346, 0.34898600, 0.35614854, 0.36331105, |
| casiotone401 | 12:33c8f06c2e03 | 157 | 0.37047359, 0.37764084, 0.38481620, 0.39199156, 0.39916691, |
| casiotone401 | 12:33c8f06c2e03 | 158 | 0.40634227, 0.41351759, 0.42069295, 0.42786831, 0.43504366, |
| casiotone401 | 12:33c8f06c2e03 | 159 | 0.44221902, 0.44939438, 0.45656973, 0.46374506, 0.47092041, |
| casiotone401 | 12:33c8f06c2e03 | 160 | 0.47809577, 0.48527113, 0.49244648, 0.49962184, 0.50685716, |
| casiotone401 | 12:33c8f06c2e03 | 161 | 0.51409578, 0.52133441, 0.52857304, 0.53581166, 0.54305035, |
| casiotone401 | 12:33c8f06c2e03 | 162 | 0.55028898, 0.55752760, 0.56476623, 0.57200485, 0.57924354, |
| casiotone401 | 12:33c8f06c2e03 | 163 | 0.58648217, 0.59372079, 0.60095942, 0.60819805, 0.61543667, |
| casiotone401 | 12:33c8f06c2e03 | 164 | 0.62267536, 0.62996829, 0.63728690, 0.64460552, 0.65192413, |
| casiotone401 | 12:33c8f06c2e03 | 165 | 0.65924275, 0.66656137, 0.67387998, 0.68119860, 0.68851727, |
| casiotone401 | 12:33c8f06c2e03 | 166 | 0.69583589, 0.70315450, 0.71047312, 0.71779174, 0.72511035, |
| casiotone401 | 12:33c8f06c2e03 | 167 | 0.73242897, 0.73974758, 0.74706620, 0.75810421, 0.77163076, |
| casiotone401 | 12:33c8f06c2e03 | 168 | 0.78515732, 0.79868382, 0.81221038, 0.82573694, 0.83926344, |
| casiotone401 | 12:33c8f06c2e03 | 169 | 0.85279000, 0.86631656, 0.88188213, 0.90110368, 0.92032516 |
| casiotone401 | 12:33c8f06c2e03 | 170 | }; |
| casiotone401 | 12:33c8f06c2e03 | 171 | |
| casiotone401 | 12:33c8f06c2e03 | 172 | // Major Scale |
| casiotone401 | 12:33c8f06c2e03 | 173 | const float calibMap2[QUAN_RES2] = { |
| casiotone401 | 12:33c8f06c2e03 | 174 | 0.01324014, 0.02853566, 0.03618342, 0.05147894, 0.06677447, |
| casiotone401 | 12:33c8f06c2e03 | 175 | 0.08206999, 0.08971775, 0.10501327, 0.12030879, 0.12775089, |
| casiotone401 | 12:33c8f06c2e03 | 176 | 0.14198242, 0.15621395, 0.17044549, 0.17756125, 0.19179279, |
| casiotone401 | 12:33c8f06c2e03 | 177 | 0.20602433, 0.21314010, 0.22737163, 0.24160317, 0.25587305, |
| casiotone401 | 12:33c8f06c2e03 | 178 | 0.26303557, 0.27736065, 0.29168573, 0.29884824, 0.31317332, |
| casiotone401 | 12:33c8f06c2e03 | 179 | 0.32749838, 0.34182346, 0.34898600, 0.36331105, 0.37764084, |
| casiotone401 | 12:33c8f06c2e03 | 180 | 0.38481620, 0.39916691, 0.41351759, 0.42786831, 0.43504366, |
| casiotone401 | 12:33c8f06c2e03 | 181 | 0.44939438, 0.46374506, 0.47092041, 0.48527113, 0.49962184, |
| casiotone401 | 12:33c8f06c2e03 | 182 | 0.51409578, 0.52133441, 0.53581166, 0.55028898, 0.55752760, |
| casiotone401 | 12:33c8f06c2e03 | 183 | 0.57200485, 0.58648217, 0.60095942, 0.60819805, 0.62267536, |
| casiotone401 | 12:33c8f06c2e03 | 184 | 0.63728690, 0.64460552, 0.65924275, 0.67387998, 0.68851727, |
| casiotone401 | 12:33c8f06c2e03 | 185 | 0.69583589, 0.71047312, 0.72511035, 0.73242897, 0.74706620, |
| casiotone401 | 12:33c8f06c2e03 | 186 | 0.77163076, 0.79868382, 0.81221038, 0.83926344, 0.86631656, |
| casiotone401 | 12:33c8f06c2e03 | 187 | 0.88188213, 0.92032516 |
| casiotone401 | 12:33c8f06c2e03 | 188 | }; |
| casiotone401 | 12:33c8f06c2e03 | 189 | |
| casiotone401 | 12:33c8f06c2e03 | 190 | // M7(9) |
| casiotone401 | 12:33c8f06c2e03 | 191 | const float calibMap3[QUAN_RES3] = { |
| casiotone401 | 12:33c8f06c2e03 | 192 | 0.02853566, 0.05147894, 0.08206999, 0.08971775, 0.12030879, |
| casiotone401 | 12:33c8f06c2e03 | 193 | 0.14198242, 0.17044549, 0.17756125, 0.20602433, 0.22737163, |
| casiotone401 | 12:33c8f06c2e03 | 194 | 0.25587305, 0.26303557, 0.29168573, 0.31317332, 0.34182346, |
| casiotone401 | 12:33c8f06c2e03 | 195 | 0.34898600, 0.37764084, 0.39916691, 0.42786831, 0.43504366, |
| casiotone401 | 12:33c8f06c2e03 | 196 | 0.44939438, 0.46374506, 0.48527113, 0.51409578, 0.52133441, |
| casiotone401 | 12:33c8f06c2e03 | 197 | 0.55028898, 0.57200485, 0.60095942, 0.60819805, 0.62267536, |
| casiotone401 | 12:33c8f06c2e03 | 198 | 0.63728690, 0.65924275, 0.68851727, 0.69583589, 0.72511035, |
| casiotone401 | 12:33c8f06c2e03 | 199 | 0.74706620, 0.79868382, 0.86631656, 0.92032516 |
| casiotone401 | 12:33c8f06c2e03 | 200 | }; |
| casiotone401 | 12:33c8f06c2e03 | 201 | |
| casiotone401 | 12:33c8f06c2e03 | 202 | // m7(9) |
| casiotone401 | 12:33c8f06c2e03 | 203 | const float calibMap4[QUAN_RES4] = { |
| casiotone401 | 12:33c8f06c2e03 | 204 | 0.01324014, 0.02088790, 0.03618342, 0.05147894, 0.07442223, |
| casiotone401 | 12:33c8f06c2e03 | 205 | 0.08971775, 0.11266103, 0.14198242, 0.16332972, 0.17756125, |
| casiotone401 | 12:33c8f06c2e03 | 206 | 0.19890857, 0.22737163, 0.24160317, 0.24871893, 0.26303557, |
| casiotone401 | 12:33c8f06c2e03 | 207 | 0.29168573, 0.31317332, 0.33466092, 0.34898600, 0.36331105, |
| casiotone401 | 12:33c8f06c2e03 | 208 | 0.37047359, 0.38481620, 0.39916691, 0.41351759, 0.42069295, |
| casiotone401 | 12:33c8f06c2e03 | 209 | 0.43504366, 0.45656973, 0.48527113, 0.50685716, 0.52133441, |
| casiotone401 | 12:33c8f06c2e03 | 210 | 0.53581166, 0.55752760, 0.57200485, 0.59372079, 0.62267536, |
| casiotone401 | 12:33c8f06c2e03 | 211 | 0.62996829, 0.64460552, 0.65924275, 0.68119860, 0.69583589, |
| casiotone401 | 12:33c8f06c2e03 | 212 | 0.71779174, 0.74706620, 0.77163076, 0.78515732, 0.81221038, |
| casiotone401 | 12:33c8f06c2e03 | 213 | 0.83926344, 0.85279000, 0.92032516 |
| casiotone401 | 12:33c8f06c2e03 | 214 | }; |
| casiotone401 | 12:33c8f06c2e03 | 215 | |
| casiotone401 | 12:33c8f06c2e03 | 216 | // Dorian Scale |
| casiotone401 | 12:33c8f06c2e03 | 217 | const float calibMap5[QUAN_RES5] = { |
| casiotone401 | 12:33c8f06c2e03 | 218 | 0.01324014, 0.02853566, 0.04383118, 0.05147894, 0.06677447, |
| casiotone401 | 12:33c8f06c2e03 | 219 | 0.08206999, 0.08971775, 0.10501327, 0.12030879, 0.13486665, |
| casiotone401 | 12:33c8f06c2e03 | 220 | 0.14198242, 0.15621395, 0.17044549, 0.17756125, 0.19179279, |
| casiotone401 | 12:33c8f06c2e03 | 221 | 0.20602433, 0.22025587, 0.22737163, 0.24160317, 0.25587305, |
| casiotone401 | 12:33c8f06c2e03 | 222 | 0.26303557, 0.27736065, 0.29168573, 0.30601078, 0.31317332, |
| casiotone401 | 12:33c8f06c2e03 | 223 | 0.32749838, 0.34182346, 0.34898600, 0.36331105, 0.37764084, |
| casiotone401 | 12:33c8f06c2e03 | 224 | 0.39199156, 0.39916691, 0.41351759, 0.42786831, 0.43504366, |
| casiotone401 | 12:33c8f06c2e03 | 225 | 0.44939438, 0.46374506, 0.47809577, 0.48527113, 0.49962184, |
| casiotone401 | 12:33c8f06c2e03 | 226 | 0.51409578, 0.52133441, 0.53581166, 0.55028898, 0.56476623, |
| casiotone401 | 12:33c8f06c2e03 | 227 | 0.57200485, 0.58648217, 0.60095942, 0.60819805, 0.62267536, |
| casiotone401 | 12:33c8f06c2e03 | 228 | 0.63728690, 0.65192413, 0.65924275, 0.67387998, 0.68851727, |
| casiotone401 | 12:33c8f06c2e03 | 229 | 0.69583589, 0.71047312, 0.72511035, 0.73974758, 0.74706620, |
| casiotone401 | 12:33c8f06c2e03 | 230 | 0.77163076, 0.79868382, 0.81221038, 0.83926344, 0.86631656, |
| casiotone401 | 12:33c8f06c2e03 | 231 | 0.90110368, 0.92032516 |
| casiotone401 | 12:33c8f06c2e03 | 232 | }; |
| casiotone401 | 12:33c8f06c2e03 | 233 | |
| casiotone401 | 12:33c8f06c2e03 | 234 | // Minor Scale |
| casiotone401 | 12:33c8f06c2e03 | 235 | const float calibMap6[QUAN_RES6] = { |
| casiotone401 | 12:33c8f06c2e03 | 236 | 0.01324014, 0.02088790, 0.03618342, 0.05147894, 0.05912671, |
| casiotone401 | 12:33c8f06c2e03 | 237 | 0.07442223, 0.08971775, 0.10501327, 0.11266103, 0.12775089, |
| casiotone401 | 12:33c8f06c2e03 | 238 | 0.14198242, 0.14909819, 0.16332972, 0.17756125, 0.19179279, |
| casiotone401 | 12:33c8f06c2e03 | 239 | 0.19890857, 0.21314010, 0.22737163, 0.23448740, 0.24871893, |
| casiotone401 | 12:33c8f06c2e03 | 240 | 0.26303557, 0.27736065, 0.28452319, 0.29884824, 0.31317332, |
| casiotone401 | 12:33c8f06c2e03 | 241 | 0.32033587, 0.33466092, 0.34898600, 0.36331105, 0.37047359, |
| casiotone401 | 12:33c8f06c2e03 | 242 | 0.38481620, 0.39916691, 0.40634227, 0.42069295, 0.43504366, |
| casiotone401 | 12:33c8f06c2e03 | 243 | 0.44939438, 0.45656973, 0.47092041, 0.48527113, 0.49244648, |
| casiotone401 | 12:33c8f06c2e03 | 244 | 0.50685716, 0.52133441, 0.53581166, 0.54305035, 0.55752760, |
| casiotone401 | 12:33c8f06c2e03 | 245 | 0.57200485, 0.57924354, 0.59372079, 0.60819805, 0.62267536, |
| casiotone401 | 12:33c8f06c2e03 | 246 | 0.62996829, 0.64460552, 0.65924275, 0.66656137, 0.68119860, |
| casiotone401 | 12:33c8f06c2e03 | 247 | 0.69583589, 0.71047312, 0.71779174, 0.73242897, 0.74706620, |
| casiotone401 | 12:33c8f06c2e03 | 248 | 0.75810421, 0.78515732, 0.81221038, 0.83926344, 0.85279000, |
| casiotone401 | 12:33c8f06c2e03 | 249 | 0.88188213, 0.92032516 |
| casiotone401 | 12:33c8f06c2e03 | 250 | }; |
| casiotone401 | 12:33c8f06c2e03 | 251 | |
| casiotone401 | 12:33c8f06c2e03 | 252 | // 5th |
| casiotone401 | 12:33c8f06c2e03 | 253 | const float calibMap7[QUAN_RES7] = { |
| casiotone401 | 12:33c8f06c2e03 | 254 | 0.01324014, 0.06677447, 0.12030879, 0.17044549, 0.22025587, |
| casiotone401 | 12:33c8f06c2e03 | 255 | 0.27019811, 0.32033587, 0.37047359, 0.42069295, 0.47092041, |
| casiotone401 | 12:33c8f06c2e03 | 256 | 0.52133441, 0.57200485, 0.62267536, 0.67387998, 0.72511035, |
| casiotone401 | 12:33c8f06c2e03 | 257 | 0.79868382, 0.90110368 |
| casiotone401 | 12:33c8f06c2e03 | 258 | }; |
| casiotone401 | 12:33c8f06c2e03 | 259 | |
| casiotone401 | 12:33c8f06c2e03 | 260 | // Whole tone |
| casiotone401 | 12:33c8f06c2e03 | 261 | const float calibMap8[QUAN_RES8] = { |
| casiotone401 | 12:33c8f06c2e03 | 262 | 0.01324014, 0.02853566, 0.04383118, 0.05912671, 0.07442223, |
| casiotone401 | 12:33c8f06c2e03 | 263 | 0.08971775, 0.10501327, 0.12030879, 0.13486665, 0.14909819, |
| casiotone401 | 12:33c8f06c2e03 | 264 | 0.16332972, 0.17756125, 0.19179279, 0.20602433, 0.22025587, |
| casiotone401 | 12:33c8f06c2e03 | 265 | 0.23448740, 0.24871893, 0.26303557, 0.27736065, 0.29168573, |
| casiotone401 | 12:33c8f06c2e03 | 266 | 0.30601078, 0.32033587, 0.33466092, 0.34898600, 0.36331105, |
| casiotone401 | 12:33c8f06c2e03 | 267 | 0.37764084, 0.39199156, 0.40634227, 0.42069295, 0.43504366, |
| casiotone401 | 12:33c8f06c2e03 | 268 | 0.44939438, 0.46374506, 0.47809577, 0.49244648, 0.50685716, |
| casiotone401 | 12:33c8f06c2e03 | 269 | 0.52133441, 0.53581166, 0.55028898, 0.56476623, 0.57924354, |
| casiotone401 | 12:33c8f06c2e03 | 270 | 0.59372079, 0.60819805, 0.62267536, 0.63728690, 0.65192413, |
| casiotone401 | 12:33c8f06c2e03 | 271 | 0.66656137, 0.68119860, 0.69583589, 0.71047312, 0.72511035, |
| casiotone401 | 12:33c8f06c2e03 | 272 | 0.73974758, 0.75810421, 0.78515732, 0.81221038, 0.83926344, |
| casiotone401 | 12:33c8f06c2e03 | 273 | 0.86631656, 0.90110368 |
| casiotone401 | 12:33c8f06c2e03 | 274 | }; |
| casiotone401 | 12:33c8f06c2e03 | 275 | |
| casiotone401 | 12:33c8f06c2e03 | 276 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 277 | // CV Meter Custom Character |
| casiotone401 | 12:33c8f06c2e03 | 278 | |
| casiotone401 | 12:33c8f06c2e03 | 279 | unsigned char str1[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F}; |
| casiotone401 | 12:33c8f06c2e03 | 280 | unsigned char str2[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F}; |
| casiotone401 | 12:33c8f06c2e03 | 281 | unsigned char str3[8] = {0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F}; |
| casiotone401 | 12:33c8f06c2e03 | 282 | unsigned char str4[8] = {0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F}; |
| casiotone401 | 12:33c8f06c2e03 | 283 | unsigned char str5[8] = {0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F,0x1F}; |
| casiotone401 | 12:33c8f06c2e03 | 284 | unsigned char str6[8] = {0x00,0x00,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}; |
| casiotone401 | 12:33c8f06c2e03 | 285 | unsigned char str7[8] = {0x00,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}; |
| casiotone401 | 12:33c8f06c2e03 | 286 | unsigned char str8[8] = {0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}; |
| casiotone401 | 12:33c8f06c2e03 | 287 | |
| casiotone401 | 12:33c8f06c2e03 | 288 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 289 | // Global Variables |
| casiotone401 | 12:33c8f06c2e03 | 290 | |
| casiotone401 | 12:33c8f06c2e03 | 291 | float gOSC_cv[8]; |
| casiotone401 | 12:33c8f06c2e03 | 292 | float gSeq_cv1[8], gSeq_cv2[8]; |
| casiotone401 | 12:33c8f06c2e03 | 293 | float gGlide; |
| casiotone401 | 12:33c8f06c2e03 | 294 | volatile int gMode; |
| casiotone401 | 12:33c8f06c2e03 | 295 | |
| casiotone401 | 12:33c8f06c2e03 | 296 | // Variables for Control |
| casiotone401 | 12:33c8f06c2e03 | 297 | |
| casiotone401 | 12:33c8f06c2e03 | 298 | float gCtrl[3]; |
| casiotone401 | 12:33c8f06c2e03 | 299 | volatile bool gCtrlSW[4] = {false}; |
| casiotone401 | 12:33c8f06c2e03 | 300 | |
| casiotone401 | 12:33c8f06c2e03 | 301 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 302 | // mbed Functions |
| casiotone401 | 12:33c8f06c2e03 | 303 | |
| casiotone401 | 12:33c8f06c2e03 | 304 | TextLCD gLCD(p9, p10, p11, p12, p13, p14); // rs, e, d4-d7 |
| casiotone401 | 12:33c8f06c2e03 | 305 | |
| casiotone401 | 12:33c8f06c2e03 | 306 | SPI gSPI(p5,p6,p7); // SPI (p6 unconnected) |
| casiotone401 | 12:33c8f06c2e03 | 307 | DigitalOut gSYNCMODE(p15); // SYNC DAC8568 |
| casiotone401 | 12:33c8f06c2e03 | 308 | DigitalOut gLDAC(p16); // LDAC DAC8568 |
| casiotone401 | 12:33c8f06c2e03 | 309 | |
| casiotone401 | 12:33c8f06c2e03 | 310 | DigitalOut gGATES[4] = {p21, p22, p23, p24}; // GateOut |
| casiotone401 | 12:33c8f06c2e03 | 311 | DigitalOut gLEDS[4] = {p18, p19, p20, p28}; // LED |
| casiotone401 | 12:33c8f06c2e03 | 312 | DigitalOut gCLOCKOUT(p25); // ClockOut |
| casiotone401 | 12:33c8f06c2e03 | 313 | |
| casiotone401 | 12:33c8f06c2e03 | 314 | AnalogIn gAIN(p17); // Glide Potentiometer |
| casiotone401 | 12:33c8f06c2e03 | 315 | InterruptIn gSW(p30); // Mode SW |
| casiotone401 | 12:33c8f06c2e03 | 316 | |
| casiotone401 | 12:33c8f06c2e03 | 317 | Timer gTimer; // Timer |
| casiotone401 | 12:33c8f06c2e03 | 318 | Ticker gPoller; // Ticker Polling |
| casiotone401 | 12:33c8f06c2e03 | 319 | |
| casiotone401 | 12:33c8f06c2e03 | 320 | // Ethernet |
| casiotone401 | 12:33c8f06c2e03 | 321 | EthernetNetIf gEth; |
| casiotone401 | 12:33c8f06c2e03 | 322 | UDPSocket gUdp; |
| casiotone401 | 12:33c8f06c2e03 | 323 | |
| casiotone401 | 12:33c8f06c2e03 | 324 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 325 | // main |
| casiotone401 | 12:33c8f06c2e03 | 326 | |
| casiotone401 | 12:33c8f06c2e03 | 327 | int main() |
| casiotone401 | 12:33c8f06c2e03 | 328 | { |
| casiotone401 | 12:33c8f06c2e03 | 329 | float pot, _pot; |
| casiotone401 | 12:33c8f06c2e03 | 330 | |
| casiotone401 | 12:33c8f06c2e03 | 331 | //http://mbed.org/forum/mbed/topic/229/?page=2#comment-13047 |
| casiotone401 | 12:33c8f06c2e03 | 332 | //Clock Up 100Mhz ------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 333 | LPC_SC->PLL0CON = 0x00; /* PLL0 Disable */ |
| casiotone401 | 12:33c8f06c2e03 | 334 | LPC_SC->PLL0FEED = 0xAA; |
| casiotone401 | 12:33c8f06c2e03 | 335 | LPC_SC->PLL0FEED = 0x55; |
| casiotone401 | 12:33c8f06c2e03 | 336 | |
| casiotone401 | 12:33c8f06c2e03 | 337 | LPC_SC->CCLKCFG = 0x00000003; /* Select Clock Divisor = 4 */ |
| casiotone401 | 12:33c8f06c2e03 | 338 | LPC_SC->PLL0CFG = 0x00020031; /* configure PLL0 */ |
| casiotone401 | 12:33c8f06c2e03 | 339 | LPC_SC->PLL0FEED = 0xAA; /* divide by 3 then multiply by 50 */ |
| casiotone401 | 12:33c8f06c2e03 | 340 | LPC_SC->PLL0FEED = 0x55; /* PLL0 frequency = 400,000,000 */ |
| casiotone401 | 12:33c8f06c2e03 | 341 | |
| casiotone401 | 12:33c8f06c2e03 | 342 | LPC_SC->PLL0CON = 0x01; /* PLL0 Enable */ |
| casiotone401 | 12:33c8f06c2e03 | 343 | LPC_SC->PLL0FEED = 0xAA; |
| casiotone401 | 12:33c8f06c2e03 | 344 | LPC_SC->PLL0FEED = 0x55; |
| casiotone401 | 12:33c8f06c2e03 | 345 | while (!(LPC_SC->PLL0STAT & (1<<26)));/* Wait for PLOCK0 */ |
| casiotone401 | 12:33c8f06c2e03 | 346 | |
| casiotone401 | 12:33c8f06c2e03 | 347 | LPC_SC->PLL0CON = 0x03; /* PLL0 Enable & Connect */ |
| casiotone401 | 12:33c8f06c2e03 | 348 | LPC_SC->PLL0FEED = 0xAA; |
| casiotone401 | 12:33c8f06c2e03 | 349 | LPC_SC->PLL0FEED = 0x55; |
| casiotone401 | 12:33c8f06c2e03 | 350 | while (!(LPC_SC->PLL0STAT & ((1<<25) | (1<<24))));/* Wait for PLLC0_STAT & PLLE0_STAT */ |
| casiotone401 | 12:33c8f06c2e03 | 351 | |
| casiotone401 | 12:33c8f06c2e03 | 352 | SystemCoreClockUpdate(); |
| casiotone401 | 12:33c8f06c2e03 | 353 | //----------------------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 354 | |
| casiotone401 | 12:33c8f06c2e03 | 355 | if(SetupEthNetIf() == -1) |
| casiotone401 | 12:33c8f06c2e03 | 356 | { |
| casiotone401 | 12:33c8f06c2e03 | 357 | for(int i = 0; i < 4; i++) |
| casiotone401 | 12:33c8f06c2e03 | 358 | { |
| casiotone401 | 12:33c8f06c2e03 | 359 | gLEDS[i] = 1; |
| casiotone401 | 12:33c8f06c2e03 | 360 | wait(0.25); |
| casiotone401 | 12:33c8f06c2e03 | 361 | } |
| casiotone401 | 12:33c8f06c2e03 | 362 | |
| casiotone401 | 12:33c8f06c2e03 | 363 | return -1; |
| casiotone401 | 12:33c8f06c2e03 | 364 | } |
| casiotone401 | 12:33c8f06c2e03 | 365 | |
| casiotone401 | 12:33c8f06c2e03 | 366 | // mdns (Bonjour) |
| casiotone401 | 12:33c8f06c2e03 | 367 | HTTPServer svr; |
| casiotone401 | 12:33c8f06c2e03 | 368 | mDNSResponder mdns; |
| casiotone401 | 12:33c8f06c2e03 | 369 | |
| casiotone401 | 12:33c8f06c2e03 | 370 | svr.addHandler<SimpleHandler>("/"); |
| casiotone401 | 12:33c8f06c2e03 | 371 | svr.bind(INPUT_PORT); |
| casiotone401 | 12:33c8f06c2e03 | 372 | IpAddr ip = gEth.getIp(); |
| casiotone401 | 12:33c8f06c2e03 | 373 | mdns.announce(ip, "OSCtoCV", "_osc._udp", INPUT_PORT, "mbed(OSCtoCV)", (char *[]) {"path=/",NULL}); |
| casiotone401 | 12:33c8f06c2e03 | 374 | |
| casiotone401 | 12:33c8f06c2e03 | 375 | InitOSCCV(); |
| casiotone401 | 12:33c8f06c2e03 | 376 | |
| casiotone401 | 12:33c8f06c2e03 | 377 | pot = _pot = 0; |
| casiotone401 | 12:33c8f06c2e03 | 378 | gGlide = gMode = 0; |
| casiotone401 | 12:33c8f06c2e03 | 379 | |
| casiotone401 | 12:33c8f06c2e03 | 380 | LCD(); |
| casiotone401 | 12:33c8f06c2e03 | 381 | gLCD.locate( 0, 1 ); |
| casiotone401 | 12:33c8f06c2e03 | 382 | gLCD.printf("12345678 G>>%3.2f", gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 383 | |
| casiotone401 | 12:33c8f06c2e03 | 384 | // loop |
| casiotone401 | 12:33c8f06c2e03 | 385 | while(1) |
| casiotone401 | 12:33c8f06c2e03 | 386 | { |
| casiotone401 | 12:33c8f06c2e03 | 387 | gGlide = pot = gAIN.read(); // Glide Value |
| casiotone401 | 12:33c8f06c2e03 | 388 | |
| casiotone401 | 12:33c8f06c2e03 | 389 | if(abs(pot - _pot) > 0.01f) |
| casiotone401 | 12:33c8f06c2e03 | 390 | { |
| casiotone401 | 12:33c8f06c2e03 | 391 | gLCD.locate( 0, 1 ); |
| casiotone401 | 12:33c8f06c2e03 | 392 | gLCD.printf("12345678 G>>%3.2f", gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 393 | |
| casiotone401 | 12:33c8f06c2e03 | 394 | _pot = gAIN.read(); |
| casiotone401 | 12:33c8f06c2e03 | 395 | } |
| casiotone401 | 12:33c8f06c2e03 | 396 | |
| casiotone401 | 12:33c8f06c2e03 | 397 | switch(gMode) |
| casiotone401 | 12:33c8f06c2e03 | 398 | { |
| casiotone401 | 12:33c8f06c2e03 | 399 | case MODE_SEQ: |
| casiotone401 | 12:33c8f06c2e03 | 400 | |
| casiotone401 | 12:33c8f06c2e03 | 401 | Seq(); |
| casiotone401 | 12:33c8f06c2e03 | 402 | break; |
| casiotone401 | 12:33c8f06c2e03 | 403 | |
| casiotone401 | 12:33c8f06c2e03 | 404 | case MODE_SHIF: |
| casiotone401 | 12:33c8f06c2e03 | 405 | |
| casiotone401 | 12:33c8f06c2e03 | 406 | ShiftCV((UpdateTrigger(gGATES[0]))); |
| casiotone401 | 12:33c8f06c2e03 | 407 | break; |
| casiotone401 | 12:33c8f06c2e03 | 408 | |
| casiotone401 | 12:33c8f06c2e03 | 409 | case MODE_LIN: |
| casiotone401 | 12:33c8f06c2e03 | 410 | |
| casiotone401 | 12:33c8f06c2e03 | 411 | SetSCV(); |
| casiotone401 | 12:33c8f06c2e03 | 412 | break; |
| casiotone401 | 12:33c8f06c2e03 | 413 | |
| casiotone401 | 12:33c8f06c2e03 | 414 | default: |
| casiotone401 | 12:33c8f06c2e03 | 415 | |
| casiotone401 | 12:33c8f06c2e03 | 416 | SetCV(); |
| casiotone401 | 12:33c8f06c2e03 | 417 | break; |
| casiotone401 | 12:33c8f06c2e03 | 418 | } |
| casiotone401 | 12:33c8f06c2e03 | 419 | } |
| casiotone401 | 12:33c8f06c2e03 | 420 | } |
| casiotone401 | 12:33c8f06c2e03 | 421 | |
| casiotone401 | 12:33c8f06c2e03 | 422 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 423 | // Initialize OSC-CV |
| casiotone401 | 12:33c8f06c2e03 | 424 | |
| casiotone401 | 12:33c8f06c2e03 | 425 | void InitOSCCV() |
| casiotone401 | 12:33c8f06c2e03 | 426 | { |
| casiotone401 | 12:33c8f06c2e03 | 427 | // write custom char LCD CGRAM |
| casiotone401 | 12:33c8f06c2e03 | 428 | WriteCustomChar(0x00, str1); |
| casiotone401 | 12:33c8f06c2e03 | 429 | WriteCustomChar(0x01, str2); |
| casiotone401 | 12:33c8f06c2e03 | 430 | WriteCustomChar(0x02, str3); |
| casiotone401 | 12:33c8f06c2e03 | 431 | WriteCustomChar(0x03, str4); |
| casiotone401 | 12:33c8f06c2e03 | 432 | WriteCustomChar(0x04, str5); |
| casiotone401 | 12:33c8f06c2e03 | 433 | WriteCustomChar(0x05, str6); |
| casiotone401 | 12:33c8f06c2e03 | 434 | WriteCustomChar(0x06, str7); |
| casiotone401 | 12:33c8f06c2e03 | 435 | WriteCustomChar(0x07, str8); |
| casiotone401 | 12:33c8f06c2e03 | 436 | |
| casiotone401 | 12:33c8f06c2e03 | 437 | // Init. SPI |
| casiotone401 | 12:33c8f06c2e03 | 438 | gLDAC = _ENABLE; |
| casiotone401 | 12:33c8f06c2e03 | 439 | gSPI.format(8,1); // Data word length 8bit, Mode=1 |
| casiotone401 | 12:33c8f06c2e03 | 440 | gSPI.frequency(SPI_RATE); |
| casiotone401 | 12:33c8f06c2e03 | 441 | |
| casiotone401 | 12:33c8f06c2e03 | 442 | UpdateCV(CLR, 0, 0); // Ignore CLR Pin |
| casiotone401 | 12:33c8f06c2e03 | 443 | |
| casiotone401 | 12:33c8f06c2e03 | 444 | gSW.mode(PullUp); // Use internal pullup for ModeSW |
| casiotone401 | 12:33c8f06c2e03 | 445 | wait(.001); |
| casiotone401 | 12:33c8f06c2e03 | 446 | |
| casiotone401 | 12:33c8f06c2e03 | 447 | gSW.rise(&CheckModeSW); // InterruptIn rising edge(ModeSW) |
| casiotone401 | 12:33c8f06c2e03 | 448 | gPoller.attach_us(&NetPoll, POLLING_INTERVAL); // Ticker Polling |
| casiotone401 | 12:33c8f06c2e03 | 449 | |
| casiotone401 | 12:33c8f06c2e03 | 450 | wait(0.2); |
| casiotone401 | 12:33c8f06c2e03 | 451 | } |
| casiotone401 | 12:33c8f06c2e03 | 452 | |
| casiotone401 | 12:33c8f06c2e03 | 453 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 454 | // Ethernet Polling |
| casiotone401 | 12:33c8f06c2e03 | 455 | |
| casiotone401 | 12:33c8f06c2e03 | 456 | inline void NetPoll() |
| casiotone401 | 12:33c8f06c2e03 | 457 | { |
| casiotone401 | 12:33c8f06c2e03 | 458 | Net::poll(); |
| casiotone401 | 12:33c8f06c2e03 | 459 | } |
| casiotone401 | 12:33c8f06c2e03 | 460 | |
| casiotone401 | 12:33c8f06c2e03 | 461 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 462 | // Sequencer Mode |
| casiotone401 | 12:33c8f06c2e03 | 463 | inline void Seq() |
| casiotone401 | 12:33c8f06c2e03 | 464 | { |
| casiotone401 | 12:33c8f06c2e03 | 465 | static int bpm, _bpm; |
| casiotone401 | 12:33c8f06c2e03 | 466 | |
| casiotone401 | 12:33c8f06c2e03 | 467 | bpm = (gCtrl[0] * 300 + 10); // Set BPM (gCtrl[0]) |
| casiotone401 | 12:33c8f06c2e03 | 468 | |
| casiotone401 | 12:33c8f06c2e03 | 469 | if(abs(bpm - _bpm) > 1) |
| casiotone401 | 12:33c8f06c2e03 | 470 | { |
| casiotone401 | 12:33c8f06c2e03 | 471 | UpdateGate(bpm, NRESET, GATEALL, 3, false); // Reset (if bpm change) |
| casiotone401 | 12:33c8f06c2e03 | 472 | _bpm = bpm; |
| casiotone401 | 12:33c8f06c2e03 | 473 | |
| casiotone401 | 12:33c8f06c2e03 | 474 | } else if (gCtrlSW[0]) { // Stop (gCtrlSW[0]) |
| casiotone401 | 12:33c8f06c2e03 | 475 | |
| casiotone401 | 12:33c8f06c2e03 | 476 | bpm = 0; |
| casiotone401 | 12:33c8f06c2e03 | 477 | } |
| casiotone401 | 12:33c8f06c2e03 | 478 | |
| casiotone401 | 12:33c8f06c2e03 | 479 | if(!gCtrlSW[2] && !gCtrlSW[3]) // Sequencer Mode1 |
| casiotone401 | 12:33c8f06c2e03 | 480 | { |
| casiotone401 | 12:33c8f06c2e03 | 481 | SeqCV((UpdateGate(bpm, N16TH, GATE1, 3, false))); // Shift Timming 16th note |
| casiotone401 | 12:33c8f06c2e03 | 482 | UpdateGate(bpm, N8TH, GATE2, 3, 0); |
| casiotone401 | 12:33c8f06c2e03 | 483 | UpdateGate(bpm, NDOT8, GATE3, 3, 0); |
| casiotone401 | 12:33c8f06c2e03 | 484 | UpdateGate(bpm, TRIP4, GATE4, 3, 0); |
| casiotone401 | 12:33c8f06c2e03 | 485 | |
| casiotone401 | 12:33c8f06c2e03 | 486 | } else if (gCtrlSW[2] && !gCtrlSW[3]) { // Sequencer Mode2 (if gCtrlSW[2] ON) |
| casiotone401 | 12:33c8f06c2e03 | 487 | |
| casiotone401 | 12:33c8f06c2e03 | 488 | SeqCV((UpdateGate(bpm, N16TH, GATE1, 3, false))); // Do shift ch 1~5 |
| casiotone401 | 12:33c8f06c2e03 | 489 | SeqCV((UpdateGate(bpm, N4TH, GATE2, 3, false))); // Do shift ch 6 |
| casiotone401 | 12:33c8f06c2e03 | 490 | SeqCV((UpdateGate(bpm, NDOT4, GATE3, 3, false))); // Do shift ch 7 |
| casiotone401 | 12:33c8f06c2e03 | 491 | SeqCV((UpdateGate(bpm, TRIP8, GATE4, 3, false))); // Do shift ch 8 |
| casiotone401 | 12:33c8f06c2e03 | 492 | |
| casiotone401 | 12:33c8f06c2e03 | 493 | } else if (gCtrlSW[3]) { // Sequencer Mode3 (if gCtrlSW[3] ON) |
| casiotone401 | 12:33c8f06c2e03 | 494 | // (ch6,7,8, short loop) |
| casiotone401 | 12:33c8f06c2e03 | 495 | SeqCV((UpdateGate(bpm, N16TH, GATE1, 3, false))); // Do shift ch 1~5 |
| casiotone401 | 12:33c8f06c2e03 | 496 | SeqCV((UpdateGate(bpm, N8TH, GATE2, 3, false))); // Do shift ch 6 |
| casiotone401 | 12:33c8f06c2e03 | 497 | SeqCV((UpdateGate(bpm, NDOT8, GATE3, 3, false))); // Do shift ch 7 |
| casiotone401 | 12:33c8f06c2e03 | 498 | SeqCV((UpdateGate(bpm, TRIP4, GATE4, 3, false))); // Do shift ch 8 |
| casiotone401 | 12:33c8f06c2e03 | 499 | } |
| casiotone401 | 12:33c8f06c2e03 | 500 | } |
| casiotone401 | 12:33c8f06c2e03 | 501 | |
| casiotone401 | 12:33c8f06c2e03 | 502 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 503 | // SPI Transfer |
| casiotone401 | 12:33c8f06c2e03 | 504 | // DAC8568 data word length 32bit (8bit shift out) |
| casiotone401 | 12:33c8f06c2e03 | 505 | |
| casiotone401 | 12:33c8f06c2e03 | 506 | inline void UpdateCV(int control, int address, const unsigned int *data) |
| casiotone401 | 12:33c8f06c2e03 | 507 | { |
| casiotone401 | 12:33c8f06c2e03 | 508 | |
| casiotone401 | 12:33c8f06c2e03 | 509 | switch(control) |
| casiotone401 | 12:33c8f06c2e03 | 510 | { |
| casiotone401 | 12:33c8f06c2e03 | 511 | case WRITE_UPDATE_N: |
| casiotone401 | 12:33c8f06c2e03 | 512 | |
| casiotone401 | 12:33c8f06c2e03 | 513 | gSYNCMODE = _DISABLE; |
| casiotone401 | 12:33c8f06c2e03 | 514 | gSPI.write(00000000|control); // padding at beginning of byte and control bits |
| casiotone401 | 12:33c8f06c2e03 | 515 | gSPI.write(address << 4 | *data >> 12); // address(ch) bits |
| casiotone401 | 12:33c8f06c2e03 | 516 | gSPI.write((*data << 4) >> 8); // middle 8 bits of data |
| casiotone401 | 12:33c8f06c2e03 | 517 | gSPI.write((*data << 12) >> 8 | 00001111); |
| casiotone401 | 12:33c8f06c2e03 | 518 | gSYNCMODE = _ENABLE; |
| casiotone401 | 12:33c8f06c2e03 | 519 | gLDAC = _DISABLE; |
| casiotone401 | 12:33c8f06c2e03 | 520 | gLDAC = _ENABLE; |
| casiotone401 | 12:33c8f06c2e03 | 521 | break; |
| casiotone401 | 12:33c8f06c2e03 | 522 | |
| casiotone401 | 12:33c8f06c2e03 | 523 | case RESET: |
| casiotone401 | 12:33c8f06c2e03 | 524 | |
| casiotone401 | 12:33c8f06c2e03 | 525 | gSYNCMODE = _DISABLE; |
| casiotone401 | 12:33c8f06c2e03 | 526 | gSPI.write(00000111); // Software RESET |
| casiotone401 | 12:33c8f06c2e03 | 527 | gSPI.write(00000000); |
| casiotone401 | 12:33c8f06c2e03 | 528 | gSPI.write(00000000); |
| casiotone401 | 12:33c8f06c2e03 | 529 | gSPI.write(00000000); |
| casiotone401 | 12:33c8f06c2e03 | 530 | gSYNCMODE = _ENABLE; |
| casiotone401 | 12:33c8f06c2e03 | 531 | break; |
| casiotone401 | 12:33c8f06c2e03 | 532 | |
| casiotone401 | 12:33c8f06c2e03 | 533 | case CLR: |
| casiotone401 | 12:33c8f06c2e03 | 534 | |
| casiotone401 | 12:33c8f06c2e03 | 535 | gSYNCMODE = _DISABLE; |
| casiotone401 | 12:33c8f06c2e03 | 536 | gSPI.write(00000101); // CLR Register |
| casiotone401 | 12:33c8f06c2e03 | 537 | gSPI.write(00000000); |
| casiotone401 | 12:33c8f06c2e03 | 538 | gSPI.write(00000000); |
| casiotone401 | 12:33c8f06c2e03 | 539 | gSPI.write(00000011); // Ignore CLR Pin |
| casiotone401 | 12:33c8f06c2e03 | 540 | gSYNCMODE = _ENABLE; |
| casiotone401 | 12:33c8f06c2e03 | 541 | break; |
| casiotone401 | 12:33c8f06c2e03 | 542 | } |
| casiotone401 | 12:33c8f06c2e03 | 543 | } |
| casiotone401 | 12:33c8f06c2e03 | 544 | |
| casiotone401 | 12:33c8f06c2e03 | 545 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 546 | // UpdateTrigger |
| casiotone401 | 12:33c8f06c2e03 | 547 | |
| casiotone401 | 12:33c8f06c2e03 | 548 | inline int UpdateTrigger(bool gate) |
| casiotone401 | 12:33c8f06c2e03 | 549 | { |
| casiotone401 | 12:33c8f06c2e03 | 550 | static bool clkstate; |
| casiotone401 | 12:33c8f06c2e03 | 551 | static int gatetime, oldgatetime; |
| casiotone401 | 12:33c8f06c2e03 | 552 | static int oldshift; |
| casiotone401 | 12:33c8f06c2e03 | 553 | |
| casiotone401 | 12:33c8f06c2e03 | 554 | int time = gTimer.read_ms(); |
| casiotone401 | 12:33c8f06c2e03 | 555 | |
| casiotone401 | 12:33c8f06c2e03 | 556 | if(gate && !clkstate) |
| casiotone401 | 12:33c8f06c2e03 | 557 | { |
| casiotone401 | 12:33c8f06c2e03 | 558 | oldgatetime = time; |
| casiotone401 | 12:33c8f06c2e03 | 559 | clkstate = 1; |
| casiotone401 | 12:33c8f06c2e03 | 560 | |
| casiotone401 | 12:33c8f06c2e03 | 561 | } else if (!gate && clkstate) { |
| casiotone401 | 12:33c8f06c2e03 | 562 | |
| casiotone401 | 12:33c8f06c2e03 | 563 | gatetime = time - oldgatetime + 2; |
| casiotone401 | 12:33c8f06c2e03 | 564 | clkstate = 0; |
| casiotone401 | 12:33c8f06c2e03 | 565 | |
| casiotone401 | 12:33c8f06c2e03 | 566 | } else if (gCtrlSW[0]) { |
| casiotone401 | 12:33c8f06c2e03 | 567 | |
| casiotone401 | 12:33c8f06c2e03 | 568 | gTimer.reset(); |
| casiotone401 | 12:33c8f06c2e03 | 569 | oldshift = clkstate = 0; |
| casiotone401 | 12:33c8f06c2e03 | 570 | } |
| casiotone401 | 12:33c8f06c2e03 | 571 | |
| casiotone401 | 12:33c8f06c2e03 | 572 | if(time >= oldshift + gatetime) |
| casiotone401 | 12:33c8f06c2e03 | 573 | { |
| casiotone401 | 12:33c8f06c2e03 | 574 | oldshift = time; |
| casiotone401 | 12:33c8f06c2e03 | 575 | return 1; |
| casiotone401 | 12:33c8f06c2e03 | 576 | |
| casiotone401 | 12:33c8f06c2e03 | 577 | } else { |
| casiotone401 | 12:33c8f06c2e03 | 578 | |
| casiotone401 | 12:33c8f06c2e03 | 579 | return 0; |
| casiotone401 | 12:33c8f06c2e03 | 580 | } |
| casiotone401 | 12:33c8f06c2e03 | 581 | } |
| casiotone401 | 12:33c8f06c2e03 | 582 | |
| casiotone401 | 12:33c8f06c2e03 | 583 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 584 | // GateOutSequence beat(Note values) length(Gate time) invert(invert Gate) |
| casiotone401 | 12:33c8f06c2e03 | 585 | |
| casiotone401 | 12:33c8f06c2e03 | 586 | inline int UpdateGate(int bpm, int beat, int ch, int length, bool invert) |
| casiotone401 | 12:33c8f06c2e03 | 587 | { |
| casiotone401 | 12:33c8f06c2e03 | 588 | int i; |
| casiotone401 | 12:33c8f06c2e03 | 589 | static int gatetime[4], oldgatetime[4]; |
| casiotone401 | 12:33c8f06c2e03 | 590 | static int bar, sync24, oldsynctime; |
| casiotone401 | 12:33c8f06c2e03 | 591 | |
| casiotone401 | 12:33c8f06c2e03 | 592 | int time = gTimer.read_us(); |
| casiotone401 | 12:33c8f06c2e03 | 593 | |
| casiotone401 | 12:33c8f06c2e03 | 594 | bar = (60.0f / bpm) * 4000000; |
| casiotone401 | 12:33c8f06c2e03 | 595 | sync24 = (bar / 4) / 24; // sync24 not tested |
| casiotone401 | 12:33c8f06c2e03 | 596 | |
| casiotone401 | 12:33c8f06c2e03 | 597 | switch(beat) // Calculate Note values |
| casiotone401 | 12:33c8f06c2e03 | 598 | { |
| casiotone401 | 12:33c8f06c2e03 | 599 | case NDOT2: |
| casiotone401 | 12:33c8f06c2e03 | 600 | |
| casiotone401 | 12:33c8f06c2e03 | 601 | gatetime[ch] = (bar / 4) * 3; |
| casiotone401 | 12:33c8f06c2e03 | 602 | break; |
| casiotone401 | 12:33c8f06c2e03 | 603 | |
| casiotone401 | 12:33c8f06c2e03 | 604 | case NDOT4: |
| casiotone401 | 12:33c8f06c2e03 | 605 | |
| casiotone401 | 12:33c8f06c2e03 | 606 | gatetime[ch] = (bar / 8) * 3; |
| casiotone401 | 12:33c8f06c2e03 | 607 | break; |
| casiotone401 | 12:33c8f06c2e03 | 608 | |
| casiotone401 | 12:33c8f06c2e03 | 609 | case NDOT8: |
| casiotone401 | 12:33c8f06c2e03 | 610 | |
| casiotone401 | 12:33c8f06c2e03 | 611 | gatetime[ch] = (bar / 16) * 3; |
| casiotone401 | 12:33c8f06c2e03 | 612 | break; |
| casiotone401 | 12:33c8f06c2e03 | 613 | |
| casiotone401 | 12:33c8f06c2e03 | 614 | case NDOT16: |
| casiotone401 | 12:33c8f06c2e03 | 615 | |
| casiotone401 | 12:33c8f06c2e03 | 616 | gatetime[ch] = (bar / 32) * 3; |
| casiotone401 | 12:33c8f06c2e03 | 617 | break; |
| casiotone401 | 12:33c8f06c2e03 | 618 | |
| casiotone401 | 12:33c8f06c2e03 | 619 | case NDOT32: |
| casiotone401 | 12:33c8f06c2e03 | 620 | |
| casiotone401 | 12:33c8f06c2e03 | 621 | gatetime[ch] = (bar / 64) * 3; |
| casiotone401 | 12:33c8f06c2e03 | 622 | break; |
| casiotone401 | 12:33c8f06c2e03 | 623 | |
| casiotone401 | 12:33c8f06c2e03 | 624 | case TRIP2: |
| casiotone401 | 12:33c8f06c2e03 | 625 | |
| casiotone401 | 12:33c8f06c2e03 | 626 | gatetime[ch] = bar / 3; |
| casiotone401 | 12:33c8f06c2e03 | 627 | break; |
| casiotone401 | 12:33c8f06c2e03 | 628 | |
| casiotone401 | 12:33c8f06c2e03 | 629 | case TRIP4: |
| casiotone401 | 12:33c8f06c2e03 | 630 | |
| casiotone401 | 12:33c8f06c2e03 | 631 | gatetime[ch] = (bar / 2) / 3; |
| casiotone401 | 12:33c8f06c2e03 | 632 | break; |
| casiotone401 | 12:33c8f06c2e03 | 633 | |
| casiotone401 | 12:33c8f06c2e03 | 634 | case TRIP8: |
| casiotone401 | 12:33c8f06c2e03 | 635 | |
| casiotone401 | 12:33c8f06c2e03 | 636 | gatetime[ch] = (bar / 4) / 3; |
| casiotone401 | 12:33c8f06c2e03 | 637 | break; |
| casiotone401 | 12:33c8f06c2e03 | 638 | |
| casiotone401 | 12:33c8f06c2e03 | 639 | case TRIP16: |
| casiotone401 | 12:33c8f06c2e03 | 640 | |
| casiotone401 | 12:33c8f06c2e03 | 641 | gatetime[ch] = (bar / 8) / 3; |
| casiotone401 | 12:33c8f06c2e03 | 642 | break; |
| casiotone401 | 12:33c8f06c2e03 | 643 | |
| casiotone401 | 12:33c8f06c2e03 | 644 | case TRIP32: |
| casiotone401 | 12:33c8f06c2e03 | 645 | |
| casiotone401 | 12:33c8f06c2e03 | 646 | gatetime[ch] = (bar / 16) / 3; |
| casiotone401 | 12:33c8f06c2e03 | 647 | break; |
| casiotone401 | 12:33c8f06c2e03 | 648 | |
| casiotone401 | 12:33c8f06c2e03 | 649 | case NRESET: |
| casiotone401 | 12:33c8f06c2e03 | 650 | |
| casiotone401 | 12:33c8f06c2e03 | 651 | for(i = 0; i < GATEALL; ++i) // Reset |
| casiotone401 | 12:33c8f06c2e03 | 652 | { |
| casiotone401 | 12:33c8f06c2e03 | 653 | gTimer.reset(); |
| casiotone401 | 12:33c8f06c2e03 | 654 | oldsynctime = oldgatetime[i] = gatetime[i] = NRESET; |
| casiotone401 | 12:33c8f06c2e03 | 655 | } |
| casiotone401 | 12:33c8f06c2e03 | 656 | break; |
| casiotone401 | 12:33c8f06c2e03 | 657 | |
| casiotone401 | 12:33c8f06c2e03 | 658 | default: |
| casiotone401 | 12:33c8f06c2e03 | 659 | |
| casiotone401 | 12:33c8f06c2e03 | 660 | gatetime[ch] = bar / beat; |
| casiotone401 | 12:33c8f06c2e03 | 661 | } |
| casiotone401 | 12:33c8f06c2e03 | 662 | |
| casiotone401 | 12:33c8f06c2e03 | 663 | if(time > oldsynctime + sync24) // sync24 not tested |
| casiotone401 | 12:33c8f06c2e03 | 664 | { |
| casiotone401 | 12:33c8f06c2e03 | 665 | oldsynctime = time; |
| casiotone401 | 12:33c8f06c2e03 | 666 | gCLOCKOUT = 1; |
| casiotone401 | 12:33c8f06c2e03 | 667 | |
| casiotone401 | 12:33c8f06c2e03 | 668 | } else if (time > sync24 - (sync24 - 2)) { |
| casiotone401 | 12:33c8f06c2e03 | 669 | |
| casiotone401 | 12:33c8f06c2e03 | 670 | gCLOCKOUT = 0; |
| casiotone401 | 12:33c8f06c2e03 | 671 | } |
| casiotone401 | 12:33c8f06c2e03 | 672 | |
| casiotone401 | 12:33c8f06c2e03 | 673 | if (ch == GATEALL) |
| casiotone401 | 12:33c8f06c2e03 | 674 | { |
| casiotone401 | 12:33c8f06c2e03 | 675 | return -1; |
| casiotone401 | 12:33c8f06c2e03 | 676 | |
| casiotone401 | 12:33c8f06c2e03 | 677 | } else if (time > oldgatetime[ch] + gatetime[ch] && !invert) { |
| casiotone401 | 12:33c8f06c2e03 | 678 | |
| casiotone401 | 12:33c8f06c2e03 | 679 | oldgatetime[ch] = time; |
| casiotone401 | 12:33c8f06c2e03 | 680 | gLEDS[ch] = gGATES[ch] = 1; |
| casiotone401 | 12:33c8f06c2e03 | 681 | |
| casiotone401 | 12:33c8f06c2e03 | 682 | return ch + 1; |
| casiotone401 | 12:33c8f06c2e03 | 683 | |
| casiotone401 | 12:33c8f06c2e03 | 684 | } else if (time > oldgatetime[ch] + gatetime[ch] && invert) { |
| casiotone401 | 12:33c8f06c2e03 | 685 | |
| casiotone401 | 12:33c8f06c2e03 | 686 | oldgatetime[ch] = time; |
| casiotone401 | 12:33c8f06c2e03 | 687 | gLEDS[ch] = gGATES[ch] = 0; |
| casiotone401 | 12:33c8f06c2e03 | 688 | |
| casiotone401 | 12:33c8f06c2e03 | 689 | return 0; |
| casiotone401 | 12:33c8f06c2e03 | 690 | |
| casiotone401 | 12:33c8f06c2e03 | 691 | } else if (time > oldgatetime[ch] + (gatetime[ch] - gatetime[ch] / length) && !invert) { |
| casiotone401 | 12:33c8f06c2e03 | 692 | |
| casiotone401 | 12:33c8f06c2e03 | 693 | gLEDS[ch] = gGATES[ch] = 0; |
| casiotone401 | 12:33c8f06c2e03 | 694 | |
| casiotone401 | 12:33c8f06c2e03 | 695 | return 0; |
| casiotone401 | 12:33c8f06c2e03 | 696 | |
| casiotone401 | 12:33c8f06c2e03 | 697 | } else if (time > oldgatetime[ch] + (gatetime[ch] - gatetime[ch] / length) && invert) { |
| casiotone401 | 12:33c8f06c2e03 | 698 | |
| casiotone401 | 12:33c8f06c2e03 | 699 | gLEDS[ch] = gGATES[ch] = 1; |
| casiotone401 | 12:33c8f06c2e03 | 700 | |
| casiotone401 | 12:33c8f06c2e03 | 701 | return ch + 1; |
| casiotone401 | 12:33c8f06c2e03 | 702 | |
| casiotone401 | 12:33c8f06c2e03 | 703 | } else { |
| casiotone401 | 12:33c8f06c2e03 | 704 | |
| casiotone401 | 12:33c8f06c2e03 | 705 | return -1; |
| casiotone401 | 12:33c8f06c2e03 | 706 | } |
| casiotone401 | 12:33c8f06c2e03 | 707 | } |
| casiotone401 | 12:33c8f06c2e03 | 708 | |
| casiotone401 | 12:33c8f06c2e03 | 709 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 710 | // Calculate CV |
| casiotone401 | 12:33c8f06c2e03 | 711 | |
| casiotone401 | 12:33c8f06c2e03 | 712 | inline void SetCV() |
| casiotone401 | 12:33c8f06c2e03 | 713 | { |
| casiotone401 | 12:33c8f06c2e03 | 714 | static int ch, quan; |
| casiotone401 | 12:33c8f06c2e03 | 715 | static float glidecv[8], oldcv[8]; |
| casiotone401 | 12:33c8f06c2e03 | 716 | unsigned int cv[8]; |
| casiotone401 | 12:33c8f06c2e03 | 717 | float qcv; |
| casiotone401 | 12:33c8f06c2e03 | 718 | |
| casiotone401 | 12:33c8f06c2e03 | 719 | switch(gMode) |
| casiotone401 | 12:33c8f06c2e03 | 720 | { |
| casiotone401 | 12:33c8f06c2e03 | 721 | case MODE_LIN: |
| casiotone401 | 12:33c8f06c2e03 | 722 | |
| casiotone401 | 12:33c8f06c2e03 | 723 | oldcv[ch] = glidecv[ch] = oldcv[ch] * gGlide + gOSC_cv[ch] * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 724 | cv[ch] = (unsigned int)glidecv[ch]; |
| casiotone401 | 12:33c8f06c2e03 | 725 | |
| casiotone401 | 12:33c8f06c2e03 | 726 | UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]); |
| casiotone401 | 12:33c8f06c2e03 | 727 | break; |
| casiotone401 | 12:33c8f06c2e03 | 728 | |
| casiotone401 | 12:33c8f06c2e03 | 729 | case MODE_QChr: |
| casiotone401 | 12:33c8f06c2e03 | 730 | |
| casiotone401 | 12:33c8f06c2e03 | 731 | quan = 40616 / QUAN_RES1; |
| casiotone401 | 12:33c8f06c2e03 | 732 | qcv = calibMap1[(unsigned int)(gOSC_cv[ch] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 733 | |
| casiotone401 | 12:33c8f06c2e03 | 734 | oldcv[ch] = glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 735 | cv[ch] = (unsigned int)glidecv[ch]; |
| casiotone401 | 12:33c8f06c2e03 | 736 | |
| casiotone401 | 12:33c8f06c2e03 | 737 | UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]); |
| casiotone401 | 12:33c8f06c2e03 | 738 | break; |
| casiotone401 | 12:33c8f06c2e03 | 739 | |
| casiotone401 | 12:33c8f06c2e03 | 740 | case MODE_QMaj: |
| casiotone401 | 12:33c8f06c2e03 | 741 | |
| casiotone401 | 12:33c8f06c2e03 | 742 | quan = 40616 / QUAN_RES2; |
| casiotone401 | 12:33c8f06c2e03 | 743 | qcv = calibMap2[(unsigned int)(gOSC_cv[ch] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 744 | |
| casiotone401 | 12:33c8f06c2e03 | 745 | oldcv[ch] = glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 746 | cv[ch] = (unsigned int)glidecv[ch]; |
| casiotone401 | 12:33c8f06c2e03 | 747 | |
| casiotone401 | 12:33c8f06c2e03 | 748 | UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]); |
| casiotone401 | 12:33c8f06c2e03 | 749 | break; |
| casiotone401 | 12:33c8f06c2e03 | 750 | |
| casiotone401 | 12:33c8f06c2e03 | 751 | case MODE_QDor: |
| casiotone401 | 12:33c8f06c2e03 | 752 | |
| casiotone401 | 12:33c8f06c2e03 | 753 | quan = 40616 / QUAN_RES5; |
| casiotone401 | 12:33c8f06c2e03 | 754 | qcv = calibMap5[(unsigned int)(gOSC_cv[ch] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 755 | |
| casiotone401 | 12:33c8f06c2e03 | 756 | oldcv[ch] = glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 757 | cv[ch] = (unsigned int)glidecv[ch]; |
| casiotone401 | 12:33c8f06c2e03 | 758 | |
| casiotone401 | 12:33c8f06c2e03 | 759 | UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]); |
| casiotone401 | 12:33c8f06c2e03 | 760 | break; |
| casiotone401 | 12:33c8f06c2e03 | 761 | |
| casiotone401 | 12:33c8f06c2e03 | 762 | case MODE_Q5th: |
| casiotone401 | 12:33c8f06c2e03 | 763 | |
| casiotone401 | 12:33c8f06c2e03 | 764 | quan = 40616 / QUAN_RES7; |
| casiotone401 | 12:33c8f06c2e03 | 765 | qcv = calibMap7[(unsigned int)(gOSC_cv[ch] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 766 | |
| casiotone401 | 12:33c8f06c2e03 | 767 | oldcv[ch] = glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 768 | cv[ch] = (unsigned int)glidecv[ch]; |
| casiotone401 | 12:33c8f06c2e03 | 769 | |
| casiotone401 | 12:33c8f06c2e03 | 770 | UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]); |
| casiotone401 | 12:33c8f06c2e03 | 771 | break; |
| casiotone401 | 12:33c8f06c2e03 | 772 | |
| casiotone401 | 12:33c8f06c2e03 | 773 | case MODE_QWht: |
| casiotone401 | 12:33c8f06c2e03 | 774 | |
| casiotone401 | 12:33c8f06c2e03 | 775 | quan = 40616 / QUAN_RES8; |
| casiotone401 | 12:33c8f06c2e03 | 776 | qcv = calibMap8[(unsigned int)(gOSC_cv[ch] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 777 | |
| casiotone401 | 12:33c8f06c2e03 | 778 | oldcv[ch] = glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 779 | cv[ch] = (unsigned int)glidecv[ch]; |
| casiotone401 | 12:33c8f06c2e03 | 780 | |
| casiotone401 | 12:33c8f06c2e03 | 781 | UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]); |
| casiotone401 | 12:33c8f06c2e03 | 782 | break; |
| casiotone401 | 12:33c8f06c2e03 | 783 | |
| casiotone401 | 12:33c8f06c2e03 | 784 | case MODE_Calb: |
| casiotone401 | 12:33c8f06c2e03 | 785 | |
| casiotone401 | 12:33c8f06c2e03 | 786 | cv[ch] = 19212; // A880.0Hz |
| casiotone401 | 12:33c8f06c2e03 | 787 | |
| casiotone401 | 12:33c8f06c2e03 | 788 | gGATES[0] = gGATES[1] = gGATES[2] = gGATES[3] = 1; |
| casiotone401 | 12:33c8f06c2e03 | 789 | gLEDS[0] = gLEDS[1] = gLEDS[2] = gLEDS[3] = 1; |
| casiotone401 | 12:33c8f06c2e03 | 790 | |
| casiotone401 | 12:33c8f06c2e03 | 791 | UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]); |
| casiotone401 | 12:33c8f06c2e03 | 792 | break; |
| casiotone401 | 12:33c8f06c2e03 | 793 | } |
| casiotone401 | 12:33c8f06c2e03 | 794 | |
| casiotone401 | 12:33c8f06c2e03 | 795 | CVMeter(ch, &cv[ch]); |
| casiotone401 | 12:33c8f06c2e03 | 796 | |
| casiotone401 | 12:33c8f06c2e03 | 797 | ch++; |
| casiotone401 | 12:33c8f06c2e03 | 798 | ch &= 0x07; |
| casiotone401 | 12:33c8f06c2e03 | 799 | } |
| casiotone401 | 12:33c8f06c2e03 | 800 | |
| casiotone401 | 12:33c8f06c2e03 | 801 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 802 | // Calculate CV |
| casiotone401 | 12:33c8f06c2e03 | 803 | |
| casiotone401 | 12:33c8f06c2e03 | 804 | inline void SetSCV() |
| casiotone401 | 12:33c8f06c2e03 | 805 | { |
| casiotone401 | 12:33c8f06c2e03 | 806 | static int ch, quan, mode; |
| casiotone401 | 12:33c8f06c2e03 | 807 | static float glidecv[8], oldcv[8]; |
| casiotone401 | 12:33c8f06c2e03 | 808 | unsigned int cv[8]; |
| casiotone401 | 12:33c8f06c2e03 | 809 | float qcv; |
| casiotone401 | 12:33c8f06c2e03 | 810 | |
| casiotone401 | 12:33c8f06c2e03 | 811 | mode = (gCtrl[1] * 8); |
| casiotone401 | 12:33c8f06c2e03 | 812 | |
| casiotone401 | 12:33c8f06c2e03 | 813 | gCLOCKOUT = gGATES[0]; |
| casiotone401 | 12:33c8f06c2e03 | 814 | |
| casiotone401 | 12:33c8f06c2e03 | 815 | switch(mode) |
| casiotone401 | 12:33c8f06c2e03 | 816 | { |
| casiotone401 | 12:33c8f06c2e03 | 817 | case Lin: |
| casiotone401 | 12:33c8f06c2e03 | 818 | |
| casiotone401 | 12:33c8f06c2e03 | 819 | oldcv[ch] = glidecv[ch] = oldcv[ch] * gGlide + gOSC_cv[ch] * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 820 | cv[ch] = (unsigned int)glidecv[ch]; |
| casiotone401 | 12:33c8f06c2e03 | 821 | |
| casiotone401 | 12:33c8f06c2e03 | 822 | UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]); |
| casiotone401 | 12:33c8f06c2e03 | 823 | break; |
| casiotone401 | 12:33c8f06c2e03 | 824 | |
| casiotone401 | 12:33c8f06c2e03 | 825 | case Chr: |
| casiotone401 | 12:33c8f06c2e03 | 826 | |
| casiotone401 | 12:33c8f06c2e03 | 827 | quan = 40616 / QUAN_RES1; |
| casiotone401 | 12:33c8f06c2e03 | 828 | qcv = calibMap1[(unsigned int)(gOSC_cv[ch] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 829 | |
| casiotone401 | 12:33c8f06c2e03 | 830 | oldcv[ch] = glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 831 | cv[ch] = (unsigned int)glidecv[ch]; |
| casiotone401 | 12:33c8f06c2e03 | 832 | |
| casiotone401 | 12:33c8f06c2e03 | 833 | UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]); |
| casiotone401 | 12:33c8f06c2e03 | 834 | break; |
| casiotone401 | 12:33c8f06c2e03 | 835 | |
| casiotone401 | 12:33c8f06c2e03 | 836 | case Maj: |
| casiotone401 | 12:33c8f06c2e03 | 837 | |
| casiotone401 | 12:33c8f06c2e03 | 838 | quan = 40616 / QUAN_RES2; |
| casiotone401 | 12:33c8f06c2e03 | 839 | qcv = calibMap2[(unsigned int)(gOSC_cv[ch] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 840 | |
| casiotone401 | 12:33c8f06c2e03 | 841 | oldcv[ch] = glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 842 | cv[ch] = (unsigned int)glidecv[ch]; |
| casiotone401 | 12:33c8f06c2e03 | 843 | |
| casiotone401 | 12:33c8f06c2e03 | 844 | UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]); |
| casiotone401 | 12:33c8f06c2e03 | 845 | break; |
| casiotone401 | 12:33c8f06c2e03 | 846 | |
| casiotone401 | 12:33c8f06c2e03 | 847 | case M7: |
| casiotone401 | 12:33c8f06c2e03 | 848 | |
| casiotone401 | 12:33c8f06c2e03 | 849 | quan = 40616 / QUAN_RES3; |
| casiotone401 | 12:33c8f06c2e03 | 850 | qcv = calibMap3[(unsigned int)(gOSC_cv[ch] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 851 | |
| casiotone401 | 12:33c8f06c2e03 | 852 | oldcv[ch] = glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 853 | cv[ch] = (unsigned int)glidecv[ch]; |
| casiotone401 | 12:33c8f06c2e03 | 854 | |
| casiotone401 | 12:33c8f06c2e03 | 855 | UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]); |
| casiotone401 | 12:33c8f06c2e03 | 856 | break; |
| casiotone401 | 12:33c8f06c2e03 | 857 | |
| casiotone401 | 12:33c8f06c2e03 | 858 | case Min7: |
| casiotone401 | 12:33c8f06c2e03 | 859 | |
| casiotone401 | 12:33c8f06c2e03 | 860 | quan = 40616 / QUAN_RES4; |
| casiotone401 | 12:33c8f06c2e03 | 861 | qcv = calibMap4[(unsigned int)(gOSC_cv[ch] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 862 | |
| casiotone401 | 12:33c8f06c2e03 | 863 | oldcv[ch] = glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 864 | cv[ch] = (unsigned int)glidecv[ch]; |
| casiotone401 | 12:33c8f06c2e03 | 865 | |
| casiotone401 | 12:33c8f06c2e03 | 866 | UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]); |
| casiotone401 | 12:33c8f06c2e03 | 867 | break; |
| casiotone401 | 12:33c8f06c2e03 | 868 | |
| casiotone401 | 12:33c8f06c2e03 | 869 | case Dor: |
| casiotone401 | 12:33c8f06c2e03 | 870 | |
| casiotone401 | 12:33c8f06c2e03 | 871 | quan = 40616 / QUAN_RES5; |
| casiotone401 | 12:33c8f06c2e03 | 872 | qcv = calibMap5[(unsigned int)(gOSC_cv[ch] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 873 | |
| casiotone401 | 12:33c8f06c2e03 | 874 | oldcv[ch] = glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 875 | cv[ch] = (unsigned int)glidecv[ch]; |
| casiotone401 | 12:33c8f06c2e03 | 876 | |
| casiotone401 | 12:33c8f06c2e03 | 877 | UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]); |
| casiotone401 | 12:33c8f06c2e03 | 878 | break; |
| casiotone401 | 12:33c8f06c2e03 | 879 | |
| casiotone401 | 12:33c8f06c2e03 | 880 | case Min: |
| casiotone401 | 12:33c8f06c2e03 | 881 | |
| casiotone401 | 12:33c8f06c2e03 | 882 | quan = 40616 / QUAN_RES6; |
| casiotone401 | 12:33c8f06c2e03 | 883 | qcv = calibMap6[(unsigned int)(gOSC_cv[ch] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 884 | |
| casiotone401 | 12:33c8f06c2e03 | 885 | oldcv[ch] = glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 886 | cv[ch] = (unsigned int)glidecv[ch]; |
| casiotone401 | 12:33c8f06c2e03 | 887 | |
| casiotone401 | 12:33c8f06c2e03 | 888 | UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]); |
| casiotone401 | 12:33c8f06c2e03 | 889 | break; |
| casiotone401 | 12:33c8f06c2e03 | 890 | |
| casiotone401 | 12:33c8f06c2e03 | 891 | case S5th: |
| casiotone401 | 12:33c8f06c2e03 | 892 | |
| casiotone401 | 12:33c8f06c2e03 | 893 | quan = 40616 / QUAN_RES7; |
| casiotone401 | 12:33c8f06c2e03 | 894 | qcv = calibMap7[(unsigned int)(gOSC_cv[ch] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 895 | |
| casiotone401 | 12:33c8f06c2e03 | 896 | oldcv[ch] = glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 897 | cv[ch] = (unsigned int)glidecv[ch]; |
| casiotone401 | 12:33c8f06c2e03 | 898 | |
| casiotone401 | 12:33c8f06c2e03 | 899 | UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]); |
| casiotone401 | 12:33c8f06c2e03 | 900 | break; |
| casiotone401 | 12:33c8f06c2e03 | 901 | |
| casiotone401 | 12:33c8f06c2e03 | 902 | case Wht: |
| casiotone401 | 12:33c8f06c2e03 | 903 | |
| casiotone401 | 12:33c8f06c2e03 | 904 | quan = 40616 / QUAN_RES8; |
| casiotone401 | 12:33c8f06c2e03 | 905 | qcv = calibMap8[(unsigned int)(gOSC_cv[ch] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 906 | |
| casiotone401 | 12:33c8f06c2e03 | 907 | oldcv[ch] = glidecv[ch] = oldcv[ch] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 908 | cv[ch] = (unsigned int)glidecv[ch]; |
| casiotone401 | 12:33c8f06c2e03 | 909 | |
| casiotone401 | 12:33c8f06c2e03 | 910 | UpdateCV(WRITE_UPDATE_N, ch, &cv[ch]); |
| casiotone401 | 12:33c8f06c2e03 | 911 | break; |
| casiotone401 | 12:33c8f06c2e03 | 912 | } |
| casiotone401 | 12:33c8f06c2e03 | 913 | |
| casiotone401 | 12:33c8f06c2e03 | 914 | CVMeter(ch, &cv[ch]); |
| casiotone401 | 12:33c8f06c2e03 | 915 | |
| casiotone401 | 12:33c8f06c2e03 | 916 | ch++; |
| casiotone401 | 12:33c8f06c2e03 | 917 | ch &= 0x07; |
| casiotone401 | 12:33c8f06c2e03 | 918 | } |
| casiotone401 | 12:33c8f06c2e03 | 919 | |
| casiotone401 | 12:33c8f06c2e03 | 920 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 921 | // Sequence & Shift Out CV |
| casiotone401 | 12:33c8f06c2e03 | 922 | |
| casiotone401 | 12:33c8f06c2e03 | 923 | inline void SeqCV(int shift) |
| casiotone401 | 12:33c8f06c2e03 | 924 | { |
| casiotone401 | 12:33c8f06c2e03 | 925 | int i, j, k; |
| casiotone401 | 12:33c8f06c2e03 | 926 | static int ch, quan, mode; |
| casiotone401 | 12:33c8f06c2e03 | 927 | static int cnt1, cnt2, cnt3; |
| casiotone401 | 12:33c8f06c2e03 | 928 | static int cntloop1, cntloop2, cntloop3; |
| casiotone401 | 12:33c8f06c2e03 | 929 | static float glidecv[8], shiftcv[8]; |
| casiotone401 | 12:33c8f06c2e03 | 930 | static float buffercv[9], loopcv[3]; |
| casiotone401 | 12:33c8f06c2e03 | 931 | unsigned int cv[8]; |
| casiotone401 | 12:33c8f06c2e03 | 932 | float qcv; |
| casiotone401 | 12:33c8f06c2e03 | 933 | |
| casiotone401 | 12:33c8f06c2e03 | 934 | mode = (gCtrl[1] * 8); // Sequencer Quantize Mode (gCtrl[1]) |
| casiotone401 | 12:33c8f06c2e03 | 935 | |
| casiotone401 | 12:33c8f06c2e03 | 936 | switch(mode) |
| casiotone401 | 12:33c8f06c2e03 | 937 | { |
| casiotone401 | 12:33c8f06c2e03 | 938 | case Lin: |
| casiotone401 | 12:33c8f06c2e03 | 939 | |
| casiotone401 | 12:33c8f06c2e03 | 940 | if(ch < 8) |
| casiotone401 | 12:33c8f06c2e03 | 941 | { |
| casiotone401 | 12:33c8f06c2e03 | 942 | glidecv[0] = glidecv[0] * gGlide + gSeq_cv1[ch] * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 943 | |
| casiotone401 | 12:33c8f06c2e03 | 944 | } else { |
| casiotone401 | 12:33c8f06c2e03 | 945 | |
| casiotone401 | 12:33c8f06c2e03 | 946 | glidecv[0] = glidecv[0] * gGlide + gSeq_cv2[ch-8] * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 947 | } |
| casiotone401 | 12:33c8f06c2e03 | 948 | |
| casiotone401 | 12:33c8f06c2e03 | 949 | cv[0] = (unsigned int)glidecv[0]; |
| casiotone401 | 12:33c8f06c2e03 | 950 | |
| casiotone401 | 12:33c8f06c2e03 | 951 | UpdateCV(WRITE_UPDATE_N, 0, &cv[0]); |
| casiotone401 | 12:33c8f06c2e03 | 952 | break; |
| casiotone401 | 12:33c8f06c2e03 | 953 | |
| casiotone401 | 12:33c8f06c2e03 | 954 | case Chr: |
| casiotone401 | 12:33c8f06c2e03 | 955 | |
| casiotone401 | 12:33c8f06c2e03 | 956 | quan = 40616 / QUAN_RES1; |
| casiotone401 | 12:33c8f06c2e03 | 957 | |
| casiotone401 | 12:33c8f06c2e03 | 958 | if(ch < 8) |
| casiotone401 | 12:33c8f06c2e03 | 959 | { |
| casiotone401 | 12:33c8f06c2e03 | 960 | qcv = calibMap1[(unsigned int)(gSeq_cv1[ch] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 961 | |
| casiotone401 | 12:33c8f06c2e03 | 962 | } else { |
| casiotone401 | 12:33c8f06c2e03 | 963 | |
| casiotone401 | 12:33c8f06c2e03 | 964 | qcv = calibMap1[(unsigned int)(gSeq_cv2[ch-8] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 965 | } |
| casiotone401 | 12:33c8f06c2e03 | 966 | |
| casiotone401 | 12:33c8f06c2e03 | 967 | glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 968 | cv[0] = (unsigned int)glidecv[0]; |
| casiotone401 | 12:33c8f06c2e03 | 969 | |
| casiotone401 | 12:33c8f06c2e03 | 970 | UpdateCV(WRITE_UPDATE_N, 0, &cv[0]); |
| casiotone401 | 12:33c8f06c2e03 | 971 | break; |
| casiotone401 | 12:33c8f06c2e03 | 972 | |
| casiotone401 | 12:33c8f06c2e03 | 973 | case Maj: |
| casiotone401 | 12:33c8f06c2e03 | 974 | |
| casiotone401 | 12:33c8f06c2e03 | 975 | quan = 40616 / QUAN_RES2; |
| casiotone401 | 12:33c8f06c2e03 | 976 | |
| casiotone401 | 12:33c8f06c2e03 | 977 | if(ch < 8) |
| casiotone401 | 12:33c8f06c2e03 | 978 | { |
| casiotone401 | 12:33c8f06c2e03 | 979 | qcv = calibMap2[(unsigned int)(gSeq_cv1[ch] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 980 | |
| casiotone401 | 12:33c8f06c2e03 | 981 | } else { |
| casiotone401 | 12:33c8f06c2e03 | 982 | |
| casiotone401 | 12:33c8f06c2e03 | 983 | qcv = calibMap2[(unsigned int)(gSeq_cv2[ch-8] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 984 | } |
| casiotone401 | 12:33c8f06c2e03 | 985 | |
| casiotone401 | 12:33c8f06c2e03 | 986 | glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 987 | cv[0] = (unsigned int)glidecv[0]; |
| casiotone401 | 12:33c8f06c2e03 | 988 | |
| casiotone401 | 12:33c8f06c2e03 | 989 | UpdateCV(WRITE_UPDATE_N, 0, &cv[0]); |
| casiotone401 | 12:33c8f06c2e03 | 990 | break; |
| casiotone401 | 12:33c8f06c2e03 | 991 | |
| casiotone401 | 12:33c8f06c2e03 | 992 | case M7: |
| casiotone401 | 12:33c8f06c2e03 | 993 | |
| casiotone401 | 12:33c8f06c2e03 | 994 | quan = 40616 / QUAN_RES3; |
| casiotone401 | 12:33c8f06c2e03 | 995 | |
| casiotone401 | 12:33c8f06c2e03 | 996 | if(ch < 8) |
| casiotone401 | 12:33c8f06c2e03 | 997 | { |
| casiotone401 | 12:33c8f06c2e03 | 998 | qcv = calibMap3[(unsigned int)(gSeq_cv1[ch] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 999 | |
| casiotone401 | 12:33c8f06c2e03 | 1000 | } else { |
| casiotone401 | 12:33c8f06c2e03 | 1001 | |
| casiotone401 | 12:33c8f06c2e03 | 1002 | qcv = calibMap3[(unsigned int)(gSeq_cv2[ch-8] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 1003 | } |
| casiotone401 | 12:33c8f06c2e03 | 1004 | |
| casiotone401 | 12:33c8f06c2e03 | 1005 | glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 1006 | cv[0] = (unsigned int)glidecv[0]; |
| casiotone401 | 12:33c8f06c2e03 | 1007 | |
| casiotone401 | 12:33c8f06c2e03 | 1008 | UpdateCV(WRITE_UPDATE_N, 0, &cv[0]); |
| casiotone401 | 12:33c8f06c2e03 | 1009 | break; |
| casiotone401 | 12:33c8f06c2e03 | 1010 | |
| casiotone401 | 12:33c8f06c2e03 | 1011 | case Min7: |
| casiotone401 | 12:33c8f06c2e03 | 1012 | |
| casiotone401 | 12:33c8f06c2e03 | 1013 | quan = 40616 / QUAN_RES4; |
| casiotone401 | 12:33c8f06c2e03 | 1014 | |
| casiotone401 | 12:33c8f06c2e03 | 1015 | if(ch < 8) |
| casiotone401 | 12:33c8f06c2e03 | 1016 | { |
| casiotone401 | 12:33c8f06c2e03 | 1017 | qcv = calibMap4[(unsigned int)(gSeq_cv1[ch] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 1018 | |
| casiotone401 | 12:33c8f06c2e03 | 1019 | } else { |
| casiotone401 | 12:33c8f06c2e03 | 1020 | |
| casiotone401 | 12:33c8f06c2e03 | 1021 | qcv = calibMap4[(unsigned int)(gSeq_cv2[ch-8] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 1022 | } |
| casiotone401 | 12:33c8f06c2e03 | 1023 | |
| casiotone401 | 12:33c8f06c2e03 | 1024 | glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 1025 | cv[0] = (unsigned int)glidecv[0]; |
| casiotone401 | 12:33c8f06c2e03 | 1026 | |
| casiotone401 | 12:33c8f06c2e03 | 1027 | UpdateCV(WRITE_UPDATE_N, 0, &cv[0]); |
| casiotone401 | 12:33c8f06c2e03 | 1028 | break; |
| casiotone401 | 12:33c8f06c2e03 | 1029 | |
| casiotone401 | 12:33c8f06c2e03 | 1030 | case Dor: |
| casiotone401 | 12:33c8f06c2e03 | 1031 | |
| casiotone401 | 12:33c8f06c2e03 | 1032 | quan = 40616 / QUAN_RES5; |
| casiotone401 | 12:33c8f06c2e03 | 1033 | |
| casiotone401 | 12:33c8f06c2e03 | 1034 | if(ch < 8) |
| casiotone401 | 12:33c8f06c2e03 | 1035 | { |
| casiotone401 | 12:33c8f06c2e03 | 1036 | qcv = calibMap5[(unsigned int)(gSeq_cv1[ch] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 1037 | |
| casiotone401 | 12:33c8f06c2e03 | 1038 | } else { |
| casiotone401 | 12:33c8f06c2e03 | 1039 | |
| casiotone401 | 12:33c8f06c2e03 | 1040 | qcv = calibMap5[(unsigned int)(gSeq_cv2[ch-8] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 1041 | } |
| casiotone401 | 12:33c8f06c2e03 | 1042 | |
| casiotone401 | 12:33c8f06c2e03 | 1043 | glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 1044 | cv[0] = (unsigned int)glidecv[0]; |
| casiotone401 | 12:33c8f06c2e03 | 1045 | |
| casiotone401 | 12:33c8f06c2e03 | 1046 | UpdateCV(WRITE_UPDATE_N, 0, &cv[0]); |
| casiotone401 | 12:33c8f06c2e03 | 1047 | break; |
| casiotone401 | 12:33c8f06c2e03 | 1048 | |
| casiotone401 | 12:33c8f06c2e03 | 1049 | case Min: |
| casiotone401 | 12:33c8f06c2e03 | 1050 | |
| casiotone401 | 12:33c8f06c2e03 | 1051 | quan = 40616 / QUAN_RES6; |
| casiotone401 | 12:33c8f06c2e03 | 1052 | |
| casiotone401 | 12:33c8f06c2e03 | 1053 | if(ch < 8) |
| casiotone401 | 12:33c8f06c2e03 | 1054 | { |
| casiotone401 | 12:33c8f06c2e03 | 1055 | qcv = calibMap6[(unsigned int)(gSeq_cv1[ch] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 1056 | |
| casiotone401 | 12:33c8f06c2e03 | 1057 | } else { |
| casiotone401 | 12:33c8f06c2e03 | 1058 | |
| casiotone401 | 12:33c8f06c2e03 | 1059 | qcv = calibMap6[(unsigned int)(gSeq_cv2[ch-8] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 1060 | } |
| casiotone401 | 12:33c8f06c2e03 | 1061 | |
| casiotone401 | 12:33c8f06c2e03 | 1062 | glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 1063 | cv[0] = (unsigned int)glidecv[0]; |
| casiotone401 | 12:33c8f06c2e03 | 1064 | |
| casiotone401 | 12:33c8f06c2e03 | 1065 | UpdateCV(WRITE_UPDATE_N, 0, &cv[0]); |
| casiotone401 | 12:33c8f06c2e03 | 1066 | break; |
| casiotone401 | 12:33c8f06c2e03 | 1067 | |
| casiotone401 | 12:33c8f06c2e03 | 1068 | case S5th: |
| casiotone401 | 12:33c8f06c2e03 | 1069 | |
| casiotone401 | 12:33c8f06c2e03 | 1070 | quan = 40616 / QUAN_RES7; |
| casiotone401 | 12:33c8f06c2e03 | 1071 | |
| casiotone401 | 12:33c8f06c2e03 | 1072 | if(ch < 8) |
| casiotone401 | 12:33c8f06c2e03 | 1073 | { |
| casiotone401 | 12:33c8f06c2e03 | 1074 | qcv = calibMap7[(unsigned int)(gSeq_cv1[ch] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 1075 | |
| casiotone401 | 12:33c8f06c2e03 | 1076 | } else { |
| casiotone401 | 12:33c8f06c2e03 | 1077 | |
| casiotone401 | 12:33c8f06c2e03 | 1078 | qcv = calibMap7[(unsigned int)(gSeq_cv2[ch-8] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 1079 | } |
| casiotone401 | 12:33c8f06c2e03 | 1080 | |
| casiotone401 | 12:33c8f06c2e03 | 1081 | glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 1082 | cv[0] = (unsigned int)glidecv[0]; |
| casiotone401 | 12:33c8f06c2e03 | 1083 | |
| casiotone401 | 12:33c8f06c2e03 | 1084 | UpdateCV(WRITE_UPDATE_N, 0, &cv[0]); |
| casiotone401 | 12:33c8f06c2e03 | 1085 | break; |
| casiotone401 | 12:33c8f06c2e03 | 1086 | |
| casiotone401 | 12:33c8f06c2e03 | 1087 | case Wht: |
| casiotone401 | 12:33c8f06c2e03 | 1088 | |
| casiotone401 | 12:33c8f06c2e03 | 1089 | quan = 40616 / QUAN_RES8; |
| casiotone401 | 12:33c8f06c2e03 | 1090 | |
| casiotone401 | 12:33c8f06c2e03 | 1091 | if(ch < 8) |
| casiotone401 | 12:33c8f06c2e03 | 1092 | { |
| casiotone401 | 12:33c8f06c2e03 | 1093 | qcv = calibMap8[(unsigned int)(gSeq_cv1[ch] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 1094 | |
| casiotone401 | 12:33c8f06c2e03 | 1095 | } else { |
| casiotone401 | 12:33c8f06c2e03 | 1096 | |
| casiotone401 | 12:33c8f06c2e03 | 1097 | qcv = calibMap8[(unsigned int)(gSeq_cv2[ch-8] / quan)]; |
| casiotone401 | 12:33c8f06c2e03 | 1098 | } |
| casiotone401 | 12:33c8f06c2e03 | 1099 | |
| casiotone401 | 12:33c8f06c2e03 | 1100 | glidecv[0] = glidecv[0] * gGlide + (qcv * SCALING_N) * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 1101 | cv[0] = (unsigned int)glidecv[0]; |
| casiotone401 | 12:33c8f06c2e03 | 1102 | |
| casiotone401 | 12:33c8f06c2e03 | 1103 | UpdateCV(WRITE_UPDATE_N, 0, &cv[0]); |
| casiotone401 | 12:33c8f06c2e03 | 1104 | break; |
| casiotone401 | 12:33c8f06c2e03 | 1105 | } |
| casiotone401 | 12:33c8f06c2e03 | 1106 | |
| casiotone401 | 12:33c8f06c2e03 | 1107 | if(!gCtrlSW[2] && !gCtrlSW[3]) // Sequencer Mode1 |
| casiotone401 | 12:33c8f06c2e03 | 1108 | { |
| casiotone401 | 12:33c8f06c2e03 | 1109 | for(i = 1; i < 8; ++i) |
| casiotone401 | 12:33c8f06c2e03 | 1110 | { |
| casiotone401 | 12:33c8f06c2e03 | 1111 | glidecv[i] = glidecv[i] * gGlide + shiftcv[i] * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 1112 | cv[i] = (unsigned int)glidecv[i]; |
| casiotone401 | 12:33c8f06c2e03 | 1113 | |
| casiotone401 | 12:33c8f06c2e03 | 1114 | UpdateCV(WRITE_UPDATE_N, i, &cv[i]); |
| casiotone401 | 12:33c8f06c2e03 | 1115 | } |
| casiotone401 | 12:33c8f06c2e03 | 1116 | |
| casiotone401 | 12:33c8f06c2e03 | 1117 | if(shift == 1) // GATE1 |
| casiotone401 | 12:33c8f06c2e03 | 1118 | { |
| casiotone401 | 12:33c8f06c2e03 | 1119 | for(j = 1; j < 8; ++j) // Shift ch2~8 |
| casiotone401 | 12:33c8f06c2e03 | 1120 | { |
| casiotone401 | 12:33c8f06c2e03 | 1121 | shiftcv[j] = glidecv[j-1]; |
| casiotone401 | 12:33c8f06c2e03 | 1122 | } |
| casiotone401 | 12:33c8f06c2e03 | 1123 | |
| casiotone401 | 12:33c8f06c2e03 | 1124 | ch++; |
| casiotone401 | 12:33c8f06c2e03 | 1125 | ch &= 0x0F; |
| casiotone401 | 12:33c8f06c2e03 | 1126 | } |
| casiotone401 | 12:33c8f06c2e03 | 1127 | |
| casiotone401 | 12:33c8f06c2e03 | 1128 | cnt1 = cnt2 = cnt3 = 0; |
| casiotone401 | 12:33c8f06c2e03 | 1129 | |
| casiotone401 | 12:33c8f06c2e03 | 1130 | } else if (gCtrlSW[2] && !gCtrlSW[3]) { // Sequencer Mode2 |
| casiotone401 | 12:33c8f06c2e03 | 1131 | |
| casiotone401 | 12:33c8f06c2e03 | 1132 | for(i = 1; i < 8; ++i) |
| casiotone401 | 12:33c8f06c2e03 | 1133 | { |
| casiotone401 | 12:33c8f06c2e03 | 1134 | glidecv[i] = glidecv[i] * gGlide + shiftcv[i] * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 1135 | cv[i] = (unsigned int)glidecv[i]; |
| casiotone401 | 12:33c8f06c2e03 | 1136 | |
| casiotone401 | 12:33c8f06c2e03 | 1137 | UpdateCV(WRITE_UPDATE_N, i, &cv[i]); |
| casiotone401 | 12:33c8f06c2e03 | 1138 | } |
| casiotone401 | 12:33c8f06c2e03 | 1139 | |
| casiotone401 | 12:33c8f06c2e03 | 1140 | if(shift == 1) // GATE1 |
| casiotone401 | 12:33c8f06c2e03 | 1141 | { |
| casiotone401 | 12:33c8f06c2e03 | 1142 | for(j = 1; j < 5; ++j) |
| casiotone401 | 12:33c8f06c2e03 | 1143 | { |
| casiotone401 | 12:33c8f06c2e03 | 1144 | shiftcv[j] = glidecv[j-1]; // Shift ch2~5 |
| casiotone401 | 12:33c8f06c2e03 | 1145 | } |
| casiotone401 | 12:33c8f06c2e03 | 1146 | |
| casiotone401 | 12:33c8f06c2e03 | 1147 | ch++; |
| casiotone401 | 12:33c8f06c2e03 | 1148 | ch &= 0x0F; |
| casiotone401 | 12:33c8f06c2e03 | 1149 | |
| casiotone401 | 12:33c8f06c2e03 | 1150 | } else if (shift == 2) { // GATE2 |
| casiotone401 | 12:33c8f06c2e03 | 1151 | |
| casiotone401 | 12:33c8f06c2e03 | 1152 | shiftcv[5] = glidecv[1]; // Shift ch6 |
| casiotone401 | 12:33c8f06c2e03 | 1153 | |
| casiotone401 | 12:33c8f06c2e03 | 1154 | } else if (shift == 3) { // GATE3 |
| casiotone401 | 12:33c8f06c2e03 | 1155 | |
| casiotone401 | 12:33c8f06c2e03 | 1156 | shiftcv[6] = glidecv[2]; // Shift ch7 |
| casiotone401 | 12:33c8f06c2e03 | 1157 | |
| casiotone401 | 12:33c8f06c2e03 | 1158 | } else if (shift == 4) { // GATE4 |
| casiotone401 | 12:33c8f06c2e03 | 1159 | |
| casiotone401 | 12:33c8f06c2e03 | 1160 | shiftcv[7] = glidecv[3]; // Shift ch8 |
| casiotone401 | 12:33c8f06c2e03 | 1161 | } |
| casiotone401 | 12:33c8f06c2e03 | 1162 | |
| casiotone401 | 12:33c8f06c2e03 | 1163 | cnt1 = cnt2 = cnt3 = 0; |
| casiotone401 | 12:33c8f06c2e03 | 1164 | |
| casiotone401 | 12:33c8f06c2e03 | 1165 | } else if (gCtrlSW[3]) { // Sequencer Mode3 |
| casiotone401 | 12:33c8f06c2e03 | 1166 | |
| casiotone401 | 12:33c8f06c2e03 | 1167 | for(i = 1; i < 5; ++i) |
| casiotone401 | 12:33c8f06c2e03 | 1168 | { |
| casiotone401 | 12:33c8f06c2e03 | 1169 | glidecv[i] = glidecv[i] * gGlide + shiftcv[i] * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 1170 | cv[i] = (unsigned int)glidecv[i]; |
| casiotone401 | 12:33c8f06c2e03 | 1171 | |
| casiotone401 | 12:33c8f06c2e03 | 1172 | UpdateCV(WRITE_UPDATE_N, i, &cv[i]); |
| casiotone401 | 12:33c8f06c2e03 | 1173 | } |
| casiotone401 | 12:33c8f06c2e03 | 1174 | |
| casiotone401 | 12:33c8f06c2e03 | 1175 | for(j = 5; j < 8; ++j) |
| casiotone401 | 12:33c8f06c2e03 | 1176 | { |
| casiotone401 | 12:33c8f06c2e03 | 1177 | glidecv[j] = glidecv[j] * gGlide + loopcv[j - 5] * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 1178 | cv[j] = (unsigned int)glidecv[j]; |
| casiotone401 | 12:33c8f06c2e03 | 1179 | |
| casiotone401 | 12:33c8f06c2e03 | 1180 | UpdateCV(WRITE_UPDATE_N, j, &cv[j]); |
| casiotone401 | 12:33c8f06c2e03 | 1181 | } |
| casiotone401 | 12:33c8f06c2e03 | 1182 | |
| casiotone401 | 12:33c8f06c2e03 | 1183 | if(shift == 1) // GATE1 |
| casiotone401 | 12:33c8f06c2e03 | 1184 | { |
| casiotone401 | 12:33c8f06c2e03 | 1185 | for(k = 1; k < 8; ++k) |
| casiotone401 | 12:33c8f06c2e03 | 1186 | { |
| casiotone401 | 12:33c8f06c2e03 | 1187 | shiftcv[k] = glidecv[k-1]; // Shift ch2~5 |
| casiotone401 | 12:33c8f06c2e03 | 1188 | } |
| casiotone401 | 12:33c8f06c2e03 | 1189 | |
| casiotone401 | 12:33c8f06c2e03 | 1190 | ch++; |
| casiotone401 | 12:33c8f06c2e03 | 1191 | ch &= 0x0F; |
| casiotone401 | 12:33c8f06c2e03 | 1192 | |
| casiotone401 | 12:33c8f06c2e03 | 1193 | } else if (shift == 2) { // GATE2 |
| casiotone401 | 12:33c8f06c2e03 | 1194 | |
| casiotone401 | 12:33c8f06c2e03 | 1195 | if(cnt1 < 4) |
| casiotone401 | 12:33c8f06c2e03 | 1196 | { |
| casiotone401 | 12:33c8f06c2e03 | 1197 | loopcv[0] = buffercv[cnt1] = shiftcv[4]; |
| casiotone401 | 12:33c8f06c2e03 | 1198 | |
| casiotone401 | 12:33c8f06c2e03 | 1199 | cnt1++; |
| casiotone401 | 12:33c8f06c2e03 | 1200 | |
| casiotone401 | 12:33c8f06c2e03 | 1201 | } else if (cnt1 >= 4) { |
| casiotone401 | 12:33c8f06c2e03 | 1202 | |
| casiotone401 | 12:33c8f06c2e03 | 1203 | loopcv[0] = buffercv[cntloop1]; |
| casiotone401 | 12:33c8f06c2e03 | 1204 | |
| casiotone401 | 12:33c8f06c2e03 | 1205 | cntloop1++; |
| casiotone401 | 12:33c8f06c2e03 | 1206 | cntloop1 &= 0x03; |
| casiotone401 | 12:33c8f06c2e03 | 1207 | } |
| casiotone401 | 12:33c8f06c2e03 | 1208 | |
| casiotone401 | 12:33c8f06c2e03 | 1209 | } else if (shift == 3) { // GATE3 |
| casiotone401 | 12:33c8f06c2e03 | 1210 | |
| casiotone401 | 12:33c8f06c2e03 | 1211 | if(cnt2 < 3) |
| casiotone401 | 12:33c8f06c2e03 | 1212 | { |
| casiotone401 | 12:33c8f06c2e03 | 1213 | loopcv[1] = buffercv[(cnt2 + 4)] = shiftcv[5]; |
| casiotone401 | 12:33c8f06c2e03 | 1214 | |
| casiotone401 | 12:33c8f06c2e03 | 1215 | cnt2++; |
| casiotone401 | 12:33c8f06c2e03 | 1216 | |
| casiotone401 | 12:33c8f06c2e03 | 1217 | } else if (cnt2 >= 3) { |
| casiotone401 | 12:33c8f06c2e03 | 1218 | |
| casiotone401 | 12:33c8f06c2e03 | 1219 | loopcv[1] = buffercv[(cntloop2 + 4)]; |
| casiotone401 | 12:33c8f06c2e03 | 1220 | |
| casiotone401 | 12:33c8f06c2e03 | 1221 | cntloop2++; |
| casiotone401 | 12:33c8f06c2e03 | 1222 | cntloop2 &= 0x03; |
| casiotone401 | 12:33c8f06c2e03 | 1223 | } |
| casiotone401 | 12:33c8f06c2e03 | 1224 | |
| casiotone401 | 12:33c8f06c2e03 | 1225 | } else if (shift == 4) { // GATE4 |
| casiotone401 | 12:33c8f06c2e03 | 1226 | |
| casiotone401 | 12:33c8f06c2e03 | 1227 | if(cnt3 < 2) |
| casiotone401 | 12:33c8f06c2e03 | 1228 | { |
| casiotone401 | 12:33c8f06c2e03 | 1229 | loopcv[2] = buffercv[(cnt3 + 7)] = shiftcv[6]; |
| casiotone401 | 12:33c8f06c2e03 | 1230 | |
| casiotone401 | 12:33c8f06c2e03 | 1231 | cnt3++; |
| casiotone401 | 12:33c8f06c2e03 | 1232 | |
| casiotone401 | 12:33c8f06c2e03 | 1233 | } else if (cnt3 >= 2) { |
| casiotone401 | 12:33c8f06c2e03 | 1234 | |
| casiotone401 | 12:33c8f06c2e03 | 1235 | loopcv[2] = buffercv[(cntloop3 + 7)]; |
| casiotone401 | 12:33c8f06c2e03 | 1236 | |
| casiotone401 | 12:33c8f06c2e03 | 1237 | cntloop3++; |
| casiotone401 | 12:33c8f06c2e03 | 1238 | cntloop3 &= 0x01; |
| casiotone401 | 12:33c8f06c2e03 | 1239 | } |
| casiotone401 | 12:33c8f06c2e03 | 1240 | } |
| casiotone401 | 12:33c8f06c2e03 | 1241 | |
| casiotone401 | 12:33c8f06c2e03 | 1242 | if(gCtrlSW[1]) // Update loop buffer (if gCtrlSW[1] ON) |
| casiotone401 | 12:33c8f06c2e03 | 1243 | { |
| casiotone401 | 12:33c8f06c2e03 | 1244 | cnt1 = cnt2 = cnt3 = 0; |
| casiotone401 | 12:33c8f06c2e03 | 1245 | } |
| casiotone401 | 12:33c8f06c2e03 | 1246 | } |
| casiotone401 | 12:33c8f06c2e03 | 1247 | |
| casiotone401 | 12:33c8f06c2e03 | 1248 | if(ch < 8) |
| casiotone401 | 12:33c8f06c2e03 | 1249 | { |
| casiotone401 | 12:33c8f06c2e03 | 1250 | CVMeter(ch, &cv[0]); |
| casiotone401 | 12:33c8f06c2e03 | 1251 | |
| casiotone401 | 12:33c8f06c2e03 | 1252 | } else { |
| casiotone401 | 12:33c8f06c2e03 | 1253 | |
| casiotone401 | 12:33c8f06c2e03 | 1254 | CVMeter((ch-8), &cv[0]); |
| casiotone401 | 12:33c8f06c2e03 | 1255 | } |
| casiotone401 | 12:33c8f06c2e03 | 1256 | } |
| casiotone401 | 12:33c8f06c2e03 | 1257 | |
| casiotone401 | 12:33c8f06c2e03 | 1258 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 1259 | // Shift CV |
| casiotone401 | 12:33c8f06c2e03 | 1260 | |
| casiotone401 | 12:33c8f06c2e03 | 1261 | inline void ShiftCV(int shift) |
| casiotone401 | 12:33c8f06c2e03 | 1262 | { |
| casiotone401 | 12:33c8f06c2e03 | 1263 | int i; |
| casiotone401 | 12:33c8f06c2e03 | 1264 | static int ch; |
| casiotone401 | 12:33c8f06c2e03 | 1265 | static float glidecv[8], shiftcv[8], oldcv; |
| casiotone401 | 12:33c8f06c2e03 | 1266 | unsigned int cv[8]; |
| casiotone401 | 12:33c8f06c2e03 | 1267 | |
| casiotone401 | 12:33c8f06c2e03 | 1268 | gLEDS[1] = gGATES[1] = gGATES[0]; |
| casiotone401 | 12:33c8f06c2e03 | 1269 | |
| casiotone401 | 12:33c8f06c2e03 | 1270 | oldcv = glidecv[0] = glidecv[0] * gGlide + gOSC_cv[0] * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 1271 | |
| casiotone401 | 12:33c8f06c2e03 | 1272 | cv[0] = (unsigned int)glidecv[0]; |
| casiotone401 | 12:33c8f06c2e03 | 1273 | |
| casiotone401 | 12:33c8f06c2e03 | 1274 | UpdateCV(WRITE_UPDATE_N, 0, &cv[0]); |
| casiotone401 | 12:33c8f06c2e03 | 1275 | |
| casiotone401 | 12:33c8f06c2e03 | 1276 | glidecv[ch+1] = glidecv[ch+1] * gGlide + shiftcv[ch+1] * (1.0f - gGlide); |
| casiotone401 | 12:33c8f06c2e03 | 1277 | cv[ch+1] = (unsigned int)glidecv[ch+1]; |
| casiotone401 | 12:33c8f06c2e03 | 1278 | |
| casiotone401 | 12:33c8f06c2e03 | 1279 | UpdateCV(WRITE_UPDATE_N, ch+1, &cv[ch+1]); |
| casiotone401 | 12:33c8f06c2e03 | 1280 | |
| casiotone401 | 12:33c8f06c2e03 | 1281 | if(shift == 1) // GATE1 |
| casiotone401 | 12:33c8f06c2e03 | 1282 | { |
| casiotone401 | 12:33c8f06c2e03 | 1283 | shiftcv[0] = oldcv; |
| casiotone401 | 12:33c8f06c2e03 | 1284 | |
| casiotone401 | 12:33c8f06c2e03 | 1285 | for(i = 7; i > 0; --i) |
| casiotone401 | 12:33c8f06c2e03 | 1286 | { |
| casiotone401 | 12:33c8f06c2e03 | 1287 | shiftcv[i] = shiftcv[i-1]; |
| casiotone401 | 12:33c8f06c2e03 | 1288 | } |
| casiotone401 | 12:33c8f06c2e03 | 1289 | } |
| casiotone401 | 12:33c8f06c2e03 | 1290 | |
| casiotone401 | 12:33c8f06c2e03 | 1291 | if(ch < 8) |
| casiotone401 | 12:33c8f06c2e03 | 1292 | { |
| casiotone401 | 12:33c8f06c2e03 | 1293 | CVMeter(ch, &cv[0]); |
| casiotone401 | 12:33c8f06c2e03 | 1294 | |
| casiotone401 | 12:33c8f06c2e03 | 1295 | } else { |
| casiotone401 | 12:33c8f06c2e03 | 1296 | |
| casiotone401 | 12:33c8f06c2e03 | 1297 | CVMeter((ch-8), &cv[0]); |
| casiotone401 | 12:33c8f06c2e03 | 1298 | } |
| casiotone401 | 12:33c8f06c2e03 | 1299 | |
| casiotone401 | 12:33c8f06c2e03 | 1300 | ch++; |
| casiotone401 | 12:33c8f06c2e03 | 1301 | ch &= 0x07; |
| casiotone401 | 12:33c8f06c2e03 | 1302 | } |
| casiotone401 | 12:33c8f06c2e03 | 1303 | |
| casiotone401 | 12:33c8f06c2e03 | 1304 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 1305 | // Check SW |
| casiotone401 | 12:33c8f06c2e03 | 1306 | |
| casiotone401 | 12:33c8f06c2e03 | 1307 | void CheckModeSW() |
| casiotone401 | 12:33c8f06c2e03 | 1308 | { |
| casiotone401 | 12:33c8f06c2e03 | 1309 | wait(0.05); |
| casiotone401 | 12:33c8f06c2e03 | 1310 | |
| casiotone401 | 12:33c8f06c2e03 | 1311 | if(gMode < MODE_NUM - 1) |
| casiotone401 | 12:33c8f06c2e03 | 1312 | { |
| casiotone401 | 12:33c8f06c2e03 | 1313 | gMode++; |
| casiotone401 | 12:33c8f06c2e03 | 1314 | |
| casiotone401 | 12:33c8f06c2e03 | 1315 | } else { |
| casiotone401 | 12:33c8f06c2e03 | 1316 | |
| casiotone401 | 12:33c8f06c2e03 | 1317 | gMode = 0; |
| casiotone401 | 12:33c8f06c2e03 | 1318 | } |
| casiotone401 | 12:33c8f06c2e03 | 1319 | |
| casiotone401 | 12:33c8f06c2e03 | 1320 | gCLOCKOUT = gGATES[0] = gGATES[1] = gGATES[2] = gGATES[3] = 0; |
| casiotone401 | 12:33c8f06c2e03 | 1321 | gLEDS[0] = gLEDS[1] = gLEDS[2] = gLEDS[3] = 0; |
| casiotone401 | 12:33c8f06c2e03 | 1322 | |
| casiotone401 | 12:33c8f06c2e03 | 1323 | if((gMode == MODE_SEQ) || (gMode == MODE_SHIF)) |
| casiotone401 | 12:33c8f06c2e03 | 1324 | { |
| casiotone401 | 12:33c8f06c2e03 | 1325 | gTimer.start(); // Sequencer Timer Start |
| casiotone401 | 12:33c8f06c2e03 | 1326 | |
| casiotone401 | 12:33c8f06c2e03 | 1327 | } else { |
| casiotone401 | 12:33c8f06c2e03 | 1328 | |
| casiotone401 | 12:33c8f06c2e03 | 1329 | gTimer.stop(); // Sequencer Timer Stop |
| casiotone401 | 12:33c8f06c2e03 | 1330 | } |
| casiotone401 | 12:33c8f06c2e03 | 1331 | |
| casiotone401 | 12:33c8f06c2e03 | 1332 | LCD(); |
| casiotone401 | 12:33c8f06c2e03 | 1333 | } |
| casiotone401 | 12:33c8f06c2e03 | 1334 | |
| casiotone401 | 12:33c8f06c2e03 | 1335 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 1336 | // CV meter |
| casiotone401 | 12:33c8f06c2e03 | 1337 | |
| casiotone401 | 12:33c8f06c2e03 | 1338 | inline void CVMeter(int ch, const unsigned int *level) |
| casiotone401 | 12:33c8f06c2e03 | 1339 | { |
| casiotone401 | 12:33c8f06c2e03 | 1340 | int cvmeter; |
| casiotone401 | 12:33c8f06c2e03 | 1341 | |
| casiotone401 | 12:33c8f06c2e03 | 1342 | cvmeter = *level / (SCALING_N / 7.9f); |
| casiotone401 | 12:33c8f06c2e03 | 1343 | |
| casiotone401 | 12:33c8f06c2e03 | 1344 | gLCD.locate ( ch, 0 ); |
| casiotone401 | 12:33c8f06c2e03 | 1345 | gLCD.putc(cvmeter); // put custom char |
| casiotone401 | 12:33c8f06c2e03 | 1346 | } |
| casiotone401 | 12:33c8f06c2e03 | 1347 | |
| casiotone401 | 12:33c8f06c2e03 | 1348 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 1349 | // Print LCD Mode Status |
| casiotone401 | 12:33c8f06c2e03 | 1350 | |
| casiotone401 | 12:33c8f06c2e03 | 1351 | void LCD() |
| casiotone401 | 12:33c8f06c2e03 | 1352 | { |
| casiotone401 | 12:33c8f06c2e03 | 1353 | switch(gMode) |
| casiotone401 | 12:33c8f06c2e03 | 1354 | { |
| casiotone401 | 12:33c8f06c2e03 | 1355 | case MODE_Calb: |
| casiotone401 | 12:33c8f06c2e03 | 1356 | gLCD.locate( 9, 0 ); |
| casiotone401 | 12:33c8f06c2e03 | 1357 | gLCD.printf("Calibr "); |
| casiotone401 | 12:33c8f06c2e03 | 1358 | break; |
| casiotone401 | 12:33c8f06c2e03 | 1359 | |
| casiotone401 | 12:33c8f06c2e03 | 1360 | case MODE_LIN: |
| casiotone401 | 12:33c8f06c2e03 | 1361 | gLCD.locate( 9, 0 ); |
| casiotone401 | 12:33c8f06c2e03 | 1362 | gLCD.printf("OSC-CV "); |
| casiotone401 | 12:33c8f06c2e03 | 1363 | break; |
| casiotone401 | 12:33c8f06c2e03 | 1364 | |
| casiotone401 | 12:33c8f06c2e03 | 1365 | case MODE_QChr: |
| casiotone401 | 12:33c8f06c2e03 | 1366 | gLCD.locate( 9, 0 ); |
| casiotone401 | 12:33c8f06c2e03 | 1367 | gLCD.printf("QUAN_C "); |
| casiotone401 | 12:33c8f06c2e03 | 1368 | break; |
| casiotone401 | 12:33c8f06c2e03 | 1369 | |
| casiotone401 | 12:33c8f06c2e03 | 1370 | case MODE_QMaj: |
| casiotone401 | 12:33c8f06c2e03 | 1371 | gLCD.locate( 9, 0 ); |
| casiotone401 | 12:33c8f06c2e03 | 1372 | gLCD.printf("QUAN_M "); |
| casiotone401 | 12:33c8f06c2e03 | 1373 | break; |
| casiotone401 | 12:33c8f06c2e03 | 1374 | |
| casiotone401 | 12:33c8f06c2e03 | 1375 | case MODE_QDor: |
| casiotone401 | 12:33c8f06c2e03 | 1376 | gLCD.locate( 9, 0 ); |
| casiotone401 | 12:33c8f06c2e03 | 1377 | gLCD.printf("QUAN_D "); |
| casiotone401 | 12:33c8f06c2e03 | 1378 | break; |
| casiotone401 | 12:33c8f06c2e03 | 1379 | |
| casiotone401 | 12:33c8f06c2e03 | 1380 | case MODE_Q5th: |
| casiotone401 | 12:33c8f06c2e03 | 1381 | gLCD.locate( 9, 0 ); |
| casiotone401 | 12:33c8f06c2e03 | 1382 | gLCD.printf("QUAN_5 "); |
| casiotone401 | 12:33c8f06c2e03 | 1383 | break; |
| casiotone401 | 12:33c8f06c2e03 | 1384 | |
| casiotone401 | 12:33c8f06c2e03 | 1385 | case MODE_QWht: |
| casiotone401 | 12:33c8f06c2e03 | 1386 | gLCD.locate( 9, 0 ); |
| casiotone401 | 12:33c8f06c2e03 | 1387 | gLCD.printf("QUAN_W "); |
| casiotone401 | 12:33c8f06c2e03 | 1388 | break; |
| casiotone401 | 12:33c8f06c2e03 | 1389 | |
| casiotone401 | 12:33c8f06c2e03 | 1390 | case MODE_SEQ: |
| casiotone401 | 12:33c8f06c2e03 | 1391 | gLCD.locate( 9, 0 ); |
| casiotone401 | 12:33c8f06c2e03 | 1392 | gLCD.printf("ASRSEQ "); |
| casiotone401 | 12:33c8f06c2e03 | 1393 | break; |
| casiotone401 | 12:33c8f06c2e03 | 1394 | |
| casiotone401 | 12:33c8f06c2e03 | 1395 | case MODE_SHIF: |
| casiotone401 | 12:33c8f06c2e03 | 1396 | gLCD.locate( 9, 0 ); |
| casiotone401 | 12:33c8f06c2e03 | 1397 | gLCD.printf("ASHSEQ "); |
| casiotone401 | 12:33c8f06c2e03 | 1398 | break; |
| casiotone401 | 12:33c8f06c2e03 | 1399 | } |
| casiotone401 | 12:33c8f06c2e03 | 1400 | } |
| casiotone401 | 12:33c8f06c2e03 | 1401 | |
| casiotone401 | 12:33c8f06c2e03 | 1402 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 1403 | // Write command Custom Char LCD CGRAM(CV Meter) |
| casiotone401 | 12:33c8f06c2e03 | 1404 | |
| casiotone401 | 12:33c8f06c2e03 | 1405 | void WriteCustomChar(unsigned char addr, unsigned char *c) |
| casiotone401 | 12:33c8f06c2e03 | 1406 | { |
| casiotone401 | 12:33c8f06c2e03 | 1407 | char cnt = 0; |
| casiotone401 | 12:33c8f06c2e03 | 1408 | addr = ((addr << 3) | 0x40); |
| casiotone401 | 12:33c8f06c2e03 | 1409 | |
| casiotone401 | 12:33c8f06c2e03 | 1410 | while(cnt < 0x08) |
| casiotone401 | 12:33c8f06c2e03 | 1411 | { |
| casiotone401 | 12:33c8f06c2e03 | 1412 | gLCD.writeCommand(addr | cnt); |
| casiotone401 | 12:33c8f06c2e03 | 1413 | gLCD.writeData(*c); |
| casiotone401 | 12:33c8f06c2e03 | 1414 | |
| casiotone401 | 12:33c8f06c2e03 | 1415 | cnt++; |
| casiotone401 | 12:33c8f06c2e03 | 1416 | c++; |
| casiotone401 | 12:33c8f06c2e03 | 1417 | } |
| casiotone401 | 12:33c8f06c2e03 | 1418 | } |
| casiotone401 | 12:33c8f06c2e03 | 1419 | |
| casiotone401 | 12:33c8f06c2e03 | 1420 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 1421 | // Setup Ethernet port |
| casiotone401 | 12:33c8f06c2e03 | 1422 | |
| casiotone401 | 12:33c8f06c2e03 | 1423 | int SetupEthNetIf() |
| casiotone401 | 12:33c8f06c2e03 | 1424 | { |
| casiotone401 | 12:33c8f06c2e03 | 1425 | gLCD.locate( 0, 1 ); |
| casiotone401 | 12:33c8f06c2e03 | 1426 | gLCD.printf("Setting up... "); |
| casiotone401 | 12:33c8f06c2e03 | 1427 | // printf("Setting up...\r\n"); |
| casiotone401 | 12:33c8f06c2e03 | 1428 | EthernetErr ethErr = gEth.setup(); |
| casiotone401 | 12:33c8f06c2e03 | 1429 | |
| casiotone401 | 12:33c8f06c2e03 | 1430 | if(ethErr) |
| casiotone401 | 12:33c8f06c2e03 | 1431 | { |
| casiotone401 | 12:33c8f06c2e03 | 1432 | gLCD.locate( 0, 1 ); |
| casiotone401 | 12:33c8f06c2e03 | 1433 | gLCD.printf("Error in setup."); |
| casiotone401 | 12:33c8f06c2e03 | 1434 | // printf("Error %d in setup.\r\n", ethErr); |
| casiotone401 | 12:33c8f06c2e03 | 1435 | return -1; |
| casiotone401 | 12:33c8f06c2e03 | 1436 | } |
| casiotone401 | 12:33c8f06c2e03 | 1437 | // printf("Setup OK\r\n"); |
| casiotone401 | 12:33c8f06c2e03 | 1438 | |
| casiotone401 | 12:33c8f06c2e03 | 1439 | // printf("IP address %d.%d.%d.%d\r\n", gEth.getIp()[0], gEth.getIp()[1], gEth.getIp()[2], gEth.getIp()[3]); |
| casiotone401 | 12:33c8f06c2e03 | 1440 | Host broadcast(IpAddr(gEth.getIp()[0], gEth.getIp()[1], gEth.getIp()[2], 255), INPUT_PORT, NULL); |
| casiotone401 | 12:33c8f06c2e03 | 1441 | gUdp.setOnEvent(&onUDPSocketEvent); |
| casiotone401 | 12:33c8f06c2e03 | 1442 | gUdp.bind(broadcast); |
| casiotone401 | 12:33c8f06c2e03 | 1443 | |
| casiotone401 | 12:33c8f06c2e03 | 1444 | gLCD.locate( 0, 1 ); |
| casiotone401 | 12:33c8f06c2e03 | 1445 | gLCD.printf("%03d.%03d.%03d.%03d", gEth.getIp()[0], gEth.getIp()[1], gEth.getIp()[2], gEth.getIp()[3]); |
| casiotone401 | 12:33c8f06c2e03 | 1446 | wait(1.0); |
| casiotone401 | 12:33c8f06c2e03 | 1447 | |
| casiotone401 | 12:33c8f06c2e03 | 1448 | return 0; |
| casiotone401 | 12:33c8f06c2e03 | 1449 | } |
| casiotone401 | 12:33c8f06c2e03 | 1450 | |
| casiotone401 | 12:33c8f06c2e03 | 1451 | //------------------------------------------------------------- |
| casiotone401 | 12:33c8f06c2e03 | 1452 | // Handller receive UDP Packet |
| casiotone401 | 12:33c8f06c2e03 | 1453 | |
| casiotone401 | 12:33c8f06c2e03 | 1454 | inline void onUDPSocketEvent(UDPSocketEvent e) |
| casiotone401 | 12:33c8f06c2e03 | 1455 | { |
| casiotone401 | 12:33c8f06c2e03 | 1456 | union OSCarg msg[10]; |
| casiotone401 | 12:33c8f06c2e03 | 1457 | char buf[768] = {0}; |
| casiotone401 | 12:33c8f06c2e03 | 1458 | int num, recvlen, len; |
| casiotone401 | 12:33c8f06c2e03 | 1459 | unsigned int absv; |
| casiotone401 | 12:33c8f06c2e03 | 1460 | int messagepos = 0; |
| casiotone401 | 12:33c8f06c2e03 | 1461 | bool bundleflag = false; |
| casiotone401 | 12:33c8f06c2e03 | 1462 | |
| casiotone401 | 12:33c8f06c2e03 | 1463 | Host host; |
| casiotone401 | 12:33c8f06c2e03 | 1464 | |
| casiotone401 | 12:33c8f06c2e03 | 1465 | switch(e) |
| casiotone401 | 12:33c8f06c2e03 | 1466 | { |
| casiotone401 | 12:33c8f06c2e03 | 1467 | case UDPSOCKET_READABLE: // The only event for now |
| casiotone401 | 12:33c8f06c2e03 | 1468 | |
| casiotone401 | 12:33c8f06c2e03 | 1469 | recvlen = gUdp.recvfrom(buf, 768, &host); // packet length |
| casiotone401 | 12:33c8f06c2e03 | 1470 | |
| casiotone401 | 12:33c8f06c2e03 | 1471 | if(recvlen <= 0) break; |
| casiotone401 | 12:33c8f06c2e03 | 1472 | |
| casiotone401 | 12:33c8f06c2e03 | 1473 | if(buf[0] == '#') // #bundle |
| casiotone401 | 12:33c8f06c2e03 | 1474 | { |
| casiotone401 | 12:33c8f06c2e03 | 1475 | messagepos += 16; // skip #bundle & timetag |
| casiotone401 | 12:33c8f06c2e03 | 1476 | recvlen -= 16; |
| casiotone401 | 12:33c8f06c2e03 | 1477 | |
| casiotone401 | 12:33c8f06c2e03 | 1478 | bundleflag = true; |
| casiotone401 | 12:33c8f06c2e03 | 1479 | } |
| casiotone401 | 12:33c8f06c2e03 | 1480 | |
| casiotone401 | 12:33c8f06c2e03 | 1481 | do { |
| casiotone401 | 12:33c8f06c2e03 | 1482 | if(bundleflag) |
| casiotone401 | 12:33c8f06c2e03 | 1483 | { |
| casiotone401 | 12:33c8f06c2e03 | 1484 | messagepos += 4; |
| casiotone401 | 12:33c8f06c2e03 | 1485 | recvlen -= 4; |
| casiotone401 | 12:33c8f06c2e03 | 1486 | |
| casiotone401 | 12:33c8f06c2e03 | 1487 | if(recvlen <= 0) |
| casiotone401 | 12:33c8f06c2e03 | 1488 | { |
| casiotone401 | 12:33c8f06c2e03 | 1489 | bundleflag = false; |
| casiotone401 | 12:33c8f06c2e03 | 1490 | break; |
| casiotone401 | 12:33c8f06c2e03 | 1491 | } |
| casiotone401 | 12:33c8f06c2e03 | 1492 | } |
| casiotone401 | 12:33c8f06c2e03 | 1493 | |
| casiotone401 | 12:33c8f06c2e03 | 1494 | if(getOSCmsg(buf + messagepos, msg) == -1) continue; |
| casiotone401 | 12:33c8f06c2e03 | 1495 | |
| casiotone401 | 12:33c8f06c2e03 | 1496 | len = strlen(msg[0].address); |
| casiotone401 | 12:33c8f06c2e03 | 1497 | |
| casiotone401 | 12:33c8f06c2e03 | 1498 | if(isdigit(msg[0].address[len-1])) |
| casiotone401 | 12:33c8f06c2e03 | 1499 | { |
| casiotone401 | 12:33c8f06c2e03 | 1500 | num = msg[0].address[len-1] - '0' - 1; |
| casiotone401 | 12:33c8f06c2e03 | 1501 | |
| casiotone401 | 12:33c8f06c2e03 | 1502 | } else { |
| casiotone401 | 12:33c8f06c2e03 | 1503 | |
| casiotone401 | 12:33c8f06c2e03 | 1504 | num = -1; |
| casiotone401 | 12:33c8f06c2e03 | 1505 | } |
| casiotone401 | 12:33c8f06c2e03 | 1506 | |
| casiotone401 | 12:33c8f06c2e03 | 1507 | absv = msg[2].f + 0; //convert -0 to 0 |
| casiotone401 | 12:33c8f06c2e03 | 1508 | |
| casiotone401 | 12:33c8f06c2e03 | 1509 | // address pattern SYNC & GATE (Type Tag int, float) |
| casiotone401 | 12:33c8f06c2e03 | 1510 | if(!strncmp(msg[0].address+(len-1)-4, "sync", 4)) |
| casiotone401 | 12:33c8f06c2e03 | 1511 | { |
| casiotone401 | 12:33c8f06c2e03 | 1512 | if(absv >= 1 || msg[2].i >= 1) gCLOCKOUT = 1; |
| casiotone401 | 12:33c8f06c2e03 | 1513 | else gCLOCKOUT = 0; |
| casiotone401 | 12:33c8f06c2e03 | 1514 | continue; |
| casiotone401 | 12:33c8f06c2e03 | 1515 | |
| casiotone401 | 12:33c8f06c2e03 | 1516 | } else if (!strncmp(msg[0].address+(len-1)-4, "gate", 4) && (num != -1)) { |
| casiotone401 | 12:33c8f06c2e03 | 1517 | if(num > 4) continue; |
| casiotone401 | 12:33c8f06c2e03 | 1518 | if(absv >= 1 || msg[2].i >= 1) gLEDS[num] = gGATES[num] = 1; |
| casiotone401 | 12:33c8f06c2e03 | 1519 | else gLEDS[num] = gGATES[num] = 0; |
| casiotone401 | 12:33c8f06c2e03 | 1520 | continue; |
| casiotone401 | 12:33c8f06c2e03 | 1521 | // (touchOSC Control push, toggle) |
| casiotone401 | 12:33c8f06c2e03 | 1522 | } else if (!strncmp(msg[0].address+(len-1)-4, "push", 4) && (num != -1)) { |
| casiotone401 | 12:33c8f06c2e03 | 1523 | if(num > 4) continue; |
| casiotone401 | 12:33c8f06c2e03 | 1524 | if(absv >= 1 || msg[2].i >= 1) gLEDS[num] = gGATES[num] = 1; |
| casiotone401 | 12:33c8f06c2e03 | 1525 | else gLEDS[num] = gGATES[num] = 0; |
| casiotone401 | 12:33c8f06c2e03 | 1526 | continue; |
| casiotone401 | 12:33c8f06c2e03 | 1527 | |
| casiotone401 | 12:33c8f06c2e03 | 1528 | } else if (!strncmp(msg[0].address+(len-1)-6, "toggle", 6) && (num != -1)) { |
| casiotone401 | 12:33c8f06c2e03 | 1529 | if(num > 4) continue; |
| casiotone401 | 12:33c8f06c2e03 | 1530 | if(absv >= 1 || msg[2].i >= 1) gLEDS[num] = gGATES[num] = 1; |
| casiotone401 | 12:33c8f06c2e03 | 1531 | else gLEDS[num] = gGATES[num] = 0; |
| casiotone401 | 12:33c8f06c2e03 | 1532 | continue; |
| casiotone401 | 12:33c8f06c2e03 | 1533 | |
| casiotone401 | 12:33c8f06c2e03 | 1534 | } else if (!strncmp(msg[0].address,"/1/multipush",12) && (num != -1)) { |
| casiotone401 | 12:33c8f06c2e03 | 1535 | if(num > 4) continue; |
| casiotone401 | 12:33c8f06c2e03 | 1536 | if(absv >= 1 || msg[2].i >= 1) gLEDS[num] = gGATES[num] = 1; |
| casiotone401 | 12:33c8f06c2e03 | 1537 | else gLEDS[num] = gGATES[num] = 0; |
| casiotone401 | 12:33c8f06c2e03 | 1538 | continue; |
| casiotone401 | 12:33c8f06c2e03 | 1539 | // address pattern CV (Type Tag float) |
| casiotone401 | 12:33c8f06c2e03 | 1540 | } else if(!strncmp(msg[0].address+(len-1)-2, "cv", 2) && (num != -1)) { |
| casiotone401 | 12:33c8f06c2e03 | 1541 | if(num > 7) continue; |
| casiotone401 | 12:33c8f06c2e03 | 1542 | if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N); |
| casiotone401 | 12:33c8f06c2e03 | 1543 | continue; |
| casiotone401 | 12:33c8f06c2e03 | 1544 | // (touchOSC Control fader, rotary, xy, multixy, multifader) |
| casiotone401 | 12:33c8f06c2e03 | 1545 | } else if (!strncmp(msg[0].address+(len-1)-5, "fader", 5) && (num != -1)) { |
| casiotone401 | 12:33c8f06c2e03 | 1546 | if(num > 7) continue; |
| casiotone401 | 12:33c8f06c2e03 | 1547 | if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N); |
| casiotone401 | 12:33c8f06c2e03 | 1548 | continue; |
| casiotone401 | 12:33c8f06c2e03 | 1549 | |
| casiotone401 | 12:33c8f06c2e03 | 1550 | } else if (!strncmp(msg[0].address+(len-1)-6, "rotary", 6) && (num != -1)) { |
| casiotone401 | 12:33c8f06c2e03 | 1551 | if(num > 7) continue; |
| casiotone401 | 12:33c8f06c2e03 | 1552 | if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N); |
| casiotone401 | 12:33c8f06c2e03 | 1553 | continue; |
| casiotone401 | 12:33c8f06c2e03 | 1554 | |
| casiotone401 | 12:33c8f06c2e03 | 1555 | } else if (!strncmp(msg[0].address+(len-1)-2, "xy", 2) && (num != -1)) { |
| casiotone401 | 12:33c8f06c2e03 | 1556 | if(num > 7) continue; |
| casiotone401 | 12:33c8f06c2e03 | 1557 | if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N); |
| casiotone401 | 12:33c8f06c2e03 | 1558 | if(msg[1].typeTag[1] == 'f') gOSC_cv[++num] = msg[3].f * (SCALING_N); |
| casiotone401 | 12:33c8f06c2e03 | 1559 | continue; |
| casiotone401 | 12:33c8f06c2e03 | 1560 | |
| casiotone401 | 12:33c8f06c2e03 | 1561 | } else if (!strncmp(msg[0].address+(len-1)-9, "multixy1/", 9) && (num != -1)) { |
| casiotone401 | 12:33c8f06c2e03 | 1562 | if(num > 7) continue; |
| casiotone401 | 12:33c8f06c2e03 | 1563 | if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N); |
| casiotone401 | 12:33c8f06c2e03 | 1564 | if(msg[1].typeTag[1] == 'f') gOSC_cv[++num] = msg[3].f * (SCALING_N); |
| casiotone401 | 12:33c8f06c2e03 | 1565 | continue; |
| casiotone401 | 12:33c8f06c2e03 | 1566 | |
| casiotone401 | 12:33c8f06c2e03 | 1567 | } else if (!strncmp(msg[0].address+(len-1)-12, "multifader1/", 12) && (num != -1)) { |
| casiotone401 | 12:33c8f06c2e03 | 1568 | if(num > 7) continue; |
| casiotone401 | 12:33c8f06c2e03 | 1569 | if(msg[1].typeTag[1] == 'f') gOSC_cv[num] = msg[2].f * (SCALING_N); |
| casiotone401 | 12:33c8f06c2e03 | 1570 | continue; |
| casiotone401 | 12:33c8f06c2e03 | 1571 | // (touchOSC multifader for Sequencer Mode) |
| casiotone401 | 12:33c8f06c2e03 | 1572 | } else if (!strncmp(msg[0].address+(len-1)-11, "sequencer1/", 11) && (num != -1)) { |
| casiotone401 | 12:33c8f06c2e03 | 1573 | if(num > 7) continue; |
| casiotone401 | 12:33c8f06c2e03 | 1574 | if(msg[1].typeTag[1] == 'f') gSeq_cv1[num] = msg[2].f * (SCALING_N); |
| casiotone401 | 12:33c8f06c2e03 | 1575 | continue; |
| casiotone401 | 12:33c8f06c2e03 | 1576 | |
| casiotone401 | 12:33c8f06c2e03 | 1577 | } else if (!strncmp(msg[0].address+(len-1)-11, "sequencer2/", 11) && (num != -1)) { |
| casiotone401 | 12:33c8f06c2e03 | 1578 | if(num > 7) continue; |
| casiotone401 | 12:33c8f06c2e03 | 1579 | if(msg[1].typeTag[1] == 'f') gSeq_cv2[num] = msg[2].f * (SCALING_N); |
| casiotone401 | 12:33c8f06c2e03 | 1580 | continue; |
| casiotone401 | 12:33c8f06c2e03 | 1581 | // address pattern for control |
| casiotone401 | 12:33c8f06c2e03 | 1582 | } else if (!strncmp(msg[0].address+(len-1)-6, "ctrlsw", 6) && (num != -1)) { |
| casiotone401 | 12:33c8f06c2e03 | 1583 | if(num > 4) continue; |
| casiotone401 | 12:33c8f06c2e03 | 1584 | if(absv >= 1 || msg[2].i >= 1) gCtrlSW[num] = true; |
| casiotone401 | 12:33c8f06c2e03 | 1585 | else gCtrlSW[num] = false; |
| casiotone401 | 12:33c8f06c2e03 | 1586 | continue; |
| casiotone401 | 12:33c8f06c2e03 | 1587 | |
| casiotone401 | 12:33c8f06c2e03 | 1588 | } else if (!strncmp(msg[0].address+(len-1)-4, "ctrl", 4) && (num != -1)) { |
| casiotone401 | 12:33c8f06c2e03 | 1589 | if(num > 3) continue; |
| casiotone401 | 12:33c8f06c2e03 | 1590 | if(msg[1].typeTag[1] == 'f') gCtrl[num] = msg[2].f; |
| casiotone401 | 12:33c8f06c2e03 | 1591 | continue; |
| casiotone401 | 12:33c8f06c2e03 | 1592 | } |
| casiotone401 | 12:33c8f06c2e03 | 1593 | |
| casiotone401 | 12:33c8f06c2e03 | 1594 | } while(bundleflag); |
| casiotone401 | 12:33c8f06c2e03 | 1595 | |
| casiotone401 | 12:33c8f06c2e03 | 1596 | } |
| casiotone401 | 12:33c8f06c2e03 | 1597 | } |