Jamba C++ API  4.1.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 
31 namespace pongasoft::VST::GUI {
32 
33 using namespace Params;
34 
40 class GUIController : public EditController, public VSTGUI::VST3EditorDelegate, public IMessageProducer
41 {
42 public:
43  // Constructor
44  explicit GUIController(char const *iXmlFileName = "Views.uidesc",
45  char const *iMainViewName = "view");
46 
47  // Destructor
48  ~GUIController() override;
49 
53  virtual GUIState *getGUIState() = 0;
54 
58  virtual IController *createCustomController(UTF8StringPtr iName,
59  IUIDescription const *iDescription,
60  IController *iBaseController) { return nullptr; };
61 
62 protected:
64  tresult PLUGIN_API initialize(FUnknown *context) override;
65 
67  tresult PLUGIN_API terminate() override;
68 
70  IPlugView *PLUGIN_API createView(const char *name) override;
71 
72  // didOpen -> track lifecycle of editor (open)
73  void didOpen(VST3Editor *editor) override;
74 
75  // willClose -> track lifecycle of editor (close)
76  void willClose(VST3Editor *editor) override;
77 
78 protected:
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 
122 public:
123  // allocateMessage - API adapter
124  IPtr<IMessage> allocateMessage() override;
125 
126  // sendMessage - API adapter
127  tresult sendMessage(IPtr<IMessage> iMessage) override;
128 
129 protected:
130  // the name of the xml file (relative) which contains the ui description
131  char const *const fXmlFileName;
132 
133  // the default knob mode to use (you can override it in your controller)
134  VSTGUI::CKnobMode fDefaultKnobMode{VSTGUI::CKnobMode::kLinearMode};
135 
136 private:
137  // view factory used to give access to GUIState to views
138  Views::CustomUIViewFactory *fViewFactory{nullptr};
139 
140  // The name of the main view
141  std::string fMainViewName;
142 
143  // The name of the current view
144  std::string fCurrentViewName;
145 
146  // we keep a reference to the editor to be able to switch views
147  VSTGUI::VST3Editor *fVST3Editor{};
148 
149 };
150 
151 }
std::string fCurrentViewName
Definition: GUIController.h:144
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:40
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:40
Abstraction for allocating and sending a message.
Definition: MessageProducer.h:33
std::string fMainViewName
Definition: GUIController.h:141
Definition: DrawContext.cpp:24
char const *const fXmlFileName
Definition: GUIController.h:131
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:58