Jamba C++ API 8.0.0
Loading...
Searching...
No Matches
GUIState.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018-2020 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
25#include <pongasoft/VST/GUI/Params/IGUIParameter.hpp> // IDE flagged as non used. Ignore! Do not remove!
29#include "ParamAwareViews.h"
30#include "IDialogHandler.h"
32
33namespace pongasoft::VST {
34
35namespace Debug { class ParamDisplay; }
36namespace GUI {
37
38using namespace Params;
39
40namespace Params {
41class GUIParamCxMgr;
42}
43
45{
46public:
47 // Constructor
48 explicit GUIState(Parameters const &iPluginParameters);
49
52 virtual tresult init(VstParametersSPtr iVstParameters,
53 IMessageProducer *iMessageProducer,
54 IDialogHandler *iDialogHandler,
55 ITransportControl *iTransportControl);
56
57 // getPluginParameters
59
63 template<typename T>
65
69 bool existsVst(ParamID iParamID) const { return fVstParameters && fVstParameters->exists(iParamID); }
70
74 bool existsJmb(ParamID iParamID) const { return fJmbParams.contains(iParamID)
75 ||
76 fPluginParameters.getJmbParamDef(iParamID) != nullptr; }
77
82 std::shared_ptr<IGUIParameter> findParam(ParamID iParamID) const;
83
87 std::shared_ptr<GUIRawVstParameter> getRawVstParameter(ParamID iParamID) const
88 {
89 if(existsVst(iParamID))
90 return std::make_shared<GUIRawVstParameter>(iParamID,
92 fPluginParameters.getRawVstParamDef(iParamID));
93 else
94 return nullptr;
95 }
96
97 // getRawVstParamDef
98 std::shared_ptr<RawVstParamDef> getRawVstParamDef(ParamID iParamID) const
99 {
100 return fPluginParameters.getRawVstParamDef(iParamID);
101 }
102
103 // getGUIVstParameter
104 template<typename T>
105 std::shared_ptr<GUIVstParameter<T>> getGUIVstParameter(ParamID iParamID) const;
106
107 // getGUIVstParameter
108 template<typename T>
109 std::shared_ptr<GUIVstParameter<T>> getGUIVstParameter(VstParam<T> iParamDef) const {
110 return iParamDef ? getGUIVstParameter<T>(iParamDef->fParamID) : nullptr;
111 }
112
119 std::unique_ptr<FObjectCx> connect(ParamID iParamID, Parameters::IChangeListener *iChangeListener) const
120 {
121 auto ptr = findParam(iParamID);
122 if(ptr)
123 return ptr->connect(iChangeListener);
124 else
125 return nullptr;
126 }
127
134 std::unique_ptr<FObjectCx> connect(ParamID iParamID, Parameters::ChangeCallback iChangeCallback) const
135 {
136 auto ptr = findParam(iParamID);
137 if(ptr)
138 return ptr->connect(iChangeCallback);
139 else
140 return nullptr;
141 }
142
160 template<CViewSubclass TView>
162 return fParamAwareViews.makeParamAware(iView, this);
163 }
164
168 std::shared_ptr<IGUIJmbParameter> getJmbParameter(ParamID iParamID) const;
169
174 virtual tresult readRTState(IBStreamer &iStreamer);
175
180 virtual tresult readGUIState(IBStreamer &iStreamer);
181
186 virtual tresult writeGUIState(IBStreamer &oStreamer) const;
187
192 std::unique_ptr<GUIParamCxMgr> createParamCxMgr();
193
197 tresult handleMessage(Message const &iMessage) { return fMessageHandler.handleMessage(iMessage); }
198
202 template<typename T>
203 tresult broadcast(JmbParam<T> const &iParamDef, T const &iMessage);
204
205 // getAllRegistrationOrder
206 std::vector<ParamID> const &getAllRegistrationOrder() const { return fAllRegistrationOrder; }
207
219 virtual tresult handleGUIStateUpgrade(int16 iDeprecatedVersion, int16 iVersion) const { return kResultTrue; }
220
223 bool showDialog(std::string iTemplateName) override;
224
227 bool dismissDialog() override;
228
230 ITransportControl *findTransportControl() const { return fTransportControl; }
231
234
235 // gives access for debug
237
238protected:
239 // the parameters
241
242 // raw vst parameters
244
245 // param aware views
247
248 // message producer (to send messages)
250
251 // handles messages (receive messages)
253
254 // handles show/dismiss dialog window
256
257 // Exposed to state to manage transport control
258 ITransportControl *fTransportControl{};
259
260 // contains all the (serializable) registered parameters (unique ID, will be checked on add)
261 std::map<ParamID, std::shared_ptr<IGUIJmbParameter>> fJmbParams{};
262
263 // order in which the parameters were registered
264 std::vector<ParamID> fAllRegistrationOrder{};
265
266protected:
267 // setParamNormalized
268 tresult setParamNormalized(NormalizedState const *iNormalizedState);
269
270 // add serializable parameter to the structures
271 void addJmbParam(std::shared_ptr<IGUIJmbParameter> iParameter);
272
273 // allocateMessage
274 IPtr<IMessage> allocateMessage() override;
275
276 // sendMessage
277 tresult sendMessage(IPtr<IMessage> iMessage) override;
278
279 virtual tresult readDeprecatedGUIState(uint16 iDeprecatedVersion,
280 IBStreamer &iStreamer,
281 NormalizedState::SaveOrder const &iLatestSaveOrder);
282
284 virtual tresult readGUIState(NormalizedState::SaveOrder const &iSaveOrder, IBStreamer &iStreamer);
285};
286
288template<typename T>
289concept GUIStateSubclass = std::derived_from<T, GUIState>;
290
296template<ParametersSubclass TPluginParameters>
298{
299public:
300 using PluginParameters = TPluginParameters;
301
302public:
303 explicit GUIPluginState(PluginParameters const &iPluginParameters) :
304 GUIState{iPluginParameters},
305 fParams{iPluginParameters}
306 { }
307
308public:
310};
311
312//------------------------------------------------------------------------
313// GUIState::add
314//------------------------------------------------------------------------
315template<typename T>
317{
318 auto guiParam = iParamDef->newGUIParam();
319 addJmbParam(guiParam);
320 return GUIJmbParam<T>(std::dynamic_pointer_cast<GUIJmbParameter<T>>(guiParam));
321}
322
323//------------------------------------------------------------------------
324// GUIState::broadcast
325//------------------------------------------------------------------------
326template<typename T>
327tresult GUIState::broadcast(JmbParam<T> const &iParamDef, const T &iMessage)
328{
329 if(!iParamDef->fShared)
330 {
331 DLOG_F(WARNING, "broadcast ignored: parameter [%d] is not marked shared", iParamDef->fParamID);
332 return kResultFalse;
333 }
334
335 tresult res = kResultOk;
336
337 auto message = allocateMessage();
338
339 if(message)
340 {
341 Message m{message.get()};
342
343 // sets the message ID
344 m.setMessageID(iParamDef->fParamID);
345
346 // serialize the content
347 if(iParamDef->writeToMessage(iMessage, m) == kResultOk)
348 res |= sendMessage(message);
349 else
350 res = kResultFalse;
351 }
352 else
353 res = kResultFalse;
354
355 return res;
356}
357
358//------------------------------------------------------------------------
359// GUIState::getGUIVstParameter
360//------------------------------------------------------------------------
361template<typename T>
362std::shared_ptr<GUIVstParameter<T>> GUIState::getGUIVstParameter(ParamID iParamID) const
363{
364 std::shared_ptr<GUIRawVstParameter> param = getRawVstParameter(iParamID);
365
366 if(!param)
367 {
368 DLOG_F(WARNING, "vst param [%d] not found", iParamID);
369 return nullptr;
370 }
371
372 auto res = param->asVstParameter<T>();
373
374 if(res)
375 return res;
376 else
377 {
378 DLOG_F(WARNING, "vst param [%d] is not of the requested type", iParamID);
379 return nullptr;
380 }
381}
382
383
384}
385}
386
387//------------------------------------------------------------------------
388// Implementation note: because of the circular dependency between
389// JmbParamDef and IGUIJmbParameter, this templated method is defined
390// here in GUIState.h since GUIState.cpp is the primary user of this
391// method.
392//------------------------------------------------------------------------
393namespace pongasoft::VST {
394//------------------------------------------------------------------------
395// JmbParamDef<T>::newGUIParam
396//------------------------------------------------------------------------
397template<typename T>
398std::shared_ptr<GUI::Params::IGUIJmbParameter> JmbParamDef<T>::newGUIParam()
399{
400 auto ptr = std::dynamic_pointer_cast<JmbParamDef<T>>(IParamDef::shared_from_this());
402}
403}
404
This helper class is used to display the parameters (vst/jmb) WARNING: this class is allocating memor...
Definition ParamDisplay.h:33
PluginParameters const & fParams
Definition GUIState.h:309
TPluginParameters PluginParameters
Definition GUIState.h:300
GUIPluginState(PluginParameters const &iPluginParameters)
Definition GUIState.h:303
bool dismissDialog() override
Dismisses the currently shown dialog.
Definition GUIState.cpp:347
Parameters const & getPluginParameters() const
Definition GUIState.h:58
std::shared_ptr< IGUIParameter > findParam(ParamID iParamID) const
Generic call which returns a param with the given id or nullptr if there isn't one.
Definition GUIState.cpp:36
std::shared_ptr< RawVstParamDef > getRawVstParamDef(ParamID iParamID) const
Definition GUIState.h:98
bool showDialog(std::string iTemplateName) override
This method is called with the name of the template to use for the dialog.
Definition GUIState.cpp:336
bool existsVst(ParamID iParamID) const
Definition GUIState.h:69
ParamAwareView< TView > * makeParamAware(TView *iView)
Allow for registering an arbitrary callback on an arbitrary view without having to inherit from the v...
Definition GUIState.h:161
virtual tresult readGUIState(IBStreamer &iStreamer)
This method is called from the GUI controller setState method and reads the state previously saved by...
Definition GUIState.cpp:119
virtual tresult readRTState(IBStreamer &iStreamer)
This method is called from the GUI controller setComponentState method and reads the state coming fro...
Definition GUIState.cpp:102
std::shared_ptr< GUIVstParameter< T > > getGUIVstParameter(VstParam< T > iParamDef) const
Definition GUIState.h:109
std::unique_ptr< FObjectCx > connect(ParamID iParamID, Parameters::IChangeListener *iChangeListener) const
Connects the paramID to the listener.
Definition GUIState.h:119
virtual tresult readDeprecatedGUIState(uint16 iDeprecatedVersion, IBStreamer &iStreamer, NormalizedState::SaveOrder const &iLatestSaveOrder)
Definition GUIState.cpp:143
std::vector< ParamID > const & getAllRegistrationOrder() const
Definition GUIState.h:206
std::unique_ptr< GUIParamCxMgr > createParamCxMgr()
The CustomView class automatically calls this method to get a handle of a ParamCxMgr used to register...
Definition GUIState.cpp:281
virtual tresult writeGUIState(IBStreamer &oStreamer) const
This method is called from the GUI controller getState method and writes the state specific to the GU...
Definition GUIState.cpp:205
virtual tresult init(VstParametersSPtr iVstParameters, IMessageProducer *iMessageProducer, IDialogHandler *iDialogHandler, ITransportControl *iTransportControl)
Called by the GUIController.
Definition GUIState.cpp:241
std::shared_ptr< IGUIJmbParameter > getJmbParameter(ParamID iParamID) const
Definition GUIState.cpp:289
IMessageProducer * fMessageProducer
Definition GUIState.h:249
tresult setParamNormalized(NormalizedState const *iNormalizedState)
Definition GUIState.cpp:86
ParamAwareViews fParamAwareViews
Definition GUIState.h:246
std::unique_ptr< FObjectCx > connect(ParamID iParamID, Parameters::ChangeCallback iChangeCallback) const
Connects the paramID to the callback.
Definition GUIState.h:134
Parameters const & fPluginParameters
Definition GUIState.h:240
IDialogHandler * fDialogHandler
Definition GUIState.h:255
std::shared_ptr< GUIRawVstParameter > getRawVstParameter(ParamID iParamID) const
Definition GUIState.h:87
VstParametersSPtr fVstParameters
Definition GUIState.h:243
std::vector< ParamID > fAllRegistrationOrder
Definition GUIState.h:264
MessageHandler fMessageHandler
Definition GUIState.h:252
ITransportControl * fTransportControl
Definition GUIState.h:258
GUIJmbParam< T > add(JmbParam< T > iParamDef)
This method is called for each parameter managed by the GUIState that is not a regular VST parameter.
Definition GUIState.h:316
ITransportControl * findTransportControl() const
Returns the low level transport control (nullptr when no transport control is available).
Definition GUIState.h:230
std::shared_ptr< GUIVstParameter< T > > getGUIVstParameter(ParamID iParamID) const
Definition GUIState.h:362
GUIState(Parameters const &iPluginParameters)
Definition GUIState.cpp:28
tresult broadcast(JmbParam< T > const &iParamDef, T const &iMessage)
Broadcast a message without requiring the need to instantiate a GUIJmbParam.
Definition GUIState.h:327
TransportControlHandler getTransportControlHandler() const
Returns the convenient transport control handler.
Definition GUIState.h:233
IPtr< IMessage > allocateMessage() override
Allocates a message instance.
Definition GUIState.cpp:314
std::map< ParamID, std::shared_ptr< IGUIJmbParameter > > fJmbParams
Definition GUIState.h:261
void addJmbParam(std::shared_ptr< IGUIJmbParameter > iParameter)
Definition GUIState.cpp:49
bool existsJmb(ParamID iParamID) const
Definition GUIState.h:74
virtual tresult handleGUIStateUpgrade(int16 iDeprecatedVersion, int16 iVersion) const
When Jamba detects that a previously saved GUI state matches a deprecated version (as registered with...
Definition GUIState.h:219
tresult sendMessage(IPtr< IMessage > iMessage) override
Sends the given message to the peer.
Definition GUIState.cpp:325
tresult handleMessage(Message const &iMessage)
Handle an incoming message => will forward to JmbParam marked shared by rtOwner.
Definition GUIState.h:197
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 manages the views that have been made "param aware".
Definition ParamAwareViews.h:88
This is the main class that the plugin should use as it exposes only the necessary methods of the par...
Definition GUIJmbParameter.h:497
This is the templated version providing serializer methods, very similar to the GUIVstParameter conce...
Definition GUIJmbParameter.h:88
Maintains the connections established between parameters and its listeners/callbacks.
Definition GUIParamCxMgr.h:33
This subclass allows for registering callbacks to any kind of view without having to inherit from it.
Definition ParamAware.h:516
This class is a thin wrapper around the ITransportControl interface to expose it as convenient method...
Definition TransportControlHandler.h:49
Abstraction for allocating and sending a message.
Definition MessageProducer.h:34
std::shared_ptr< GUI::Params::IGUIJmbParameter > newGUIParam() override
Create a new IGUIJmbParameter of the proper subtype.
Definition GUIState.h:398
Simple implementation of IMessageHandler which will delegate the message handling based on MessageID.
Definition MessageHandler.h:41
Simple wrapper class with better api.
Definition Messaging.h:43
void setMessageID(MessageID messageID)
Definition Messaging.h:52
Used to communicate the state between the UI and the RT and read/write to stream.
Definition NormalizedState.h:39
Interface to implement to receive parameter changes.
Definition Parameters.h:47
This is the class that maintains all the registered parameters.
Definition Parameters.h:41
std::function< void()> ChangeCallback
A callback that will be invoked for changes.
Definition Parameters.h:61
Concept for a subclass of GUIState.
Definition GUIState.h:289
Definition ParamDisplay.cpp:29
Definition GUIState.h:40
std::shared_ptr< VstParameters > VstParametersSPtr
Definition VstParameters.h:92
Definition DrawContext.cpp:25
std::shared_ptr< T > make_sfo(Args &&...iArgs)
The VST SDK uses the concept of FObject (which are self contained reference counted objects) but requ...
Definition Utils.h:86
Definition Clock.h:24
std::shared_ptr< JmbParamDef< T > > JmbParam
Definition ParamDef.h:522
std::shared_ptr< VstParamDef< T > > VstParam
Definition ParamDef.h:509
Maintains the order used to save/restore the RT and GUI state.
Definition NormalizedState.h:45