Jamba C++ API 7.5.0
Loading...
Searching...
No Matches
GUIParamCxMgr.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 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
22
23//------------------------------------------------------------------------
24// GUIParamCxMgr::registerOptionalParam
25//------------------------------------------------------------------------
26template<typename T>
28 Parameters::IChangeListener *iChangeListener)
29{
30 auto param = fGUIState->findParam(iParamID);
31 std::shared_ptr<ITGUIParameter<T>> optionalParam = nullptr;
32
33 if(param)
34 {
35 auto typedParam = param->cast<T>();
36 if(typedParam)
37 {
38 optionalParam = std::move(typedParam);
39 }
40 else
41 {
42 DLOG_F(WARNING, "param [%d] is not of the requested type [%s]", iParamID, Utils::typeString<T>().c_str());
43 }
44 }
45
46 // no vst or jmb parameter match => using default
47 if(!optionalParam)
48 {
49 optionalParam = VstUtils::make_sfo<GUIValParameter<T>>(iParamID, T{});
50
51#ifndef NDEBUG
52 if(iParamID != UNDEFINED_PARAM_ID)
53 DLOG_F(WARNING, "could not find any parameter (vst or jmb) with id [%d]... reverting to default", iParamID);
54#endif
55 }
56
57 return __registerListener(GUIOptionalParam<T>(std::move(optionalParam)), iChangeListener);
58}
59
60//------------------------------------------------------------------------
61// GUIParamCxMgr::registerVstParam
62//------------------------------------------------------------------------
63template<typename T>
65{
66 auto param = fGUIState->getGUIVstParameter<T>(iParamID);
67
68 return __registerListener(GUIVstParam<T>(std::move(param)), iChangeListener);
69}
70
71//------------------------------------------------------------------------
72// GUIParamCxMgr::registerJmbParam
73//------------------------------------------------------------------------
74template<typename T>
76{
77 auto param = fGUIState->getJmbParameter(iParamID);
78
79 if(!param)
80 {
81 DLOG_F(WARNING, "jmb param [%d] not found", iParamID);
82 return GUIJmbParam<T>{};
83 }
84
85 auto res = std::dynamic_pointer_cast<GUIJmbParameter<T>>(param);
86 if(!res)
87 {
88 DLOG_F(WARNING, "jmb param [%d] is not of the requested type [%s]", iParamID, typeid(T).name());
89 }
90
91 return __registerListener(GUIJmbParam<T>(std::move(res)), iChangeListener);
92}
93
94//------------------------------------------------------------------------
95// GUIParamCxMgr::__registerCallback
96//------------------------------------------------------------------------
97template<typename TParam>
98inline TParam GUIParamCxMgr::__registerCallback(TParam iParam, Parameters::ChangeCallback iCallback, bool iInvokeCallback)
99{
100 if(!iCallback)
101 {
102 DLOG_F(WARNING, "Callback is empty... unlikely what you want to do");
103 return iParam;
104 }
105
106 if(iParam.exists())
107 {
108 if(iInvokeCallback)
109 iCallback();
110
111 fParamCxs.emplace_back(iParam.connect(std::move(iCallback)));
112 }
113
114 return iParam;
115}
116
117//------------------------------------------------------------------------
118// GUIParamCxMgr::__registerCallback1
119//------------------------------------------------------------------------
120template<typename TParam>
121inline TParam GUIParamCxMgr::__registerCallback1(TParam iParam,
123 bool iInvokeCallback)
124{
125 if(!iCallback)
126 {
127 DLOG_F(WARNING, "Callback is empty... unlikely what you want to do");
128 return iParam;
129 }
130
131 if(iParam.exists())
132 {
133 // Implementation note: iParam is copied on purpose as we do not know its lifespan (and iParam are simple
134 // wrappers around a shared pointer so cheap/quick to copy)
135 auto callback = [iParam, cb2 = std::move(iCallback)] () mutable { cb2(iParam); };
136
137 if(iInvokeCallback)
138 callback();
139
140 fParamCxs.emplace_back(iParam.connect(std::move(callback)));
141 }
142
143 return iParam;
144}
145
146}
This is the main class that the plugin should use as it exposes only the necessary methods of the par...
Definition GUIJmbParameter.h:497
Represents an optional parameter (Jmb, Vst or no param at all).
Definition GUIOptionalParam.h:50
TParam __registerCallback1(TParam iParam, Parameters::ChangeCallback1< TParam > iCallback, bool iInvokeCallback)
Definition GUIParamCxMgr.hpp:121
GUIJmbParam< T > registerJmbParam(ParamID iParamID, Parameters::IChangeListener *iChangeListener=nullptr)
Definition GUIParamCxMgr.hpp:75
TParam __registerListener(TParam iParam, Parameters::IChangeListener *iChangeListener)
Definition GUIParamCxMgr.h:216
GUIOptionalParam< T > registerOptionalParam(ParamID iParamID, Parameters::IChangeListener *iChangeListener=nullptr)
Definition GUIParamCxMgr.hpp:27
GUIState * fGUIState
Definition GUIParamCxMgr.h:231
GUIVstParam< T > registerVstParam(ParamID iParamID, Parameters::IChangeListener *iChangeListener=nullptr)
Definition GUIParamCxMgr.hpp:64
TParam __registerCallback(TParam iParam, Parameters::ChangeCallback iCallback, bool iInvokeCallback)
Definition GUIParamCxMgr.hpp:98
std::vector< std::unique_ptr< FObjectCx > > fParamCxs
Definition GUIParamCxMgr.h:234
This is the main class that the plugin should use as it exposes only the necessary methods of the par...
Definition GUIVstParameter.h:280
Interface to implement to receive parameter changes.
Definition Parameters.h:45
std::function< void()> ChangeCallback
A callback that will be invoked for changes.
Definition Parameters.h:56
std::function< void(Param &)> ChangeCallback1
A callback which will be invoked for changes with the param as an argument.
Definition Parameters.h:62
std::string typeString()
typeid(T).name() does not account for const or reference.
Definition Metaprogramming.h:121
Definition GUIState.h:38
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
constexpr ParamID UNDEFINED_PARAM_ID
Constant used throughout the code to test whether the ParamID represents a valid id or an undefined o...
Definition Types.h:48