Jamba  3.0.2
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>
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)
85 
86  // the value when the control parameter is not assigned
88 
89 public:
90  class Creator : public CustomViewCreator<TCustomControlView<T>, CustomControlView>
91  {
92  private:
94  public:
95  explicit Creator(char const *iViewName = nullptr, char const *iDisplayName = nullptr) :
96  CustomViewCreatorT(iViewName, iDisplayName)
97  {
98  }
99  };
100 };
101 
103 // TCustomControlView<T>::getControlValue
105 template<typename T>
107 {
108  if(fControlParameter.exists())
109  return fControlParameter.getValue();
110  else
111  return fControlValue;
112 }
113 
115 // TCustomControlView<T>::setControlValue
117 template<typename T>
118 void TCustomControlView<T>::setControlValue(T const &iControlValue)
119 {
120  if(fControlParameter.exists())
121  fControlParameter.setValue(iControlValue);
122  else
123  {
124  if(fControlValue != iControlValue)
125  {
126  fControlValue = iControlValue;
127  markDirty();
128  }
129  }
130 }
131 
133 // TCustomControlView<T>::registerParameters
135 template<typename T>
137 {
139 
140  __internal__registerVstControl(getControlTag(), fControlValue, fControlParameter);
141 }
142 
143 //------------------------------------------------------------------------
144 // TCustomControlView<T>::setControlTag
145 //------------------------------------------------------------------------
146 template<typename T>
148 {
150  registerParameters();
151 }
152 
153 }
154 }
155 }
156 }
Definition: CustomViewCreator.h:981
virtual void setControlValue(T const &iControlValue)
Definition: CustomControlView.h:118
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
TCustomControlView(const CRect &iSize)
Definition: CustomControlView.h:67
Definition: CustomControlView.h:63
void setControlTag(int32_t iTag) override
Definition: CustomControlView.h:147
Definition: CustomView.h:100
virtual void setControlTag(int32_t iTag)
Definition: CustomControlView.h:36
Definition: GUIVstParameter.h:233
virtual void registerParameters()
Definition: GUIParamCxAware.h:217
void registerParameters() override
Definition: CustomControlView.h:136
Creator(char const *iViewName=nullptr, char const *iDisplayName=nullptr)
Definition: CustomControlView.h:95
T getControlValue() const
Definition: CustomControlView.h:106
T fControlValue
Definition: CustomControlView.h:87
Creator(char const *iViewName=nullptr, char const *iDisplayName=nullptr)
Definition: CustomControlView.h:49
int32_t fControlTag
Definition: CustomControlView.h:43
CustomControlView(const CRect &iSize)
Definition: CustomControlView.h:33
GUIVstParam< T > fControlParameter
Definition: CustomControlView.h:84
Definition: CustomControlView.h:30