Jamba C++ API  5.0.0
ParamTable.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 
25 #include "ParamDisplay.h"
26 
27 #include <string>
28 
29 namespace pongasoft {
30 namespace VST {
31 namespace Debug {
32 
37 {
38 public:
39  explicit ParamTable(ParamDisplay iParamDisplay) : fParamDisplay{std::move(iParamDisplay)} {}
40 
41 public:
42  // builder pattern to initialize the table
43  ParamTable &precision(int32 iPrecision) { fParamDisplay.precision(iPrecision); return *this; }
44  ParamTable &keys(std::vector<ParamDisplay::Key> const &iKeys) { fParamDisplay.keys(iKeys); return *this; };
45  ParamTable &key(ParamDisplay::Key iKey) { fParamDisplay.key(iKey); return *this; }
46  ParamTable &ids(std::vector<ParamID> const &iParamIDs) { fParamDisplay.ids(iParamIDs); return *this; };
47  ParamTable &id(ParamID iParamID) { fParamDisplay.id(iParamID); return *this; };
48  ParamTable &header(bool iDisplayHeader = true) { fDisplayHeader = iDisplayHeader; return *this; };
49  ParamTable &showHeader() { return header(true); };
50  ParamTable &hideHeader() { return header(false); };
51  ParamTable &headerSeparation(bool iDisplayHeaderSeparation = true) { fDisplayHeaderSeparation = iDisplayHeaderSeparation; return *this; };
54  ParamTable &lineSeparation(bool iDisplayLineSeparation = true) { fDisplayLineSeparation = iDisplayLineSeparation; return *this; };
57  ParamTable &cellSeparation(bool iDisplayCellSeparation = true) { fDisplayCellSeparation = iDisplayCellSeparation; return *this; };
60 
63 
64  // returns the table as a vector of rows
65  std::vector<std::string> rows() const;
66 
67  // returns a tabular representation of the params
68  std::string toString() const;
69 
70  // print the table
71  void print(std::string const &iFirstLine = "") const;
72 
73  // returns the table as a vector of rows
74  std::vector<std::string> rows(NormalizedState const &iNormalizedState) const;
75 
76  // returns a tabular representation of the params
77  std::string toString(NormalizedState const &iNormalizedState) const;
78 
79  // print the table
80  void print(NormalizedState const &iNormalizedState, std::string const &iFirstLine = "") const;
81 
82 protected:
83  // computeSizes
84  std::string::size_type computeSizes(ParamDisplay::ValueMap const &iHeader,
85  ParamDisplay::ParamMap const &iParams,
86  std::map<ParamDisplay::Key, std::string::size_type> &oSizes) const;
87 
88  // computeHeader
90 
91  // returns the table as a vector of rows
92  std::vector<std::string> rows(ParamDisplay::ParamMap const &iParamMap) const;
93 
94 public:
98  static ParamTable from(Parameters const &iParams);
99 
103  static ParamTable from(RT::RTState const *iState, bool iSaveStateOnly = false);
104 
108  static ParamTable from(GUI::GUIState const *iState, bool iSaveStateOnly = false);
109 
110 private:
111  bool fDisplayHeader{true};
115 
117 };
118 
119 }
120 }
121 }
122 
ParamDisplay fParamDisplay
Definition: ParamTable.h:116
ParamTable & showHeaderSeparation()
Definition: ParamTable.h:52
This is the class which maintains all the registered parameters.
Definition: Parameters.h:37
std::map< Key, Value > ValueMap
Definition: ParamDisplay.h:58
Definition: GUIState.h:41
ParamTable & hideHeaderSeparation()
Definition: ParamTable.h:53
ParamTable & key(ParamDisplay::Key iKey)
Definition: ParamTable.h:45
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
ParamTable & showHeader()
Definition: ParamTable.h:49
void print(std::string const &iFirstLine="") const
Definition: ParamTable.cpp:59
ParamDisplay & keys(std::vector< Key > const &iKeys)
Definition: ParamDisplay.h:68
ParamDisplay & id(ParamID iParamID)
Definition: ParamDisplay.h:71
ParamTable & headerSeparation(bool iDisplayHeaderSeparation=true)
Definition: ParamTable.h:51
ParamTable & ids(std::vector< ParamID > const &iParamIDs)
Definition: ParamTable.h:46
ParamDisplay & precision(int32 iPrecision)
Definition: ParamDisplay.h:67
bool fDisplayLineSeparation
Definition: ParamTable.h:113
bool fDisplayCellSeparation
Definition: ParamTable.h:114
Manages the state used by the processor: you add all the parameters that the state manages using the ...
Definition: RTState.h:43
ParamDisplay::ValueMap computeHeader() const
Definition: ParamTable.cpp:187
ParamTable & full()
Definition: ParamTable.h:62
std::string::size_type computeSizes(ParamDisplay::ValueMap const &iHeader, ParamDisplay::ParamMap const &iParams, std::map< ParamDisplay::Key, std::string::size_type > &oSizes) const
Definition: ParamTable.cpp:202
ParamTable & compact()
Definition: ParamTable.h:61
Used to communicate the state between the UI and the RT and read/write to stream.
Definition: NormalizedState.h:37
ParamTable & cellSeparation(bool iDisplayCellSeparation=true)
Definition: ParamTable.h:57
This helper class is used to display the parameters (vst/jmb) in a table WARNING: this class is alloc...
Definition: ParamTable.h:36
ParamTable & lineSeparation(bool iDisplayLineSeparation=true)
Definition: ParamTable.h:54
ParamTable & id(ParamID iParamID)
Definition: ParamTable.h:47
ParamDisplay & key(Key iKey)
Definition: ParamDisplay.h:69
std::map< ParamID, ValueMap > ParamMap
Definition: ParamDisplay.h:59
ParamTable & showLineSeparation()
Definition: ParamTable.h:55
ParamTable & hideLineSeparation()
Definition: ParamTable.h:56
bool fDisplayHeaderSeparation
Definition: ParamTable.h:112
ParamTable & header(bool iDisplayHeader=true)
Definition: ParamTable.h:48
std::string toString() const
Definition: ParamTable.cpp:40
ParamTable & showCellSeparation()
Definition: ParamTable.h:58
ParamDisplay & ids(std::vector< ParamID > const &iParamIDs)
Definition: ParamDisplay.h:70
static ParamTable from(Parameters const &iParams)
Shortcut to create a table for all registered parameter (definition not current value)
Definition: ParamTable.cpp:241
bool fDisplayHeader
Definition: ParamTable.h:111
ParamTable & hideHeader()
Definition: ParamTable.h:50
ParamTable & keys(std::vector< ParamDisplay::Key > const &iKeys)
Definition: ParamTable.h:44
ParamTable & hideCellSeparation()
Definition: ParamTable.h:59
ParamTable & precision(int32 iPrecision)
Definition: ParamTable.h:43
std::vector< std::string > rows() const
Definition: ParamTable.cpp:134
ParamTable(ParamDisplay iParamDisplay)
Definition: ParamTable.h:39