Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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