Skip to content

Commit

Permalink
tweak singer setup view
Browse files Browse the repository at this point in the history
  • Loading branch information
stakira committed Jun 11, 2023
1 parent a52c64d commit a227d56
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 61 deletions.
4 changes: 2 additions & 2 deletions OpenUtau.Core/Classic/VoicebankInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public VoicebankInstaller(string basePath, Action<double, string> progress, Enco
Directory.CreateDirectory(basePath);
this.basePath = basePath;
this.progress = progress;
this.archiveEncoding = archiveEncoding ?? Encoding.GetEncoding("shift_jis");
this.textEncoding = textEncoding ?? Encoding.GetEncoding("shift_jis");
this.archiveEncoding = archiveEncoding;
this.textEncoding = textEncoding;
}

public void Install(string path, string singerType) {
Expand Down
2 changes: 1 addition & 1 deletion OpenUtau/Strings/Strings.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ Hold Ctrl to select</system:String>
<system:String x:Key="singersetup.back">Back</system:String>
<system:String x:Key="singersetup.install">Install</system:String>
<system:String x:Key="singersetup.next">Next</system:String>
<system:String x:Key="singersetup.missinginfo">Some info are missing from character.yaml!</system:String>
<system:String x:Key="singersetup.singertype">Singer Type</system:String>
<system:String x:Key="singersetup.singertype.prompt">Select the type of singer.</system:String>
<system:String x:Key="singersetup.textfileencoding">Text File Encoding</system:String>
<system:String x:Key="singersetup.textfileencoding.prompt">Choose an encoding that make file contents look right.</system:String>

Expand Down
100 changes: 46 additions & 54 deletions OpenUtau/ViewModels/SingerSetupViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,73 +1,61 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DynamicData.Binding;
using OpenUtau.Classic;
using OpenUtau.Core;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using SharpCompress.Archives;
using SharpCompress.Common;
using SharpCompress.Readers;

namespace OpenUtau.App.ViewModels {
public class SingerSetupViewModel : ViewModelBase {
public int Step {
get => step;
set => this.RaiseAndSetIfChanged(ref step, value);
}
[Reactive] public int Step { get; set; }
public ObservableCollection<string> TextItems => textItems;
public string ArchiveFilePath {
get => archiveFilePath;
set => this.RaiseAndSetIfChanged(ref archiveFilePath, value);
}
public Encoding[] Encodings => encodings;
public Encoding ArchiveEncoding {
get => archiveEncoding;
set => this.RaiseAndSetIfChanged(ref archiveEncoding, value);
}
public Encoding TextEncoding {
get => textEncoding;
set => this.RaiseAndSetIfChanged(ref textEncoding, value);
}
public string[] SingerTypes => singerTypes;
public string SingerType {
get => singerType;
set => this.RaiseAndSetIfChanged(ref singerType, value);
}
[Reactive] public string ArchiveFilePath { get; set; } = string.Empty;
public Encoding[] Encodings { get; set; } = new Encoding[] {
Encoding.GetEncoding("shift_jis"),
Encoding.UTF8,
Encoding.GetEncoding("gb2312"),
Encoding.GetEncoding("big5"),
Encoding.GetEncoding("ks_c_5601-1987"),
Encoding.GetEncoding("Windows-1252"),
Encoding.GetEncoding("macintosh"),
};
[Reactive] public Encoding ArchiveEncoding { get; set; }
[Reactive] public Encoding TextEncoding { get; set; }
[Reactive] public bool MissingInfo { get; set; }
public string[] SingerTypes { get; set; } = new[] { "utau", "enunu" };
[Reactive] public string SingerType { get; set; }

private int step;
private string[] singerTypes;
private string singerType;
private ObservableCollectionExtended<string> textItems;
private string archiveFilePath;
private Encoding[] encodings;
private Encoding archiveEncoding;
private Encoding textEncoding;

public SingerSetupViewModel() {
#if DEBUG
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
#endif
singerTypes = new[] { "utau", "enunu" };
singerType = singerTypes[0];
archiveFilePath = string.Empty;
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"),
};
archiveEncoding = encodings[0];
textEncoding = encodings[0];
SingerType = SingerTypes[0];
ArchiveEncoding = Encodings[0];
TextEncoding = Encodings[0];
textItems = new ObservableCollectionExtended<string>();

this.WhenAnyValue(vm => vm.ArchiveFilePath)
.Subscribe(_ => {
if (!string.IsNullOrEmpty(ArchiveFilePath)) {
var config = LoadCharacterYaml(ArchiveFilePath);
MissingInfo = string.IsNullOrEmpty(config?.SingerType);
if (!string.IsNullOrEmpty(config?.TextFileEncoding)) {
try {
TextEncoding = Encoding.GetEncoding(config.TextFileEncoding);
} catch { }
}
}
});
this.WhenAnyValue(vm => vm.Step, vm => vm.ArchiveEncoding, vm => vm.ArchiveFilePath)
.Subscribe(_ => RefreshArchiveItems());
this.WhenAnyValue(vm => vm.Step, vm => vm.TextEncoding)
Expand Down Expand Up @@ -101,6 +89,18 @@ private void RefreshArchiveItems() {
}
}

private VoicebankConfig? LoadCharacterYaml(string archiveFilePath) {
using (var archive = ArchiveFactory.Open(archiveFilePath)) {
var entry = archive.Entries.FirstOrDefault(e => e.Key.EndsWith("character.yaml"));
if (entry == null) {
return null;
}
using (var stream = entry.OpenEntryStream()) {
return VoicebankConfig.Load(stream);
}
}
}

private void RefreshTextItems() {
if (Step != 1) {
return;
Expand Down Expand Up @@ -134,22 +134,14 @@ private void RefreshTextItems() {
}
}

class Character {
public string file;
public List<string> otoSets = new List<string>();
public Character(string file) {
this.file = file;
}
}

public Task Install() {
string archiveFilePath = ArchiveFilePath;
var archiveEncoding = ArchiveEncoding;
var textEncoding = TextEncoding;
return Task.Run(() => {
try {
var basePath = PathManager.Inst.SingersInstallPath;
var installer = new Classic.VoicebankInstaller(basePath, (progress, info) => {
var installer = new VoicebankInstaller(basePath, (progress, info) => {
DocManager.Inst.ExecuteCmd(new ProgressBarNotification(progress, info));
}, archiveEncoding, textEncoding);
installer.Install(archiveFilePath, SingerType);
Expand Down
16 changes: 12 additions & 4 deletions OpenUtau/Views/SingerSetupDialog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@
Content="{DynamicResource singersetup.back}"/>
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal" Spacing="10">
<TextBlock Margin="0,1,0,0" Text="{DynamicResource singersetup.textfileencoding.prompt}"/>
<Button Margin="0" Command="{Binding Next}"
<Button Margin="0" Command="{Binding Next}" IsVisible="{Binding MissingInfo}"
Content="{DynamicResource singersetup.next}"/>
<Button Margin="0" Click="InstallClicked" IsVisible="{Binding !MissingInfo}"
Content="{DynamicResource singersetup.install}"/>
</StackPanel>
</Grid>
</Grid>
Expand All @@ -78,14 +80,20 @@
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Margin="10" Spacing="10" Orientation="Horizontal" HorizontalAlignment="Left">
<TextBlock Margin="0,1,0,0" Text="{DynamicResource singersetup.singertype}"/>
<ComboBox Grid.Row="1" Width="240" Margin="0" ItemsSource="{Binding SingerTypes}" SelectedItem="{Binding SingerType}"/>
<TextBlock Margin="0,1,0,0" Text="{DynamicResource singersetup.missinginfo}" Foreground="Red"/>
</StackPanel>
<Grid Grid.Row="1" Margin="10,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Margin="0,1,0,0" Text="{DynamicResource singersetup.singertype}"/>
<ComboBox Grid.Row="0" Grid.Column="1" Width="240" Margin="0" ItemsSource="{Binding SingerTypes}" SelectedItem="{Binding SingerType}"/>
</Grid>
<Grid Grid.Row="2" Margin="10" HorizontalAlignment="Stretch">
<Button Margin="0" Command="{Binding Back}" HorizontalAlignment="Left"
Content="{DynamicResource singersetup.back}"/>
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal" Spacing="10">
<TextBlock Margin="0,1,0,0" Text="{DynamicResource singersetup.singertype.prompt}"/>
<Button Margin="0" HorizontalAlignment="Right" Click="InstallClicked"
Content="{DynamicResource singersetup.install}"/>
</StackPanel>
Expand Down

0 comments on commit a227d56

Please sign in to comment.