Skip to content

Commit a227d56

Browse files
committed
tweak singer setup view
1 parent a52c64d commit a227d56

File tree

4 files changed

+61
-61
lines changed

4 files changed

+61
-61
lines changed

OpenUtau.Core/Classic/VoicebankInstaller.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public VoicebankInstaller(string basePath, Action<double, string> progress, Enco
2424
Directory.CreateDirectory(basePath);
2525
this.basePath = basePath;
2626
this.progress = progress;
27-
this.archiveEncoding = archiveEncoding ?? Encoding.GetEncoding("shift_jis");
28-
this.textEncoding = textEncoding ?? Encoding.GetEncoding("shift_jis");
27+
this.archiveEncoding = archiveEncoding;
28+
this.textEncoding = textEncoding;
2929
}
3030

3131
public void Install(string path, string singerType) {

OpenUtau/Strings/Strings.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ Hold Ctrl to select</system:String>
347347
<system:String x:Key="singersetup.back">Back</system:String>
348348
<system:String x:Key="singersetup.install">Install</system:String>
349349
<system:String x:Key="singersetup.next">Next</system:String>
350+
<system:String x:Key="singersetup.missinginfo">Some info are missing from character.yaml!</system:String>
350351
<system:String x:Key="singersetup.singertype">Singer Type</system:String>
351-
<system:String x:Key="singersetup.singertype.prompt">Select the type of singer.</system:String>
352352
<system:String x:Key="singersetup.textfileencoding">Text File Encoding</system:String>
353353
<system:String x:Key="singersetup.textfileencoding.prompt">Choose an encoding that make file contents look right.</system:String>
354354

OpenUtau/ViewModels/SingerSetupViewModel.cs

Lines changed: 46 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,61 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Collections.ObjectModel;
43
using System.IO;
54
using System.Linq;
65
using System.Text;
76
using System.Threading.Tasks;
87
using DynamicData.Binding;
8+
using OpenUtau.Classic;
99
using OpenUtau.Core;
1010
using ReactiveUI;
11+
using ReactiveUI.Fody.Helpers;
1112
using SharpCompress.Archives;
1213
using SharpCompress.Common;
1314
using SharpCompress.Readers;
1415

1516
namespace OpenUtau.App.ViewModels {
1617
public class SingerSetupViewModel : ViewModelBase {
17-
public int Step {
18-
get => step;
19-
set => this.RaiseAndSetIfChanged(ref step, value);
20-
}
18+
[Reactive] public int Step { get; set; }
2119
public ObservableCollection<string> TextItems => textItems;
22-
public string ArchiveFilePath {
23-
get => archiveFilePath;
24-
set => this.RaiseAndSetIfChanged(ref archiveFilePath, value);
25-
}
26-
public Encoding[] Encodings => encodings;
27-
public Encoding ArchiveEncoding {
28-
get => archiveEncoding;
29-
set => this.RaiseAndSetIfChanged(ref archiveEncoding, value);
30-
}
31-
public Encoding TextEncoding {
32-
get => textEncoding;
33-
set => this.RaiseAndSetIfChanged(ref textEncoding, value);
34-
}
35-
public string[] SingerTypes => singerTypes;
36-
public string SingerType {
37-
get => singerType;
38-
set => this.RaiseAndSetIfChanged(ref singerType, value);
39-
}
20+
[Reactive] public string ArchiveFilePath { get; set; } = string.Empty;
21+
public Encoding[] Encodings { get; set; } = new Encoding[] {
22+
Encoding.GetEncoding("shift_jis"),
23+
Encoding.UTF8,
24+
Encoding.GetEncoding("gb2312"),
25+
Encoding.GetEncoding("big5"),
26+
Encoding.GetEncoding("ks_c_5601-1987"),
27+
Encoding.GetEncoding("Windows-1252"),
28+
Encoding.GetEncoding("macintosh"),
29+
};
30+
[Reactive] public Encoding ArchiveEncoding { get; set; }
31+
[Reactive] public Encoding TextEncoding { get; set; }
32+
[Reactive] public bool MissingInfo { get; set; }
33+
public string[] SingerTypes { get; set; } = new[] { "utau", "enunu" };
34+
[Reactive] public string SingerType { get; set; }
4035

41-
private int step;
42-
private string[] singerTypes;
43-
private string singerType;
4436
private ObservableCollectionExtended<string> textItems;
45-
private string archiveFilePath;
46-
private Encoding[] encodings;
47-
private Encoding archiveEncoding;
48-
private Encoding textEncoding;
4937

5038
public SingerSetupViewModel() {
5139
#if DEBUG
5240
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
5341
#endif
54-
singerTypes = new[] { "utau", "enunu" };
55-
singerType = singerTypes[0];
56-
archiveFilePath = string.Empty;
57-
encodings = new Encoding[] {
58-
Encoding.GetEncoding("shift_jis"),
59-
Encoding.ASCII,
60-
Encoding.UTF8,
61-
Encoding.GetEncoding("gb2312"),
62-
Encoding.GetEncoding("big5"),
63-
Encoding.GetEncoding("ks_c_5601-1987"),
64-
Encoding.GetEncoding("Windows-1252"),
65-
Encoding.GetEncoding("macintosh"),
66-
};
67-
archiveEncoding = encodings[0];
68-
textEncoding = encodings[0];
42+
SingerType = SingerTypes[0];
43+
ArchiveEncoding = Encodings[0];
44+
TextEncoding = Encodings[0];
6945
textItems = new ObservableCollectionExtended<string>();
7046

47+
this.WhenAnyValue(vm => vm.ArchiveFilePath)
48+
.Subscribe(_ => {
49+
if (!string.IsNullOrEmpty(ArchiveFilePath)) {
50+
var config = LoadCharacterYaml(ArchiveFilePath);
51+
MissingInfo = string.IsNullOrEmpty(config?.SingerType);
52+
if (!string.IsNullOrEmpty(config?.TextFileEncoding)) {
53+
try {
54+
TextEncoding = Encoding.GetEncoding(config.TextFileEncoding);
55+
} catch { }
56+
}
57+
}
58+
});
7159
this.WhenAnyValue(vm => vm.Step, vm => vm.ArchiveEncoding, vm => vm.ArchiveFilePath)
7260
.Subscribe(_ => RefreshArchiveItems());
7361
this.WhenAnyValue(vm => vm.Step, vm => vm.TextEncoding)
@@ -101,6 +89,18 @@ private void RefreshArchiveItems() {
10189
}
10290
}
10391

92+
private VoicebankConfig? LoadCharacterYaml(string archiveFilePath) {
93+
using (var archive = ArchiveFactory.Open(archiveFilePath)) {
94+
var entry = archive.Entries.FirstOrDefault(e => e.Key.EndsWith("character.yaml"));
95+
if (entry == null) {
96+
return null;
97+
}
98+
using (var stream = entry.OpenEntryStream()) {
99+
return VoicebankConfig.Load(stream);
100+
}
101+
}
102+
}
103+
104104
private void RefreshTextItems() {
105105
if (Step != 1) {
106106
return;
@@ -134,22 +134,14 @@ private void RefreshTextItems() {
134134
}
135135
}
136136

137-
class Character {
138-
public string file;
139-
public List<string> otoSets = new List<string>();
140-
public Character(string file) {
141-
this.file = file;
142-
}
143-
}
144-
145137
public Task Install() {
146138
string archiveFilePath = ArchiveFilePath;
147139
var archiveEncoding = ArchiveEncoding;
148140
var textEncoding = TextEncoding;
149141
return Task.Run(() => {
150142
try {
151143
var basePath = PathManager.Inst.SingersInstallPath;
152-
var installer = new Classic.VoicebankInstaller(basePath, (progress, info) => {
144+
var installer = new VoicebankInstaller(basePath, (progress, info) => {
153145
DocManager.Inst.ExecuteCmd(new ProgressBarNotification(progress, info));
154146
}, archiveEncoding, textEncoding);
155147
installer.Install(archiveFilePath, SingerType);

OpenUtau/Views/SingerSetupDialog.axaml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@
6565
Content="{DynamicResource singersetup.back}"/>
6666
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal" Spacing="10">
6767
<TextBlock Margin="0,1,0,0" Text="{DynamicResource singersetup.textfileencoding.prompt}"/>
68-
<Button Margin="0" Command="{Binding Next}"
68+
<Button Margin="0" Command="{Binding Next}" IsVisible="{Binding MissingInfo}"
6969
Content="{DynamicResource singersetup.next}"/>
70+
<Button Margin="0" Click="InstallClicked" IsVisible="{Binding !MissingInfo}"
71+
Content="{DynamicResource singersetup.install}"/>
7072
</StackPanel>
7173
</Grid>
7274
</Grid>
@@ -78,14 +80,20 @@
7880
<RowDefinition Height="40"/>
7981
</Grid.RowDefinitions>
8082
<StackPanel Grid.Row="0" Margin="10" Spacing="10" Orientation="Horizontal" HorizontalAlignment="Left">
81-
<TextBlock Margin="0,1,0,0" Text="{DynamicResource singersetup.singertype}"/>
82-
<ComboBox Grid.Row="1" Width="240" Margin="0" ItemsSource="{Binding SingerTypes}" SelectedItem="{Binding SingerType}"/>
83+
<TextBlock Margin="0,1,0,0" Text="{DynamicResource singersetup.missinginfo}" Foreground="Red"/>
8384
</StackPanel>
85+
<Grid Grid.Row="1" Margin="10,0">
86+
<Grid.ColumnDefinitions>
87+
<ColumnDefinition Width="120"/>
88+
<ColumnDefinition Width="*"/>
89+
</Grid.ColumnDefinitions>
90+
<TextBlock Grid.Row="0" Grid.Column="0" Margin="0,1,0,0" Text="{DynamicResource singersetup.singertype}"/>
91+
<ComboBox Grid.Row="0" Grid.Column="1" Width="240" Margin="0" ItemsSource="{Binding SingerTypes}" SelectedItem="{Binding SingerType}"/>
92+
</Grid>
8493
<Grid Grid.Row="2" Margin="10" HorizontalAlignment="Stretch">
8594
<Button Margin="0" Command="{Binding Back}" HorizontalAlignment="Left"
8695
Content="{DynamicResource singersetup.back}"/>
8796
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal" Spacing="10">
88-
<TextBlock Margin="0,1,0,0" Text="{DynamicResource singersetup.singertype.prompt}"/>
8997
<Button Margin="0" HorizontalAlignment="Right" Click="InstallClicked"
9098
Content="{DynamicResource singersetup.install}"/>
9199
</StackPanel>

0 commit comments

Comments
 (0)