-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResetProject.py
134 lines (107 loc) · 3.19 KB
/
ResetProject.py
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
import json
from tkinter import Tk, Button, messagebox, filedialog
import ctypes
#手绘参数名称
parameterNames = ["pitchDelta", "vibratoEnv", "loudness", "tension", "breathiness",
"voicing", "gender", "toneShift"]
#还原音符组默认设置
def restoreGroupDefaults(group):
#遍历所有手绘参数
for paraName in parameterNames:
#清空参数点
group["parameters"][paraName]["points"] = []
#遍历所有音符
for noteIndex in range(0, len(group["notes"])):
#读取
note = group["notes"][noteIndex]
#清除音符属性
note["phonemes"] = ""
note["detune"] = 0
note["attributes"] = {}
note["systemAttributes"] = {}
note["pitchTakes"] = {
"activeTakeId": 0,
"takes": [
{
"id": 0,
"expr": 1.0,
"liked": False
}
]
}
note["timbreTakes"] = {
"activeTakeId": 0,
"takes": [
{
"id": 0,
"expr": 1.0,
"liked": False
}
]
}
#还原轨道默认设置
def restoreTrackDefaults(track):
#清空主音轨参数
restoreGroupDefaults(track["mainGroup"])
#重置主音轨全局参数
track["mainRef"]["voice"] = {
"vocalModeInherited": True,
"vocalModePreset": "",
"vocalModeParams": {}
}
#重置音符组全局参数
for groupIndex in range(0, len(track["groups"])):
track["groups"][groupIndex]["voice"] = {
"vocalModeInherited": True,
"vocalModePreset": "",
"vocalModeParams": {}
}
#重置工程
def resetProject(projectDir):
#打开工程
inFile = open(projectDir, "r", encoding="utf8")
svProject = json.loads(inFile.read().rstrip("\x00"))
inFile.close()
#遍历音符组库中的每个音符组
for libIndex in range(0, len(svProject["library"])):
#重置音符组参数
restoreGroupDefaults(svProject["library"][libIndex])
#遍历每个轨道
for trackIndex in range(0, len(svProject["tracks"])):
#如果是伴奏轨,不改动
if(svProject["tracks"][trackIndex]["mainRef"]["isInstrumental"]):
continue
#重置轨道参数
restoreTrackDefaults(svProject["tracks"][trackIndex])
return svProject
#按钮按下时
def onButtonClick():
#选择读取工程路径
inFileDir = filedialog.askopenfilename(title="选择读取的工程文件",
filetypes=(("Synthesizer V R2工程文件", "*.svp*"),))
#重置SV工程
svProjectReset = resetProject(inFileDir)
#选择保存工程路径
outFileDir = filedialog.asksaveasfilename(title="选择工程保存路径",
filetypes=(("Synthesizer V R2工程文件", "*.svp*"),))
#保存
if (outFileDir != ""):
#检查文件路径
if not outFileDir.endswith(".svp"):
outFileDir += ".svp"
#写入
outFile = open(outFileDir, "w", encoding="utf8")
json.dump(svProjectReset, outFile)
outFile.close()
messagebox.showinfo("处理完成", "已保存重置的工程到" + outFileDir)
#GUI
mainWindow = Tk()
mainWindow.geometry("240x160")
mainWindow.title("一键重置SV工程")
ctypes.windll.shcore.SetProcessDpiAwareness(1)
ScaleFactor=ctypes.windll.shcore.GetScaleFactorForDevice(0)
mainWindow.tk.call('tk', 'scaling', ScaleFactor/75)
loadProjectButton = Button(mainWindow, text="选择工程文件", command=onButtonClick,
height=1, width=10)
loadProjectButton.place(x=70, y=60)
mainWindow.mainloop()