Jamba C++ API 8.0.0
Loading...
Searching...
No Matches
GUIController.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018-2019 pongasoft
3 *
4 * Licensed under the Apache License, Version 2.0 or the MIT license,
5 * at your option. You may not use this file except in compliance with
6 * one of these licenses. You may obtain copies of the licenses at:
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 * https://opensource.org/licenses/MIT
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 *
17 * @author Yan Pujante
18 */
19#pragma once
20
21#include <memory>
22
23#include <public.sdk/source/vst/vsteditcontroller.h>
24#include <vstgui4/vstgui/lib/cframe.h>
31#include <vstgui4/vstgui/plugin-bindings/vst3editor.h>
32#include "IDialogHandler.h"
33
34namespace pongasoft::VST::GUI {
35
36using namespace Params;
37
43class GUIController : public EditController, public VSTGUI::VST3EditorDelegate, public IMessageProducer, public IDialogHandler
44{
45public:
46 // Constructor
47 explicit GUIController(char const *iXmlFileName = "Views.uidesc",
48 char const *iMainViewName = "view");
49
50 // Destructor
51 ~GUIController() override;
52
56 virtual GUIState *getGUIState() = 0;
57
61 virtual IController *createCustomController(UTF8StringPtr iName,
62 IUIDescription const *iDescription,
63 IController *iBaseController) { return nullptr; }
64
65protected:
67 tresult PLUGIN_API initialize(FUnknown *context) override;
68
70 tresult PLUGIN_API terminate() override;
71
73 IPlugView *PLUGIN_API createView(const char *name) override;
74
75 // didOpen -> track lifecycle of editor (open)
76 void didOpen(VST3Editor *editor) override;
77
78 // willClose -> track lifecycle of editor (close)
79 void willClose(VST3Editor *editor) override;
80
82 tresult PLUGIN_API setComponentState(IBStream *state) override;
83
85 tresult PLUGIN_API setState(IBStream *state) override;
86
88 tresult PLUGIN_API getState(IBStream *state) override;
89
91 tresult PLUGIN_API notify(IMessage *message) SMTG_OVERRIDE;
92
94 IController *createSubController(UTF8StringPtr iName,
95 const IUIDescription *iDescription,
96 VST3Editor *iEditor) override;
97
98 // registerParameters (if not nullptr)
99 void registerParameters(ParamAware *iParamAware);
100
117 virtual bool switchToView(char const *iViewName);
118
122 virtual bool switchToMainView() { return switchToView(fMainViewName.c_str()) ; }
123
125 bool maybeShowDialog();
126
128 ITransportControl *findTransportControl() const { return fTransportControl; }
129
132
133public:
134 // allocateMessage - API adapter
135 IPtr<IMessage> allocateMessage() override;
136
137 // sendMessage - API adapter
138 tresult sendMessage(IPtr<IMessage> iMessage) override;
139
142 bool showDialog(std::string iTemplateName) override;
143
146 bool dismissDialog() override;
147
148protected:
149 // the name of the xml file (relative) which contains the ui description
150 char const *const fXmlFileName;
151
152 // the default knob mode to use (you can override it in your controller)
153 VSTGUI::CKnobMode fDefaultKnobMode{VSTGUI::CKnobMode::kLinearMode};
154
155private:
156 // view factory used to give access to GUIState to views
158
159 // The name of the main view
160 std::string fMainViewName;
161
162 // The name of the current view
163 std::string fCurrentViewName;
164
165 // Maintains a reference to the ui description
166 SharedPointer<UIDescription> fUIDescription{};
167
168 // The name of the template for the dialog window => empty means no dialog
169 std::string fDialogTemplateName{};
170
171 // The modal view session (managed by SDK)
172 Optional<ModalViewSessionID> fModalViewSession{};
173
174 // we keep a reference to the editor to be able to switch views
175 VSTGUI::VST3Editor *fVST3Editor{};
176
177 // Exposed to controller and state to manage transport control
178 ITransportControl *fTransportControl{};
179};
180
181}
bool dismissDialog() override
Dismisses the currently shown dialog.
Definition GUIController.cpp:279
tresult PLUGIN_API setState(IBStream *state) override
Restore the state (UI only!) (ex: after loading preset or project).
Definition GUIController.cpp:176
virtual IController * createCustomController(UTF8StringPtr iName, IUIDescription const *iDescription, IController *iBaseController)
Subclasses should override this method to return the custom controller or nullptr if it doesn't match...
Definition GUIController.h:61
bool showDialog(std::string iTemplateName) override
This method is called with the name of the template to use for the dialog.
Definition GUIController.cpp:262
tresult PLUGIN_API initialize(FUnknown *context) override
Called at first after constructor.
Definition GUIController.cpp:54
Optional< ModalViewSessionID > fModalViewSession
Definition GUIController.h:172
~GUIController() override
Definition GUIController.cpp:46
bool maybeShowDialog()
Shows the dialog if necessary.
Definition GUIController.cpp:296
std::string fDialogTemplateName
Definition GUIController.h:169
tresult PLUGIN_API getState(IBStream *state) override
Called to save the state (UI only!) (before saving a preset or project).
Definition GUIController.cpp:188
void willClose(VST3Editor *editor) override
Definition GUIController.cpp:153
virtual bool switchToMainView()
Switch back to the main view.
Definition GUIController.h:122
SharedPointer< UIDescription > fUIDescription
Definition GUIController.h:166
tresult PLUGIN_API notify(IMessage *message) SMTG_OVERRIDE
Called to handle a message (coming from RT).
Definition GUIController.cpp:200
IPlugView *PLUGIN_API createView(const char *name) override
Create the view.
Definition GUIController.cpp:129
GUIController(char const *iXmlFileName="Views.uidesc", char const *iMainViewName="view")
Definition GUIController.cpp:34
void didOpen(VST3Editor *editor) override
Definition GUIController.cpp:143
void registerParameters(ParamAware *iParamAware)
Definition GUIController.cpp:94
Views::CustomUIViewFactory * fViewFactory
Definition GUIController.h:157
virtual bool switchToView(char const *iViewName)
This method should be called to display a totally different (root) view.
Definition GUIController.cpp:241
tresult PLUGIN_API setComponentState(IBStream *state) override
Sets the component state (after setting the processor) or after restore.
Definition GUIController.cpp:162
virtual GUIState * getGUIState()=0
Subclasses must implement this method to return the state.
tresult PLUGIN_API terminate() override
Called at the end before destructor.
Definition GUIController.cpp:107
ITransportControl * fTransportControl
Definition GUIController.h:178
VSTGUI::VST3Editor * fVST3Editor
Definition GUIController.h:175
ITransportControl * findTransportControl() const
Returns the low level transport control (nullptr when no transport control is available).
Definition GUIController.h:128
TransportControlHandler getTransportControlHandler() const
Returns the convenient transport control handler.
Definition GUIController.h:131
IController * createSubController(UTF8StringPtr iName, const IUIDescription *iDescription, VST3Editor *iEditor) override
Called when a sub controller needs to be created.
Definition GUIController.cpp:229
IPtr< IMessage > allocateMessage() override
Allocates a message instance.
Definition GUIController.cpp:213
std::string fCurrentViewName
Definition GUIController.h:163
VSTGUI::CKnobMode fDefaultKnobMode
Definition GUIController.h:153
std::string fMainViewName
Definition GUIController.h:160
char const *const fXmlFileName
Definition GUIController.h:150
tresult sendMessage(IPtr< IMessage > iMessage) override
Sends the given message to the peer.
Definition GUIController.cpp:221
Definition GUIState.h:45
Defines the interface to show or dismiss a modal/dialog window which is a window that captures all ev...
Definition IDialogHandler.h:46
This class is inherited by classes who want to be aware of parameters and be notified when they chang...
Definition ParamAware.h:64
This class is a thin wrapper around the ITransportControl interface to expose it as convenient method...
Definition TransportControlHandler.h:49
Custom view factory to give access to vst parameters.
Definition CustomViewFactory.h:32
Abstraction for allocating and sending a message.
Definition MessageProducer.h:34
Definition GUIState.h:40
Definition DrawContext.cpp:25