Jamba  3.0.2
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::unique_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 
ParamDisplay & precision(int32 iPrecision)
Definition: ParamDisplay.h:67
Definition: Parameters.h:39
std::vector< ParamID > fParamIDs
Definition: ParamDisplay.h:122
Definition: ParamDef.h:199
Definition: GUIState.h:39
Definition: GUIJmbParameter.h:40
Definition: ParamDisplay.h:33
ParamDisplay & ids(std::vector< ParamID > const &iParamIDs)
Definition: ParamDisplay.h:70
ParamDisplay & key(Key iKey)
Definition: ParamDisplay.h:69
ParamMap getParamMap(std::vector< ParamID > const &iParamIDs={}) const
Definition: ParamDisplay.cpp:87
Definition: Clock.h:22
ParamDisplay(RT::RTState const *iState)
Definition: ParamDisplay.h:63
ValueMap getValues(ParamID iParamID, std::vector< Key > const &iKeys={}) const
Definition: ParamDisplay.cpp:70
GUI::GUIState const * fGUIState
Definition: ParamDisplay.h:127
Definition: RTState.h:43
Parameters const * fParameters
Definition: ParamDisplay.h:125
ParamDisplay(Parameters const &iParams)
Definition: ParamDisplay.h:62
Value getValue(Key iKey) const
Definition: ParamDisplay.cpp:386
RT::RTState const * fRTState
Definition: ParamDisplay.h:126
static ParamDisplay from(Parameters const &iParams)
Definition: ParamDisplay.cpp:444
ParamDisplay & keys(std::vector< Key > const &iKeys)
Definition: ParamDisplay.h:68
int32 fPrecision
Definition: ParamDisplay.h:123
ParamDisplay::ValueMap ValueMap
Definition: ParamTable.cpp:34
Definition: ParamDef.h:72
Key
Definition: ParamDisplay.h:36
std::string Value
Definition: ParamDisplay.h:57
std::map< Key, Value > ValueMap
Definition: ParamDisplay.h:58
std::vector< Key > const & keys() const
Definition: ParamDisplay.h:79
ParamDisplay(GUI::GUIState const *iState)
Definition: ParamDisplay.h:64
std::map< ParamID, ValueMap > ParamMap
Definition: ParamDisplay.h:59
std::shared_ptr< RawVstParamDef > getRawVstParamDef(ParamID iParamID) const
Definition: ParamDisplay.cpp:53
std::vector< ParamID > const & ids() const
Definition: ParamDisplay.h:80
ParamDisplay & id(ParamID iParamID)
Definition: ParamDisplay.h:71
std::vector< Key > fKeys
Definition: ParamDisplay.h:121