Jamba C++ API  4.3.0
CustomControlView.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 "CustomView.h"
21 
23 
42 {
43 public:
44  explicit CustomControlView(const CRect &iSize) : CustomView(iSize) {}
45 
47  virtual void setControlTag (ParamID iTag) { fControlTag = iTag; };
48 
58  ParamID getControlTag () const { return fControlTag; }
59 
60 public:
61  CLASS_METHODS_NOCOPY(CustomControlView, CustomView)
62 
63 protected:
65 
66 public:
67  class Creator : public CustomViewCreator<CustomControlView, CustomView>
68  {
69  public:
70  explicit Creator(char const *iViewName = nullptr, char const *iDisplayName = nullptr) :
71  CustomViewCreator(iViewName, iDisplayName)
72  {
74  }
75  };
76 };
77 
87 template<typename T>
89 {
90 public:
91  // TCustomControlView
92  explicit TCustomControlView(const CRect &iSize) : CustomControlView(iSize) {}
93 
94 public:
95  CLASS_METHODS_NOCOPY(TCustomControlView, CustomControlView)
96 
97 
99  T getControlValue() const;
100 
103  virtual void setControlValue(T const &iControlValue);
104 
107  void registerParameters() override;
108 
109 protected:
110  // the gui parameter tied to the control (handle vst/jmb or simple value)
112 
113 public:
115 };
116 
124 
153 {
154 public:
155  // CustomDiscreteControlView
156  explicit CustomDiscreteControlView(const CRect &iSize) : TCustomControlView<int32>(iSize) {}
157 
165  int32 getStepCount() const { return fStepCount; }
166 
168  void setStepCount(int32 iStepCount) { fStepCount = iStepCount; }
169 
170 public:
172 
173 
174  void registerParameters() override;
175 
176 protected:
177  int32 fStepCount{-1};
178 
179 public:
180  class Creator : public CustomViewCreator<CustomDiscreteControlView, TCustomControlView<int32>>
181  {
182  public:
183  explicit Creator(char const *iViewName = nullptr, char const *iDisplayName = nullptr) :
184  CustomViewCreator(iViewName, iDisplayName)
185  {
186  registerIntegerAttribute<int32>("step-count", &CustomDiscreteControlView::getStepCount, &CustomDiscreteControlView::setStepCount);
187  }
188  };
189 };
190 
191 //------------------------------------------------------------------------
192 // TCustomControlView<T>::getControlValue
193 //------------------------------------------------------------------------
194 template<typename T>
196 {
197  return fControlParameter.getValue();
198 }
199 
200 //------------------------------------------------------------------------
201 // TCustomControlView<T>::setControlValue
202 //------------------------------------------------------------------------
203 template<typename T>
204 void TCustomControlView<T>::setControlValue(T const &iControlValue)
205 {
206  fControlParameter.update(iControlValue);
207 }
208 
209 //------------------------------------------------------------------------
210 // TCustomControlView<T>::registerParameters
211 //------------------------------------------------------------------------
212 template<typename T>
214 {
216  fControlParameter = registerOptionalParam<T>(getControlTag());
217 }
218 
219 }
virtual void setControlValue(T const &iControlValue)
Sets the value of the managed parameter to the provided value.
Definition: CustomControlView.h:204
Inherit from this class to provide the factory for a custom view.
Definition: CustomViewCreator.h:1312
GUIOptionalParam< T > fControlParameter
Definition: CustomControlView.h:111
ParamID getControlTag() const
Id of the parameter that this view manages.
Definition: CustomControlView.h:58
ParamID fControlTag
Definition: CustomControlView.h:64
Base class which extends CustomControlView to provide the type (T) of the underlying parameter this v...
Definition: CustomControlView.h:88
Class you should inherit from if you want to write a custom view.
Definition: CustomView.h:60
Creator(char const *iViewName=nullptr, char const *iDisplayName=nullptr)
Definition: CustomControlView.h:183
void registerTagAttribute(std::string const &iName, typename TagAttribute::Getter iGetter, typename TagAttribute::Setter iSetter)
Registers a tag attribute with the given name and getter/setter.
Definition: CustomViewCreator.h:1048
virtual void registerParameters()
Subclasses should override this method to register each parameter.
Definition: ParamAware.h:497
virtual void setControlTag(ParamID iTag)
Definition: CustomControlView.h:47
void registerParameters() override
Registers the optional parameter using getControlTag() as its id.
Definition: CustomControlView.cpp:26
T getControlValue() const
Returns the value of the managed parameter (properly typed)
Definition: CustomControlView.h:195
CustomDiscreteControlView(const CRect &iSize)
Definition: CustomControlView.h:156
void registerParameters() override
Registers the optional parameter using getControlTag() as its id.
Definition: CustomControlView.h:213
CustomControlView(const CRect &iSize)
Definition: CustomControlView.h:44
Definition: CustomController.h:24
TCustomControlView(const CRect &iSize)
Definition: CustomControlView.h:92
Creator(char const *iViewName=nullptr, char const *iDisplayName=nullptr)
Definition: CustomControlView.h:70
Specialization of TCustomControlView for discrete values.
Definition: CustomControlView.h:152
int32 fStepCount
Definition: CustomControlView.h:177
Base class for custom views which are tied to one parameter only (similar to CControl).
Definition: CustomControlView.h:41
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:47
void setStepCount(int32 iStepCount)
Definition: CustomControlView.h:168
int32 getStepCount() const
The number of steps of the managed discrete parameter as specified by this view.
Definition: CustomControlView.h:165
Represents an optional parameter (Jmb, Vst or no param at all).
Definition: GUIOptionalParam.h:48