Skip to content

Commit

Permalink
Merge pull request #941 from maiko3tattun/1123_FasterStartup
Browse files Browse the repository at this point in the history
Faster startup
  • Loading branch information
stakira authored Nov 25, 2023
2 parents 01f1728 + 2471065 commit a5db9c7
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions OpenUtau.Core/Classic/VoicebankLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,10 @@ public IEnumerable<Voicebank> SearchAll() {

public static void LoadVoicebank(Voicebank voicebank) {
LoadInfo(voicebank, voicebank.File, voicebank.BasePath);
LoadSubbanks(voicebank);
LoadOtoSets(voicebank, Path.GetDirectoryName(voicebank.File));
}

public static void LoadOtoSets(Voicebank voicebank, string dirPath) {
var otoFile = Path.Combine(dirPath, kOtoIni);
if (File.Exists(otoFile)) {
var otoSet = ParseOtoSet(otoFile, voicebank.TextFileEncoding);
var voicebankDir = Path.GetDirectoryName(voicebank.File);
otoSet.Name = Path.GetRelativePath(voicebankDir, dirPath);
if (otoSet.Name == ".") {
otoSet.Name = string.Empty;
}
voicebank.OtoSets.Add(otoSet);
}
var dirs = Directory.GetDirectories(dirPath);
foreach (var dir in dirs) {
LoadOtoSets(voicebank, dir);
}
}

public static void LoadInfo(Voicebank voicebank, string filePath, string basePath) {
var dir = Path.GetDirectoryName(filePath);
var yamlFile = Path.Combine(dir, kCharYaml);
Expand Down Expand Up @@ -126,14 +110,6 @@ public static void LoadInfo(Voicebank voicebank, string filePath, string basePat
if (bankConfig != null) {
ApplyConfig(voicebank, bankConfig);
}
if (voicebank.Subbanks.Count == 0) {
LoadPrefixMap(voicebank);
}
if (voicebank.Subbanks.Count == 0) {
voicebank.Subbanks.Add(new Subbank() {
ToneRanges = new string[0],
});
}
}

public static void ParseCharacterTxt(Voicebank voicebank, Stream stream, string filePath, string basePath, Encoding encoding) {
Expand Down Expand Up @@ -230,6 +206,17 @@ public static void ApplyConfig(Voicebank bank, VoicebankConfig bankConfig) {
}
}

public static void LoadSubbanks(Voicebank voicebank) {
if (voicebank.Subbanks.Count == 0) {
LoadPrefixMap(voicebank);
}
if (voicebank.Subbanks.Count == 0) {
voicebank.Subbanks.Add(new Subbank() {
ToneRanges = new string[0],
});
}
}

public static void LoadPrefixMap(Voicebank voicebank) {
var dir = Path.GetDirectoryName(voicebank.File);
var filePath = Path.Combine(dir, "prefix.map");
Expand Down Expand Up @@ -304,6 +291,23 @@ public static Dictionary<Tuple<string, string>, SortedSet<int>> ParsePrefixMap(S
}
}

public static void LoadOtoSets(Voicebank voicebank, string dirPath) {
var otoFile = Path.Combine(dirPath, kOtoIni);
if (File.Exists(otoFile)) {
var otoSet = ParseOtoSet(otoFile, voicebank.TextFileEncoding);
var voicebankDir = Path.GetDirectoryName(voicebank.File);
otoSet.Name = Path.GetRelativePath(voicebankDir, dirPath);
if (otoSet.Name == ".") {
otoSet.Name = string.Empty;
}
voicebank.OtoSets.Add(otoSet);
}
var dirs = Directory.GetDirectories(dirPath);
foreach (var dir in dirs) {
LoadOtoSets(voicebank, dir);
}
}

public static OtoSet ParseOtoSet(string filePath, Encoding encoding) {
try {
using (var stream = File.OpenRead(filePath)) {
Expand Down

0 comments on commit a5db9c7

Please sign in to comment.