This program can confirm several command for eVY1 Sheeld by character. mbed and eVY1 Sheeld connect only 5V/3.3V/GND/tx(p9)

Dependencies:   mbed

Fork of eVY1Sheld_test_for_LPC1768 by Yuji Notsu

Committer:
y_notsu
Date:
Mon Nov 25 13:10:02 2013 +0000
Revision:
1:139a18be7b78
Parent:
0:35804e977865
eVY1 command confirm program from Switch Science Shinichi-Ohki

Who changed what in which revision?

UserRevisionLine numberNew contents of line
y_notsu 1:139a18be7b78 1 ////////////////////////////////////////////////////////
y_notsu 1:139a18be7b78 2 // eVY1 Sheeld Program
y_notsu 1:139a18be7b78 3 // mml_play.ino
y_notsu 1:139a18be7b78 4 // auther Shinichi-Ohki
y_notsu 1:139a18be7b78 5 // Copyright(c) 2013 Yamaha Corporation
y_notsu 1:139a18be7b78 6 // Copyright(c) 2013 Switch Science
y_notsu 1:139a18be7b78 7 // CDEFGAB(ドレミファソラシド) 対応
y_notsu 1:139a18be7b78 8 // 音符の後ろの長さの数字 対応
y_notsu 1:139a18be7b78 9 // . 付点(1.5倍) 対応
y_notsu 1:139a18be7b78 10 // R 休符 対応
y_notsu 1:139a18be7b78 11 // T テンポ 対応
y_notsu 1:139a18be7b78 12 // V ボリューム 対応
y_notsu 1:139a18be7b78 13 // L 長さセット 対応
y_notsu 1:139a18be7b78 14 // O オクターブ変化 対応
y_notsu 1:139a18be7b78 15 // < 1オクターブ下げる 対応
y_notsu 1:139a18be7b78 16 // > 1オクターブ上げる 対応
y_notsu 1:139a18be7b78 17 // P パン 未着手
y_notsu 1:139a18be7b78 18 // # シャープ たぶん対応
y_notsu 1:139a18be7b78 19 // & タイ 未着手
y_notsu 1:139a18be7b78 20 // P ポルタメント 未着手
y_notsu 1:139a18be7b78 21 // 2013/11/25 : modified for mbed1769
y_notsu 1:139a18be7b78 22 ////////////////////////////////////////////////////////
y_notsu 0:35804e977865 23 #include "mbed.h"
y_notsu 0:35804e977865 24
y_notsu 0:35804e977865 25 Serial evy1(p9, p10); // tx, rx configured for LPC800-MAX
y_notsu 0:35804e977865 26 //Serial evy1(PTA2, PTA1); // tx, rx configured for FRDM-KL25Z
y_notsu 1:139a18be7b78 27 DigitalOut myled(LED1);
y_notsu 0:35804e977865 28
y_notsu 0:35804e977865 29 // DO NOT EDIT!!
y_notsu 0:35804e977865 30 const char* phoneticSymbols[] = {
y_notsu 0:35804e977865 31 "a", "i", "M", "e", "o", // あいうえお0-4
y_notsu 0:35804e977865 32 "k a", "k' i", "k M", "k e", "k o", // かきくけこ5-9
y_notsu 0:35804e977865 33 "s a", "S i", "s M", "s e", "s o", // さしすえそ10-14
y_notsu 0:35804e977865 34 "t a", "tS i", "ts M", "t e", "t o", // たちつてと15-19
y_notsu 0:35804e977865 35 "n a", "J i", "n M", "n e", "n o", //なにぬねの20-24
y_notsu 0:35804e977865 36 "h a", "C i", "p\\ M", "h e", "h o", // はひふへほ25-29
y_notsu 0:35804e977865 37 "m a", "m' i", "m M", "m e", "m o", // まみむめも30-34
y_notsu 0:35804e977865 38 "j a","i", "j M","e","j o",//やいゆえよ35-39
y_notsu 0:35804e977865 39 "4 a", "4' i", "4 M", "4 e", "4 o", // らりるれろ40-44
y_notsu 0:35804e977865 40 "w a","w o","N\\","","",// わをん 45-49
y_notsu 0:35804e977865 41 "g a", "g' i", "g M", "g e", "g o",//がぎぐげご 50-54
y_notsu 0:35804e977865 42 "dz a", "dZ i", "dz M", "dz e", "dz o",//ざじずぜぞ55-59
y_notsu 0:35804e977865 43 "d a", "dZ i", "dz M", "d e", "d o",//だじづでど60-64
y_notsu 0:35804e977865 44 "b a", "b' i", "b M", "b e", "b o",//ばびぶべぼ 65-69
y_notsu 0:35804e977865 45 "p a", "p' i", "p M", "p e", "p o"//ぱぴぷぺぽ70-74
y_notsu 0:35804e977865 46 };
y_notsu 0:35804e977865 47
y_notsu 0:35804e977865 48 //lylics
y_notsu 0:35804e977865 49 //さんまのうたがきこえてくるよ
y_notsu 1:139a18be7b78 50 //int lylics[]={10,47,30,24,2,15,50,6,9,3,18,7,42,39};
y_notsu 1:139a18be7b78 51 //char mml[] ="CDEFEDC EFGAGFE";
y_notsu 1:139a18be7b78 52
y_notsu 1:139a18be7b78 53 // 歌詞
y_notsu 1:139a18be7b78 54 //int voice[] = {25,31,25,31,25,31,1,30,25,31,25,31,30,0};
y_notsu 1:139a18be7b78 55 int voice[] = {
y_notsu 1:139a18be7b78 56 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
y_notsu 1:139a18be7b78 57 0,0,0,0,0,0,0,
y_notsu 1:139a18be7b78 58 0,1,2,3,4,5,6,7,8,9,
y_notsu 1:139a18be7b78 59 0,0,0,0,0,
y_notsu 1:139a18be7b78 60 0,1,2,3,4,
y_notsu 1:139a18be7b78 61 5,6,7,8,9,
y_notsu 1:139a18be7b78 62 10,11,12,13,14,
y_notsu 1:139a18be7b78 63 50,50,50,50
y_notsu 1:139a18be7b78 64 };
y_notsu 1:139a18be7b78 65 //int voice[] = {6,47,9,47,5,47,9,47,6,47,9,47,5,47,9,47};
y_notsu 1:139a18be7b78 66 // メロディ
y_notsu 1:139a18be7b78 67 //char melody[] = "R1T60L8O6EC>G<CDGGGDED>G<CC4";
y_notsu 1:139a18be7b78 68 char melody[] = "o5cdefgab<cdefgab<co5v1cv3cv7cv15cv31cv63cv127v8cccccccccccrcrrcrrrcrrrrcrrrrrl1cl2cl4cl8cl16cl32cl1rt10crt20crt30crt40crt50crt40c16c8c4c2c1r2l2crc2rc2.rc.";
y_notsu 1:139a18be7b78 69 //char melody[] = "T80L4O5FF32AA32GG32CC16RCC32GG32AA32FF32";
y_notsu 1:139a18be7b78 70 //--------------------------------------------
y_notsu 1:139a18be7b78 71
y_notsu 1:139a18be7b78 72 char tempo,tempo_now;
y_notsu 1:139a18be7b78 73 char volume,volume_now;
y_notsu 1:139a18be7b78 74 char octave,octave_now;
y_notsu 1:139a18be7b78 75 char current_time,time_now;
y_notsu 1:139a18be7b78 76 int temp_int;
y_notsu 1:139a18be7b78 77 int melody_counter;
y_notsu 1:139a18be7b78 78 char old_key;
y_notsu 1:139a18be7b78 79 char time_table[] = {0,32,16,0,8,0,0,0,4,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
y_notsu 1:139a18be7b78 80
y_notsu 0:35804e977865 81
y_notsu 0:35804e977865 82 void Short_Message(int cmd, int d1, int d2) {
y_notsu 0:35804e977865 83 evy1.putc(cmd);
y_notsu 0:35804e977865 84 evy1.putc(d1);
y_notsu 0:35804e977865 85 evy1.putc(d2);
y_notsu 0:35804e977865 86 }
y_notsu 0:35804e977865 87
y_notsu 0:35804e977865 88 // send lylics
y_notsu 1:139a18be7b78 89 void send_voice(int num){
y_notsu 0:35804e977865 90 //hedaer
y_notsu 1:139a18be7b78 91 //manual page.8 eVocaloid Phonetic symbols
y_notsu 0:35804e977865 92 evy1.putc(0xF0);
y_notsu 0:35804e977865 93 evy1.putc(0x43);
y_notsu 0:35804e977865 94 evy1.putc(0x79);
y_notsu 0:35804e977865 95 evy1.putc(0x09);
y_notsu 0:35804e977865 96 evy1.putc(0x00);
y_notsu 0:35804e977865 97 evy1.putc(0x50);
y_notsu 1:139a18be7b78 98 evy1.putc(0x10); //1m Mode m=0(replace)/m=1(append)
y_notsu 0:35804e977865 99
y_notsu 1:139a18be7b78 100 //The number of data have to be under 128byte
y_notsu 0:35804e977865 101 for(int i=0;i<num;i++){
y_notsu 0:35804e977865 102 if(i != 0) evy1.putc(0x2c); // 0x2c is separator
y_notsu 1:139a18be7b78 103 evy1.printf(phoneticSymbols[voice[i]]);
y_notsu 0:35804e977865 104 }
y_notsu 0:35804e977865 105 //footer
y_notsu 0:35804e977865 106 evy1.putc(0x00); // footer for NSX-1
y_notsu 0:35804e977865 107 evy1.putc(0xF7); // footer of MIDI sys-ex
y_notsu 0:35804e977865 108 }
y_notsu 1:139a18be7b78 109
y_notsu 1:139a18be7b78 110 void read_num() {
y_notsu 1:139a18be7b78 111 bool flag = true;
y_notsu 1:139a18be7b78 112 temp_int = 0;
y_notsu 1:139a18be7b78 113 while (true) {
y_notsu 1:139a18be7b78 114 if ((melody[melody_counter + 1] >= '0') && (melody[melody_counter + 1] <= '9')) {
y_notsu 1:139a18be7b78 115 temp_int = temp_int * 10 + melody[++melody_counter] - '0';
y_notsu 1:139a18be7b78 116 flag = false;
y_notsu 1:139a18be7b78 117 } else {
y_notsu 1:139a18be7b78 118 if (flag == true) temp_int = -1;
y_notsu 1:139a18be7b78 119 else melody_counter++;
y_notsu 1:139a18be7b78 120 break;
y_notsu 1:139a18be7b78 121 }
y_notsu 1:139a18be7b78 122 }
y_notsu 1:139a18be7b78 123 }
y_notsu 0:35804e977865 124
y_notsu 0:35804e977865 125
y_notsu 0:35804e977865 126 int main() {
y_notsu 1:139a18be7b78 127 //int key = 0x3c; //C
y_notsu 1:139a18be7b78 128 tempo = 40;
y_notsu 1:139a18be7b78 129 current_time = 4;
y_notsu 1:139a18be7b78 130 volume = 5;
y_notsu 1:139a18be7b78 131 octave = 4;
y_notsu 0:35804e977865 132 evy1.baud(31250); // MIDI speed
y_notsu 0:35804e977865 133 wait(5); // waiting for eVY1 module boot up
y_notsu 0:35804e977865 134 while(1)
y_notsu 0:35804e977865 135 {
y_notsu 1:139a18be7b78 136 // 歌詞転送
y_notsu 1:139a18be7b78 137 int voice_len = sizeof(voice) / sizeof(voice[0]);
y_notsu 1:139a18be7b78 138 send_voice(voice_len);
y_notsu 0:35804e977865 139
y_notsu 1:139a18be7b78 140 int melody_len = sizeof(melody) / sizeof(melody[0]);
y_notsu 1:139a18be7b78 141 // MML解析&PLAY
y_notsu 1:139a18be7b78 142 for (melody_counter = 0;melody_counter < melody_len - 1;melody_counter++) {
y_notsu 1:139a18be7b78 143 bool flag = true;
y_notsu 1:139a18be7b78 144 while (flag) {
y_notsu 1:139a18be7b78 145 char c = melody[melody_counter];
y_notsu 1:139a18be7b78 146 if ((c >= 'a') && (c <= 'z')) { // 小文字を大文字に補正
y_notsu 1:139a18be7b78 147 c -= 0x20;
y_notsu 1:139a18be7b78 148 }
y_notsu 1:139a18be7b78 149 if (((c >= 'A') && (c <= 'G')) || (c == 'R')) { // 音符または休符
y_notsu 1:139a18be7b78 150 int time_temp;
y_notsu 1:139a18be7b78 151 if (c != 'R') {
y_notsu 1:139a18be7b78 152 char table[] = {9,11,0,2,4,5,7}; // A,B,C,D,E,F,G
y_notsu 1:139a18be7b78 153 old_key = table[c - 'A'] + octave_now * 12;
y_notsu 1:139a18be7b78 154 if (melody[melody_counter + 1] == '#') {
y_notsu 1:139a18be7b78 155 old_key++;
y_notsu 1:139a18be7b78 156 melody_counter++;
y_notsu 1:139a18be7b78 157 }
y_notsu 1:139a18be7b78 158 Short_Message(0x90,old_key,volume_now); // 鳴らす
y_notsu 1:139a18be7b78 159 } else {
y_notsu 1:139a18be7b78 160 Short_Message(0x80,old_key,volume_now); // 止める
y_notsu 1:139a18be7b78 161 }
y_notsu 1:139a18be7b78 162 read_num();
y_notsu 1:139a18be7b78 163 if (temp_int != -1) {
y_notsu 1:139a18be7b78 164 if ((temp_int > 0) && (temp_int <= 32)) {
y_notsu 1:139a18be7b78 165 melody_counter--;
y_notsu 1:139a18be7b78 166 time_temp = time_table[temp_int];
y_notsu 1:139a18be7b78 167 } else {
y_notsu 1:139a18be7b78 168 myled=1;
y_notsu 1:139a18be7b78 169 while(true) {}
y_notsu 1:139a18be7b78 170 }
y_notsu 1:139a18be7b78 171 } else {
y_notsu 1:139a18be7b78 172 time_temp = time_table[time_now];
y_notsu 1:139a18be7b78 173 }
y_notsu 1:139a18be7b78 174 if (melody[melody_counter + 1] == '.') {
y_notsu 1:139a18be7b78 175 time_temp = time_temp * 15 / 10;
y_notsu 1:139a18be7b78 176 melody_counter++;
y_notsu 0:35804e977865 177 }
y_notsu 1:139a18be7b78 178 wait_ms(tempo_now * time_temp); // 通常の音符長
y_notsu 1:139a18be7b78 179 flag = false;
y_notsu 1:139a18be7b78 180 } else { // 音符以外
y_notsu 1:139a18be7b78 181 switch (c) {
y_notsu 1:139a18be7b78 182 case 'T': // テンポのセット(5~100)
y_notsu 1:139a18be7b78 183 read_num();
y_notsu 1:139a18be7b78 184 if ((temp_int == -1) || (temp_int < 5) || (temp_int > 100)) {
y_notsu 1:139a18be7b78 185 myled=1;
y_notsu 1:139a18be7b78 186 while(true) {}
y_notsu 1:139a18be7b78 187 }
y_notsu 1:139a18be7b78 188 tempo_now = (char)temp_int;
y_notsu 1:139a18be7b78 189 break;
y_notsu 1:139a18be7b78 190
y_notsu 1:139a18be7b78 191 case 'V': // ボリュームのセット(0~127)
y_notsu 1:139a18be7b78 192 read_num();
y_notsu 1:139a18be7b78 193 if ((temp_int == -1) || (temp_int < 0) || (temp_int > 127)) {
y_notsu 1:139a18be7b78 194 myled=1;
y_notsu 1:139a18be7b78 195 while(true) {}
y_notsu 1:139a18be7b78 196 }
y_notsu 1:139a18be7b78 197 volume_now = (char)temp_int;
y_notsu 1:139a18be7b78 198 break;
y_notsu 1:139a18be7b78 199 case 'O': // オクターブのセット(0~10)
y_notsu 1:139a18be7b78 200 read_num();
y_notsu 1:139a18be7b78 201 if ((temp_int == -1) || (temp_int < 0) || (temp_int > 10)) {
y_notsu 1:139a18be7b78 202 myled=1;
y_notsu 1:139a18be7b78 203 while(true) {}
y_notsu 1:139a18be7b78 204 }
y_notsu 1:139a18be7b78 205 octave_now = (char)temp_int;
y_notsu 1:139a18be7b78 206 break;
y_notsu 1:139a18be7b78 207 case '>': // オクターブ1下げる
y_notsu 1:139a18be7b78 208 if (octave >= 0) {
y_notsu 1:139a18be7b78 209 octave_now--;
y_notsu 1:139a18be7b78 210 melody_counter++;
y_notsu 1:139a18be7b78 211 } else {
y_notsu 1:139a18be7b78 212 myled=1;
y_notsu 1:139a18be7b78 213 while(true) {}
y_notsu 1:139a18be7b78 214 }
y_notsu 1:139a18be7b78 215 break;
y_notsu 1:139a18be7b78 216 case '<': // オクターブ1上げる
y_notsu 1:139a18be7b78 217 if (octave <= 10) {
y_notsu 1:139a18be7b78 218 octave_now++;
y_notsu 1:139a18be7b78 219 melody_counter++;
y_notsu 1:139a18be7b78 220 } else {
y_notsu 1:139a18be7b78 221 myled=1;
y_notsu 1:139a18be7b78 222 while(true) {}
y_notsu 1:139a18be7b78 223 }
y_notsu 1:139a18be7b78 224 break;
y_notsu 1:139a18be7b78 225 case 'L': // 音の長さのセット(1,2,4,8,16,32)
y_notsu 1:139a18be7b78 226 read_num();
y_notsu 1:139a18be7b78 227 if ((temp_int > 0) && (temp_int <= 32)) {
y_notsu 1:139a18be7b78 228 time_now = temp_int;
y_notsu 1:139a18be7b78 229 } else {
y_notsu 1:139a18be7b78 230 myled=1;
y_notsu 1:139a18be7b78 231 while (true) {}
y_notsu 1:139a18be7b78 232 }
y_notsu 1:139a18be7b78 233 break;
y_notsu 1:139a18be7b78 234 }
y_notsu 1:139a18be7b78 235 }
y_notsu 0:35804e977865 236 }
y_notsu 0:35804e977865 237 }
y_notsu 1:139a18be7b78 238 Short_Message(0x80,old_key,volume_now); // 止める
y_notsu 0:35804e977865 239 wait(0.5);
y_notsu 0:35804e977865 240 }
y_notsu 0:35804e977865 241 }
y_notsu 0:35804e977865 242