Class PluginEditorView
VST3 editor view (NPlug NPlug.IAudioPluginView) hosting a PluginUI element tree in a UIHost:
window lifecycle, content scale, resizing negotiation with the DAW, keyboard and wheel forwarding,
host parameter context menus (with MIDI learn), findParameter and notes played on the editor.
public abstract class PluginEditorView : IAudioPluginView, IDisposable
- Inheritance
-
PluginEditorView
- Implements
-
IAudioPluginView
- Inherited Members
Remarks
Derive and build the UI in Build(), binding controls with Parameters:
public sealed class MyEditor(MyController controller) : PluginEditorView(controller, new Size(480, 300))
{
protected override UIElement Build()
{
var root = new Canvas();
var gain = new Knob { Parameter = Parameters[controller.Model.Gain] };
gain.SetBounds(20, 20, 64, 84);
root.Children.Add(gain);
return root;
}
}
The tree is built lazily (first Size or attach) and kept between openings of the editor while the view object lives; the DAW usually creates a new view each time the editor opens.
Constructors
PluginEditorView(IParameterEditSink, Size, SizingMode)
Creates the view.
protected PluginEditorView(IParameterEditSink sink, Size designSize, SizingMode sizing = SizingMode.Fixed)
Parameters
sinkIParameterEditSinkEdit bridge (the controller).
designSizeSizeLogical size of the editor at 100 %.
sizingSizingModeResizing behavior offered to the DAW.
Properties
ForwardHostKeysToControls
Sends the keys the DAW forwards through IPlugView::onKeyDown to any focused control (arrows, Delete...).
Off by default: only text input, open menus/dialogs and the live-edit shortcut receive them, so that DAW
shortcuts (transport, delete, navigation) keep working after a click on a knob.
public bool ForwardHostKeysToControls { get; set; }
Property Value
Host
The UI host (created on first use).
public UIHost Host { get; }
Property Value
Parameters
Parameter wrappers to bind controls: knob.Parameter = Parameters[model.Gain].
public NPlugParameterSet Parameters { get; }
Property Value
Sink
Edit bridge (the controller).
public IParameterEditSink Sink { get; }
Property Value
Size
Returns the size of the platform representation of the view.
public ViewRectangle Size { get; }
Property Value
- ViewRectangle
Methods
Attached(nint, AudioPluginViewPlatform)
The parent window of the view has been created, the (platform) representation of the view should now be created as well. Note that the parent is owned by the caller and you are not allowed to alter it in any way other than adding your own views. Note that in this call the plug-in could call a IPlugFrame::resizeView ()!
public void Attached(nint parent, AudioPluginViewPlatform type)
Parameters
parentnint: platform handle of the parent window or view
typeAudioPluginViewPlatform: @ref platformUIType which should be created
Build()
Builds the element tree (called once per view).
protected abstract UIElement Build()
Returns
CanResize()
Is view sizable by user.
public bool CanResize()
Returns
CheckSizeConstraint(ref ViewRectangle)
On live resize this is called to check if the view can be resized to the given rect, if not adjust the rect to the allowed size.
public bool CheckSizeConstraint(ref ViewRectangle rect)
Parameters
rectViewRectangle
Returns
ConfigureHost(UIHost)
Configures the host after creation (theme, minimum/maximum size, zoom...).
protected virtual void ConfigureHost(UIHost host)
Parameters
hostUIHost
ConnectKeyboard(PianoKeyboard, int)
Sends the notes played on keyboard (mouse, computer keyboard) to the processor, which reads
them with TryDequeueUINote(out UINoteEvent). Notes still held when the editor closes are
released.
protected void ConnectKeyboard(PianoKeyboard keyboard, int channel = 0)
Parameters
keyboardPianoKeyboardAn on-screen keyboard of this editor.
channelintMIDI channel of the notes, 0-based.
Dispose()
Called by NPlug when the DAW releases the view (safety net if removed() was skipped).
public void Dispose()
GetExtraContextMenuItems(NPlugParameter)
Adds plug-in entries to the DAW's parameter context menu (right click on a bound control). Return the items to append (null or empty: host items only).
protected virtual IReadOnlyList<MenuItem>? GetExtraContextMenuItems(NPlugParameter parameter)
Parameters
parameterNPlugParameter
Returns
IsPlatformTypeSupported(AudioPluginViewPlatform)
Is Platform UI Type supported
public bool IsPlatformTypeSupported(AudioPluginViewPlatform platform)
Parameters
platformAudioPluginViewPlatformthe type of the platform
Returns
OnAttached()
Called after the editor window was created.
protected virtual void OnAttached()
OnFocus(bool)
Focus changed message.
public void OnFocus(bool state)
Parameters
statebool
OnKeyDown(ushort, short, short)
Handling of keyboard events : Key Down.
public bool OnKeyDown(ushort key, short keyCode, short modifiers)
Parameters
keyushort: unicode code of key
keyCodeshort: virtual keycode for non ascii keys - see @ref VirtualKeyCodes in keycodes.h
modifiersshort: any combination of modifiers - see @ref KeyModifier in keycodes.h
Returns
- bool
true(kResultTrue) if the key is handled, otherwisefalse(kResultFalse). Please note thattruemust only be returned if the key has really been handled. Otherwise key command handling of the host might be blocked!
OnKeyUp(ushort, short, short)
Handling of keyboard events : Key Up.
public bool OnKeyUp(ushort key, short keyCode, short modifiers)
Parameters
keyushort: unicode code of key
keyCodeshort: virtual keycode for non ascii keys - see @ref VirtualKeyCodes in keycodes.h
modifiersshort: any combination of KeyModifier - see @ref KeyModifier in keycodes.h
Returns
- bool
true(kResultTrue) if the key is handled, otherwisefalse(kResultFalse).
OnRemoved()
Called before the editor window is destroyed.
protected virtual void OnRemoved()
OnSize(ViewRectangle)
Resizes the platform representation of the view to the given rect. Note that if the plug-in requests a resize (IPlugFrame::resizeView ()) onSize has to be called afterward.
public void OnSize(ViewRectangle newSize)
Parameters
newSizeViewRectangle
OnWheel(float)
Handling of mouse wheel.
public bool OnWheel(float distance)
Parameters
distancefloat
Returns
- bool
trueif the wheel event was handled by the view,falseto let the host handle it.
Removed()
The parent window of the view is about to be destroyed. You have to remove all your own views from the parent window or view.
public void Removed()
SetContentScaleFactor(float)
This interface communicates the content scale factor from the host to the plug-in view on systems where plug-ins cannot get this information directly like Microsoft Windows.
The host calls setContentScaleFactor directly before or after the plug-in view is attached and when the scale factor changes while the view is attached (system change or window moved to another screen with different scaling settings).
The host may call setContentScaleFactor in a different context, for example: scaling the plug-in editor for better readability.
When a plug-in handles this (by returning kResultTrue), it needs to scale the width and height of its view by the scale factor and inform the host via a IPlugFrame::resizeView(). The host will then call IPlugView::onSize().
Note that the host is allowed to call setContentScaleFactor() at any time the IPlugView is valid. If this happens before the IPlugFrame object is set on your view, make sure that when the host calls IPlugView::getSize() afterwards you return the size of your view for that new scale factor.
It is recommended to implement this interface on Microsoft Windows to let the host know that the plug-in is able to render in different scalings.
public bool SetContentScaleFactor(float factor)
Parameters
factorfloatThe content scale factor (1.0 = 100 %).
Returns
- bool
trueif the view handles content scaling;falseto tell the host that the view does not scale itself.
Remarks
IPlugViewContentScaleSupport
SetFrame(IAudioPluginFrame?)
Sets IPlugFrame object to allow the plug-in to inform the host about resizing.
public void SetFrame(IAudioPluginFrame? frame)
Parameters
frameIAudioPluginFrameThe frame, or
nullwhen the host detaches it (typically after NPlug.IAudioPluginView.Removed()). A view must not use a previously received frame after receivingnull.
TryFindParameter(int, int, out AudioParameterId)
Find out which parameter in plug-in view is at given position (relative to plug-in view).
public bool TryFindParameter(int xPos, int yPos, out AudioParameterId parameterId)
Parameters
Returns
Remarks
IParameterFinder