Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions OpenUtau.Core/Classic/VoicebankInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,19 @@ public void Install(string path, string singerType) {
using (var stream = File.Open(filePath, FileMode.Open)) {
config = VoicebankConfig.Load(stream);
}
bool changed = false;
if (string.IsNullOrEmpty(config.SingerType)) {
config.SingerType = singerType;
changed = true;
}
// Honor the text encoding chosen in the wizard. Without this, a
// character.yaml lacking text_file_encoding keeps being read as
// shift_jis even after the user picks another encoding.
if (!string.Equals(config.TextFileEncoding, textEncoding.WebName, StringComparison.OrdinalIgnoreCase)) {
config.TextFileEncoding = textEncoding.WebName;
changed = true;
}
if (changed) {
SaveConfigSafely(filePath, config);
}
}
Expand Down
38 changes: 38 additions & 0 deletions OpenUtauMobile/Helpers/SingerListHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Collections.Generic;
using System.Linq;
using OpenUtau.Core;
using OpenUtau.Core.Ustx;

namespace OpenUtauMobile.Helpers;

/// <summary>
/// 歌手列表辅助方法。
/// </summary>
public static class SingerListHelper
{
/// <summary>
/// 按歌手类型固定顺序展开 <see cref="SingerManager.SingerGroups"/>。
/// <see cref="SingerManager.SingerGroups"/> 的分组顺序取决于文件系统的目录枚举顺序,
/// 安装新歌手后目录顺序变化会让 DiffSinger 等分组跑到列表最前面,因此这里按
/// <see cref="USingerType"/> 的数值顺序展开以保证列表稳定;分组内部保持 Core 已有的本地化排序。
/// </summary>
/// <returns>按类型、再按名称排序后的歌手列表。</returns>
public static List<USinger> GetOrderedSingers()
{
Dictionary<USingerType, List<USinger>> groups = SingerManager.Inst.SingerGroups;
List<USinger> singers = [];
foreach (KeyValuePair<USingerType, List<USinger>> pair in groups.OrderBy(pair => pair.Key))
{
if (pair.Value == null) continue;
foreach (USinger singer in pair.Value)
{
if (singer != null)
{
singers.Add(singer);
}
}
}

return singers;
}
}
20 changes: 2 additions & 18 deletions OpenUtauMobile/ViewModels/SingerManagementViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Reactive;
using System.Threading.Tasks;
using DynamicData.Binding;
using OpenUtau.Core;
using OpenUtau.Core.Ustx;
using OpenUtauMobile.Helpers;
using OpenUtauMobile.Services.Dialogs;
Expand Down Expand Up @@ -80,23 +79,8 @@ public override void OnNavigatedTo()

private async Task RefreshSingersAsync()
{
List<USinger> list = await Task.Run(() =>
{
List<USinger> singers = [];
foreach (var group in SingerManager.Inst.SingerGroups.Values)
{
if (group == null) continue;
foreach (var singer in group)
{
if (singer != null)
{
singers.Add(singer);
}
}
}

return singers;
});
// 按歌手类型固定顺序展开,避免安装新歌手后分组顺序随目录枚举顺序变化
List<USinger> list = await Task.Run(SingerListHelper.GetOrderedSingers);

Singers.Load(list);
}
Expand Down
21 changes: 3 additions & 18 deletions OpenUtauMobile/ViewModels/SingerPickerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using System.Reactive;
using System.Threading.Tasks;
using DynamicData.Binding;
using OpenUtau.Core;
using OpenUtau.Core.Ustx;
using OpenUtauMobile.Helpers;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;

Expand Down Expand Up @@ -38,23 +38,8 @@ public SingerPickerViewModel()
private async Task LoadSingersAsync()
{
IsLoading = true;
List<USinger> list = await Task.Run(() =>
{
List<USinger> singers = [];
foreach (var group in SingerManager.Inst.SingerGroups.Values)
{
if (group == null) continue;
foreach (var singer in group)
{
if (singer != null)
{
singers.Add(singer);
}
}
}

return singers;
});
// 按歌手类型固定顺序展开,保证与歌手管理页顺序一致
List<USinger> list = await Task.Run(SingerListHelper.GetOrderedSingers);
Singers.Load(list);
IsLoading = false;
}
Expand Down
Loading