Table of Contents

Class PluginUIProcessor<TModel>

Namespace
PluginUI.NPlug
Assembly
PluginUI.NPlug.dll

Base audio processor for plug-ins with a PluginUI editor: receives the notes played on the editor (TryDequeueUINote(out UINoteEvent)) and shares an object with the controller (CreateSharedState()), for meters, note activity or waveforms read by the UI without locks.

public abstract class PluginUIProcessor<TModel> : AudioProcessor<TModel>, IAudioConnectionPoint, IAudioProcessorProgramListData, IAudioProcessorUnitData, IAudioProcessor, IAudioPluginComponent, IAudioPluginObject where TModel : AudioProcessorModel, new()

Type Parameters

TModel

Parameter model shared with the controller.

Inheritance
AudioPluginComponent
AudioProcessor<TModel>
PluginUIProcessor<TModel>
Implements
IAudioConnectionPoint
IAudioProcessorProgramListData
IAudioProcessorUnitData
IAudioProcessor
IAudioPluginComponent
IAudioPluginObject
Inherited Members
AudioProcessor<TModel>.AddDefaultStereoAudioInput()
AudioProcessor<TModel>.AddDefaultStereoAudioOutput()
AudioProcessor<TModel>.AddDefaultEventInput()
AudioProcessor<TModel>.GetBusInfoList(BusMediaType, BusDirection)
AudioProcessor<TModel>.GetAudioOutputBuses()
AudioProcessor<TModel>.GetAudioInputBuses()
AudioProcessor<TModel>.GetEventOutputBuses()
AudioProcessor<TModel>.GetEventInputBuses()
AudioProcessor<TModel>.IsSampleSizeSupported(AudioSampleSize)
AudioProcessor<TModel>.Initialize(AudioHostApplication)
AudioProcessor<TModel>.TryGetBusRoutingInfo(in BusRoutingInfo, out BusRoutingInfo)
AudioProcessor<TModel>.OnSetupProcessing(in AudioProcessSetupData)
AudioProcessor<TModel>.SaveState(PortableBinaryWriter)
AudioProcessor<TModel>.PreProcess(in AudioProcessData)
AudioProcessor<TModel>.Process(in AudioProcessData)
AudioProcessor<TModel>.ProcessMain(in AudioProcessData)
AudioProcessor<TModel>.ProcessRecalculate(in AudioProcessData)
AudioProcessor<TModel>.ProcessParameterChanges(in AudioProcessData)
AudioProcessor<TModel>.ProcessEvents(in AudioProcessData)
AudioProcessor<TModel>.ProcessEvent(in AudioEvent)
AudioProcessor<TModel>.ProcessByPass(in AudioProcessData)
AudioProcessor<TModel>.PostProcessCheckSilence(in AudioProcessData)
AudioProcessor<TModel>.SampleSizeSupport
AudioProcessor<TModel>.Model
AudioProcessor<TModel>.ProcessContextRequirementFlags
AudioProcessor<TModel>.ControllerClassId
AudioProcessor<TModel>.InputOutputMode
AudioProcessor<TModel>.LatencySamples
AudioProcessor<TModel>.TailSamples
AudioProcessor<TModel>.IsActive
AudioProcessor<TModel>.ProcessSetupData
AudioProcessor<TModel>.IsProcessing
AudioProcessor<TModel>.ShouldByPass
AudioPluginComponent.OnDisconnect(IAudioConnectionPoint)
AudioPluginComponent.Host
AudioPluginComponent.ConnectionPoint

Examples

public sealed class SynthShared { public NoteActivity Notes { get; } = new(); }

public sealed class SynthProcessor : PluginUIProcessor<SynthModel>
{
    private readonly SynthShared _shared = new();
    protected override object? CreateSharedState() => _shared;
    protected override void ProcessMain(in AudioProcessData data)
    {
        while (TryDequeueUINote(out var note)) { /* start / stop voices */ }
        ...
    }
}

Remarks

Messages arrive on the UI thread; notes wait in a bounded queue that the audio thread drains at the start of each block, so they play at sample offset 0 of the next block. Override OnMessage(AudioMessage), OnConnect(IAudioConnectionPoint), RestoreState(PortableBinaryReader) or Terminate() only with a call to the base method.

The shared state is a plain object created once per processor instance. Both VST3 components of a plug-in run in the same process, which makes this the simplest way to feed real-time displays: write it from the audio thread with lock-free types (PeakValue, AudioRingBuffer, NoteActivity), read it from the UI.

Constructors

PluginUIProcessor(AudioSampleSizeSupport)

Creates the processor.

protected PluginUIProcessor(AudioSampleSizeSupport sampleSizeSupport)

Parameters

sampleSizeSupport AudioSampleSizeSupport

Sample sizes the processor supports.

Properties

SharedState

The object shared with the controller, or null before the components connect.

protected object? SharedState { get; }

Property Value

object

UINotes

Notes received from the editor, waiting for the audio thread.

protected UINoteQueue UINotes { get; }

Property Value

UINoteQueue

Methods

CreateSharedState()

Creates the object shared with the controller (called on the UI thread when the components connect, once per initialization). The default returns null: nothing is shared. The processor keeps its own reference to the object for the audio thread.

protected virtual object? CreateSharedState()

Returns

object

The shared object, or null.

OnConnect(IAudioConnectionPoint)

Called when this component is connected to another component.

protected override void OnConnect(IAudioConnectionPoint connectionPoint)

Parameters

connectionPoint IAudioConnectionPoint

OnMessage(AudioMessage)

Called when this component receives a message from another component.

protected override void OnMessage(AudioMessage message)

Parameters

message AudioMessage

The message. The sender owns it: it is valid during this call only and must not be disposed.

RestoreState(PortableBinaryReader)

This method is called when restoring the state to the associated model of this processor.

protected override void RestoreState(PortableBinaryReader reader)

Parameters

reader PortableBinaryReader

The output reader.

Terminate()

Called when this component is terminated.

protected override void Terminate()

TryConsumeStateRestored()

true once after the host restored the processor state (project or preset load): the parameters changed without parameter-change events, so derived processors refresh their DSP settings (audio thread, no allocation).

protected bool TryConsumeStateRestored()

Returns

bool

true if a state was restored since the previous call.

TryDequeueUINote(out UINoteEvent)

Takes the next note played on the editor (audio thread, no allocation).

protected bool TryDequeueUINote(out UINoteEvent note)

Parameters

note UINoteEvent

The event.

Returns

bool

false when no note is waiting.