Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/vvvv/VL.Audio.VST
Browse files Browse the repository at this point in the history
  • Loading branch information
joreg committed Oct 30, 2024
2 parents 1d70040 + 5f37be0 commit 8df5b52
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
19 changes: 11 additions & 8 deletions src/EffectHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void Dispose()
window?.Dispose();
outputSignal.Dispose();

var state = PluginState.From(component, controller);
var state = PluginState.From(plugProvider.ClassInfo.ID, component, controller);
var statePin = (StatePin)Inputs[0];
var channel = statePin.Value;
if (channel.IsValid())
Expand All @@ -213,15 +213,18 @@ private static bool Acknowledge<T>(ref T current, T value)

public void Update()
{
if (Acknowledge(ref state, ((StatePin)Inputs[0]).Value?.Value) && state != null)
if (Acknowledge(ref state, ((StatePin)Inputs[0]).Value?.Value))
{
if (state.HasComponentData)
{
component.IgnoreNotImplementedException(c => c.setState(state.GetComponentStream()));
controller?.IgnoreNotImplementedException(c => c.setComponentState(state.GetComponentStream()));
if (state != null && state.Id == plugProvider.ClassInfo.ID)
{
if (state.HasComponentData)
{
component.IgnoreNotImplementedException(c => c.setState(state.GetComponentStream()));
controller?.IgnoreNotImplementedException(c => c.setComponentState(state.GetComponentStream()));
}
if (state.HasControllerData)
controller?.IgnoreNotImplementedException(c => c.setState(state.GetControllerStream()));
}
if (state.HasControllerData)
controller?.IgnoreNotImplementedException(c => c.setState(state.GetControllerStream()));
}

if (Acknowledge(ref midiInput, midiInputPin.Value))
Expand Down
10 changes: 6 additions & 4 deletions src/PluginState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace VL.Audio.VST;

public record PluginState(ImmutableArray<byte> Component, ImmutableArray<byte> Controller)
public record PluginState(Guid Id, ImmutableArray<byte> Component, ImmutableArray<byte> Controller)
{
public static readonly PluginState Default = new PluginState(ImmutableArray<byte>.Empty, ImmutableArray<byte>.Empty);
public static readonly PluginState Default = new PluginState(default, ImmutableArray<byte>.Empty, ImmutableArray<byte>.Empty);

internal bool HasComponentData => Component.Length > 0;
internal bool HasControllerData => Controller.Length > 0;
Expand All @@ -27,12 +27,12 @@ private IBStream GetStream(ImmutableArray<byte> bytes)
return new BStreamAdapter(memoryStream);
}

internal static PluginState From(IComponent component, IEditController? controller)
internal static PluginState From(Guid id, IComponent component, IEditController? controller)
{
var memoryStream = new MemoryStream();
var componentState = Read(s => component.getState(s));
var controllerState = Read(s => controller?.getState(s));
return new PluginState(componentState, controllerState);
return new PluginState(id, componentState, controllerState);

ImmutableArray<byte> Read(Action<IBStream> reader)
{
Expand All @@ -58,6 +58,7 @@ internal sealed class Serializer : ISerializer<PluginState>
public PluginState Deserialize(SerializationContext context, object content, Type type)
{
return new PluginState(
context.Deserialize<Guid>(content, nameof(Id)),
context.Deserialize<ImmutableArray<byte>>(content, nameof(Component)),
context.Deserialize<ImmutableArray<byte>>(content, nameof(Controller)));
}
Expand All @@ -66,6 +67,7 @@ public object Serialize(SerializationContext context, PluginState value)
{
return new object[]
{
context.Serialize(nameof(Id), value.Id),
context.Serialize(nameof(Component), value.Component),
context.Serialize(nameof(Controller), value.Controller)
};
Expand Down

0 comments on commit 8df5b52

Please sign in to comment.