From 2a19971d64b6da2ee98fed572abdee51c965e88c Mon Sep 17 00:00:00 2001 From: oxygen-dioxide <54425948+oxygen-dioxide@users.noreply.github.com> Date: Fri, 26 Jan 2024 19:23:01 +0800 Subject: [PATCH] Show the current selection when setting encoding, singer type and default phonemizer --- OpenUtau.Core/Classic/VoicebankLoader.cs | 32 ++++----- OpenUtau.Core/Ustx/USinger.cs | 15 +++++ OpenUtau/ViewModels/MenuItemViewModel.cs | 1 + OpenUtau/ViewModels/SingersViewModel.cs | 82 +++++++++++++----------- OpenUtau/Views/SingersDialog.axaml | 35 +++++++++- 5 files changed, 104 insertions(+), 61 deletions(-) diff --git a/OpenUtau.Core/Classic/VoicebankLoader.cs b/OpenUtau.Core/Classic/VoicebankLoader.cs index d518d6a67..f5cbca08e 100644 --- a/OpenUtau.Core/Classic/VoicebankLoader.cs +++ b/OpenUtau.Core/Classic/VoicebankLoader.cs @@ -88,28 +88,20 @@ public static void LoadInfo(Voicebank voicebank, string filePath, string basePat Log.Error(e, $"Failed to load yaml {yamlFile}"); } } - switch (bankConfig?.SingerType) { - case "utau": - voicebank.SingerType = USingerType.Classic; - break; - case "enunu": + string singerType = bankConfig?.SingerType ?? string.Empty; + if(SingerTypeUtils.SingerTypeFromName.ContainsKey(singerType)){ + voicebank.SingerType = SingerTypeUtils.SingerTypeFromName[singerType]; + }else{ + // Legacy detection code. Do not add more here. + var enuconfigFile = Path.Combine(dir, kEnuconfigYaml); + var dsconfigFile = Path.Combine(dir, kDsconfigYaml); + if (File.Exists(enuconfigFile)) { voicebank.SingerType = USingerType.Enunu; - break; - case "diffsinger": + } else if (File.Exists(dsconfigFile)) { voicebank.SingerType = USingerType.DiffSinger; - break; - default: - // Legacy detection code. Do not add more here. - var enuconfigFile = Path.Combine(dir, kEnuconfigYaml); - var dsconfigFile = Path.Combine(dir, kDsconfigYaml); - if (File.Exists(enuconfigFile)) { - voicebank.SingerType = USingerType.Enunu; - } else if (File.Exists(dsconfigFile)) { - voicebank.SingerType = USingerType.DiffSinger; - } else if (voicebank.SingerType != USingerType.Enunu) { - voicebank.SingerType = USingerType.Classic; - } - break; + } else if (voicebank.SingerType != USingerType.Enunu) { + voicebank.SingerType = USingerType.Classic; + } } Encoding encoding = Encoding.GetEncoding("shift_jis"); if (!string.IsNullOrEmpty(bankConfig?.TextFileEncoding)) { diff --git a/OpenUtau.Core/Ustx/USinger.cs b/OpenUtau.Core/Ustx/USinger.cs index e13e34534..134748a85 100644 --- a/OpenUtau.Core/Ustx/USinger.cs +++ b/OpenUtau.Core/Ustx/USinger.cs @@ -187,6 +187,21 @@ private static void AddToneRange(string range, SortedSet set) { [Flags] public enum USingerType { Classic = 0x1, Enunu = 0x2, Vogen = 0x4, DiffSinger=0x5 } + public static class SingerTypeUtils{ + public static Dictionary SingerTypeNames = new Dictionary(){ + {USingerType.Classic, "utau"}, + {USingerType.Enunu, "enunu"}, + {USingerType.DiffSinger, "diffsinger"}, + }; + + public static Dictionary SingerTypeFromName = new Dictionary(){ + {"utau", USingerType.Classic}, + {"enunu", USingerType.Enunu}, + {"diffsinger", USingerType.DiffSinger}, + }; + + } + public class USinger : INotifyPropertyChanged, IEquatable { protected static readonly List emptyOtos = new List(); diff --git a/OpenUtau/ViewModels/MenuItemViewModel.cs b/OpenUtau/ViewModels/MenuItemViewModel.cs index cf3c27948..d12f84e90 100644 --- a/OpenUtau/ViewModels/MenuItemViewModel.cs +++ b/OpenUtau/ViewModels/MenuItemViewModel.cs @@ -8,5 +8,6 @@ public class MenuItemViewModel { public object? CommandParameter { get; set; } public IList? Items { get; set; } public double Height { get; set; } = 24; + public bool IsChecked { get; set; } = false; } } diff --git a/OpenUtau/ViewModels/SingersViewModel.cs b/OpenUtau/ViewModels/SingersViewModel.cs index d342b0a16..90fda6da1 100644 --- a/OpenUtau/ViewModels/SingersViewModel.cs +++ b/OpenUtau/ViewModels/SingersViewModel.cs @@ -45,16 +45,19 @@ private readonly ObservableCollectionExtended subbanks private readonly ObservableCollectionExtended otos = new ObservableCollectionExtended(); private readonly ReactiveCommand setEncodingCommand; - private readonly List setEncodingMenuItems; + private List setEncodingMenuItems; private readonly ReactiveCommand setSingerTypeCommand; - private readonly List setSingerTypeMenuItems; + private List setSingerTypeMenuItems; private readonly ReactiveCommand setDefaultPhonemizerCommand; - private readonly List setDefaultPhonemizerMenuItems; + private List setDefaultPhonemizerMenuItems; public SingersViewModel() { #if DEBUG Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); #endif + setEncodingMenuItems = new List(); + setSingerTypeMenuItems = new List(); + setDefaultPhonemizerMenuItems = new List(); if (Singers.Count() > 0) { Singer = Singers.FirstOrDefault(); } @@ -93,56 +96,59 @@ void AttachSinger() { DocManager.Inst.ExecuteCmd(new OtoChangedNotification()); this.RaisePropertyChanged(nameof(IsClassic)); this.RaisePropertyChanged(nameof(UseSearchAlias)); + var encodings = new Encoding[] { + Encoding.GetEncoding("shift_jis"), + Encoding.ASCII, + Encoding.UTF8, + Encoding.GetEncoding("gb2312"), + Encoding.GetEncoding("big5"), + Encoding.GetEncoding("ks_c_5601-1987"), + Encoding.GetEncoding("Windows-1252"), + Encoding.GetEncoding("macintosh"), + }; + setEncodingMenuItems = encodings.Select(encoding => + new MenuItemViewModel() { + Header = encoding.EncodingName, + Command = setEncodingCommand, + CommandParameter = encoding, + IsChecked = singer.TextFileEncoding == encoding, + } + ).ToList(); + var singerTypes = new string[] { + "utau", "enunu", "diffsinger" + }; + setSingerTypeMenuItems = singerTypes.Select(singerType => + new MenuItemViewModel() { + Header = singerType, + Command = setSingerTypeCommand, + CommandParameter = singerType, + IsChecked = (SingerTypeUtils.SingerTypeNames.TryGetValue(singer.SingerType, out var name) ? name : "") == singerType, + } + ).ToList(); + setDefaultPhonemizerMenuItems = DocManager.Inst.PhonemizerFactories.Select(factory => new MenuItemViewModel() { + Header = factory.ToString(), + Command = setDefaultPhonemizerCommand, + CommandParameter = factory, + IsChecked = singer.DefaultPhonemizer == factory.type.FullName, + }).ToList(); + this.RaisePropertyChanged(nameof(SetEncodingMenuItems)); + this.RaisePropertyChanged(nameof(SetSingerTypeMenuItems)); + this.RaisePropertyChanged(nameof(SetDefaultPhonemizerMenuItems)); } }); this.WhenAnyValue(vm => vm.SearchAlias) .Subscribe(alias => { Search(); }); - setEncodingCommand = ReactiveCommand.Create(encoding => { SetEncoding(encoding); }); - var encodings = new Encoding[] { - Encoding.GetEncoding("shift_jis"), - Encoding.ASCII, - Encoding.UTF8, - Encoding.GetEncoding("gb2312"), - Encoding.GetEncoding("big5"), - Encoding.GetEncoding("ks_c_5601-1987"), - Encoding.GetEncoding("Windows-1252"), - Encoding.GetEncoding("macintosh"), - }; - setEncodingMenuItems = encodings.Select(encoding => - new MenuItemViewModel() { - Header = encoding.EncodingName, - Command = setEncodingCommand, - CommandParameter = encoding, - } - ).ToList(); - setSingerTypeCommand = ReactiveCommand.Create(singerType => { SetSingerType(singerType); }); - var singerTypes = new string[] { - "utau", "enunu", "diffsinger" - }; - setSingerTypeMenuItems = singerTypes.Select(singerType => - new MenuItemViewModel() { - Header = singerType, - Command = setSingerTypeCommand, - CommandParameter = singerType, - } - ).ToList(); - setDefaultPhonemizerCommand = ReactiveCommand.Create(factory => { SetDefaultPhonemizer(factory); }); - setDefaultPhonemizerMenuItems = DocManager.Inst.PhonemizerFactories.Select(factory => new MenuItemViewModel() { - Header = factory.ToString(), - Command = setDefaultPhonemizerCommand, - CommandParameter = factory, - }).ToList(); } private void SetEncoding(Encoding encoding) { diff --git a/OpenUtau/Views/SingersDialog.axaml b/OpenUtau/Views/SingersDialog.axaml index d2aceabee..197eea787 100644 --- a/OpenUtau/Views/SingersDialog.axaml +++ b/OpenUtau/Views/SingersDialog.axaml @@ -75,27 +75,56 @@ + + + + + + - + + + + + - + + + + + - + + + + +