Class PluginUIController<TModel>
Base edit controller for plug-ins with a PluginUI editor: implements IParameterEditSink on top of NPlug's concurrent edit support, creates the view on Windows only, sends the notes played on the editor to the processor, receives the processor's shared state and provides MIDI learn.
public abstract class PluginUIController<TModel> : AudioController<TModel>, IAudioConnectionPoint, IAudioControllerExtended, IAudioControllerUnitInfo, IAudioControllerMidiMapping, IParameterEditSink, IAudioControllerMidiLearn, IAudioController, IAudioPluginComponent, IAudioPluginObject where TModel : AudioProcessorModel, new()
Type Parameters
TModelParameter model shared with the processor.
- Inheritance
-
AudioPluginComponentAudioController<TModel>PluginUIController<TModel>
- Implements
-
IAudioConnectionPointIAudioControllerExtendedIAudioControllerUnitInfoIAudioControllerMidiMappingIAudioControllerMidiLearnIAudioControllerIAudioPluginComponentIAudioPluginObject
- Inherited Members
-
AudioController<TModel>.Initialize(AudioHostApplication)AudioController<TModel>.RestoreComponentState(PortableBinaryReader)AudioController<TModel>.TrySetKnobMode(AudioControllerKnobModes)AudioController<TModel>.SetMidiCCMapping(AudioMidiControllerNumber, AudioParameter)AudioController<TModel>.IsEditingParameter(AudioParameter)AudioController<TModel>.BeginGroupEditParameters()AudioController<TModel>.EndGroupEditParameters()AudioController<TModel>.BeginEditParameter(AudioParameter)AudioController<TModel>.EndEditParameter(AudioParameter)AudioController<TModel>.EndEditParameter()AudioController<TModel>.RestartComponent(AudioRestartFlags)AudioController<TModel>.ClearMapBusToUnit()AudioController<TModel>.ModelAudioController<TModel>.HandlerAudioController<TModel>.MapMidiCCToAudioParameterAudioController<TModel>.EditedParameterAudioController<TModel>.EditedParameterCountAudioController<TModel>.SelectedUnitAudioPluginComponent.Terminate()AudioPluginComponent.HostAudioPluginComponent.ConnectionPoint
Examples
public sealed class MyController : PluginUIController<MyModel>
{
protected override PluginEditorView CreateEditor() => new MyEditor(this);
}
Remarks
MIDI learn (MidiLearn, offered when IsMidiLearnEnabled is set): the controller
implements VST3 IMidiLearn and IMidiMapping;
learned assignments are saved with the controller state by SaveState(PortableBinaryWriter) and read back by
RestoreState(PortableBinaryReader). Derived classes that store their own controller data call the base method first.
Override OnMessage(AudioMessage) or OnConnect(IAudioConnectionPoint) only with a call to the base method.
Constructors
PluginUIController()
Creates the controller.
protected PluginUIController()
Properties
IsMidiLearnEnabled
When true, the editor's context menus offer MIDI learn. Default false: enable it for plug-ins with an
event input (instruments, MIDI-controlled effects), since hosts send MIDI controllers only to those. Learned
assignments apply whatever this setting.
public bool IsMidiLearnEnabled { get; set; }
Property Value
MidiLearn
MIDI learn service (assign MIDI controllers to parameters from the editor's context menu).
public NPlugMidiLearn MidiLearn { get; }
Property Value
SharedState
Object shared by the processor (CreateSharedState()), or null
until the components are connected (or if the processor shares nothing).
public object? SharedState { get; }
Property Value
Methods
CreateEditor()
Creates the editor view (called on Windows 10 1809+ only).
protected abstract PluginEditorView? CreateEditor()
Returns
CreateView()
Create a view for this controller. This is called by NPlug.IAudioController.CreateView().
protected override IAudioPluginView? CreateView()
Returns
- IAudioPluginView
OnConnect(IAudioConnectionPoint)
Called when this component is connected to another component.
protected override void OnConnect(IAudioConnectionPoint connectionPoint)
Parameters
connectionPointIAudioConnectionPoint
OnDisconnect(IAudioConnectionPoint)
Called when this component is disconnected from another component.
protected override void OnDisconnect(IAudioConnectionPoint connectionPoint)
Parameters
connectionPointIAudioConnectionPoint
OnLiveMidiControllerInput(int, short, AudioMidiControllerNumber)
Live MIDI controller reported by the host (VST3 IMidiLearn, UI thread).
protected virtual bool OnLiveMidiControllerInput(int busIndex, short channel, AudioMidiControllerNumber midiCC)
Parameters
busIndexintEvent input bus.
channelshortMIDI channel, 0-based.
midiCCAudioMidiControllerNumberController number.
Returns
- bool
trueif a learn completed.
OnMessage(AudioMessage)
Called when this component receives a message from another component.
protected override void OnMessage(AudioMessage message)
Parameters
messageAudioMessageThe message. The sender owns it: it is valid during this call only and must not be disposed.
OnParameterValueChanged(AudioParameter, bool)
This method is called whenever a parameter value is changed in the model. It will replicate the change to the host via the NPlug.AudioController<TAudioControllerModel>.Handler.
protected override void OnParameterValueChanged(AudioParameter parameter, bool parameterValueChangedFromHost)
Parameters
parameterAudioParameterThe audio parameter that changed.
parameterValueChangedFromHostbooltrueif the value was changed by the host.
Remarks
Without a host connection (tests, snapshots, standalone use) changes are kept in the model only.
Exceptions
RestoreState(PortableBinaryReader)
This method is called by the host when restoring the state of this controller (different from the audio processor component state).
protected override void RestoreState(PortableBinaryReader reader)
Parameters
readerPortableBinaryReaderThe reader stream to restore specific controller data.
Remarks
Reads the learned MIDI assignments; overrides call this first, then read their own data.
SaveState(PortableBinaryWriter)
This method is called by the host when saving the state of this controller (different from the audio processor component state).
protected override void SaveState(PortableBinaryWriter writer)
Parameters
writerPortableBinaryWriterThe writer stream to store specific controller data.
Remarks
Writes the learned MIDI assignments; overrides call this first, then write their own data.
SendNote(UINoteEvent)
Sends a note played on the editor to the processor (UI thread).
public bool SendNote(UINoteEvent note)
Parameters
noteUINoteEventThe note event.
Returns
- bool
falseif the processor is not connected.
TryGetMidiControllerAssignment(int, int, AudioMidiControllerNumber, out AudioParameterId)
Gets an (preferred) associated NPlug.AudioParameterId for a given Input Event Bus index, channel and MIDI Controller.
protected override bool TryGetMidiControllerAssignment(int busIndex, int channel, AudioMidiControllerNumber midiControllerNumber, out AudioParameterId id)
Parameters
busIndexintThe index of the bus.
channelintThe index of the channel.
midiControllerNumberAudioMidiControllerNumberThe MIDI CC number.
idAudioParameterIdThe output parameter id.
Returns
- bool
trueif themidiControllerNumberis associated with a parameter;falseotherwise.
Remarks
Learned assignments first, then the fixed mappings declared with SetMidiCCMapping.
TryGetSharedState<T>(out T?)
Typed access to SharedState.
public bool TryGetSharedState<T>(out T? state) where T : class
Parameters
stateTThe shared object.
Returns
- bool
trueif the processor shares an object of this type.
Type Parameters
TType of the shared object.
Events
SharedStateChanged
Raised on the UI thread when SharedState becomes available.
public event Action? SharedStateChanged