Skip to content

Commit

Permalink
Wpf interop with avalonia. Swap out singers dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
stakira committed Sep 19, 2021
1 parent 30bd101 commit 1b506b5
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 25 deletions.
2 changes: 1 addition & 1 deletion OpenUtau.App/Controls/PartsCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public double Track {
private double _tick;
private double _track;

Dictionary<UPart, PartControl> partControls = new();
Dictionary<UPart, PartControl> partControls = new Dictionary<UPart, PartControl>();

public PartsCanvas() {
this.WhenAnyValue(x => x.TickWidth, x => x.TrackHeight, x => x.Tick, x => x.Track)
Expand Down
2 changes: 1 addition & 1 deletion OpenUtau.App/Controls/TickBackground.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace OpenUtau.App.Controls {
class TickBackground : TemplatedControl {
private static readonly IDashStyle DashStyle = new ImmutableDashStyle(new double[] { 2, 4 }, 0);
readonly Dictionary<int, FormattedText> fTextPool = new();
readonly Dictionary<int, FormattedText> fTextPool = new Dictionary<int, FormattedText>();

public static readonly DirectProperty<TickBackground, int> BeatPerBarProperty =
AvaloniaProperty.RegisterDirect<TickBackground, int>(
Expand Down
2 changes: 1 addition & 1 deletion OpenUtau.App/OpenUtau.App.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Nullable>enable</Nullable>
<Version>0.0.0</Version>
</PropertyGroup>
Expand Down
12 changes: 7 additions & 5 deletions OpenUtau.App/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using Avalonia;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.ReactiveUI;
using System;

namespace OpenUtau.App
{
class Program
{
namespace OpenUtau.App {
public class Program {
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
Expand All @@ -19,5 +17,9 @@ public static AppBuilder BuildAvaloniaApp()
.UsePlatformDetect()
.LogToTrace()
.UseReactiveUI();

public static void InitInterop() {
AppBuilder.Configure<App>().UseWin32().UseSkia().SetupWithoutStarting();
}
}
}
4 changes: 4 additions & 0 deletions OpenUtau.App/Strings/Strings.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
<system:String x:Key="oto.alias">Alias</system:String>
<system:String x:Key="oto.set">Set</system:String>
<system:String x:Key="oto.file">File</system:String>
<system:String x:Key="oto.phonetic">Phonetic</system:String>
<system:String x:Key="oto.prefix">Prefix</system:String>
<system:String x:Key="oto.suffix">Suffix</system:String>
<system:String x:Key="oto.flavor">Flavor</system:String>
<system:String x:Key="oto.offset">Offset</system:String>
<system:String x:Key="oto.consonant">Consonant</system:String>
<system:String x:Key="oto.cutoff">Cutoff</system:String>
Expand Down
2 changes: 1 addition & 1 deletion OpenUtau.App/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void ImportAudio(string file) {
return;
}
var project = DocManager.Inst.Project;
UWavePart part = Core.Formats.Wave.CreatePart(file);
UWavePart part = Core.Formats.Wave.CreatePart(project, file);
if (part == null) {
return;
}
Expand Down
12 changes: 10 additions & 2 deletions OpenUtau.App/ViewModels/PreferencesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,17 @@ public PreferencesViewModel() {
Resamplers = Core.ResamplerDriver.ResamplerDriver.Search(PathManager.Inst.GetEngineSearchPath());
if (Resamplers.Count() > 0) {
int index = Resamplers.FindIndex(resampler => resampler.Name == Preferences.Default.ExternalPreviewEngine);
PreviewResampler = index > 0 ? Resamplers[index] : null;
if (index > 0) {
PreviewResampler = Resamplers[index];
} else {
PreviewResampler = null;
}
index = Resamplers.FindIndex(resampler => resampler.Name == Preferences.Default.ExternalExportEngine);
ExportResampler = index > 0 ? Resamplers[index] : null;
if (index > 0) {
ExportResampler = Resamplers[index];
} else {
ExportResampler = null;
}
}
this.WhenAnyValue(vm => vm.PreviewResampler)
.WhereNotNull()
Expand Down
4 changes: 2 additions & 2 deletions OpenUtau.App/ViewModels/SingersViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace OpenUtau.App.ViewModels {
public class SingersViewModel : ViewModelBase {
public IEnumerable<USinger> Singers => DocManager.Inst.Singers.Values;
public IEnumerable<USinger> Singers => DocManager.Inst.SingersOrdered;
public USinger? Singer {
get => singer;
set => this.RaiseAndSetIfChanged(ref singer, value);
Expand Down Expand Up @@ -43,7 +43,7 @@ public SingersViewModel() {
.Subscribe(singer => {
Avatar = LoadAvatar(singer);
Otos = singer.OtoSets.SelectMany(set => set.Otos.Values).SelectMany(list => list).ToList();
Info = $"Author: {singer.Author}\nWeb: {singer.Web}\n{singer.OtherInfo}";
Info = $"Author: {singer.Author}\nWeb: {singer.Web}\n{singer.OtherInfo}\n\n{string.Join("\n", singer.OtoSets.SelectMany(set => set.Errors))}";
});
}

Expand Down
8 changes: 6 additions & 2 deletions OpenUtau.App/Views/SingersDialog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="600"
x:Class="OpenUtau.App.Views.SingersDialog"
Title="{DynamicResource singers.caption}" Width="500" Height="600">
Title="{DynamicResource singers.caption}" Width="500" Height="600" MinWidth="500" MinHeight="600">
<Design.DataContext>
<vm:SingersViewModel/>
</Design.DataContext>
Expand All @@ -23,11 +23,15 @@
<ScrollViewer Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="140,10,10,10" Height="118">
<TextBlock x:Name="info" TextWrapping="Wrap" Text="{Binding Info}"/>
</ScrollViewer>
<DataGrid Grid.Row="1" Margin="10,0,10,10" Items="{Binding Otos}" IsReadOnly="True">
<DataGrid Grid.Row="1" Margin="10,0,10,10" Items="{Binding Otos}" IsReadOnly="True" CanUserResizeColumns="True">
<DataGrid.Columns>
<DataGridTextColumn Header="{StaticResource oto.alias}" Binding="{Binding Alias}"/>
<DataGridTextColumn Header="{StaticResource oto.set}" Binding="{Binding Set}"/>
<DataGridTextColumn Header="{StaticResource oto.file}" Binding="{Binding DisplayFile}"/>
<DataGridTextColumn Header="{StaticResource oto.phonetic}" Binding="{Binding Phonetic}"/>
<DataGridTextColumn Header="{StaticResource oto.prefix}" Binding="{Binding Prefix}"/>
<DataGridTextColumn Header="{StaticResource oto.suffix}" Binding="{Binding Suffix}"/>
<DataGridTextColumn Header="{StaticResource oto.flavor}" Binding="{Binding Flavor}"/>
<DataGridTextColumn Header="{StaticResource oto.offset}" Binding="{Binding Offset}"/>
<DataGridTextColumn Header="{StaticResource oto.consonant}" Binding="{Binding Consonant}"/>
<DataGridTextColumn Header="{StaticResource oto.cutoff}" Binding="{Binding Cutoff}"/>
Expand Down
2 changes: 2 additions & 0 deletions OpenUtau.Core/DocManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class DocManager {
public int playPosTick = 0;

public Dictionary<string, USinger> Singers { get; private set; } = new Dictionary<string, USinger>();
public List<USinger> SingersOrdered { get; private set; } = new List<USinger>();
public Plugin[] Plugins { get; private set; }
public Phonemizer[] Phonemizers { get; private set; }
public Transformer[] Transformers { get; private set; }
Expand All @@ -39,6 +40,7 @@ public void Initialize() {
public void SearchAllSingers() {
var stopWatch = Stopwatch.StartNew();
Singers = Formats.UtauSoundbank.FindAllSingers();
SingersOrdered = Singers.Values.OrderBy(singer => singer.Name).ToList();
Directory.CreateDirectory(PathManager.Inst.GetEngineSearchPath());
stopWatch.Stop();
Log.Information($"Search all singers: {stopWatch.Elapsed}");
Expand Down
5 changes: 1 addition & 4 deletions OpenUtau.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenUtau.Test", "OpenUtau.T
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenUtau.Core", "OpenUtau.Core\OpenUtau.Core.csproj", "{7793257C-054C-4935-A1EF-CAB345E9F6C5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenUtau.App", "OpenUtau.App\OpenUtau.App.csproj", "{9535E26C-4584-4126-B6F7-B91B41113196}"
ProjectSection(ProjectDependencies) = postProject
{D951492F-0901-4296-AE7F-831430C07FA9} = {D951492F-0901-4296-AE7F-831430C07FA9}
EndProjectSection
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenUtau.App", "OpenUtau.App\OpenUtau.App.csproj", "{9535E26C-4584-4126-B6F7-B91B41113196}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
2 changes: 1 addition & 1 deletion OpenUtau/App.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Application x:Class="OpenUtau.App"
<Application x:Class="OpenUtau.WpfApp"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:OpenUtau">
Expand Down
4 changes: 2 additions & 2 deletions OpenUtau/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace OpenUtau {
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application {
public App() {
public partial class WpfApp : Application {
public WpfApp() {
InitializeComponent();
InitializeCulture();
InitializeTheme();
Expand Down
6 changes: 6 additions & 0 deletions OpenUtau/OpenUtau.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
<Version>0.0.0.0</Version>
</PropertyGroup>

<ItemGroup>
<Page Remove="MainApp.xaml" />
<Page Remove="WpfApp.xaml" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Autoupdater.NET.Official" Version="1.7.0" />
<PackageReference Include="MvvmLightLibs" Version="5.4.1.1" />
Expand All @@ -23,6 +28,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\OpenUtau.App\OpenUtau.App.csproj" />
<ProjectReference Include="..\OpenUtau.Core\OpenUtau.Core.csproj" />
</ItemGroup>

Expand Down
3 changes: 2 additions & 1 deletion OpenUtau/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ private static void Main() {
Core.PlaybackManager.Inst.AudioOutput = new Audio.WaveOutAudioOutput();
Core.AudioFileUtilsProvider.Utils = new Audio.NAudioFileUtils();

var app = new App();
App.Program.InitInterop();
var app = new WpfApp();
var window = new UI.MainWindow();
app.Run(window);
}
Expand Down
6 changes: 4 additions & 2 deletions OpenUtau/UI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,10 @@ private void MenuImportMidi_Click(object sender, RoutedEventArgs e) {
}

private void MenuSingers_Click(object sender, RoutedEventArgs e) {
var w = new Dialogs.SingerViewDialog() { Owner = this };
w.ShowDialog();
var dialog = new App.Views.SingersDialog() {
DataContext = new App.ViewModels.SingersViewModel(),
};
dialog.Show();
}

private void MenuInstallSingers_Click(object sender, RoutedEventArgs e) {
Expand Down

0 comments on commit 1b506b5

Please sign in to comment.