diff --git a/src/EffectHost.cs b/src/EffectHost.cs index 3969127..4543ae3 100644 --- a/src/EffectHost.cs +++ b/src/EffectHost.cs @@ -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()) @@ -213,15 +213,18 @@ private static bool Acknowledge(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)) diff --git a/src/PluginState.cs b/src/PluginState.cs index 5d57f6a..b9aee4f 100644 --- a/src/PluginState.cs +++ b/src/PluginState.cs @@ -6,9 +6,9 @@ namespace VL.Audio.VST; -public record PluginState(ImmutableArray Component, ImmutableArray Controller) +public record PluginState(Guid Id, ImmutableArray Component, ImmutableArray Controller) { - public static readonly PluginState Default = new PluginState(ImmutableArray.Empty, ImmutableArray.Empty); + public static readonly PluginState Default = new PluginState(default, ImmutableArray.Empty, ImmutableArray.Empty); internal bool HasComponentData => Component.Length > 0; internal bool HasControllerData => Controller.Length > 0; @@ -27,12 +27,12 @@ private IBStream GetStream(ImmutableArray 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 Read(Action reader) { @@ -58,6 +58,7 @@ internal sealed class Serializer : ISerializer public PluginState Deserialize(SerializationContext context, object content, Type type) { return new PluginState( + context.Deserialize(content, nameof(Id)), context.Deserialize>(content, nameof(Component)), context.Deserialize>(content, nameof(Controller))); } @@ -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) };