Skip to content

Commit

Permalink
Add option to load only top directories of singers
Browse files Browse the repository at this point in the history
  • Loading branch information
maiko3tattun committed Jan 13, 2024
1 parent d432a1f commit d5d8faf
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 14 deletions.
6 changes: 1 addition & 5 deletions OpenUtau.Core/Classic/ClassicSingerLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ static USinger AdjustSingerType(Voicebank v) {
}
public static IEnumerable<USinger> FindAllSingers() {
List<USinger> singers = new List<USinger>();
foreach (var path in new string[] {
PathManager.Inst.SingersPathOld,
PathManager.Inst.SingersPath,
PathManager.Inst.AdditionalSingersPath,
}) {
foreach (var path in PathManager.Inst.SingersPaths) {
var loader = new VoicebankLoader(path);
singers.AddRange(loader.SearchAll()
.Select(AdjustSingerType));
Expand Down
11 changes: 10 additions & 1 deletion OpenUtau.Core/Classic/VoicebankLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text;
using OpenUtau.Core;
using OpenUtau.Core.Ustx;
using OpenUtau.Core.Util;
using Serilog;

namespace OpenUtau.Classic {
Expand Down Expand Up @@ -45,7 +46,15 @@ public IEnumerable<Voicebank> SearchAll() {
if (!Directory.Exists(basePath)) {
return result;
}
result.AddRange(Directory.EnumerateFiles(basePath, kCharTxt, SearchOption.AllDirectories)
IEnumerable<string> files;
if (Preferences.Default.LoadDeepFolderSinger) {
files = Directory.EnumerateFiles(basePath, kCharTxt, SearchOption.AllDirectories);
} else {
// TopDirectoryOnly
files = Directory.GetDirectories(basePath)
.SelectMany(path => Directory.EnumerateFiles(path, kCharTxt));
}
result.AddRange(files
.Select(filePath => {
try {
var voicebank = new Voicebank();
Expand Down
3 changes: 2 additions & 1 deletion OpenUtau.Core/SingerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public void SearchAllSingers() {
Directory.CreateDirectory(PathManager.Inst.SingersPath);
var stopWatch = Stopwatch.StartNew();
var singers = ClassicSingerLoader.FindAllSingers()
.Concat(Vogen.VogenSingerLoader.FindAllSingers());
.Concat(Vogen.VogenSingerLoader.FindAllSingers())
.Distinct();
Singers = singers
.ToLookup(s => s.Id)
.ToDictionary(g => g.Key, g => g.First());
Expand Down
12 changes: 11 additions & 1 deletion OpenUtau.Core/Ustx/USinger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private static void AddToneRange(string range, SortedSet<int> set) {

[Flags] public enum USingerType { Classic = 0x1, Enunu = 0x2, Vogen = 0x4, DiffSinger=0x5 }

public class USinger : INotifyPropertyChanged {
public class USinger : INotifyPropertyChanged, IEquatable<USinger> {
protected static readonly List<UOto> emptyOtos = new List<UOto>();

public virtual string Id { get; }
Expand Down Expand Up @@ -268,6 +268,16 @@ public virtual bool TryGetMappedOto(string phoneme, int tone, string color, out
public virtual byte[] LoadPortrait() => null;
public virtual byte[] LoadSample() => null;
public override string ToString() => Name;
public bool Equals(USinger other) {
// Tentative: Since only the singer's Id is recorded in ustx and preferences, singers with the same Id are considered identical.
// Singer with the same directory name in different locations may be identical.
if (other != null && other.Id == this.Id) {
return true;
} else {
return false;
}
}
public override int GetHashCode() => Id.GetHashCode();

public static USinger CreateMissing(string name) {
return new USinger() {
Expand Down
14 changes: 14 additions & 0 deletions OpenUtau.Core/Util/PathManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
Expand Down Expand Up @@ -85,6 +86,19 @@ public PathManager() {
public string NotePresetsFilePath => Path.Combine(DataPath, "notepresets.json");
public string BackupsPath => Path.Combine(DataPath, "Backups");

public List<string> SingersPaths {
get {
var list = new List<string> { SingersPath };
if (Directory.Exists(SingersPathOld)) {
list.Add(SingersPathOld);
}
if (Directory.Exists(AdditionalSingersPath)) {
list.Add(AdditionalSingersPath);
}
return list.Distinct().ToList();
}
}

Regex invalid = new Regex("[\\x00-\\x1f<>:\"/\\\\|?*]|^(CON|PRN|AUX|NUL|COM[0-9]|LPT[0-9]|CLOCK\\$)(\\.|$)|[\\.]$", RegexOptions.IgnoreCase);

public string GetPartSavePath(string exportPath, string partName, int partNo) {
Expand Down
1 change: 1 addition & 0 deletions OpenUtau.Core/Util/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public class SerializablePreferences {
public string SkipUpdate = string.Empty;
public string AdditionalSingerPath = string.Empty;
public bool InstallToAdditionalSingersPath = true;
public bool LoadDeepFolderSinger = true;
public bool PreferCommaSeparator = false;
public bool ResamplerLogging = false;
public List<string> RecentSingers = new List<string>();
Expand Down
16 changes: 10 additions & 6 deletions OpenUtau.Core/Vogen/VogenSingerLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ class VogenSingerLoader {

public static IEnumerable<USinger> FindAllSingers() {
List<USinger> singers = new List<USinger>();
foreach (var path in new string[] {
PathManager.Inst.SingersPathOld,
PathManager.Inst.SingersPath,
PathManager.Inst.AdditionalSingersPath,
}) {
foreach (var path in PathManager.Inst.SingersPaths) {
var loader = new VogenSingerLoader(path);
singers.AddRange(loader.SearchAll());
}
Expand All @@ -50,7 +46,15 @@ public IEnumerable<USinger> SearchAll() {
if (!Directory.Exists(basePath)) {
return result;
}
result.AddRange(Directory.EnumerateFiles(basePath, "*.vogeon", SearchOption.AllDirectories)
IEnumerable<string> files;
if (Preferences.Default.LoadDeepFolderSinger) {
files = Directory.EnumerateFiles(basePath, "*.vogeon", SearchOption.AllDirectories);
} else {
// TopDirectoryOnly
files = Directory.GetDirectories(basePath)
.SelectMany(path => Directory.EnumerateFiles(path, "*.vogeon"));
}
result.AddRange(files
.Select(filePath => {
try {
return LoadSinger(filePath);
Expand Down
1 change: 1 addition & 0 deletions OpenUtau/Strings/Strings.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ Warning: this option removes custom presets.</system:String>
<system:String x:Key="prefs.paths">Paths</system:String>
<system:String x:Key="prefs.paths.addlsinger">Additional Singer Path</system:String>
<system:String x:Key="prefs.paths.addlsinger.install">Install to Additional Singer Path</system:String>
<system:String x:Key="prefs.paths.loaddeepfolders">Load all depth folders</system:String>
<system:String x:Key="prefs.paths.reset">Reset</system:String>
<system:String x:Key="prefs.paths.select">Select</system:String>
<system:String x:Key="prefs.playback">Playback</system:String>
Expand Down
1 change: 1 addition & 0 deletions OpenUtau/Strings/Strings.ja-JP.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@
<system:String x:Key="prefs.paths">ファイルの場所</system:String>
<system:String x:Key="prefs.paths.addlsinger">シンガーの場所(追加)</system:String>
<system:String x:Key="prefs.paths.addlsinger.install">シンガーの場所(追加)にインストール</system:String>
<system:String x:Key="prefs.paths.loaddeepfolders">深い階層のフォルダも読み込む</system:String>
<system:String x:Key="prefs.paths.reset">リセット</system:String>
<system:String x:Key="prefs.paths.select">選択</system:String>
<system:String x:Key="prefs.playback">再生</system:String>
Expand Down
7 changes: 7 additions & 0 deletions OpenUtau/ViewModels/PreferencesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public AudioOutputDevice? AudioOutputDevice {
[Reactive] public int LockStartTime { get; set; }
public string AdditionalSingersPath => !string.IsNullOrWhiteSpace(PathManager.Inst.AdditionalSingersPath)? PathManager.Inst.AdditionalSingersPath : "(None)";
[Reactive] public bool InstallToAdditionalSingersPath { get; set; }
[Reactive] public bool LoadDeepFolders { get; set; }
[Reactive] public bool PreRender { get; set; }
public List<string> DefaultRendererOptions { get; set; }
[Reactive] public string DefaultRenderer { get; set; }
Expand Down Expand Up @@ -111,6 +112,7 @@ public PreferencesViewModel() {
PlayPosMarkerMargin = Preferences.Default.PlayPosMarkerMargin;
LockStartTime = Preferences.Default.LockStartTime;
InstallToAdditionalSingersPath = Preferences.Default.InstallToAdditionalSingersPath;
LoadDeepFolders = Preferences.Default.LoadDeepFolderSinger;
ToolsManager.Inst.Initialize();
var pattern = new Regex(@"Strings\.([\w-]+)\.axaml");
Languages = App.GetLanguages().Keys
Expand Down Expand Up @@ -189,6 +191,11 @@ public PreferencesViewModel() {
Preferences.Default.InstallToAdditionalSingersPath = additionalSingersPath;
Preferences.Save();
});
this.WhenAnyValue(vm => vm.LoadDeepFolders)
.Subscribe(loadDeepFolders => {
Preferences.Default.LoadDeepFolderSinger = loadDeepFolders;
Preferences.Save();
});
this.WhenAnyValue(vm => vm.PreRender)
.Subscribe(preRender => {
Preferences.Default.PreRender = preRender;
Expand Down
4 changes: 4 additions & 0 deletions OpenUtau/Views/PreferencesDialog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@
<TextBlock Text="{DynamicResource prefs.paths.addlsinger.install}" HorizontalAlignment="Left"/>
<ToggleSwitch IsChecked="{Binding InstallToAdditionalSingersPath}"/>
</Grid>
<Grid>
<TextBlock Text="{DynamicResource prefs.paths.loaddeepfolders}" HorizontalAlignment="Left"/>
<ToggleSwitch IsChecked="{Binding LoadDeepFolders}"/>
</Grid>
</StackPanel>
</HeaderedContentControl>
<HeaderedContentControl Classes="groupbox" Header="{DynamicResource prefs.cache}">
Expand Down

0 comments on commit d5d8faf

Please sign in to comment.