Krotos Modules 3
Loading...
Searching...
No Matches
Kwidget.h
Go to the documentation of this file.
1namespace krotos
2{
3 class KwidgetProcessor;
4 class KwidgetAudioProcessor;
5 class KwidgetGUI;
6
7 class Kwidget : public ResourceLock
8 {
9 public:
14 {
15 String id;
16 String name;
17 NormalisableRange<float> range;
19 };
20
21 struct Constants
22 {
23 static const String ChildDelimiter;
24 static const String Parent;
25 static const String Bounds;
26 static const String Renderstyle;
27 };
28
34 Kwidget(const String& kwidgetType, const String& kwidgetID);
35
37 virtual ~Kwidget() = default;
38
42 void init();
43
47 std::unique_ptr<KwidgetProcessor> createVoice();
48
52 std::unique_ptr<KwidgetGUI> createControls();
53
55 KwidgetProcessor* getVoice(int idx) const;
56
58 int getNumVoices() const;
59
62
72 virtual void noteOn(int voiceIdx, int midiNote, float velocity);
73
82 virtual void noteOff(int voiceIdx, float velocity);
83
89 virtual void noteCleared(int voiceIdx);
90
91 virtual bool isActive(int voiceIdx);
92
94 void addModulator(const String& paramID, Kwidget* modulator, int modulatorIdx, float depth = 0.99f,
96
98 void removeModulator(const String& paramID, Kwidget* modulator, int modulatorIdx);
99
100 /* Set the depth of a given modulator with range [-1, 1] */
101 void setModulatorDepth(const String& paramID, Kwidget* modulator, int modulatorIdx, float depth);
102
103 /* Set the polarity of a given modulator, either Bipolar [-1, 1] or Unipolar [0, 1] */
104 void setModulatorPolarity(const String& paramID, Kwidget* modulator, int modulatorIdx,
105 KAttachment::Polarity polarity);
106
108 const std::vector<std::shared_ptr<KParameter>>& getParameters() const;
109
119 KParameter* getParameter(const String& parameterID) const noexcept;
120
127 std::shared_ptr<KParameter> getParameterToAttach(const String& parameterID) const noexcept;
128
130 CustomParameter* getCustomParameter(const String& parameterID);
131
138 CustomParameterTree* getCustomParameterTree(const Identifier& type);
139
151 template <typename T> T* getCustomParameter(const Identifier& type);
152
157
159 const ValueTree& getState();
160
162 virtual void setState(const ValueTree& newState, KwidgetAudioProcessor& processor);
163
167 void flushState();
168
170 bool isModulator() const;
171
173 int getNumModulators() const;
174
176 const String& getKwidgetType() const;
177
179 const String& getKwidgetID() const;
180
184 const String& getKwidgetVersionFromCurrentState() const;
185
186 /* Get the latest version number of the kwidget
187 * By default this will be 1.0, an updated kwidget can use setKwidgetVersion to update this
188 * @return string of the two digit kwidget version number e.g. "1.1"
189 * @see setKwidgetVersion */
190 String getKwidgetVersion() const;
191
195 virtual const String& getKwidgetLabel();
196
199 StringArray getDragID(const String& parameterID);
200
201 /* Index for drag and drop description parameter identifiers*/
203 {
205 ParameterID = 1
206 };
207
208 /* override if the kwidget needs more than one Gui representation*/
209 virtual size_t numGUIImplementations() { return 1; }
210
212 virtual String getGuiName(int /*i*/) { return "None"; }
213
216
217 bool isAChildKwidget();
218
219 std::vector<Kwidget*>& getChildKwidgets() { return m_childKwidgets; }
220
225 static String getParentID(String childKwidgetID);
226
228 // KwidgetGUI* getGui() { return m_gui; }
229
231
232 /* Add a child kwidget to the kwidget*/
233 void addChildKwidget(Kwidget* child);
234
235 /* remove a child kwidget from the Kwidget*/
236 void removeChildKwidgetFromTree(String kwidgetID);
237
238 /* find the child kwidget with the ID*/
239 Kwidget* findChildKwidget(String kiwdgetID);
240
246 void addParameterCallback(const String& paramID, std::function<void(float)> callback);
247
259 void addVersionedParameterCallback(StringRef kwidgetVersionTheParameterChangedIn, const String& paramID,
260 std::function<void(float)> callback);
261
264 int getTemplateID();
265
266 protected:
268 virtual std::vector<ParameterInfo> createParameters() = 0;
269
271 virtual std::unique_ptr<KwidgetProcessor> createProcessor() = 0;
272
274 virtual std::unique_ptr<KwidgetGUI> createGUI() = 0;
275
276 /*add the child Guis to the kwidgetGUI */
277 void addChildGuis(std::unique_ptr<KwidgetGUI>& parentGui);
278
288 CustomParameter* createAndAddCustomParameter(const String& paramID, const var& value);
289
309 template <typename T> T* createAndAddCustomParameter(const Identifier& type);
310
317 void setKwidgetVersion(const String& kwidgetVersionString);
318
319 std::vector<Kwidget*> m_childKwidgets;
320
321 private:
323
324 const String m_kwidgetType;
325 const String m_kwidgetID;
326 // kwidget version number from preset data
328
329 ValueTree m_kwidgetTree;
330 ValueTree m_paramTree;
332 ValueTree m_childTree;
334
335 std::vector<std::shared_ptr<KParameter>> m_parameters;
336 std::map<String, int> m_parameterIDs;
337
338 Array<KwidgetProcessor*> m_processors;
340 std::unique_ptr<KwidgetProcessor> m_initialVoice;
341
342 OwnedArray<CustomParameter> m_customParameters;
343 std::map<String, int> m_customParameterIDs;
344
345 OwnedArray<CustomParameterTree> m_customParameterTrees;
346 std::map<Identifier, int> m_customParameterTreeTypes;
347
348 OwnedArray<KParameter::AudioListenerObject> m_parameterCallbacks;
349
350 bool m_stateChanging{false};
351 };
352} // namespace krotos
A wrapper around juce::ValueTree designed to store custom plugin state (strings, arrays,...
Definition CustomParameter.h:9
Definition CustomParameterTree.h:15
Polarity
Definition KAttachment.h:120
@ Bipolar
Definition KAttachment.h:121
Internal Kwidget parameter that can receive changes from a GenericParameter.
Definition KParameter.h:17
Definition KwidgetAudioProcessor.h:12
Definition Kwidget.h:8
const String m_kwidgetType
Definition Kwidget.h:324
void init()
Definition Kwidget.cpp:27
static String getParentID(String childKwidgetID)
Definition Kwidget.cpp:250
std::vector< Kwidget * > & getChildKwidgets()
Definition Kwidget.h:219
virtual void setState(const ValueTree &newState, KwidgetAudioProcessor &processor)
Definition Kwidget.cpp:268
OwnedArray< KParameter::AudioListenerObject > m_parameterCallbacks
Definition Kwidget.h:348
String m_kwidgetStateVersion
Definition Kwidget.h:327
KwidgetProcessor * getActiveVoice() const
Definition Kwidget.h:61
int getNumVoices() const
Definition Kwidget.cpp:65
std::map< String, int > m_customParameterIDs
Definition Kwidget.h:343
const String & getKwidgetVersionFromCurrentState() const
Definition Kwidget.cpp:369
virtual std::vector< ParameterInfo > createParameters()=0
ValueTree m_kwidgetTree
Definition Kwidget.h:329
void addVersionedParameterCallback(StringRef kwidgetVersionTheParameterChangedIn, const String &paramID, std::function< void(float)> callback)
Add an action to be performed when a specified parameter of a specific kwidget version changes value....
Definition Kwidget.cpp:464
ValueTree m_customParamTree
Definition Kwidget.h:331
void addChildKwidget(Kwidget *child)
Definition Kwidget.cpp:325
void flushState()
Definition Kwidget.cpp:312
void setKwidgetVersion(const String &kwidgetVersionString)
Definition Kwidget.cpp:371
std::unique_ptr< KwidgetProcessor > m_initialVoice
Definition Kwidget.h:340
virtual std::unique_ptr< KwidgetProcessor > createProcessor()=0
virtual bool isActive(int voiceIdx)
Definition Kwidget.cpp:80
const String m_kwidgetID
Definition Kwidget.h:325
bool isAChildKwidget()
Definition Kwidget.cpp:248
KwidgetProcessor * getVoice(int idx) const
Definition Kwidget.cpp:38
virtual void noteOn(int voiceIdx, int midiNote, float velocity)
Definition Kwidget.cpp:67
OwnedArray< CustomParameterTree > m_customParameterTrees
Definition Kwidget.h:345
virtual void noteCleared(int voiceIdx)
Definition Kwidget.cpp:78
OwnedArray< CustomParameter > m_customParameters
Definition Kwidget.h:342
void addChildGuis(std::unique_ptr< KwidgetGUI > &parentGui)
Definition Kwidget.cpp:498
const ValueTree & getState()
Definition Kwidget.cpp:242
std::vector< Kwidget * > m_childKwidgets
Definition Kwidget.h:319
KwidgetProcessor * m_activeVoice
Definition Kwidget.h:339
void addModulator(const String &paramID, Kwidget *modulator, int modulatorIdx, float depth=0.99f, KAttachment::Polarity=KAttachment::Polarity::Bipolar)
Definition Kwidget.cpp:82
KParameter * getParameter(const String &parameterID) const noexcept
Get a raw pointer to a KParameter belonging to this Kwidget's KwidgetProcessor. Useful for low overhe...
Definition Kwidget.cpp:168
String getKwidgetVersion() const
Definition Kwidget.cpp:376
const String & getKwidgetType() const
Definition Kwidget.cpp:365
int getNumModulators() const
Definition Kwidget.cpp:357
Kwidget * findChildKwidget(String kiwdgetID)
Definition Kwidget.cpp:478
void removeModulator(const String &paramID, Kwidget *modulator, int modulatorIdx)
Definition Kwidget.cpp:108
virtual String getGuiName(int)
Definition Kwidget.h:212
CustomParameter * createAndAddCustomParameter(const String &paramID, const var &value)
Definition Kwidget.cpp:419
const String & getKwidgetID() const
Definition Kwidget.cpp:367
std::vector< std::shared_ptr< KParameter > > m_parameters
Definition Kwidget.h:335
CustomParameter * getCustomParameter(const String &parameterID)
Definition Kwidget.cpp:188
CustomParameterTree * getCustomParameterTree(const Identifier &type)
Get a CustomParameterTree belonging to this Kwidget.
Definition Kwidget.cpp:202
std::map< Identifier, int > m_customParameterTreeTypes
Definition Kwidget.h:346
std::unique_ptr< KwidgetProcessor > createVoice()
Definition Kwidget.cpp:44
StringArray getDragID(const String &parameterID)
Definition Kwidget.cpp:394
bool m_stateChanging
Definition Kwidget.h:350
Kwidget(const String &kwidgetType, const String &kwidgetID)
Definition Kwidget.cpp:8
virtual void createNestedKwidgets(KwidgetAudioProcessor &)
Definition Kwidget.h:215
bool isModulator() const
Definition Kwidget.cpp:355
void setModulatorDepth(const String &paramID, Kwidget *modulator, int modulatorIdx, float depth)
Definition Kwidget.cpp:127
virtual ~Kwidget()=default
virtual size_t numGUIImplementations()
Definition Kwidget.h:209
KParameter * createAndAddParameter(const ParameterInfo &info)
Definition Kwidget.cpp:402
bool isStateChanging()
Definition Kwidget.h:230
Array< KwidgetProcessor * > m_processors
Definition Kwidget.h:338
virtual void noteOff(int voiceIdx, float velocity)
Definition Kwidget.cpp:76
DragID_Index
Definition Kwidget.h:203
@ KwidgetID
Definition Kwidget.h:204
@ ParameterID
Definition Kwidget.h:205
void setModulatorPolarity(const String &paramID, Kwidget *modulator, int modulatorIdx, KAttachment::Polarity polarity)
Definition Kwidget.cpp:146
int getTemplateID()
Definition Kwidget.cpp:261
std::unique_ptr< KwidgetGUI > createControls()
Definition Kwidget.cpp:58
ValueTree m_customDataTree
Definition Kwidget.h:333
std::map< String, int > m_parameterIDs
Definition Kwidget.h:336
ValueTree m_paramTree
Definition Kwidget.h:330
virtual const String & getKwidgetLabel()
Definition Kwidget.cpp:378
std::shared_ptr< KParameter > getParameterToAttach(const String &parameterID) const noexcept
Get a shared pointer to a KParameter, for use with KParameter::Listener objects and situations where ...
Definition Kwidget.cpp:178
void notifyAllParametersListeners()
Call every parameter's value changed listeners with their current values.
Definition Kwidget.cpp:233
void removeChildKwidgetFromTree(String kwidgetID)
Definition Kwidget.cpp:344
virtual std::unique_ptr< KwidgetGUI > createGUI()=0
const std::vector< std::shared_ptr< KParameter > > & getParameters() const
Definition Kwidget.cpp:166
ValueTree m_childTree
Definition Kwidget.h:332
void addParameterCallback(const String &paramID, std::function< void(float)> callback)
Definition Kwidget.cpp:458
An interface for an audio processor designed for modular use.
Definition KwidgetProcessor.h:8
Class used to manage access to a resource from multiple users / threads In this version,...
Definition ResourceLock.h:19
Definition AirAbsorptionFilter.cpp:2
Definition Kwidget.h:22
static const String Parent
Definition Kwidget.h:24
static const String Renderstyle
Definition Kwidget.h:26
static const String ChildDelimiter
Definition Kwidget.h:23
static const String Bounds
Definition Kwidget.h:25
Holds the information needed to create a new Kwidget parameter.
Definition Kwidget.h:14
NormalisableRange< float > range
Definition Kwidget.h:17
String name
Definition Kwidget.h:16
String id
Definition Kwidget.h:15
float defaultValue
Definition Kwidget.h:18