Skip to content

Commit

Permalink
Merge pull request stakira#1021 from oxygen-dioxide/singeredit
Browse files Browse the repository at this point in the history
Show the current selection when setting encoding, singer type and default phonemizer
  • Loading branch information
stakira authored Jan 28, 2024
2 parents 6f3b7b6 + 2a19971 commit 0643434
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 61 deletions.
32 changes: 12 additions & 20 deletions OpenUtau.Core/Classic/VoicebankLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
15 changes: 15 additions & 0 deletions OpenUtau.Core/Ustx/USinger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,21 @@ private static void AddToneRange(string range, SortedSet<int> set) {

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

public static class SingerTypeUtils{
public static Dictionary<USingerType?, string> SingerTypeNames = new Dictionary<USingerType?, string>(){
{USingerType.Classic, "utau"},
{USingerType.Enunu, "enunu"},
{USingerType.DiffSinger, "diffsinger"},
};

public static Dictionary<string, USingerType> SingerTypeFromName = new Dictionary<string, USingerType>(){
{"utau", USingerType.Classic},
{"enunu", USingerType.Enunu},
{"diffsinger", USingerType.DiffSinger},
};

}

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

Expand Down
1 change: 1 addition & 0 deletions OpenUtau/ViewModels/MenuItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class MenuItemViewModel {
public object? CommandParameter { get; set; }
public IList<MenuItemViewModel>? Items { get; set; }
public double Height { get; set; } = 24;
public bool IsChecked { get; set; } = false;
}

public class SingerMenuItemViewModel : MenuItemViewModel {
Expand Down
82 changes: 44 additions & 38 deletions OpenUtau/ViewModels/SingersViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,19 @@ private readonly ObservableCollectionExtended<USubbank> subbanks
private readonly ObservableCollectionExtended<UOto> otos
= new ObservableCollectionExtended<UOto>();
private readonly ReactiveCommand<Encoding, Unit> setEncodingCommand;
private readonly List<MenuItemViewModel> setEncodingMenuItems;
private List<MenuItemViewModel> setEncodingMenuItems;
private readonly ReactiveCommand<string, Unit> setSingerTypeCommand;
private readonly List<MenuItemViewModel> setSingerTypeMenuItems;
private List<MenuItemViewModel> setSingerTypeMenuItems;
private readonly ReactiveCommand<Api.PhonemizerFactory, Unit> setDefaultPhonemizerCommand;
private readonly List<MenuItemViewModel> setDefaultPhonemizerMenuItems;
private List<MenuItemViewModel> setDefaultPhonemizerMenuItems;

public SingersViewModel() {
#if DEBUG
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
#endif
setEncodingMenuItems = new List<MenuItemViewModel>();
setSingerTypeMenuItems = new List<MenuItemViewModel>();
setDefaultPhonemizerMenuItems = new List<MenuItemViewModel>();
if (Singers.Count() > 0) {
Singer = Singers.FirstOrDefault();
}
Expand Down Expand Up @@ -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>(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<string>(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<Api.PhonemizerFactory>(factory => {
SetDefaultPhonemizer(factory);
});
setDefaultPhonemizerMenuItems = DocManager.Inst.PhonemizerFactories.Select(factory => new MenuItemViewModel() {
Header = factory.ToString(),
Command = setDefaultPhonemizerCommand,
CommandParameter = factory,
}).ToList();
}

private void SetEncoding(Encoding encoding) {
Expand Down
35 changes: 32 additions & 3 deletions OpenUtau/Views/SingersDialog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,56 @@
</Path>
<Button.ContextMenu>
<ContextMenu Name="SingerMenu" PlacementMode="Bottom">
<ContextMenu.Styles>
<Style Selector="CheckBox">
<Setter Property="IsHitTestVisible" Value="False" />
<Style Selector="^:unchecked /template/ Border#NormalRectangle">
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Background" Value="Transparent"/>
</Style>
<Style Selector="^:checked /template/ Path#CheckGlyph">
<Setter Property="Fill" Value="{DynamicResource SelectedTrackAccentBrush}" />
<Setter Property="Width" Value="12" />
</Style>
<Style Selector="^:checked /template/ Border#NormalRectangle">
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Background" Value="Transparent"/>
</Style>
</Style>
</ContextMenu.Styles>
<MenuItem Header="{DynamicResource singers.visitwebsite}" Click="OnVisitWebsite" IsEnabled="{Binding HasWebsite}"/>
<MenuItem Header="{DynamicResource singers.setimage}" Click="OnSetImage"/>
<MenuItem Header="{DynamicResource singers.setportrait}" Click="OnSetPortrait"/>
<MenuItem Header="{DynamicResource singers.setencoding}" ItemsSource="{Binding SetEncodingMenuItems}">
<MenuItem.DataTemplates>
<DataTemplate DataType="vm:MenuItemViewModel">
<MenuItem Header="{Binding Header}" Command="{Binding Command, FallbackValue={x:Null}}" CommandParameter="{Binding CommandParameter}"/>
<MenuItem Header="{Binding Header}" Command="{Binding Command, FallbackValue={x:Null}}" CommandParameter="{Binding CommandParameter}">
<MenuItem.Icon>
<CheckBox IsChecked="{Binding IsChecked}" />
</MenuItem.Icon>
</MenuItem>
</DataTemplate>
</MenuItem.DataTemplates>
</MenuItem>
<MenuItem Header="{DynamicResource singers.setsingertype}" ItemsSource="{Binding SetSingerTypeMenuItems}">
<MenuItem.DataTemplates>
<DataTemplate DataType="vm:MenuItemViewModel">
<MenuItem Header="{Binding Header}" Command="{Binding Command, FallbackValue={x:Null}}" CommandParameter="{Binding CommandParameter}"/>
<MenuItem Header="{Binding Header}" Command="{Binding Command, FallbackValue={x:Null}}" CommandParameter="{Binding CommandParameter}">
<MenuItem.Icon>
<CheckBox IsChecked="{Binding IsChecked}" />
</MenuItem.Icon>
</MenuItem>
</DataTemplate>
</MenuItem.DataTemplates>
</MenuItem>
<MenuItem Header="{DynamicResource singers.setdefaultphonemizer}" ItemsSource="{Binding SetDefaultPhonemizerMenuItems}">
<MenuItem.DataTemplates>
<DataTemplate DataType="vm:MenuItemViewModel">
<MenuItem Header="{Binding Header}" Command="{Binding Command, FallbackValue={x:Null}}" CommandParameter="{Binding CommandParameter}"/>
<MenuItem Header="{Binding Header}" Command="{Binding Command, FallbackValue={x:Null}}" CommandParameter="{Binding CommandParameter}">
<MenuItem.Icon>
<CheckBox IsChecked="{Binding IsChecked}" />
</MenuItem.Icon>
</MenuItem>
</DataTemplate>
</MenuItem.DataTemplates>
</MenuItem>
Expand Down

0 comments on commit 0643434

Please sign in to comment.