Jamba C++ API 7.5.0
Loading...
Searching...
No Matches
RTJmbInParameter.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018-2023 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
20#pragma once
21
25
27
28using namespace Utils;
29
34{
35public:
36 // Constructor
37 explicit IRTJmbInParameter(std::shared_ptr<IJmbParamDef> iParamDef) : fParamDef{std::move(iParamDef)} {}
38
39 // getParamDef
40 inline IJmbParamDef const *getParamDef() const { return fParamDef.get(); }
41
42 // getParamID
43 ParamID getParamID() const { return fParamDef->fParamID; }
44
45 // destructor
46 ~IRTJmbInParameter() override = default;
47
48 // hasUpdate
49 virtual bool hasUpdate() const = 0;
50
51 // readFromMessage
52 virtual tresult readFromMessage(Message const &iMessage) = 0;
53
54 // handleMessage
55 tresult handleMessage(Message const &iMessage) override { return readFromMessage(iMessage); }
56
57 // writeToStream
58 virtual void writeToStream(std::ostream &oStream) const = 0;
59
60protected:
61 std::shared_ptr<IJmbParamDef> fParamDef;
62};
63
70template<typename T>
72{
73public:
74 using ParamType = T;
75
76 explicit RTJmbInParameter(std::shared_ptr<JmbParamDef<T>> iParamDef) :
77 IRTJmbInParameter(iParamDef),
78 fUpdateQueue{std::make_unique<T>(iParamDef->fDefaultValue), true}
79 {}
80
81 // getParamDef
82 inline JmbParamDef<T> const *getParamDefT() const
83 {
84 return static_cast<JmbParamDef<T> const *>(getParamDef());
85 }
86
87 // pop
88 inline ParamType *pop() { return fUpdateQueue.pop(); }
89
90 // last
91 inline ParamType const *last() const { return fUpdateQueue.last(); }
92
93 // popOrLast
94 inline ParamType const *popOrLast() { return fUpdateQueue.popOrLast(); }
95
96 // hasUpdate
97 bool hasUpdate() const override { return !fUpdateQueue.isEmpty(); }
98
99 // readFromMessage - called to extract the value from the message
100 tresult readFromMessage(Message const &iMessage) override;
101
102 // writeToStream
103 void writeToStream(std::ostream &oStream) const override;
104
105private:
107};
108
109//------------------------------------------------------------------------
110// RTJmbInParameter::readFromMessage
111//------------------------------------------------------------------------
112template<typename T>
114{
115 bool res = fUpdateQueue.updateAndPushIf([this, &iMessage](auto oUpdate) -> bool {
116 return getParamDefT()->readFromMessage(iMessage, *oUpdate) == kResultOk;
117 });
118
119 return res ? kResultOk : kResultFalse;
120}
121
122//------------------------------------------------------------------------
123// RTJmbInParameter::writeToStream
124//------------------------------------------------------------------------
125template<typename T>
126void RTJmbInParameter<T>::writeToStream(std::ostream &oStream) const
127{
128 getParamDefT()->writeToStream(*last(), oStream);
129}
130
131//------------------------------------------------------------------------
132// RTJmbInParam - wrapper to make writing the code much simpler and natural
133//------------------------------------------------------------------------
140template<typename T>
142{
143public:
144 RTJmbInParam(RTJmbInParameter<T> *iPtr) : fPtr{iPtr} // NOLINT (not marked explicit on purpose)
145 {
146 DCHECK_F(fPtr != nullptr);
147 }
148
149 // getParamID
150 inline ParamID getParamID() const { return fPtr->getParamID(); }
151
152 // pop - nullptr if no update
153 inline T *pop() { return fPtr->pop(); }
154
155 // last - last value popped (does not pop!)
156 inline T const *last() const { return fPtr->last(); }
157
158 // popOrLast - call pop and no new value then call last
159 inline T const *popOrLast() { return fPtr->popOrLast(); }
160
161 // hasUpdate
162 bool hasUpdate() const { return fPtr->hasUpdate(); }
163
164 // getValue
165 inline T const &getValue() const { return *fPtr->last(); }
166
167 // value - synonym
168 inline T const &value() const { return *fPtr->last(); }
169
170 // allow to use the param as the underlying ParamType (ex: "if(param)" in the case ParamType is bool))
171 inline operator T const &() const { return *fPtr->last(); } // NOLINT
172
173 // allow writing param->xxx to access the underlying type directly (if not a primitive)
174 inline T const *operator->() const { return fPtr->last(); }
175
176private:
178};
179
180template<typename T, size_t N>
181using RTJmbInParams = std::array<RTJmbInParam<T>, N>;
182
183}
This is the lock free version of the SingleElementQueue.
Definition Concurrent.h:150
Base class for jamba parameters (non templated).
Definition ParamDef.h:281
Interface defining a message handler.
Definition MessageHandler.h:32
Base class for all non vst parameters (need to provide serialization/deserialization).
Definition ParamDef.h:318
Simple wrapper class with better api.
Definition Messaging.h:46
tresult handleMessage(Message const &iMessage) override
Definition RTJmbInParameter.h:55
IJmbParamDef const * getParamDef() const
Definition RTJmbInParameter.h:40
virtual tresult readFromMessage(Message const &iMessage)=0
virtual void writeToStream(std::ostream &oStream) const =0
ParamID getParamID() const
Definition RTJmbInParameter.h:43
std::shared_ptr< IJmbParamDef > fParamDef
Definition RTJmbInParameter.h:61
IRTJmbInParameter(std::shared_ptr< IJmbParamDef > iParamDef)
Definition RTJmbInParameter.h:37
virtual bool hasUpdate() const =0
RTJmbInParameter< T > * fPtr
Definition RTJmbInParameter.h:177
bool hasUpdate() const
Definition RTJmbInParameter.h:162
T const * popOrLast()
Definition RTJmbInParameter.h:159
T * pop()
Definition RTJmbInParameter.h:153
RTJmbInParam(RTJmbInParameter< T > *iPtr)
Definition RTJmbInParameter.h:144
ParamID getParamID() const
Definition RTJmbInParameter.h:150
T const * operator->() const
Definition RTJmbInParameter.h:174
T const * last() const
Definition RTJmbInParameter.h:156
T const & value() const
Definition RTJmbInParameter.h:168
T const & getValue() const
Definition RTJmbInParameter.h:165
Templated class for RT Jamba Inbound parameter.
Definition RTJmbInParameter.h:72
ParamType const * last() const
Definition RTJmbInParameter.h:91
bool hasUpdate() const override
Definition RTJmbInParameter.h:97
ParamType * pop()
Definition RTJmbInParameter.h:88
ParamType const * popOrLast()
Definition RTJmbInParameter.h:94
Concurrent::LockFree::SingleElementQueue< T > fUpdateQueue
Definition RTJmbInParameter.h:106
JmbParamDef< T > const * getParamDefT() const
Definition RTJmbInParameter.h:82
T ParamType
Definition RTJmbInParameter.h:74
RTJmbInParameter(std::shared_ptr< JmbParamDef< T > > iParamDef)
Definition RTJmbInParameter.h:76
tresult readFromMessage(Message const &iMessage) override
Definition RTJmbInParameter.h:113
void writeToStream(std::ostream &oStream) const override
Definition RTJmbInParameter.h:126
Definition CircularBuffer.h:26
Definition RTJmbInParameter.h:26
std::array< RTJmbInParam< T >, N > RTJmbInParams
Definition RTJmbInParameter.h:181