Jamba C++ API 7.5.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>
30#include <vstgui4/vstgui/plugin-bindings/vst3editor.h>
31#include "IDialogHandler.h"
32
33namespace pongasoft::VST::GUI {
34
35using namespace Params;
36
42class GUIController : public EditController, public VSTGUI::VST3EditorDelegate, public IMessageProducer, public IDialogHandler
43{
44public:
45 // Constructor
46 explicit GUIController(char const *iXmlFileName = "Views.uidesc",
47 char const *iMainViewName = "view");
48
49 // Destructor
50 ~GUIController() override;
51
55 virtual GUIState *getGUIState() = 0;
56
60 virtual IController *createCustomController(UTF8StringPtr iName,
61 IUIDescription const *iDescription,
62 IController *iBaseController) { return nullptr; };
63
64protected:
66 tresult PLUGIN_API initialize(FUnknown *context) override;
67
69 tresult PLUGIN_API terminate() override;
70
72 IPlugView *PLUGIN_API createView(const char *name) override;
73
74 // didOpen -> track lifecycle of editor (open)
75 void didOpen(VST3Editor *editor) override;
76
77 // willClose -> track lifecycle of editor (close)
78 void willClose(VST3Editor *editor) override;
79
81 tresult PLUGIN_API setComponentState(IBStream *state) override;
82
84 tresult PLUGIN_API setState(IBStream *state) override;
85
87 tresult PLUGIN_API getState(IBStream *state) override;
88
90 tresult PLUGIN_API notify(IMessage *message) SMTG_OVERRIDE;
91
93 IController *createSubController(UTF8StringPtr iName,
94 const IUIDescription *iDescription,
95 VST3Editor *iEditor) override;
96
97 // registerParameters (if not nullptr)
98 void registerParameters(ParamAware *iParamAware);
99
116 virtual bool switchToView(char const *iViewName);
117
121 virtual bool switchToMainView() { return switchToView(fMainViewName.c_str()) ; }
122
124 bool maybeShowDialog();
125
126public:
127 // allocateMessage - API adapter
128 IPtr<IMessage> allocateMessage() override;
129
130 // sendMessage - API adapter
131 tresult sendMessage(IPtr<IMessage> iMessage) override;
132
135 bool showDialog(std::string iTemplateName) override;
136
139 bool dismissDialog() override;
140
141protected:
142 // the name of the xml file (relative) which contains the ui description
143 char const *const fXmlFileName;
144
145 // the default knob mode to use (you can override it in your controller)
146 VSTGUI::CKnobMode fDefaultKnobMode{VSTGUI::CKnobMode::kLinearMode};
147
148private:
149 // view factory used to give access to GUIState to views
151
152 // The name of the main view
153 std::string fMainViewName;
154
155 // The name of the current view
156 std::string fCurrentViewName;
157
158 // Maintains a reference to the ui description
159 SharedPointer<UIDescription> fUIDescription{};
160
161 // The name of the template for the dialog window => empty means no dialog
162 std::string fDialogTemplateName{};
163
164 // The modal view session (managed by SDK)
165 Optional<ModalViewSessionID> fModalViewSession{};
166
167 // we keep a reference to the editor to be able to switch views
168 VSTGUI::VST3Editor *fVST3Editor{};
169
170};
171
172}
bool dismissDialog() override
Dismisses the currently shown dialog.
Definition GUIController.cpp:274
tresult PLUGIN_API setState(IBStream *state) override
Restore the state (UI only!) (ex: after loading preset or project).
Definition GUIController.cpp:171
virtual IController * createCustomController(UTF8StringPtr iName, IUIDescription const *iDescription, IController *iBaseController)
Subclasses should override this method to return the custom controller or nullptr if doesn't match th...
Definition GUIController.h:60
bool showDialog(std::string iTemplateName) override
This method is called with the name of the template to use for the dialog.
Definition GUIController.cpp:257
tresult PLUGIN_API initialize(FUnknown *context) override
Called at first after constructor.
Definition GUIController.cpp:53
Optional< ModalViewSessionID > fModalViewSession
Definition GUIController.h:165
~GUIController() override
Definition GUIController.cpp:45
bool maybeShowDialog()
Shows the dialog if necessary.
Definition GUIController.cpp:291
std::string fDialogTemplateName
Definition GUIController.h:162
tresult PLUGIN_API getState(IBStream *state) override
Called to save the state (UI only!) (before saving a preset or project).
Definition GUIController.cpp:183
void willClose(VST3Editor *editor) override
Definition GUIController.cpp:148
virtual bool switchToMainView()
Switch back to the main view.
Definition GUIController.h:121
SharedPointer< UIDescription > fUIDescription
Definition GUIController.h:159
tresult PLUGIN_API notify(IMessage *message) SMTG_OVERRIDE
Called to handle a message (coming from RT).
Definition GUIController.cpp:195
IPlugView *PLUGIN_API createView(const char *name) override
Create the view.
Definition GUIController.cpp:124
GUIController(char const *iXmlFileName="Views.uidesc", char const *iMainViewName="view")
Definition GUIController.cpp:33
void didOpen(VST3Editor *editor) override
Definition GUIController.cpp:138
void registerParameters(ParamAware *iParamAware)
Definition GUIController.cpp:89
Views::CustomUIViewFactory * fViewFactory
Definition GUIController.h:150
virtual bool switchToView(char const *iViewName)
This method should be called to display a totally different (root) view.
Definition GUIController.cpp:236
tresult PLUGIN_API setComponentState(IBStream *state) override
Sets the component state (after setting the processor) or after restore.
Definition GUIController.cpp:157
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:102
VSTGUI::VST3Editor * fVST3Editor
Definition GUIController.h:168
IController * createSubController(UTF8StringPtr iName, const IUIDescription *iDescription, VST3Editor *iEditor) override
Called when a sub controller needs to be created.
Definition GUIController.cpp:224
IPtr< IMessage > allocateMessage() override
Allocates a message instance.
Definition GUIController.cpp:208
std::string fCurrentViewName
Definition GUIController.h:156
VSTGUI::CKnobMode fDefaultKnobMode
Definition GUIController.h:146
std::string fMainViewName
Definition GUIController.h:153
char const *const fXmlFileName
Definition GUIController.h:143
tresult sendMessage(IPtr< IMessage > iMessage) override
Sends the given message to the peer.
Definition GUIController.cpp:216
Definition GUIState.h:43
Defines the interface to show or dismiss a modal/dialog window which is a window that captures all ev...
Definition IDialogHandler.h:47
This class is inherited by classes who want to be aware of parameters and be notified when they chang...
Definition ParamAware.h:65
Custom view factory to give access to vst parameters.
Definition CustomViewFactory.h:32
Abstraction for allocating and sending a message.
Definition MessageProducer.h:35
Definition GUIState.h:38
Definition DrawContext.cpp:25