Skip to content

Commit a52c64d

Browse files
committed
add select singer type step to install
1 parent 391d336 commit a52c64d

File tree

6 files changed

+88
-170
lines changed

6 files changed

+88
-170
lines changed

OpenUtau.Core/Classic/VoicebankConfig.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
using System.Collections.Generic;
2-
using System.IO;
3-
using System.Linq;
1+
using System.IO;
42
using System.Text;
53
using OpenUtau.Core;
6-
using YamlDotNet.Serialization;
74

85
namespace OpenUtau.Classic {
96
public enum SymbolSetPreset { unknown, hiragana, arpabet }
@@ -39,6 +36,7 @@ public class Subbank {
3936

4037
public class VoicebankConfig {
4138
public string Name;
39+
public string SingerType;
4240
public string TextFileEncoding;
4341
public string Image;
4442
public string Portrait;

OpenUtau.Core/Classic/VoicebankInstaller.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public VoicebankInstaller(string basePath, Action<double, string> progress, Enco
2828
this.textEncoding = textEncoding ?? Encoding.GetEncoding("shift_jis");
2929
}
3030

31-
public void LoadArchive(string path) {
31+
public void Install(string path, string singerType) {
3232
progress.Invoke(0, "Analyzing archive...");
3333
var readerOptions = new ReaderOptions {
3434
ArchiveEncoding = new ArchiveEncoding {
@@ -57,11 +57,24 @@ public void LoadArchive(string path) {
5757
if (!hasCharacterYaml && filePath.EndsWith(kCharacterTxt)) {
5858
var config = new VoicebankConfig() {
5959
TextFileEncoding = textEncoding.WebName,
60+
SingerType = singerType,
6061
};
6162
using (var stream = File.Open(filePath.Replace(".txt", ".yaml"), FileMode.Create)) {
6263
config.Save(stream);
6364
}
6465
}
66+
if (hasCharacterYaml && filePath.EndsWith(kCharacterYaml)) {
67+
VoicebankConfig? config = null;
68+
using (var stream = File.Open(filePath, FileMode.Open)) {
69+
config = VoicebankConfig.Load(stream);
70+
}
71+
if (string.IsNullOrEmpty(config.SingerType)) {
72+
config.SingerType = singerType;
73+
using (var stream = File.Open(filePath, FileMode.Open)) {
74+
config.Save(stream);
75+
}
76+
}
77+
}
6578
}
6679
}
6780
foreach (var touch in touches) {

OpenUtau.Core/Classic/VoicebankLoader.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static void LoadOtoSets(Voicebank voicebank, string dirPath) {
8282
public static void LoadInfo(Voicebank voicebank, string filePath, string basePath) {
8383
var dir = Path.GetDirectoryName(filePath);
8484
var yamlFile = Path.Combine(dir, kCharYaml);
85-
VoicebankConfig bankConfig = null;
85+
VoicebankConfig? bankConfig = null;
8686
if (File.Exists(yamlFile)) {
8787
try {
8888
using (var stream = File.OpenRead(yamlFile)) {
@@ -92,18 +92,22 @@ public static void LoadInfo(Voicebank voicebank, string filePath, string basePat
9292
Log.Error(e, $"Failed to load yaml {yamlFile}");
9393
}
9494
}
95-
string[] modelPaths = new string[] { dir, dir + @"\model" };
96-
foreach (string modelPath in modelPaths) {
97-
if (File.Exists(Path.Join(modelPath, kConfigYaml))) {
95+
switch (bankConfig?.SingerType) {
96+
case "utau":
97+
voicebank.SingerType = USingerType.Classic;
98+
break;
99+
case "enunu":
98100
voicebank.SingerType = USingerType.Enunu;
99-
}
100-
}
101-
var enuconfigFile = Path.Combine(dir, kEnuconfigYaml);
102-
if (File.Exists(enuconfigFile)) {
103-
voicebank.SingerType = USingerType.Enunu;
104-
}else if(voicebank.SingerType != USingerType.Enunu)
105-
{
106-
voicebank.SingerType = USingerType.Classic;
101+
break;
102+
default:
103+
// Legacy detection code. Do not add more here.
104+
var enuconfigFile = Path.Combine(dir, kEnuconfigYaml);
105+
if (File.Exists(enuconfigFile)) {
106+
voicebank.SingerType = USingerType.Enunu;
107+
} else if (voicebank.SingerType != USingerType.Enunu) {
108+
voicebank.SingerType = USingerType.Classic;
109+
}
110+
break;
107111
}
108112
Encoding encoding = Encoding.GetEncoding("shift_jis");
109113
if (!string.IsNullOrEmpty(bankConfig?.TextFileEncoding)) {
@@ -125,8 +129,6 @@ public static void LoadInfo(Voicebank voicebank, string filePath, string basePat
125129
}
126130
}
127131

128-
129-
130132
public static void ParseCharacterTxt(Voicebank voicebank, Stream stream, string filePath, string basePath, Encoding encoding) {
131133
using (var reader = new StreamReader(stream, encoding)) {
132134
voicebank.BasePath = basePath;

OpenUtau/Strings/Strings.axaml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,18 @@
7070
<system:String x:Key="lyrics.reset">Reset</system:String>
7171
<system:String x:Key="lyrics.selectnotes">Select some notes first!</system:String>
7272
<system:String x:Key="lyrics.separators">Separators</system:String>
73+
7374
<system:String x:Key="lyricsreplace.after">After :</system:String>
7475
<system:String x:Key="lyricsreplace.before">Before :</system:String>
75-
<system:String x:Key="lyricsreplace.presets">Presets</system:String>
76-
<system:String x:Key="lyricsreplace.preview">Preview</system:String>
77-
<system:String x:Key="lyricsreplace.regex">Regular expressions can be used</system:String>
78-
<system:String x:Key="lyricsreplace.replace">General lyrics replacement</system:String>
7976
<system:String x:Key="lyricsreplace.preset.rmvalphabet">Remove alphabet</system:String>
8077
<system:String x:Key="lyricsreplace.preset.rmvnonhiragana">Remove non-hiragana</system:String>
8178
<system:String x:Key="lyricsreplace.preset.rmvphonetichint">Remove phonetic hint</system:String>
82-
<system:String x:Key="lyricsreplace.preset.rmvtone">Remove tone suffix</system:String>
8379
<system:String x:Key="lyricsreplace.preset.rmvspace">Remove spaces and earlier</system:String>
80+
<system:String x:Key="lyricsreplace.preset.rmvtone">Remove tone suffix</system:String>
81+
<system:String x:Key="lyricsreplace.presets">Presets</system:String>
82+
<system:String x:Key="lyricsreplace.preview">Preview</system:String>
83+
<system:String x:Key="lyricsreplace.regex">Regular expressions can be used</system:String>
84+
<system:String x:Key="lyricsreplace.replace">General lyrics replacement</system:String>
8485

8586
<system:String x:Key="menu.edit">Edit</system:String>
8687
<system:String x:Key="menu.edit.copy">Copy</system:String>
@@ -188,8 +189,8 @@ Warning: this option removes custom presets.</system:String>
188189
<system:String x:Key="pianoroll.menu.lyrics.hanzitopinyin">Hanzi to Pinyin</system:String>
189190
<system:String x:Key="pianoroll.menu.lyrics.hiraganatoromaji">Hiragana to Romaji</system:String>
190191
<system:String x:Key="pianoroll.menu.lyrics.javcvtocv">Japanese VCV to CV</system:String>
191-
<system:String x:Key="pianoroll.menu.lyrics.removelettersuffix">Remove Letter Suffix</system:String>
192192
<system:String x:Key="pianoroll.menu.lyrics.movesuffixtovoicecolor">Move Suffix to VoiceColor</system:String>
193+
<system:String x:Key="pianoroll.menu.lyrics.removelettersuffix">Remove Letter Suffix</system:String>
193194
<system:String x:Key="pianoroll.menu.lyrics.removephonetichint">Remove Phonetic Hint</system:String>
194195
<system:String x:Key="pianoroll.menu.lyrics.removetonesuffix">Remove Tone Suffix</system:String>
195196
<system:String x:Key="pianoroll.menu.lyrics.romajitohiragana">Romaji to Hiragana</system:String>
@@ -279,8 +280,8 @@ Hold Ctrl to select</system:String>
279280
<system:String x:Key="prefs.playback.lockstarttime.on">Move cursor back to where you started playing</system:String>
280281
<system:String x:Key="prefs.playback.test">Test</system:String>
281282
<system:String x:Key="prefs.rendering">Rendering</system:String>
282-
<system:String x:Key="prefs.rendering.onnxrunner">Machine Learning Runner</system:String>
283283
<system:String x:Key="prefs.rendering.onnxgpu">GPU</system:String>
284+
<system:String x:Key="prefs.rendering.onnxrunner">Machine Learning Runner</system:String>
284285
<system:String x:Key="prefs.rendering.phasecomp">Phase Compensation</system:String>
285286
<system:String x:Key="prefs.rendering.prerender">Pre-render</system:String>
286287
<system:String x:Key="prefs.rendering.resampler">Resampler</system:String>
@@ -299,9 +300,9 @@ Hold Ctrl to select</system:String>
299300
<system:String x:Key="prefs.rendering.threads.numthreads">Maximum Render Threads</system:String>
300301
<system:String x:Key="prefs.rendering.wavtool">Wavtool</system:String>
301302

303+
<system:String x:Key="progress.loadingsingers">Loading Singers...</system:String>
302304
<system:String x:Key="progress.saved">Project saved. {0}</system:String>
303305
<system:String x:Key="progress.waitingrendering">Waiting Rendering</system:String>
304-
<system:String x:Key="progress.loadingsingers">Loading Singers...</system:String>
305306

306307
<system:String x:Key="singers.caption">Singers</system:String>
307308
<system:String x:Key="singers.editoto.editinvlabeler">Edit In vLabeler</system:String>
@@ -341,6 +342,16 @@ Hold Ctrl to select</system:String>
341342
<system:String x:Key="singers.subbanks.toneranges">Tone Ranges</system:String>
342343
<system:String x:Key="singers.visitwebsite">Visit Website</system:String>
343344

345+
<system:String x:Key="singersetup.archivefileencoding">Archive File Encoding</system:String>
346+
<system:String x:Key="singersetup.archivefileencoding.prompt">Choose an encoding that make file names look right.</system:String>
347+
<system:String x:Key="singersetup.back">Back</system:String>
348+
<system:String x:Key="singersetup.install">Install</system:String>
349+
<system:String x:Key="singersetup.next">Next</system:String>
350+
<system:String x:Key="singersetup.singertype">Singer Type</system:String>
351+
<system:String x:Key="singersetup.singertype.prompt">Select the type of singer.</system:String>
352+
<system:String x:Key="singersetup.textfileencoding">Text File Encoding</system:String>
353+
<system:String x:Key="singersetup.textfileencoding.prompt">Choose an encoding that make file contents look right.</system:String>
354+
344355
<system:String x:Key="tip.aliasbox">Override Alias</system:String>
345356
<system:String x:Key="tip.exps">
346357
Left Button Draw: Set expressions

OpenUtau/ViewModels/SingerSetupViewModel.cs

Lines changed: 12 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -32,41 +32,27 @@ public Encoding TextEncoding {
3232
get => textEncoding;
3333
set => this.RaiseAndSetIfChanged(ref textEncoding, value);
3434
}
35-
public bool CanInstall {
36-
get => canInstall;
37-
set => this.RaiseAndSetIfChanged(ref canInstall, value);
38-
}
39-
public bool CreateRootDirectory {
40-
get => createRootDirectory;
41-
set => this.RaiseAndSetIfChanged(ref createRootDirectory, value);
42-
}
43-
public bool CreateCharacterTxt {
44-
get => createCharacterTxt;
45-
set => this.RaiseAndSetIfChanged(ref createCharacterTxt, value);
46-
}
47-
public string CreateRootDirectoryName {
48-
get => createRootDirectoryName;
49-
set => this.RaiseAndSetIfChanged(ref createRootDirectoryName, value);
50-
}
51-
public string CreateCharacterTxtName {
52-
get => createCharacterTxtName;
53-
set => this.RaiseAndSetIfChanged(ref createCharacterTxtName, value);
35+
public string[] SingerTypes => singerTypes;
36+
public string SingerType {
37+
get => singerType;
38+
set => this.RaiseAndSetIfChanged(ref singerType, value);
5439
}
5540

5641
private int step;
42+
private string[] singerTypes;
43+
private string singerType;
5744
private ObservableCollectionExtended<string> textItems;
5845
private string archiveFilePath;
5946
private Encoding[] encodings;
6047
private Encoding archiveEncoding;
6148
private Encoding textEncoding;
6249

63-
private bool canInstall;
64-
private bool createRootDirectory;
65-
private bool createCharacterTxt;
66-
private string createRootDirectoryName = string.Empty;
67-
private string createCharacterTxtName = string.Empty;
68-
6950
public SingerSetupViewModel() {
51+
#if DEBUG
52+
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
53+
#endif
54+
singerTypes = new[] { "utau", "enunu" };
55+
singerType = singerTypes[0];
7056
archiveFilePath = string.Empty;
7157
encodings = new Encoding[] {
7258
Encoding.GetEncoding("shift_jis"),
@@ -82,20 +68,10 @@ public SingerSetupViewModel() {
8268
textEncoding = encodings[0];
8369
textItems = new ObservableCollectionExtended<string>();
8470

85-
this.WhenAnyValue(vm => vm.Step)
86-
.Subscribe(_ => OnStep());
8771
this.WhenAnyValue(vm => vm.Step, vm => vm.ArchiveEncoding, vm => vm.ArchiveFilePath)
8872
.Subscribe(_ => RefreshArchiveItems());
8973
this.WhenAnyValue(vm => vm.Step, vm => vm.TextEncoding)
9074
.Subscribe(_ => RefreshTextItems());
91-
this.WhenAnyValue(
92-
vm => vm.CreateRootDirectory,
93-
vm => vm.CreateRootDirectoryName,
94-
vm => vm.CreateCharacterTxt,
95-
vm => vm.CreateCharacterTxtName)
96-
.Subscribe(_ => CanInstall =
97-
(!CreateRootDirectory || !string.IsNullOrWhiteSpace(CreateRootDirectoryName)) &&
98-
(!CreateCharacterTxt || !string.IsNullOrWhiteSpace(CreateCharacterTxtName)));
9975
}
10076

10177
public void Back() {
@@ -166,72 +142,6 @@ public Character(string file) {
166142
}
167143
}
168144

169-
private void OnStep() {
170-
if (Step == 2) {
171-
BuildTree();
172-
}
173-
}
174-
175-
private void BuildTree() {
176-
var readerOptions = new ReaderOptions {
177-
ArchiveEncoding = new ArchiveEncoding(ArchiveEncoding, ArchiveEncoding),
178-
};
179-
using var archive = ArchiveFactory.Open(ArchiveFilePath, readerOptions);
180-
var banks = archive.Entries
181-
.Where(entry => !entry.IsDirectory && Path.GetFileName(entry.Key) == "character.txt")
182-
.OrderByDescending(bank => bank.Key.Length)
183-
.Select(bank => new Character(bank.Key))
184-
.ToList();
185-
var otoSets = archive.Entries
186-
.Where(entry => !entry.IsDirectory && Path.GetFileName(entry.Key) == "oto.ini")
187-
.ToArray();
188-
var prefixMaps = archive.Entries
189-
.Where(entry => !entry.IsDirectory && Path.GetFileName(entry.Key) == "prefix.map")
190-
.ToArray();
191-
var bankDirs = banks
192-
.Select(bank => Path.GetDirectoryName(bank.file)!)
193-
.ToArray();
194-
var unknownBank = new Character("(Unknown)");
195-
foreach (var otoSet in otoSets) {
196-
var dir = Path.GetDirectoryName(otoSet.Key);
197-
if (dir == null) {
198-
continue;
199-
}
200-
bool foundBank = false;
201-
for (int i = 0; i < bankDirs.Length; ++i) {
202-
if (dir.StartsWith(bankDirs[i])) {
203-
string relPath = Path.GetRelativePath(bankDirs[i], dir);
204-
if (relPath == ".") {
205-
relPath = string.Empty;
206-
}
207-
banks[i].otoSets.Add(otoSet.Key);
208-
foundBank = true;
209-
break;
210-
}
211-
}
212-
if (!foundBank) {
213-
unknownBank.otoSets.Add(otoSet.Key);
214-
}
215-
}
216-
textItems.Clear();
217-
foreach (var bank in banks) {
218-
textItems.Add($"{bank.file}");
219-
textItems.AddRange(bank.otoSets.Select(set => $" | {set}"));
220-
}
221-
222-
if (unknownBank.otoSets.Count > 0) {
223-
CreateCharacterTxt = true;
224-
banks.Add(unknownBank);
225-
}
226-
227-
List<string> dirs = banks.Select(b => Path.GetDirectoryName(b.file)).OfType<string>().ToList();
228-
dirs.AddRange(otoSets.Select(set => Path.GetDirectoryName(set.Key)).OfType<string>());
229-
string? root = dirs.OrderBy(dir => dir.Length).FirstOrDefault();
230-
if (string.IsNullOrEmpty(root) || root == ".") {
231-
CreateRootDirectory = true;
232-
}
233-
}
234-
235145
public Task Install() {
236146
string archiveFilePath = ArchiveFilePath;
237147
var archiveEncoding = ArchiveEncoding;
@@ -242,7 +152,7 @@ public Task Install() {
242152
var installer = new Classic.VoicebankInstaller(basePath, (progress, info) => {
243153
DocManager.Inst.ExecuteCmd(new ProgressBarNotification(progress, info));
244154
}, archiveEncoding, textEncoding);
245-
installer.LoadArchive(archiveFilePath);
155+
installer.Install(archiveFilePath, SingerType);
246156
} finally {
247157
new Task(() => {
248158
DocManager.Inst.ExecuteCmd(new ProgressBarNotification(0, ""));

0 commit comments

Comments
 (0)