-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chn2Esp.lua
172 lines (151 loc) · 4.14 KB
/
Chn2Esp.lua
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
-- Chn2Esp.lua
-- Mapping of Chinese VSQ(X)'s to Spanish phonetics.
function manifest()
myManifest = {
name = "CHN->ESP",
comment = "Convert Chinese VSQX for Spanish libraries.",
author = "Slidingwall",
pluginID = "{CHINESE0-SILD-INGW-ALL0-00000SPANISH}",
pluginVersion = "For Bruno&Clara",
apiVersion = "3.0.1.0"
}
return myManifest
end
function main(processParam, envParam)
-- local beginPosTick = processParam.beginPosTick
-- local endPosTick = processParam.endPosTick
-- local songPosTick = processParam.songPosTick
-- local scriptDir = envParam.scriptDir
-- local scriptName = envParam.scriptName
-- local tempDir = envParam.tempDir
local mapping = {}
local mapping2 = {}
local noteEx = {}
local noteExList = {}
local noteCount
local retCode
local idx
mapping["7"] = "o"
mapping["i"] = "i"
mapping["u"] = "u"
mapping["y"] = "j u"
mapping["@`"] = "a l"
mapping["i\\"] = "i"
mapping["i`"] = "u"
mapping["aI"] = "a I"
mapping["ei"] = "e I"
mapping["AU"] = "a U"
mapping["@U"] = "o U"
mapping["ia"] = "j a"
mapping["iE_r"] = "j e"
mapping["ua"] = "w a"
mapping["uo"] = "w o"
mapping["yE_r"] = "j u e"
mapping["iAU"] = "j a U"
mapping["i@U"] = "j o U"
mapping["uaI"] = "w a I"
mapping["uei"] = "w e I"
mapping["a_n"] = "a n"
mapping["@_n"] = "e n"
mapping["i_n"] = "i n"
mapping["iE_n"] = "j e n"
mapping["ua_n"] = "w a n"
mapping["u@_n"] = "w e n"
mapping["y_n"] = "j u n"
mapping["y{_n"] = "j u e n"
mapping["AN"] = "a n"
mapping["@N"] = "o n"
mapping["iN"] = "i n"
mapping["iAN"] = "j a n"
mapping["uAN"] = "w a n"
mapping["u@N"] = "w o n"
mapping["UN"] = "o U n"
mapping["iUN"] = "j o U n"
mapping["p_h"] = "p"
mapping["t_h"] = "t"
mapping["n"] = "n"
mapping["k"] = "g"
mapping["k_h"] = "k"
mapping["ts\\"] = "t s"
mapping["ts\\_h"] = "tS"
mapping["s\\"] = "s"
mapping["ts`"] = "tS"
mapping["ts`_h"] = "tS"
mapping["s`"] = "s"
mapping["z`"] = "r"
mapping["ts"] = "t s"
mapping["ts_h"] = "t s"
mapping["Sil"] = "Sil"
-- get list of notes
VSSeekToBeginNote()
idx = 1
retCode, noteEx = VSGetNextNoteEx()
while (retCode == 1) do
noteExList[idx] = noteEx
retCode, noteEx = VSGetNextNoteEx()
idx = idx + 1
end
-- check if empty
noteCount = table.getn(noteExList)
if (noteCount == 0) then
VSMessageBox("No notes to process!", 0)
return 0
end
-- check Job Plugin can lock phoneme
local bPhLock = canPhLock(noteExList[1])
-- transform notes
for idx = 1, noteCount do
local updNoteEx = {}
updNoteEx = noteExList[idx]
-- split on whitespace
local phns = {}
for token in string.gmatch(updNoteEx.phonemes, "[^%s]+") do
table.insert(phns, token)
end
-- do phoneme-by-phoneme mapping
for i = 1, table.getn(phns) do
-- try exceptions first
local mapped = false
if i + 1 <= table.getn(phns) then
twophn = phns[i] .. " " .. phns[i + 1]
if mapping2[twophn] then
phns[i] = mapping2[twophn][1]
phns[i + 1] = mapping2[twophn][2]
-- (in this case no need to increment i because mapping2[twophn][2] is always "i", so will map to "i" on next iteration)
mapped = true -- there's no continue in lua
end
end
-- general mapping second
if not mapped then
if mapping[phns[i]] then
phns[i] = mapping[phns[i]]
end
end
end
-- join by space
updNoteEx.phonemes = table.concat(phns, " ");
-- Do phoneme lock
if (bPhLock) then
updNoteEx.phLock = 1
end
-- update note
retCode = VSUpdateNoteEx(updNoteEx);
if (retCode ~= 1) then
VSMessageBox("Failed to update note!", 0)
return 1
end
end
-- Success
return 0
end
-- Check if note has phLock property (only in newer API, Editor 3.0.5+)
function canPhLock(note)
local status = false
for key, val in pairs(note) do
if (key == "phLock") then
status = true
break
end
end
return status
end