Jamba  3.0.2
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 {
32 namespace VST {
33 namespace GUI {
34 
35 using namespace Params;
36 
42 class GUIController : public EditController, public VSTGUI::VST3EditorDelegate, public IMessageProducer
43 {
44 public:
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 
64 protected:
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 
80 protected:
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(GUIParamCxAware *iGUIParamCxAware);
100 
117  virtual bool switchToView(char const *iViewName);
118 
122  virtual bool switchToMainView() { return switchToView(fMainViewName.c_str()) ; }
123 
124 public:
125  // allocateMessage - API adapter
126  IPtr<IMessage> allocateMessage() override;
127 
128  // sendMessage - API adapter
129  tresult sendMessage(IPtr<IMessage> iMessage) override;
130 
131 protected:
132  // the name of the xml file (relative) which contains the ui description
133  char const *const fXmlFileName;
134 
135  // the default knob mode to use (you can override it in your controller)
136  VSTGUI::CKnobMode fDefaultKnobMode{VSTGUI::CKnobMode::kLinearMode};
137 
138 private:
139  // view factory used to give access to GUIState to views
140  Views::CustomUIViewFactory *fViewFactory{nullptr};
141 
142  // The name of the main view
143  std::string fMainViewName;
144 
145  // The name of the current view
146  std::string fCurrentViewName;
147 
148  // we keep a reference to the editor to be able to switch views
149  VSTGUI::VST3Editor *fVST3Editor{};
150 
151 };
152 
153 }
154 }
155 }
std::string fCurrentViewName
Definition: GUIController.h:146
Definition: GUIState.h:39
Definition: GUIController.h:42
Definition: MessageProducer.h:33
Definition: Clock.h:22
virtual IController * createCustomController(UTF8StringPtr iName, IUIDescription const *iDescription, IController *iBaseController)
Definition: GUIController.h:60
virtual bool switchToMainView()
Definition: GUIController.h:122
std::string fMainViewName
Definition: GUIController.h:143
Definition: CustomViewFactory.h:33
Definition: GUIParamCxAware.h:38
char const *const fXmlFileName
Definition: GUIController.h:133