forked from sdercolin/UtaFormatix
-
Notifications
You must be signed in to change notification settings - Fork 2
/
MainWindow.xaml.cs
277 lines (260 loc) · 10.6 KB
/
MainWindow.xaml.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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Forms;
using MessageBox = System.Windows.MessageBox;
namespace UtaFormatix
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
private const string Version = "ver1.51EX";
Data maindata;
Data exportingdata;
bool Imported = false;
public MainWindow()
{
InitializeComponent();
LblVer.Content = Version;
}
private void ExportVsq4(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (Imported)
{
exportingdata = new Data(maindata);
if(!Transformlyrics(UtaFormat.Vsq4))
{
return;
}
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Title = "Export";
saveFileDialog.Filter = "VOCALOID Project|*.vsqx";
saveFileDialog.FileName = exportingdata.ProjectName;
saveFileDialog.FilterIndex = 1;
saveFileDialog.RestoreDirectory = true;
if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string filename = saveFileDialog.FileName;
try
{
exportingdata.ExportVsq4(filename);
MessageBox.Show("Vsqx is successfully exported." + Environment.NewLine + "If it only pronounces \"a\", please select all notes and run \"Lyrics\"→\"Convert Phonemes\". ", "Export Vsqx");
}
catch (Exception ex)
{
Console.WriteLine(ex);
MessageBox.Show("Error occured", "Failed");
}
}
exportingdata = null;
}
else
{
MessageBox.Show("You have not imported a project.", "Export");
}
}
private void ExportCcs(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (Imported)
{
exportingdata = new Data(maindata);
if (!Transformlyrics(UtaFormat.Ccs))
{
return;
}
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Title = "Export";
saveFileDialog.Filter = "CeVIO Project|*.ccs";
saveFileDialog.FileName = exportingdata.ProjectName;
saveFileDialog.FilterIndex = 1;
saveFileDialog.RestoreDirectory = true;
if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string filename = saveFileDialog.FileName;
try
{
exportingdata.ExportCcs(filename);
MessageBox.Show("Ccs is successfully exported", "Succeed");
}
catch (Exception ex)
{
Console.WriteLine(ex);
MessageBox.Show("Error occured", "Failed");
}
}
exportingdata = null;
}
else
{
MessageBox.Show("You have not imported a project.", "Export");
}
}
private void ExportUst(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (Imported)
{
exportingdata = new Data(maindata);
if (!Transformlyrics(UtaFormat.Ust))
{
return;
}
FolderBrowserDialog selectFolder = new FolderBrowserDialog();
selectFolder.Description = "Please choose a folder to export ust(s):";
selectFolder.SelectedPath = exportingdata.Files[0].Replace(System.IO.Path.GetFileName(exportingdata.Files[0]), "");
if (selectFolder.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string foldpath = selectFolder.SelectedPath;
string omit = exportingdata.ExportUst(foldpath);
MessageBox.Show(omit + "Ust is successfully exported.", "Export Ust");
}
exportingdata = null;
}
else
{
MessageBox.Show("You have not imported a project.", "Export");
}
}
private void Import(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog
{
Title = "Import",
Filter =
"Project File|*.vsqx;*.ccs;*.ust|VOCALOID Project|*.vsqx|UTAU Project|*.ust|CeVIO Project|*.ccs",
FileName = string.Empty,
FilterIndex = 1,
RestoreDirectory = true,
Multiselect = true
};
DialogResult result = openFileDialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.Cancel)
{
return;
}
List<string> fileNames = new List<string>();
fileNames.AddRange(openFileDialog.FileNames);
maindata = new Data();
Imported = maindata.Import(fileNames);
if (!Imported)
{
MessageBox.Show("The format of this file is not supported.", "Import");
}
}
private void BtnImport_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
BtnImport.Opacity = 0.1;
BtnImport_Cover.Visibility = Visibility.Visible;
}
private void BtnImport_Cover_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
BtnImport.Opacity = 1;
BtnImport_Cover.Visibility = Visibility.Hidden;
}
private void BtnExportCcs_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
BtnExportCcs.Opacity = 0.1;
BtnExportCcs_Cover.Visibility = Visibility.Visible;
}
private void BtnExportUst_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
BtnExportUst.Opacity = 0.1;
BtnExportUst_Cover.Visibility = Visibility.Visible;
}
private void BtnExportVsqx_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
BtnExportVsqx.Opacity = 0.1;
BtnExportVsqx_Cover.Visibility = Visibility.Visible;
}
private void BtnExportVsqx_Cover_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
BtnExportVsqx.Opacity = 1;
BtnExportVsqx_Cover.Visibility = Visibility.Hidden;
}
private void BtnExportUst_Cover_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
BtnExportUst.Opacity = 1;
BtnExportUst_Cover.Visibility = Visibility.Hidden;
}
private void BtnExportCcs_Cover_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
BtnExportCcs.Opacity = 1;
BtnExportCcs_Cover.Visibility = Visibility.Hidden;
}
private void Grid_DragEnter(object sender, System.Windows.DragEventArgs e)
{
Droping.Visibility = Visibility.Visible;
}
private void Grid_DragLeave(object sender, System.Windows.DragEventArgs e)
{
Droping.Visibility = Visibility.Hidden;
}
private void Grid_Drop(object sender, System.Windows.DragEventArgs e)
{
e.Effects = e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop) ?
System.Windows.DragDropEffects.Link : System.Windows.DragDropEffects.None;
string[] dropfiles = e.Data.GetData(System.Windows.DataFormats.FileDrop) as string[];
maindata = new Data();
Imported = maindata.Import(dropfiles?.ToList());
Droping.Visibility = Visibility.Hidden;
if (!Imported)
{
MessageBox.Show("The format of this file is not supported.", "Import");
}
}
bool Transformlyrics(UtaFormat toFormat)
{
ChangeLyrics changelyrics = new ChangeLyrics();
switch (maindata.Lyric.AnalyzedType)
{
case Lyric.LyricType.None:
MessageBox.Show("The type of the lyrics is not detected, please select the correct type by yourself.", "Lyrics Transformation");
changelyrics.RdoRomaCV.IsChecked = true;
break;
case Lyric.LyricType.Romaji_Tandoku:
changelyrics.RdoRomaCV.IsChecked = true;
break;
case Lyric.LyricType.Romaji_Renzoku:
changelyrics.RdoRomaVCV.IsChecked = true;
break;
case Lyric.LyricType.Kana_Tandoku:
changelyrics.RdoKanaCV.IsChecked = true;
break;
case Lyric.LyricType.Kana_Renzoku:
changelyrics.RdoKanaVCV.IsChecked = true;
break;
default:
break;
}
changelyrics.Rdo2KanaCV.IsChecked = true;
switch (toFormat)
{
case UtaFormat.Vsq4:
changelyrics.Rdo2RomaVCV.Visibility = Visibility.Hidden;
changelyrics.Rdo2KanaVCV.Visibility = Visibility.Hidden;
changelyrics.Rdo2KanaCV.Margin = changelyrics.Rdo2RomaVCV.Margin;
break;
case UtaFormat.Ccs:
changelyrics.Rdo2RomaCV.Visibility = Visibility.Hidden;
changelyrics.Rdo2RomaVCV.Visibility = Visibility.Hidden;
changelyrics.Rdo2KanaVCV.Visibility = Visibility.Hidden;
changelyrics.Rdo2KanaCV.Margin = changelyrics.Rdo2RomaCV.Margin;
break;
default:
break;
}
var dialogResult = changelyrics.ShowDialog();
if (dialogResult == true)
{
exportingdata.Lyric.Transform(changelyrics.fromType, changelyrics.ToType);
return true;
}
else
{
return false;
}
}
}
}