-
Notifications
You must be signed in to change notification settings - Fork 0
/
eVY1driver.cs
114 lines (104 loc) · 3.2 KB
/
eVY1driver.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System.Collections.Generic;
using System;
using System.Threading;
using System.Text;
namespace jp.ropo {
class eVY1driver {
string[] phoneticSymbols = new string[]{
"a", "i", "M", "e", "o", // あいうえお0-4
"k a", "k' i", "k M", "k e", "k o", // かきくけこ5-9
"s a", "S i", "s M", "s e", "s o", // さしすえそ10-14
"t a", "tS i", "ts M", "t e", "t o", // たちつてと15-19
"n a", "J i", "n M", "n e", "n o", //なにぬねの20-24
"h a", "C i", "p\\ M", "h e", "h o", // はひふへほ25-29
"m a", "m' i", "m M", "m e", "m o", // まみむめも30-34
"j a","i", "j M","e","j o", //やいゆえよ35-39
"4 a", "4' i", "4 M", "4 e", "4 o", // らりるれろ40-44
"w a","w o","N\\","","", // わをん 45-49
"g a", "g' i", "g M", "g e", "g o", //がぎぐげご 50-54
"dz a", "dZ i", "dz M", "dz e", "dz o", //ざじずぜぞ55-59
"d a", "dZ i", "dz M", "d e", "d o", //だじづでど60-64
"b a", "b' i", "b M", "b e", "b o", //ばびぶべぼ 65-69
"p a", "p' i", "p M", "p e", "p o" //ぱぴぷぺぽ70-74
};
const string phonetics = "あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやいゆえよらりるれろわをん がぎぐげござじずぜぞだぢづでどばびぶべぼぱぴぷぺぽ";
Win32MidiOutPort dev = new Win32MidiOutPort();
public bool Open(int id) {
bool result = dev.Open(id);
dev.Reset();
return result;
}
public void SendLylic(string lylic) {
if (dev == null)
return;
var ary = new List<byte>();
ary.Add(0xf0);
ary.Add(0x43);
ary.Add(0x79);
ary.Add(0x09);
ary.Add(0x00);
ary.Add(0x50);
ary.Add(0x10);
int index;
int count = 0;
for (int i = 0; i < lylic.Length; i++) {
index = phonetics.IndexOf( lylic[i] );
if( index >= 0 ) {
if( count != 0 ) ary.Add(0x2c);
var asciis = Encoding.ASCII.GetBytes(phoneticSymbols[index]);
foreach( byte ascii in asciis )
ary.Add( ascii );
count++;
}
}
ary.Add(0x00);
ary.Add(0xf7);
dev.SendLongMessage(ary.ToArray());
}
private Thread trdPlay;
private string mml;
public void Play(string mml) {
if (dev == null)
return;
if (trdPlay != null && trdPlay.IsAlive )
trdPlay.Abort();
this.mml =mml;
trdPlay = new Thread( new ThreadStart(playing) );
trdPlay.IsBackground = true;
trdPlay.Start();
}
public void Stop() {
if (dev == null)
return;
if (trdPlay != null && trdPlay.IsAlive)
trdPlay.Abort();
}
protected void playing() {
byte note = 0x3c;
foreach (var ascii in mml)
{
note = 0x3c;
switch (ascii) {
case 'C': note+=0; break;
case 'D': note+=2; break;
case 'E': note+=4; break;
case 'F': note+=5; break;
case 'G': note+=7; break;
case 'A': note+=9; break;
case 'B': note+=11; break;
default: note=0; break;
}
if( note != 0 )
SendMessage(new byte[] { 0x90, note, 0x40 });
System.Threading.Thread.Sleep(300);
}
SendMessage(new byte[] { 0x90, note, 0x00 });
}
private void SendMessage(byte[] msg) {
if (dev == null)
return;
dev.SendShortMessage(msg[0], msg[1],msg[2]);
}
}
}