-
Notifications
You must be signed in to change notification settings - Fork 1
/
Form1.cs
166 lines (148 loc) · 5.57 KB
/
Form1.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
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using FastResampler.Note;
using FastResampler.Param;
namespace FastResampler
{
public partial class Form1 : Form
{
/*public delegate void setProgressMax(int max);
public delegate void setProgressNow(int now);
public event setProgressMax setProgressMaxEvent;
public event setProgressNow setProgressNowEvent;*/
public int progress1MaxNum;
public int progress1NowNum;
public int progress2MaxNum;
public int progress2NowNum;
public string status1 = "", status2 = "";
public NotePainter painter;
public string rootDir = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
public Form1()
{
InitializeComponent();
Global.config = new Config(this.rootDir + "FastResampler.xml");
Global.lang = new LangPack(rootDir + "language.xml", Global.config);
}
public void SetProgress1MaxNum(int max)
{
this.progress1MaxNum = max;
}
public void SetProgress1NowNum(int now)
{
this.progress1NowNum = now;
int progress = Convert.ToInt32(Math.Round(Convert.ToDouble(this.progress1NowNum) / Convert.ToDouble(this.progress1MaxNum) * 100));
labelStatus.Text = string.Format("{0} ({1}/{2}) {3}%", this.status1, this.progress1NowNum, this.progress1MaxNum, progress);
progressResampler.Value = progress;
}
public void SetProgress2MaxNum(int max)
{
this.progress2MaxNum = max;
}
public void SetProgress2NowNum(int now, bool multiThread = false)
{
this.progress2NowNum = now;
int progress = Convert.ToInt32(Math.Round(Convert.ToDouble(this.progress2NowNum) / Convert.ToDouble(this.progress2MaxNum) * 100));
string statusString = string.Format("{0} ({1}/{2}) {3}%", this.status2, this.progress2NowNum, this.progress2MaxNum, progress);
if (multiThread == false)
labelStatus.Text = statusString;
else
labelStatusWavtool.Text = statusString;
progressWavtool.Value = progress;
}
public void SetStatus1(string status)
{
this.status1 = status;
}
public void SetStatus2(string status)
{
this.status2 = status;
}
private void Form1_Load(object sender, EventArgs e)
{
this.Text = Global.lang.fetch("正在合成……");
label1.Text = Global.lang.fetch("合成进度:");
label2.Text = Global.lang.fetch("拼接进度:");
labelStatus.Text = Global.lang.fetch("加载中……");
Control.CheckForIllegalCrossThreadCalls = false;
#if DEBUG
//System.Environment.CurrentDirectory = @"C:\Users\Administrator\AppData\Local\Temp\utau1";
#endif
string batFile = System.Environment.CurrentDirectory + "\\temp.bat";
if (!Global.config.showConsole)
{
Utils.hideBat();
}
if (File.Exists(batFile))
{
labelStatus.Text = Global.lang.fetch("正在解析数据……");
try
{
NoteList noteList = new NoteList();
UtauBat bat = new UtauBat(batFile);
//this.painter = new NotePainter(noteCanvas.CreateGraphics(), noteCanvas.Width, noteCanvas.Height, bat);
Resampler resampler = new Resampler(bat, this);
Thread thread = new Thread(new ThreadStart(resampler.synthetise));
thread.Start();
}
catch (FileNotFoundException fe)
{
MessageBox.Show(string.Format("{0}{1}", lang.fetch("文件不存在:"), fe.Message), lang.fetch("错误"), MessageBoxButtons.OK, MessageBoxIcon.Error);
this.SafeClose();
}
catch (Exception ex)
{
Utils.log("error: " + string.Format("{0}, {1}", ex.Message, ex.StackTrace));
MessageBox.Show(string.Format("{0}, {1}", ex.Message, ex.StackTrace));
}
}
else
{
MessageBox.Show(Global.lang.fetch("请在UTAU中调用!"), Global.lang.fetch("错误"), MessageBoxButtons.OK, MessageBoxIcon.Error);
this.SafeClose();
}
}
public void VHide()
{
this.WindowState = FormWindowState.Minimized;
}
public void VShow()
{
this.WindowState = FormWindowState.Normal;
}
public void stop()
{
this.SafeClose();
}
public void SafeClose()
{
if (!Global.config.showConsole)
{
Utils.showBat();
}
Utils.killBat();
this.Close();
}
private void progressBar1_Click(object sender, EventArgs e)
{
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (!Global.config.showConsole)
{
Utils.showBat();
}
Utils.killBat();
}
private void progressBar2_Click(object sender, EventArgs e)
{
}
}
}