Skip to content

Commit

Permalink
Fixed MacOS build plus some random bug fixes (#6)
Browse files Browse the repository at this point in the history
* Fixes for MacOS build

* MacOS Fixes

* Added a first rudimentary implementation for bundleEntry and bundleExit in NPlugFactory.

* Reverted back to DllImport to not pollute the project with unnecessary unsafe code.

* Get the PluginClassInfo category dynamically based on the type, instead of always returning an AudioProcessor
  • Loading branch information
basdp authored Apr 29, 2024
1 parent b07104f commit eb444ee
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/NPlug.Proxy/NPlug.Proxy.msbuildproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.Build.NoTargets/3.7.0">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable Condition="'$(IsPackable)' == ''">false</IsPackable>
<Version>2.0.1</Version>
</PropertyGroup>
Expand Down
4 changes: 4 additions & 0 deletions src/NPlug.Proxy/build/NPlug.Proxy.targets
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<NPlugVstArch Condition="'$(NPlugVstArch)' == '' and '$(NPlugRuntimeIdentifier)' == 'osx-x64'">MacOS</NPlugVstArch>
<NPlugVstArch Condition="'$(NPlugVstArch)' == '' and '$(NPlugRuntimeIdentifier)' == 'osx-arm64'">MacOS</NPlugVstArch>

<NPlugIsWindows Condition="'$(NPlugIsWindows)' == '' and $(NPlugRuntimeIdentifier.StartsWith('win'))">true</NPlugIsWindows>
<NPlugIsMacOS Condition="'$(NPlugIsMacOS)' == '' and $(NPlugRuntimeIdentifier.StartsWith('osx'))">true</NPlugIsMacOS>
<NPlugIsLinux Condition="'$(NPlugIsLinux)' == '' and $(NPlugRuntimeIdentifier.StartsWith('linux'))">true</NPlugIsLinux>

<NPlugVstNativeLibraryExtension Condition="'$(NPlugVstNativeLibraryExtension)' == '' and $(NPlugRuntimeIdentifier.StartsWith('win'))">.vst3</NPlugVstNativeLibraryExtension>
<NPlugVstNativeLibraryExtension Condition="'$(NPlugVstNativeLibraryExtension)' == '' and $(NPlugRuntimeIdentifier.StartsWith('osx'))">.dylib</NPlugVstNativeLibraryExtension>
<NPlugVstNativeLibraryExtension Condition="'$(NPlugVstNativeLibraryExtension)' == ''">.so</NPlugVstNativeLibraryExtension>
Expand Down
3 changes: 2 additions & 1 deletion src/NPlug/Interop/LibVst.IBStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public partial struct IBStream
/// <summary>
/// Reads binary data from stream.
/// </summary>
/// <param name="self"></param>
/// <param name="buffer">: destination buffer</param>
/// <param name="numBytes">: amount of bytes to be read</param>
/// <param name="numBytesRead">: result - how many bytes have been read from stream (set to 0 if this is of no interest)</param>
Expand Down Expand Up @@ -58,7 +59,7 @@ internal static IBStreamClient GetStream(IBStream* state)
}

public IBStream* NativeStream { get; set; }

public override void Flush()
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/NPlug/Interop/LibVst.IPluginFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static partial ComResult getClassInfo_ToManaged(IPluginFactory* self, in
var pluginClassInfo = Get(self).GetPluginClassInfo(index);
info->cid = pluginClassInfo.ClassId.ConvertToPlatform();
info->cardinality = pluginClassInfo.Cardinality;
CopyStringToUTF8(AudioEffectCategory, info->category, 32);
CopyStringToUTF8(GetPluginCategory(pluginClassInfo), info->category, 32);
CopyStringToUTF8(pluginClassInfo.Name, info->name, 64);
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions src/NPlug/NPlug.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<GenerateDocumentationFile>True</GenerateDocumentationFile>

<!--Do not warn about lower-cased ascii character names, they are from the VST SDK -->
<NoWarn>$(NoWarn);CS8981</NoWarn>
</PropertyGroup>

<Target Name="OverrideMinVer" AfterTargets="MinVer" Condition="'$(DesignTimeBuild)' != 'true'">
Expand Down
14 changes: 13 additions & 1 deletion src/NPlug/build/NPlug.targets
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
<NPlugFactoryExport Condition="'$(NPlugFactoryExport)' == ''">true</NPlugFactoryExport>
</PropertyGroup>

<PropertyGroup>
<NPlugRuntimeIdentifier Condition="'$(NPlugRuntimeIdentifier)' == ''">$(RuntimeIdentifier)</NPlugRuntimeIdentifier>
<NPlugRuntimeIdentifier Condition="'$(NPlugRuntimeIdentifier)' == ''">$(NETCoreSdkRuntimeIdentifier)</NPlugRuntimeIdentifier>

<NPlugIsWindows Condition="'$(NPlugIsWindows)' == '' and $(NPlugRuntimeIdentifier.StartsWith('win'))">true</NPlugIsWindows>
<NPlugIsMacOS Condition="'$(NPlugIsMacOS)' == '' and $(NPlugRuntimeIdentifier.StartsWith('osx'))">true</NPlugIsMacOS>
<NPlugIsLinux Condition="'$(NPlugIsLinux)' == '' and $(NPlugRuntimeIdentifier.StartsWith('linux'))">true</NPlugIsLinux>
</PropertyGroup>

<PropertyGroup Condition="'$(NPlugFactoryExport)' == 'true'">
<!--Disable a warning for the usage of `ModuleInitializer` in a library, as we can use it for a plugin that is exported natively-->
<!-- https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca2255 -->
Expand Down Expand Up @@ -45,11 +54,14 @@
<Compile Include="$(MSBuildThisFileDirectory)NPlugFactoryExport.cs">
<Visible>false</Visible>
</Compile>
<Compile Condition="'$(NPlugIsMacOS)' == 'true'" Include="$(MSBuildThisFileDirectory)NPlugFactoryExportMacOS.cs">
<Visible>false</Visible>
</Compile>
</ItemGroup>

<!--If AOT is disabled, we are using the proxy to load the managed DLL-->
<ItemGroup Condition="'$(PublishAot)' != 'true'">
<!--Copy the proxy with the name name than the target library-->
<!--Copy the proxy with the name name than the target library-->
<Content Condition="Exists('$(NPlugProxyLibraryFile)')" Include="$(NPlugProxyLibraryFile)" Link="$(TargetName).vst3">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
Expand Down
2 changes: 1 addition & 1 deletion src/NPlug/build/NPlugFactoryExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace NPlug.Interop;
/// <summary>
/// This class is responsible for exporting the current registered factory in <see cref="AudioPluginFactoryExporter.Instance"/>.
/// </summary>
internal static class NPlugFactoryExport
internal static partial class NPlugFactoryExport
{
[UnmanagedCallersOnly(EntryPoint = nameof(GetPluginFactory))]
private static nint GetPluginFactory()
Expand Down
47 changes: 47 additions & 0 deletions src/NPlug/build/NPlugFactoryExportMacOS.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) Alexandre Mutel. All rights reserved.
// Licensed under the BSD-Clause 2 license.
// See license.txt file in the project root for full license information.

using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace NPlug.Interop;

/// <summary>
/// This class is responsible for exporting the current registered factory in <see cref="AudioPluginFactoryExporter.Instance"/>.
/// </summary>
internal static partial class NPlugFactoryExport
{
private static readonly List<nint> BundleRefs = [];

[DllImport("/System/Library/Frameworks/CoreFoundation.framework/Versions/Current/Resources/BridgeSupport/CoreFoundation.dylib")]
private static extern nint CFRetain(nint theArrayRef);

[DllImport("/System/Library/Frameworks/CoreFoundation.framework/Versions/Current/Resources/BridgeSupport/CoreFoundation.dylib")]
private static extern void CFRelease(nint theArrayRef);

[UnmanagedCallersOnly(EntryPoint = nameof(bundleEntry))]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Exported function required by VST3 API")]
// ReSharper disable once InconsistentNaming
private static bool bundleEntry(nint bundlePointer)
{
if (bundlePointer != 0)
{
BundleRefs.Add(CFRetain(bundlePointer));
}
return true;
}

[UnmanagedCallersOnly(EntryPoint = nameof(bundleExit))]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Exported function required by VST3 API")]
// ReSharper disable once InconsistentNaming
private static bool bundleExit(nint bundlePointer)
{
if (bundlePointer != 0)
{
BundleRefs.Remove(bundlePointer);
CFRelease(bundlePointer);
}
return BundleRefs.Count > 0;
}
}

0 comments on commit eb444ee

Please sign in to comment.