Skip to content

Commit 678704c

Browse files
committed
Cleanup some unnecessary UI.
1 parent 29d2027 commit 678704c

17 files changed

+426
-236
lines changed

.editorconfig

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ indent_style = space
1010
indent_size = 4
1111
insert_final_newline = true
1212
charset = utf-8-bom
13+
guidelines = 100
1314
###############################
1415
# .NET Coding Conventions #
1516
###############################

OpenUtau/App.config

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<configSections>
44
</configSections>
55
<startup>
6-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
6+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
77
</startup>
88
</configuration>

OpenUtau/App.xaml.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Diagnostics;
43
using System.Globalization;
54
using System.Linq;
@@ -46,6 +45,10 @@ private static void Main() {
4645
NBug.Settings.StoragePath = NBug.Enums.StoragePath.CurrentDirectory;
4746
NBug.Settings.UIMode = NBug.Enums.UIMode.Full;
4847

48+
var characters = Classic.Character.SearchAndLoadCharacters(Core.Util.Preferences.GetSingerSearchPaths());
49+
50+
Classic.VoicebankInstaller.IndexAllArchive(Core.Util.Preferences.GetSingerSearchPaths());
51+
4952
Core.DocManager.Inst.SearchAllSingers();
5053
var pm = new Core.PartManager();
5154

OpenUtau/Classic/Character.cs

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Text;
5+
using OpenUtau.SimpleHelpers;
6+
using Serilog;
7+
8+
namespace OpenUtau.Classic {
9+
10+
/// <summary>
11+
/// A character. May contains multiple voice banks.
12+
/// </summary>
13+
public class Character {
14+
15+
private Character() {
16+
}
17+
18+
public string Name { private set; get; }
19+
public string DisplayName => Loaded ? Name : $"{Name}[Unloaded]";
20+
public string BasePath { private set; get; }
21+
public string CharacterFile { private set; get; }
22+
public string Author { private set; get; }
23+
public string Website { private set; get; }
24+
public string Language { private set; get; }
25+
public List<Voicebank> Voicebanks { private set; get; }
26+
public bool Loaded { private set; get; }
27+
28+
public static List<Character> SearchAndLoadCharacters(List<string> searchPaths) {
29+
const string CharacterFileName = "character.txt";
30+
var characterFiles = new HashSet<string>();
31+
foreach (var searchPath in searchPaths) {
32+
if (!Directory.Exists(searchPath)) {
33+
continue;
34+
}
35+
var files = Directory.GetFiles(searchPath, CharacterFileName,
36+
SearchOption.AllDirectories);
37+
foreach (var file in files) {
38+
characterFiles.Add(file);
39+
}
40+
}
41+
var result = new List<Character>();
42+
foreach (var file in characterFiles) {
43+
var character = new Character {
44+
BasePath = Path.GetDirectoryName(file),
45+
CharacterFile = file,
46+
};
47+
character.LoadVoicebanks();
48+
result.Add(character);
49+
}
50+
return result;
51+
}
52+
53+
public void LoadVoicebanks() {
54+
const string OtoFileName = "oto.ini";
55+
var otoFiles = Directory.GetFiles(BasePath, OtoFileName, SearchOption.AllDirectories);
56+
var voicebanks = new List<Voicebank>();
57+
foreach (var otoFile in otoFiles) {
58+
try {
59+
var voicebank = new Voicebank.Builder(otoFile)
60+
.SetOtoEncoding(FileEncoding.DetectFileEncoding(
61+
otoFile, Encoding.GetEncoding("shift_jis")))
62+
.SetPathEncoding(Encoding.Default)
63+
.Build();
64+
voicebanks.Add(voicebank);
65+
} catch (Exception e) {
66+
Log.Error(e, "Failed to load {0}", otoFile);
67+
}
68+
}
69+
Log.Information("Loaded {0} voicebanks from character {1}", voicebanks.Count, BasePath);
70+
Voicebanks = voicebanks;
71+
Loaded = true;
72+
}
73+
}
74+
}

OpenUtau/Classic/Oto.cs

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System.Linq;
2+
3+
namespace OpenUtau.Classic {
4+
5+
/// <summary>
6+
/// A sound in a voice bank. Corresponds to one line in oto.ini file.
7+
/// </summary>
8+
public class Oto {
9+
public string AudioFile;
10+
public string Alias;
11+
public int Offset;
12+
public int Consonant;
13+
public int Cutoff;
14+
public int Preutter;
15+
public int Overlap;
16+
17+
public static Oto Parse(string line) {
18+
if (!line.Contains('=')) {
19+
return null;
20+
}
21+
var parts = line.Split('=');
22+
if (parts.Length != 2) {
23+
return null;
24+
}
25+
var audioClip = parts[0].Trim();
26+
parts = parts[1].Split(',');
27+
if (parts.Length != 6) {
28+
return null;
29+
}
30+
var result = new Oto {
31+
AudioFile = audioClip,
32+
Alias = parts[0].Trim()
33+
};
34+
int.TryParse(parts[1], out result.Offset);
35+
int.TryParse(parts[2], out result.Consonant);
36+
int.TryParse(parts[3], out result.Cutoff);
37+
int.TryParse(parts[4], out result.Preutter);
38+
int.TryParse(parts[5], out result.Overlap);
39+
return result;
40+
}
41+
42+
public override string ToString() {
43+
return Alias;
44+
}
45+
}
46+
}

OpenUtau/Classic/VoiceBank.cs

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using System.Text;
4+
using Serilog;
5+
6+
namespace OpenUtau.Classic {
7+
8+
/// <summary>
9+
/// A sound bank. Corresponds to a single oto.ini file.
10+
/// </summary>
11+
public class Voicebank {
12+
13+
private Voicebank() {
14+
}
15+
16+
public string BasePath { private set; get; }
17+
public string OtoFile { private set; get; }
18+
public List<Oto> OtoList { private set; get; }
19+
public Encoding OtoEncoding { private set; get; }
20+
public Encoding PathEncoding { private set; get; }
21+
22+
public class Builder {
23+
private readonly Voicebank voicebank;
24+
private readonly byte[] otoBytes;
25+
private int audioFilesFound;
26+
27+
public Builder(string otoFile) {
28+
otoBytes = File.ReadAllBytes(otoFile);
29+
voicebank = new Voicebank() {
30+
OtoFile = otoFile,
31+
BasePath = Path.GetDirectoryName(otoFile),
32+
PathEncoding = Encoding.Default,
33+
};
34+
}
35+
36+
public string TestOtoEncoding(Encoding encoding) {
37+
return encoding.GetString(otoBytes);
38+
}
39+
40+
public Builder SetOtoEncoding(Encoding encoding) {
41+
voicebank.OtoEncoding = encoding;
42+
var lines = new List<string>();
43+
using (var stream = new StreamReader(new MemoryStream(otoBytes), encoding)) {
44+
while (!stream.EndOfStream) {
45+
lines.Add(stream.ReadLine());
46+
}
47+
}
48+
var otoList = new List<Oto>();
49+
foreach (var line in lines) {
50+
var oto = Oto.Parse(line);
51+
if (oto != null) {
52+
otoList.Add(oto);
53+
}
54+
}
55+
voicebank.OtoList = otoList;
56+
return this;
57+
}
58+
59+
public double TestPathEncoding(Encoding encoding) {
60+
if (voicebank.OtoList == null) {
61+
return 0;
62+
}
63+
if (voicebank.OtoList.Count == 0) {
64+
return 1;
65+
}
66+
audioFilesFound = 0;
67+
foreach (var oto in voicebank.OtoList) {
68+
try {
69+
var file = encoding.GetString(voicebank.OtoEncoding.GetBytes(oto.AudioFile));
70+
if (File.Exists(Path.Combine(voicebank.BasePath, file))) {
71+
audioFilesFound++;
72+
}
73+
} catch { }
74+
}
75+
return (double)audioFilesFound / voicebank.OtoList.Count;
76+
}
77+
78+
public Builder SetPathEncoding(Encoding encoding) {
79+
voicebank.PathEncoding = encoding;
80+
return this;
81+
}
82+
83+
public Voicebank Build() {
84+
var score = TestPathEncoding(voicebank.PathEncoding);
85+
Log.Information("Loaded {0} otos and {1:F2}% audio files from {2}",
86+
voicebank.OtoList.Count, score * 100, voicebank.OtoFile);
87+
return voicebank;
88+
}
89+
}
90+
}
91+
}
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using System.IO.Compression;
4+
using System.Text;
5+
using Serilog;
6+
7+
namespace OpenUtau.Classic {
8+
9+
internal class VoicebankInstaller {
10+
11+
public static void IndexAllArchive(IEnumerable<string> searchPaths) {
12+
foreach (var path in searchPaths) {
13+
if (Directory.Exists(path)) {
14+
var zips = Directory.GetFiles(path, "*.zip", SearchOption.AllDirectories);
15+
foreach (var zip in zips) {
16+
Log.Information($"{zip}");
17+
IndexArchive(zip);
18+
}
19+
}
20+
}
21+
}
22+
23+
public static void IndexArchive(string path) {
24+
using (var stream = new FileStream(path, FileMode.Open)) {
25+
using (var archive = new ZipArchive(stream, ZipArchiveMode.Read, false, Encoding.GetEncoding("shift_jis"))) {
26+
foreach (var entry in archive.Entries) {
27+
if (entry.Name == "character.txt" || entry.Name == "oto.ini") {
28+
Log.Information($"{entry.Name} {entry.FullName}");
29+
}
30+
}
31+
}
32+
}
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)