Jamba C++ API  5.0.0
NormalizedState.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2020 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 <pluginterfaces/vst/vsttypes.h>
21 #include <base/source/fstreamer.h>
22 #include <pongasoft/logging/logging.h>
23 
24 #include <string>
25 #include <vector>
26 
27 namespace pongasoft::VST {
28 
29 using namespace Steinberg::Vst;
30 using namespace Steinberg;
31 
32 class Parameters;
33 
38 {
39 public:
43  struct SaveOrder
44  {
45  int16 fVersion{0};
46  std::vector<ParamID> fOrder{};
47  inline int getCount() const { return static_cast<int>(fOrder.size()); }
48  };
49 
50  // Constructor
51  explicit NormalizedState(SaveOrder const *iSaveOrder);
52 
53  // Destructor
54  ~NormalizedState();
55 
56  // Copy constructor
57  NormalizedState(NormalizedState const &other);
58 
59  // Copies the content of the array ONLY when same SaveOrder (which is the case internally)
60  NormalizedState& operator=(NormalizedState const &other);
61 
68  int copyValuesTo(NormalizedState &oDestination) const;
69 
76  inline int copyValuesFrom(NormalizedState const &iSource) { return iSource.copyValuesTo(*this); }
77 
78  // getCount
79  inline int getCount() const { return fSaveOrder->getCount(); }
80 
81  // getVersion
82  inline int16 getVersion() const { return fSaveOrder->fVersion; }
83 
88  int findParamIndex(ParamID iParamID) const;
89 
91  inline void set(int iIdx, ParamValue iParamValue)
92  {
93  DCHECK_F(iIdx >= 0 && iIdx < fSaveOrder->getCount());
94  fValues[iIdx] = iParamValue;
95  }
96 
98  inline ParamValue get(int iIdx) const
99  {
100  DCHECK_F(iIdx >= 0 && iIdx < fSaveOrder->getCount());
101  return fValues[iIdx];
102  }
103 
104  // readFromStream
105  virtual tresult readFromStream(Parameters const *iParameters, IBStreamer &iStreamer);
106 
107  // writeToStream
108  virtual tresult writeToStream(Parameters const *iParameters, IBStreamer &oStreamer) const;
109 
114  tresult getNormalizedValue(ParamID iParamID, ParamValue &oValue) const;
115 
120  tresult setNormalizedValue(ParamID iParamID, ParamValue iValue);
121 
122 
123  // toString
124  std::string toString() const;
125 
126 public:
128  ParamValue *fValues{nullptr};
129 };
130 
131 
132 }
133 
This is the class which maintains all the registered parameters.
Definition: Parameters.h:37
ParamValue get(int iIdx) const
Gets the param value.
Definition: NormalizedState.h:98
Maintains the order used to save/restore the RT and GUI state.
Definition: NormalizedState.h:43
SaveOrder const * fSaveOrder
Definition: NormalizedState.h:127
int copyValuesFrom(NormalizedState const &iSource)
Copy values from the source (iSource) state to this state.
Definition: NormalizedState.h:76
int getCount() const
Definition: NormalizedState.h:47
Used to communicate the state between the UI and the RT and read/write to stream.
Definition: NormalizedState.h:37
int16 getVersion() const
Definition: NormalizedState.h:82
int copyValuesTo(NormalizedState &oDestination) const
Copy values from this to the destination (oDestination) state.
Definition: NormalizedState.cpp:82
void set(int iIdx, ParamValue iParamValue)
Sets the param value.
Definition: NormalizedState.h:91
int getCount() const
Definition: NormalizedState.h:79
Definition: Clock.h:23