Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
vst3_contract_view.hpp
Go to the documentation of this file.
1#pragma once
2
3// The VST3 editor of a processor that supplies an editor factory
4// (`Processor::editor_factory()`, see pulp/format/editor_host.hpp).
5//
6// `PulpVst3Processor::createView()` returns one of these whenever the factory
7// is non-null, and falls back to `make_plug_view()` (the `create_view()` path)
8// when it is null. The view translates IPlugView calls into the contract:
9//
10// attached(parent, type) -> Editor::attach(NativeParent)
11// removed() -> every gesture released, Editor::detach()
12// getSize / onSize -> Editor::size() / Editor::set_size()
13// canResize -> Editor::size_hints() (equal min and max: fixed)
14// checkSizeConstraint -> Editor::adjust_size(), clamped to the hints
15// onKeyDown / onKeyUp -> Editor::offer_key() (forward = kResultFalse,
16// so Space stays the host's transport key)
17// onFocus -> Editor::focus_changed()
18// setContentScaleFactor -> Editor::set_size() with the new scale
19// (IPlugViewContentScaleSupport)
20// while attached -> Editor::idle() from a main-thread timer
21// (detail::MainThreadTimer), started by attached()
22// and stopped by removed(), owner termination and
23// destruction; once stopped it runs no more
24// plug-in code
25// adapter terminate -> every gesture released and Editor::detach()
26// while the host's window is still there, then the
27// editor is destroyed before the processor that
28// owns its factory
29//
30// Each view owns one ContractEditorSession (contract_editor_session.hpp): the
31// editor, its StateStoreParamPort over the adapter's store (so edits reach the
32// host through HostParameterEditBridge -> beginEdit/performEdit/endEdit, and
33// closing one view never ends a gesture another view holds), and the idle
34// tick. This class only maps IPlugView calls onto it.
35//
36// View-free: this names no view, canvas or render type, so it compiles into
37// pulp-format-core with the audio adapter.
38
41
42#include <pluginterfaces/gui/iplugviewcontentscalesupport.h>
43#include <public.sdk/source/common/pluginview.h>
44
45#include <functional>
46#include <memory>
47
48namespace pulp::state {
49class StateStore;
50}
51
52namespace pulp::format::vst3 {
53
55
56class ContractPlugView final : public Steinberg::CPluginView,
57 public Steinberg::IPlugViewContentScaleSupport {
58 public:
61
62 using HostActionHandler = std::function<bool(const HostActionRequest&)>;
63
67 static ContractPlugView* create(PulpVst3Processor& owner, Processor& processor,
68 state::StateStore& store, EditorFactory& factory,
69 HostActionHandler host_action);
70
72
73 // IPlugView
74 Steinberg::tresult PLUGIN_API isPlatformTypeSupported(Steinberg::FIDString type) override;
75 Steinberg::tresult PLUGIN_API attached(void* parent, Steinberg::FIDString type) override;
76 Steinberg::tresult PLUGIN_API removed() override;
77 Steinberg::tresult PLUGIN_API onKeyDown(Steinberg::char16 key, Steinberg::int16 keyCode,
78 Steinberg::int16 modifiers) override;
79 Steinberg::tresult PLUGIN_API onKeyUp(Steinberg::char16 key, Steinberg::int16 keyCode,
80 Steinberg::int16 modifiers) override;
81 Steinberg::tresult PLUGIN_API getSize(Steinberg::ViewRect* size) override;
82 Steinberg::tresult PLUGIN_API onSize(Steinberg::ViewRect* newSize) override;
83 Steinberg::tresult PLUGIN_API onFocus(Steinberg::TBool state) override;
84 Steinberg::tresult PLUGIN_API canResize() override;
85 Steinberg::tresult PLUGIN_API checkSizeConstraint(Steinberg::ViewRect* rect) override;
86
87 // IPlugViewContentScaleSupport
88 Steinberg::tresult PLUGIN_API setContentScaleFactor(ScaleFactor factor) override;
89
90 OBJ_METHODS(ContractPlugView, CPluginView)
91 DEFINE_INTERFACES
92 DEF_INTERFACE(IPlugViewContentScaleSupport)
93 END_DEFINE_INTERFACES(CPluginView)
94 REFCOUNT_METHODS(CPluginView)
95
96
101
103 Editor* editor() const {
104 return session_ ? session_->editor() : nullptr;
105 }
106
108 return session_ ? session_->param_port() : nullptr;
109 }
110
113 static NativeParentKind parent_kind(Steinberg::FIDString type);
115 static EditorKeyEvent key_event(Steinberg::char16 key, Steinberg::int16 key_code,
116 Steinberg::int16 modifiers, bool is_down);
117
118 private:
119 explicit ContractPlugView(PulpVst3Processor& owner);
120 Steinberg::tresult offer(const EditorKeyEvent& event);
121
122 PulpVst3Processor* owner_;
123 std::unique_ptr<ContractEditorSession> session_;
124};
125
126} // namespace pulp::format::vst3
static constexpr int kIdleIntervalMs
Interval of the session's own idle tick while attached (about 60 Hz).
Definition contract_editor_session.hpp:95
Builds a processor's editors.
Definition editor_host.hpp:576
One editor instance in one native window.
Definition editor_host.hpp:429
Definition processor.hpp:174
The default ParamPort, over a processor's StateStore.
Definition editor_host.hpp:186
StateStoreParamPort * param_port() const
This view's parameter port, or null after owner_terminated().
Definition vst3_contract_view.hpp:107
static NativeParentKind parent_kind(Steinberg::FIDString type)
The contract's parent kind for a VST3 platform type, or none for a type it has no kind for.
static EditorKeyEvent key_event(Steinberg::char16 key, Steinberg::int16 key_code, Steinberg::int16 modifiers, bool is_down)
The contract's key event for a VST3 key callback.
Steinberg::tresult PLUGIN_API onFocus(Steinberg::TBool state) override
Steinberg::tresult PLUGIN_API onKeyDown(Steinberg::char16 key, Steinberg::int16 keyCode, Steinberg::int16 modifiers) override
Editor * editor() const
The editor, or null after owner_terminated().
Definition vst3_contract_view.hpp:103
Steinberg::tresult PLUGIN_API onKeyUp(Steinberg::char16 key, Steinberg::int16 keyCode, Steinberg::int16 modifiers) override
std::function< bool(const HostActionRequest &)> HostActionHandler
Definition vst3_contract_view.hpp:62
Steinberg::tresult PLUGIN_API setContentScaleFactor(ScaleFactor factor) override
Steinberg::tresult PLUGIN_API getSize(Steinberg::ViewRect *size) override
Steinberg::tresult PLUGIN_API onSize(Steinberg::ViewRect *newSize) override
Steinberg::tresult PLUGIN_API isPlatformTypeSupported(Steinberg::FIDString type) override
Steinberg::tresult PLUGIN_API checkSizeConstraint(Steinberg::ViewRect *rect) override
Steinberg::tresult PLUGIN_API canResize() override
static ContractPlugView * create(PulpVst3Processor &owner, Processor &processor, state::StateStore &store, EditorFactory &factory, HostActionHandler host_action)
A view over a new editor from factory in the editor role, or null when the factory builds none.
Steinberg::tresult PLUGIN_API attached(void *parent, Steinberg::FIDString type) override
Steinberg::tresult PLUGIN_API removed() override
static constexpr int kIdleIntervalMs
Interval of the main-thread idle tick while attached (about 60 Hz).
Definition vst3_contract_view.hpp:60
DEFINE_INTERFACES void owner_terminated()
The adapter is terminating or being destroyed while the host still holds this view.
Definition vst3_adapter.hpp:140
Centralized parameter storage with lock-free value access.
Definition store.hpp:164
The editor-host contract: how a host (a format adapter, the standalone app, a test) opens,...
Definition vst3_adapter.hpp:61
NativeParentKind
The kind of native window handle an editor is attached to.
Definition editor_host.hpp:315
SequencerStateChannel is the audio-safe transport for a plugin's structured NON-parameter state: the ...
Definition audio_device_manager.hpp:48
A key the host offers to the editor before acting on it itself.
Definition editor_host.hpp:368
One host action and its arguments.
Definition editor_host.hpp:520