Jamba C++ API  5.0.0
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 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  *
16  * @author Yan Pujante
17  */
18 #pragma once
19 
20 #include <memory>
21 
22 #include <public.sdk/source/vst/vsteditcontroller.h>
23 #include <vstgui4/vstgui/lib/cframe.h>
29 #include <vstgui4/vstgui/plugin-bindings/vst3editor.h>
30 #include "IDialogHandler.h"
31 
32 namespace pongasoft::VST::GUI {
33 
34 using namespace Params;
35 
41 class GUIController : public EditController, public VSTGUI::VST3EditorDelegate, public IMessageProducer, public IDialogHandler
42 {
43 public:
44  // Constructor
45  explicit GUIController(char const *iXmlFileName = "Views.uidesc",
46  char const *iMainViewName = "view");
47 
48  // Destructor
49  ~GUIController() override;
50 
54  virtual GUIState *getGUIState() = 0;
55 
59  virtual IController *createCustomController(UTF8StringPtr iName,
60  IUIDescription const *iDescription,
61  IController *iBaseController) { return nullptr; };
62 
63 protected:
65  tresult PLUGIN_API initialize(FUnknown *context) override;
66 
68  tresult PLUGIN_API terminate() override;
69 
71  IPlugView *PLUGIN_API createView(const char *name) override;
72 
73  // didOpen -> track lifecycle of editor (open)
74  void didOpen(VST3Editor *editor) override;
75 
76  // willClose -> track lifecycle of editor (close)
77  void willClose(VST3Editor *editor) override;
78 
80  tresult PLUGIN_API setComponentState(IBStream *state) override;
81 
83  tresult PLUGIN_API setState(IBStream *state) override;
84 
86  tresult PLUGIN_API getState(IBStream *state) override;
87 
89  tresult PLUGIN_API notify(IMessage *message) SMTG_OVERRIDE;
90 
92  IController *createSubController(UTF8StringPtr iName,
93  const IUIDescription *iDescription,
94  VST3Editor *iEditor) override;
95 
96  // registerParameters (if not nullptr)
97  void registerParameters(ParamAware *iParamAware);
98 
115  virtual bool switchToView(char const *iViewName);
116 
120  virtual bool switchToMainView() { return switchToView(fMainViewName.c_str()) ; }
121 
123  bool maybeShowDialog();
124 
125 public:
126  // allocateMessage - API adapter
127  IPtr<IMessage> allocateMessage() override;
128 
129  // sendMessage - API adapter
130  tresult sendMessage(IPtr<IMessage> iMessage) override;
131 
134  bool showDialog(std::string iTemplateName) override;
135 
138  bool dismissDialog() override;
139 
140 protected:
141  // the name of the xml file (relative) which contains the ui description
142  char const *const fXmlFileName;
143 
144  // the default knob mode to use (you can override it in your controller)
145  VSTGUI::CKnobMode fDefaultKnobMode{VSTGUI::CKnobMode::kLinearMode};
146 
147 private:
148  // view factory used to give access to GUIState to views
149  Views::CustomUIViewFactory *fViewFactory{nullptr};
150 
151  // The name of the main view
152  std::string fMainViewName;
153 
154  // The name of the current view
155  std::string fCurrentViewName;
156 
157  // Maintains a reference to the ui description
158  SharedPointer<UIDescription> fUIDescription{};
159 
160  // The name of the template for the dialog window => empty means no dialog
161  std::string fDialogTemplateName{};
162 
163  // The modal view session (managed by SDK)
164  Optional<ModalViewSessionID> fModalViewSession{};
165 
166  // we keep a reference to the editor to be able to switch views
167  VSTGUI::VST3Editor *fVST3Editor{};
168 
169 };
170 
171 }
std::string fCurrentViewName
Definition: GUIController.h:155
This class is inherited by classes who want to be aware of parameters and be notified when they chang...
Definition: ParamAware.h:63
Definition: GUIState.h:41
virtual bool switchToMainView()
Switch back to the main view.
Definition: GUIController.h:120
Base class from which the actual controller inherits from.
Definition: GUIController.h:41
Abstraction for allocating and sending a message.
Definition: MessageProducer.h:33
std::string fMainViewName
Definition: GUIController.h:152
Definition: DrawContext.cpp:24
char const *const fXmlFileName
Definition: GUIController.h:142
Custom view factory to give access to vst parameters.
Definition: CustomViewFactory.h:30
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:59
Defines the interface to show or dismiss a modal/dialog window which is a window that captures all ev...
Definition: IDialogHandler.h:45