-
Notifications
You must be signed in to change notification settings - Fork 0
/
Esp2Chn.lua
316 lines (296 loc) · 9.69 KB
/
Esp2Chn.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
-- Esp2Chn.lua
-- Mapping of Spanish VSQ(X)'s to Chinese phonetics.
function manifest()
myManifest = {
name = "ESP->CHN",
comment = "Convert Spanish VSQX for Chinese Libraries.",
author = "Slidingwall",
pluginID = "{SPANISH-SILD-INGW-ALL0-00000CHINESE}",
pluginVersion = "For Chinese Libraries",
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 mapping3 = {}
local noteEx = {}
local noteExList = {}
local noteCount
local retCode
local idx
mapping3["x w a"] = "x ua"
mapping3["x j u"] = "x 7_0 i@U"
mapping3["x j o"] = "x 7_0 iAU"
mapping3["x j e"] = "x 7_0 iE_r"
mapping3["x j a"] = "x 7_0 ia"
mapping3["w e I"] = "uei"
mapping3["w a I"] = "uaI"
mapping3["tS j u"] = "ts\\ i@U"
mapping3["tS j o"] = "ts\\ iAU"
mapping3["tS j e"] = "ts\\ iE_r"
mapping3["tS j a"] = "ts\\ ia"
mapping3["t j u"] = "t_h i @U"
mapping3["T j u"] = "ts\\ i@U"
mapping3["T j o"] = "ts\\ iAU"
mapping3["T j e"] = "ts\\ iE_r"
mapping3["t j a"] = "t_h i a"
mapping3["T j a"] = "ts\\ ia"
mapping3["s j u"] = "s\\ i@U"
mapping3["s j o"] = "s\\ iAU"
mapping3["s j e"] = "s\\ iE_r"
mapping3["s j a"] = "s\\ ia"
mapping3["rr w e"] = "l u ei"
mapping3["rr o I"] = "l o i"
mapping3["r w e"] = "l u ei"
mapping3["r o I"] = "l o i"
mapping3["p w o"] = "p_h uo"
mapping3["p w e"] = "p_h u ei"
mapping3["p o I"] = "p_h o i"
mapping3["p j u"] = "p_h i @U"
mapping3["p j a"] = "p_h i a"
mapping3["n w e"] = "n u ei"
mapping3["m w o"] = "m uo"
mapping3["m w e"] = "m u ei"
mapping3["m o I"] = "m o i"
mapping3["L w o"] = "i uo"
mapping3["L w i"] = "y"
mapping3["l w e"] = "l u ei"
mapping3["L w e"] = "i uei"
mapping3["L w a"] = "i ua"
mapping3["L o U"] = "i@U"
mapping3["l o I"] = "l o i"
mapping3["L o I"] = "iAU i"
mapping3["L e U"] = "i@U"
mapping3["L e I"] = "iE_r ei"
mapping3["L a U"] = "iAU"
mapping3["L a I"] = "ia aI"
mapping3["k w a"] = "k_h ua"
mapping3["k j u"] = "k_h 7_0 i@U"
mapping3["k j o"] = "k_h 7_0 iAU"
mapping3["k j e"] = "k_h 7_0 iE_r"
mapping3["k j a"] = "k_h 7_0 ia"
mapping3["j\\ w o"] = "i uo"
mapping3["j\\ w i"] = "y"
mapping3["j\\ w e"] = "iE_r"
mapping3["j\\ w a"] = "i ua"
mapping3["j\\ o U"] = "i@U"
mapping3["j\\ o I"] = "iAU i"
mapping3["j\\ e U"] = "i@U"
mapping3["j\\ e I"] = "iE_r ei"
mapping3["j\\ a U"] = "iAU"
mapping3["j\\ a I"] = "ia aI"
mapping3["J w o"] = "n i uo"
mapping3["J w i"] = "n y"
mapping3["J w e"] = "n i uei"
mapping3["J w a"] = "n i ua"
mapping3["J o U"] = "n i@U"
mapping3["J o I"] = "n iAU i"
mapping3["J e U"] = "n i@U"
mapping3["J e I"] = "n iE_r ei"
mapping3["j e I"] = "iE_r ei"
mapping3["J a U"] = "n iAU"
mapping3["J a I"] = "n ia aI"
mapping3["j a I"] = "ia aI"
mapping3["G w a"] = "x ua"
mapping3["g w a"] = "k ua"
mapping3["G j u"] = "x 7_0 i@U"
mapping3["G j o"] = "x 7_0 iAU"
mapping3["G j e"] = "x 7_0 iE_r"
mapping3["G j a"] = "x 7_0 ia"
mapping3["f w o"] = "f uo"
mapping3["f w e"] = "f u ei"
mapping3["f o I"] = "f o i"
mapping3["f j u"] = "f o_0 i@U"
mapping3["f j o"] = "f o_0 iAU"
mapping3["f j e"] = "f o_0 iE_r"
mapping3["f j a"] = "f o_0 ia"
mapping3["f a U"] = "f a AU"
mapping3["f a I"] = "f a ai"
mapping3["D j u"] = "s\\ i@U"
mapping3["D j o"] = "s\\ iAU"
mapping3["D j e"] = "s\\ iE_r"
mapping3["D j a"] = "s\\ ia"
mapping3["b w o"] = "p uo"
mapping3["B w o"] = "uo"
mapping3["B w i"] = "u i"
mapping3["b w e"] = "p u ei"
mapping3["B w e"] = "uei"
mapping3["B w a"] = "ua"
mapping3["B o U"] = "u @U"
mapping3["b o I"] = "p o i"
mapping3["B o I"] = "uo i"
mapping3["b j u"] = "p i @U"
mapping3["B j u"] = "u i@U"
mapping3["B j o"] = "u iAU"
mapping3["B j e"] = "u iE_r"
mapping3["b j a"] = "p i a"
mapping3["B j a"] = "u ia"
mapping3["B e U"] = "u @U"
mapping3["B e I"] = "uei"
mapping3["B a U"] = "u AU"
mapping3["B a I"] = "uaI"
mapping2["- I"] = "- ei"
mapping2["- U"] = "- @U"
mapping2["- N"] = "- @N"
mapping2["x i"] = "x 7_0 i"
mapping2["w o"] = "uo"
mapping2["w i"] = "u i"
mapping2["w e"] = "uei"
mapping2["w a"] = "u a"
mapping2["tS i"] = "ts\\ i"
mapping2["T i"] = "ts\\ i"
mapping2["s i"] = "s\\ i"
mapping2["rr o"] = "l o"
mapping2["r o"] = "l o"
mapping2["p o"] = "p_h o"
mapping2["o U"] = "@U"
mapping2["o I"] = "@U i"
mapping2["m o"] = "m o"
mapping2["L u"] = "i@U"
mapping2["l o"] = "l o"
mapping2["L o"] = "iAU"
mapping2["L i"] = "i"
mapping2["L e"] = "iE_r"
mapping2["L a"] = "ia"
mapping2["k i"] = "k_h 7_0 i"
mapping2["j\\ u"] = "i@U"
mapping2["j\\ o"] = "iAU"
mapping2["j\\ i"] = "i"
mapping2["j\\ e"] = "iE_r"
mapping2["j\\ a"] = "ia"
mapping2["j u"] = "i@U"
mapping2["J u"] = "n i@U"
mapping2["j o"] = "iAU"
mapping2["J o"] = "n iAU"
mapping2["J i"] = "n i"
mapping2["j e"] = "iE_r"
mapping2["J e"] = "n iE_r"
mapping2["j a"] = "ia"
mapping2["J a"] = "n ia"
mapping2["G i"] = "x 7_0 i"
mapping2["g i"] = "k 7_0 i"
mapping2["f o"] = "f o"
mapping2["f i"] = "f o_0 i"
mapping2["e U"] = "@U"
mapping2["e I"] = "ei"
mapping2["D i"] = "s\\ i"
mapping2["B u"] = "u"
mapping2["b o"] = "p o"
mapping2["B o"] = "uo"
mapping2["B i"] = "u i"
mapping2["B e"] = "uei"
mapping2["B a"] = "ua"
mapping2["a U"] = "AU"
mapping2["a I"] = "aI"
mapping["tS"] = "ts`"
mapping["T"] = "ts"
mapping["t"] = "t_h"
mapping["Sil"] = "Sil"
mapping["rr"] = "l"
mapping["r"] = "l"
mapping["p"] = "p_h"
mapping["o"] = "@U"
mapping["l"] = "l"
mapping["L"] = "i"
mapping["k"] = "k_h"
mapping["j\\"] = "i"
mapping["J"] = "n i"
mapping["G"] = "x"
mapping["g"] = "k"
mapping["e"] = "ei"
mapping["d"] = "t"
mapping["D"] = "s"
mapping["B"] = "u"
mapping["b"] = "p"
-- 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 + 2 <= table.getn(phns) then
threephn = phns[i] .. " " .. phns[i + 1] .. " " .. phns[i + 2]
if mapping3[threephn] then
phns[i] = mapping3[threephn]
phns[i + 1] = ""
phns[i + 2] = ""
mapped = true
end
end
if not mapped then
if i + 1 <= table.getn(phns) then
twophn = phns[i] .. " " .. phns[i + 1]
if mapping2[twophn] then
phns[i] = mapping2[twophn]
phns[i + 1] = ""
-- (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
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