Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP do not merge] VST3/LV2 support implementation #104

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,44 @@ ASALocalRun/

# Test usts
OpenUtau.Test/Usts/*

# Jetbrains IDE stuff
.idea
cmake-build-debug
cmake-build-release
build

# C++ stuff

# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "VST/dpf"]
path = VST/dpf
url = https://github.com/DISTRHO/DPF.git
[submodule "VST/libs/tiny-process-library"]
path = VST/libs/tiny-process-library
url = https://gitlab.com/eidheim/tiny-process-library.git
[submodule "VST/libs/asio"]
path = VST/libs/asio
url = https://github.com/chriskohlhoff/asio.git
6 changes: 6 additions & 0 deletions OpenUtau.App/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
using OpenUtau.App.Views;
using Avalonia.Markup.Xaml.MarkupExtensions;
using System.Linq;
using Avalonia.Threading;
using OpenUtau.Core;

namespace OpenUtau.App {
public class App : Application {
private DispatcherTimer timer;
public override void Initialize() {
AvaloniaXamlLoader.Load(this);
InitializeCulture();
InitializeTheme();
timer = new DispatcherTimer(DispatcherPriority.Render);
timer.Tick += (sender,args) => DocManager.Inst.VSTClient.Update();
timer.Start();
}

public override void OnFrameworkInitializationCompleted() {
Expand Down
6 changes: 4 additions & 2 deletions OpenUtau.App/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Text;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.ReactiveUI;
using OpenUtau.Core.Network;
using Serilog;

namespace OpenUtau.App {
Expand Down Expand Up @@ -47,8 +49,8 @@ public static void InitLogging() {
});
}

public static void InitOpenUtau() {
Core.DocManager.Inst.Initialize();
public static void InitOpenUtau(string[] args = null!) {
Core.DocManager.Inst.Initialize(args);
}

public static Action? AutoUpdate { get;set; }
Expand Down
6 changes: 5 additions & 1 deletion OpenUtau.App/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System.IO;
using System.Linq;
using System.Reactive;
using System.Threading.Tasks;
using Avalonia.Threading;
using DynamicData.Binding;
using OpenUtau.Core;
using OpenUtau.Core.Network;
using OpenUtau.Core.Ustx;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
Expand All @@ -13,13 +16,14 @@ public class MainWindowViewModel : ViewModelBase, ICmdSubscriber {
[Reactive] public TracksViewModel TracksViewModel { get; set; }
[Reactive] public ReactiveCommand<string, Unit>? OpenRecentCommand { get; private set; }
public ObservableCollectionExtended<MenuItemViewModel> OpenRecent => openRecent;

public bool ProjectSaved => !string.IsNullOrEmpty(DocManager.Inst.Project.FilePath) && DocManager.Inst.Project.Saved;
public string AppVersion => $"OpenUtau v{System.Reflection.Assembly.GetEntryAssembly()?.GetName().Version}";
public double Progress {
get => progress;
set => this.RaiseAndSetIfChanged(ref progress, value);
}

public string ProgressText {
get => progressText;
set => this.RaiseAndSetIfChanged(ref progressText, value);
Expand Down
4 changes: 4 additions & 0 deletions OpenUtau.App/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,10 @@ public void PartsCanvasPointerWheelChanged(object sender, PointerWheelEventArgs
}

public async void WindowClosing(object? sender, CancelEventArgs e) {
if (DocManager.Inst.isVst) {
e.Cancel = true;
return;
}
if (!forceClose && !DocManager.Inst.ChangesSaved) {
e.Cancel = true;
var result = await MessageBox.Show(
Expand Down
26 changes: 25 additions & 1 deletion OpenUtau.Core/DocManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using OpenUtau.Core.Network;
using OpenUtau.Api;
using OpenUtau.Classic;
using OpenUtau.Core.Lib;
Expand All @@ -23,6 +25,9 @@ public class DocManager {
public int playPosTick = 0;

public Dictionary<string, USinger> Singers { get; private set; } = new Dictionary<string, USinger>();
public bool isVst { get; private set; }

public VSTClient VSTClient { get; private set; }
public List<USinger> SingersOrdered { get; private set; } = new List<USinger>();
public Plugin[] Plugins { get; private set; }
public PhonemizerFactory[] PhonemizerFactories { get; private set; }
Expand All @@ -31,7 +36,26 @@ public class DocManager {
public bool HasOpenUndoGroup => undoGroup != null;
public List<UNote> NotesClipboard { get; set; }

public void Initialize() {
public void Initialize(string[] args) {

for(int i = 0; i < args.Length;i++) {
string arg = args[i];
switch (arg) {
case "-vst":
isVst = true;
break;
case "-port":
string portNum = args[i + 1];
int output;
if (!int.TryParse(portNum, out output)) {
throw new ArgumentException($"The port number {portNum} is invalid !");
}

VSTClient = new VSTClient("127.0.0.1", output);
Task.Run(VSTClient.Connect);
break;
}
}
SearchAllSingers();
SearchAllPlugins();
SearchAllLegacyPlugins();
Expand Down
81 changes: 81 additions & 0 deletions OpenUtau.Core/Network/VSTClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.IO;
using System.Linq.Expressions;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using OpenUtau.Core.SignalChain;

namespace OpenUtau.Core.Network {
public class VSTClient {
private TcpClient client;
private Stream stream;
private VSTData data;
public VSTClient(string host, int port = 1556) {
this.port = port;
this.host = host;
Console.WriteLine("Created VST client");
}

~VSTClient() {
stream.Dispose();
client.Dispose();
}

public static T ByteToType<T>(BinaryReader reader)
{
byte[] bytes = reader.ReadBytes(Marshal.SizeOf(typeof(T)));

GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
T theStructure = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T));
handle.Free();

return theStructure;
}

public void Update() {
if (client.Connected) {
Console.WriteLine(data.playing);
var project = DocManager.Inst.Project;
data.ticks = data.ticks * project.BeatTicks / data.ticksPerBeat;
DocManager.Inst.playPosTick = (int)data.ticks;
/* if (PlaybackManager.Inst.Playing && PlaybackManager.Inst.AudioOutput.GetPosition() != (long)data.ticks) {
PlaybackManager.Inst.PlayOrPause();
PlaybackManager.Inst.PlayOrPause();
}*/
if (data.playing && !PlaybackManager.Inst.Playing) {
PlaybackManager.Inst.PlayOrPause();
} else if (!data.playing && PlaybackManager.Inst.Playing) {
PlaybackManager.Inst.StopPlayback();
}
}
}

public void Connect() {
client = new TcpClient();
Console.WriteLine("Connecting to the tcp server");
if (!client.ConnectAsync(host, port).Wait(5000)) {
Console.WriteLine("An error occurred when trying to connect to the server");
return;
}
Console.WriteLine("Connected to the server");
stream = client.GetStream();
while (client.Connected) {
if (stream.CanRead) {
using BinaryReader reader = new BinaryReader(stream, Encoding.Default, true);
data = ByteToType<VSTData>(reader);

} else {
Console.WriteLine("Can't read stream");
}
}
}

private int port;
private string host;
}
}
14 changes: 14 additions & 0 deletions OpenUtau.Core/Network/VSTData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace OpenUtau.Core.Network {
public struct VSTData {
public bool playing;
public double ticks;
public double ticksPerBeat;
}
}
1 change: 1 addition & 0 deletions OpenUtau.Core/OpenUtau.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<SatelliteResourceLanguages>none</SatelliteResourceLanguages>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions OpenUtau.Core/Ustx/UProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public int EndTick {
}
}
[YamlIgnore] public int BarTicks => resolution * 4 * beatPerBar / beatUnit;
public int BeatTicks => BarTicks / beatPerBar;

public void RegisterExpression(UExpressionDescriptor descriptor) {
if (!expressions.ContainsKey(descriptor.abbr)) {
Expand Down
2 changes: 1 addition & 1 deletion OpenUtau/OpenUtau.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<SatelliteResourceLanguages>none</SatelliteResourceLanguages>
<UseWPF>true</UseWPF>
Expand Down
Loading