Jamba C++ API  4.1.0
ParamDisplay.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 
19 #pragma once
20 
24 #include <string>
25 
26 namespace pongasoft {
27 namespace VST {
28 namespace Debug {
29 
34 {
35 public:
36  enum class Key
37  {
38  kID,
39  kType,
40  kTitle,
41  kOwner,
42  kTransient,
44  kDefault,
46  kValue,
47  kSteps,
48  kFlags,
50  kPrecision,
51  kUnitID,
52  kUnits,
53  kShared
54  };
55 
56 public:
57  using Value = std::string;
58  using ValueMap = std::map<Key, Value>;
59  using ParamMap = std::map<ParamID, ValueMap>;
60 
61 public:
62  explicit ParamDisplay(Parameters const &iParams) : fParameters{&iParams} {}
63  explicit ParamDisplay(RT::RTState const *iState) : fRTState{iState} {}
64  explicit ParamDisplay(GUI::GUIState const *iState) : fGUIState{iState} {}
65 
66  // builder pattern to initialize the display
67  ParamDisplay &precision(int32 iPrecision) { fPrecision = iPrecision; return *this; }
68  ParamDisplay &keys(std::vector<Key> const &iKeys) { fKeys = iKeys; return *this; };
69  ParamDisplay &key(Key iKey) { fKeys.emplace_back(iKey); return *this; }
70  ParamDisplay &ids(std::vector<ParamID> const &iParamIDs) { fParamIDs = iParamIDs; return *this; };
71  ParamDisplay &id(ParamID iParamID) { fParamIDs.emplace_back(iParamID); return *this; };
72 
73  Value getValue(Key iKey) const;
74  Value getValue(ParamID iParamID, Key iKey) const;
75  ValueMap getValues(ParamID iParamID, std::vector<Key> const &iKeys = {}) const;
76  ParamMap getParamMap(std::vector<ParamID> const &iParamIDs = {}) const;
77  ParamMap getParamMap(NormalizedState const &iNormalizedState) const;
78 
79  std::vector<Key> const &keys() const { return fKeys; }
80  std::vector<ParamID> const &ids() const { return fParamIDs; }
81 
82 protected:
83  Value getValue(RawVstParamDef const *iParamDef, Key iKey) const;
84  Value getValue(IJmbParamDef const *iParamDef, Key iKey) const;
85  Value getValue(std::unique_ptr<RT::RTRawVstParameter> const &iParam, Key iKey) const;
86  Value getValue(std::unique_ptr<RT::IRTJmbInParameter> const &iParam, Key iKey) const;
87  Value getValue(std::unique_ptr<RT::IRTJmbOutParameter> const &iParam, Key iKey) const;
88  Value getValue(std::shared_ptr<GUI::GUIRawVstParameter> const &iParam, Key iKey, Parameters const *iParameters) const;
89  Value getValue(GUI::IGUIJmbParameter const &iParam, Key iKey) const;
90 
91  Value getValue(Parameters const *iParams, ParamID iParamID, Key iKey) const;
92  Value getValue(RT::RTState const *iState, ParamID iParamID, Key iKey) const;
93  Value getValue(GUI::GUIState const *iState, ParamID iParamID, Key iKey) const;
94 
95  // convenient call which uses the precision to render the raw value
96  Value getValue(ParamValue iValue) const;
97 
98  // getRawVstParamDef (nullptr if not found)
99  std::shared_ptr<RawVstParamDef> getRawVstParamDef(ParamID iParamID) const;
100 
101 public:
106  static ParamDisplay from(Parameters const &iParams);
107 
112  static ParamDisplay from(RT::RTState const *iState, bool iSaveStateOnly = false);
113 
118  static ParamDisplay from(GUI::GUIState const *iState, bool iSaveStateOnly = false);
119 
120 private:
121  std::vector<Key> fKeys{};
122  std::vector<ParamID> fParamIDs{};
123  int32 fPrecision{3};
124 
128 };
129 
130 }
131 }
132 }
133 
GUI::GUIState const * fGUIState
Definition: ParamDisplay.h:127
This is the class which maintains all the registered parameters.
Definition: Parameters.h:37
std::map< Key, Value > ValueMap
Definition: ParamDisplay.h:58
Parameters const * fParameters
Definition: ParamDisplay.h:125
Definition: GUIState.h:40
ParamMap getParamMap(std::vector< ParamID > const &iParamIDs={}) const
Definition: ParamDisplay.cpp:85
Base class for a Jamba (Jmb) GUI parameter.
Definition: GUIJmbParameter.h:40
int32 fPrecision
Definition: ParamDisplay.h:123
This helper class is used to display the parameters (vst/jmb) WARNING: this class is allocating memor...
Definition: ParamDisplay.h:33
Key
Definition: ParamDisplay.h:36
Definition: Clock.h:22
ParamDisplay(Parameters const &iParams)
Definition: ParamDisplay.h:62
ParamDisplay & keys(std::vector< Key > const &iKeys)
Definition: ParamDisplay.h:68
ParamDisplay & id(ParamID iParamID)
Definition: ParamDisplay.h:71
ParamDisplay & precision(int32 iPrecision)
Definition: ParamDisplay.h:67
std::vector< ParamID > fParamIDs
Definition: ParamDisplay.h:122
Manages the state used by the processor: you add all the parameters that the state manages using the ...
Definition: RTState.h:43
std::shared_ptr< RawVstParamDef > getRawVstParamDef(ParamID iParamID) const
Definition: ParamDisplay.cpp:51
std::vector< ParamID > const & ids() const
Definition: ParamDisplay.h:80
std::string Value
Definition: ParamDisplay.h:57
ParamDisplay(GUI::GUIState const *iState)
Definition: ParamDisplay.h:64
Value getValue(Key iKey) const
Definition: ParamDisplay.cpp:384
ParamDisplay & key(Key iKey)
Definition: ParamDisplay.h:69
std::map< ParamID, ValueMap > ParamMap
Definition: ParamDisplay.h:59
ParamDisplay::ValueMap ValueMap
Definition: ParamTable.cpp:34
ParamDisplay(RT::RTState const *iState)
Definition: ParamDisplay.h:63
static ParamDisplay from(Parameters const &iParams)
Shortcut to create a table for all registered parameter (definition not current value).
Definition: ParamDisplay.cpp:442
ValueMap getValues(ParamID iParamID, std::vector< Key > const &iKeys={}) const
Definition: ParamDisplay.cpp:68
RT::RTState const * fRTState
Definition: ParamDisplay.h:126
ParamDisplay & ids(std::vector< ParamID > const &iParamIDs)
Definition: ParamDisplay.h:70
std::vector< Key > const & keys() const
Definition: ParamDisplay.h:79
std::vector< Key > fKeys
Definition: ParamDisplay.h:121