Jamba  3.1.0
CustomControlView.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 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 
22 namespace pongasoft {
23 namespace VST {
24 namespace GUI {
25 namespace Views {
26 
31 {
32 public:
33  explicit CustomControlView(const CRect &iSize) : CustomView(iSize) {}
34 
35  // get/setControlTag
36  virtual void setControlTag (int32_t iTag) { fControlTag = iTag; };
37  int32_t getControlTag () const { return fControlTag; }
38 
39 public:
40  CLASS_METHODS_NOCOPY(CustomControlView, CustomView)
41 
42 protected:
43  int32_t fControlTag{-1};
44 
45 public:
46  class Creator : public CustomViewCreator<CustomControlView, CustomView>
47  {
48  public:
49  explicit Creator(char const *iViewName = nullptr, char const *iDisplayName = nullptr) :
50  CustomViewCreator(iViewName, iDisplayName)
51  {
53  }
54  };
55 };
56 
62 template<typename T, typename TGUIParam = GUIVstParam<T>>
64 {
65 public:
66  // TCustomControlView
67  explicit TCustomControlView(const CRect &iSize) : CustomControlView(iSize) {}
68 
69 public:
70  CLASS_METHODS_NOCOPY(TCustomControlView, CustomControlView)
71 
72  // when the control tag changes we need to handle it
73  void setControlTag(int32_t iTag) override;
74 
75  // set/getControlValue
76  T getControlValue() const;
77  virtual void setControlValue(T const &iControlValue);
78 
79  // registerParameters
80  void registerParameters() override;
81 
82 protected:
83  // the gui parameter tied to the control (optional)
84  TGUIParam fControlParameter{};
85 
86  // the value when the control parameter is not assigned
88 
89 public:
91 };
92 
97 
98 //------------------------------------------------------------------------
99 // TCustomControlView<T>::getControlValue
100 //------------------------------------------------------------------------
101 template<typename T, typename TGUIParam>
103 {
104  if(fControlParameter.exists())
105  return fControlParameter.getValue();
106  else
107  return fControlValue;
108 }
109 
110 //------------------------------------------------------------------------
111 // TCustomControlView<T>::setControlValue
112 //------------------------------------------------------------------------
113 template<typename T, typename TGUIParam>
115 {
116  if(fControlParameter.exists())
117  fControlParameter.setValue(iControlValue);
118  else
119  {
120  if(fControlValue != iControlValue)
121  {
122  fControlValue = iControlValue;
123  markDirty();
124  }
125  }
126 }
127 
128 //------------------------------------------------------------------------
129 // TCustomControlView<T>::registerParameters
130 //------------------------------------------------------------------------
131 template<typename T, typename TGUIParam>
133 {
135 
136  __internal__registerVstControl(getControlTag(), fControlValue, fControlParameter);
137 }
138 
139 //------------------------------------------------------------------------
140 // TCustomControlView<T>::setControlTag
141 //------------------------------------------------------------------------
142 template<typename T, typename TGUIParam>
144 {
146  registerParameters();
147 }
148 
149 }
150 }
151 }
152 }
Definition: CustomViewCreator.h:981
int32_t getControlTag() const
Definition: CustomControlView.h:37
void registerTagAttribute(std::string const &iName, typename TagAttribute::Getter iGetter, typename TagAttribute::Setter iSetter)
Definition: CustomViewCreator.h:807
Definition: Clock.h:22
Definition: CustomControlView.h:63
Definition: CustomView.h:44
virtual void setControlValue(T const &iControlValue)
Definition: CustomControlView.h:114
virtual void setControlTag(int32_t iTag)
Definition: CustomControlView.h:36
virtual void registerParameters()
Definition: GUIParamCxAware.h:229
TGUIParam fControlParameter
Definition: CustomControlView.h:84
TCustomControlView(const CRect &iSize)
Definition: CustomControlView.h:67
void setControlTag(int32_t iTag) override
Definition: CustomControlView.h:143
void registerParameters() override
Definition: CustomControlView.h:132
Creator(char const *iViewName=nullptr, char const *iDisplayName=nullptr)
Definition: CustomControlView.h:49
int32_t fControlTag
Definition: CustomControlView.h:43
T fControlValue
Definition: CustomControlView.h:87
CustomControlView(const CRect &iSize)
Definition: CustomControlView.h:33
Definition: CustomControlView.h:30
T getControlValue() const
Definition: CustomControlView.h:102