Krotos Modules 3
Loading...
Searching...
No Matches
KAttachment.h
Go to the documentation of this file.
1namespace krotos
2{
3 //==============================================================================
12 class KAttachment : public AudioProcessorParameter::Listener, public Modulator::Listener
13 {
14 public:
23 {
24 public:
26
27 void next()
28 {
29 // Update parameter if the update counter resets to 0
30 if (m_updateCounter == 0)
32
34 }
35
36 void reset()
37 {
40 }
41
42 private:
44 {
45 auto bufferPtr = m_owner.m_valueBuffer.getWritePointer(0);
47 }
48
54
58 };
59
71 KAttachment(std::shared_ptr<KParameter> paramToAttach, std::function<void(float)> updateFunction = nullptr);
72
85 KAttachment(std::shared_ptr<KParameter> paramToAttach, float smoothingTimeSeconds, int updateRate,
86 std::function<void(float)> updateFunction = nullptr);
87
89 ~KAttachment() override;
90
94 void prepare(double sampleRate, int samplesPerBlock);
95
104 bool nextBlock(int numSamples);
105
107 const float* data();
108
110 bool needsUpdate() const;
111
118
124
126 void addModulator(Modulator* m, float depth = 1.0f, Polarity polarity = Polarity::Bipolar);
127
129 void removeModulator(Modulator* m);
130
135 void setModulatorDepth(Modulator* m, float depth);
136
141 void setModulatorPolarity(Modulator* m, Polarity polarity);
142
148 void applyPendingUpdates();
149
150 private:
151 friend class ParameterUpdater;
152
153 enum Mode
154 {
157 };
158
159 void parameterValueChanged(int /*paramIndex*/, float newValue) override;
160 void parameterGestureChanged(int, bool) override {}
161 void sendInitialUpdate();
162 void modulatorChanged(const Modulator* m) override;
163 void updateSmoother();
164
165 std::weak_ptr<RangedAudioParameter> const m_parameterPtr;
166 RangedAudioParameter* m_cachedParameterPtr;
168 AudioBuffer<float> m_valueBuffer;
170 std::unique_ptr<ParameterUpdater> m_updater;
171
172 SmoothedValue<float> m_smoother{0.0f};
175
176 Array<Modulator*> m_slowModulators;
177 Array<Modulator*> m_fastModulators;
178
179 struct Depth
180 {
181 float value;
183 };
184
185 std::map<Modulator*, Depth> m_depthMap;
186
187 double m_sampleRate{0.0};
189
190 bool m_needsUpdate{false};
191 bool m_wasSmoothing{false};
192 const std::function<void(float)> m_updateFunction;
194
195 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(KAttachment)
196 };
197} // namespace krotos
Definition KAttachment.h:23
void reset()
Definition KAttachment.h:36
void incrementCounters()
Definition KAttachment.h:49
ParameterUpdater(KAttachment &owner)
Definition KAttachment.h:25
void callUpdateFunction()
Definition KAttachment.h:43
KAttachment & m_owner
Definition KAttachment.h:55
int m_updateCounter
Definition KAttachment.h:56
int m_sampleCounter
Definition KAttachment.h:57
void next()
Definition KAttachment.h:27
Attaches to a KParameter to provide parameter smoothing and modulation.
Definition KAttachment.h:13
int m_numSmoothingSamples
Definition KAttachment.h:174
std::unique_ptr< ParameterUpdater > m_updater
Definition KAttachment.h:170
void sendInitialUpdate()
Definition KAttachment.cpp:226
bool m_wasSmoothing
Definition KAttachment.h:191
const float * data()
Definition KAttachment.cpp:155
void updateSmoother()
Definition KAttachment.cpp:249
void applyPendingUpdates()
Definition KAttachment.cpp:212
SmoothedValue< float > m_smoother
Definition KAttachment.h:172
void setModulatorDepth(Modulator *m, float depth)
Definition KAttachment.cpp:195
void modulatorChanged(const Modulator *m) override
Definition KAttachment.cpp:243
Array< Modulator * > m_fastModulators
Definition KAttachment.h:177
Polarity
Definition KAttachment.h:120
@ Bipolar
Definition KAttachment.h:121
@ Unipolar
Definition KAttachment.h:122
AudioBuffer< float > m_valueBuffer
Definition KAttachment.h:168
bool m_needsUpdate
Definition KAttachment.h:190
void addModulator(Modulator *m, float depth=1.0f, Polarity polarity=Polarity::Bipolar)
Definition KAttachment.cpp:166
std::map< Modulator *, Depth > m_depthMap
Definition KAttachment.h:185
Array< Modulator * > m_slowModulators
Definition KAttachment.h:176
void prepare(double sampleRate, int samplesPerBlock)
Definition KAttachment.cpp:53
void setModulatorPolarity(Modulator *m, Polarity polarity)
Definition KAttachment.cpp:204
bool nextBlock(int numSamples)
Definition KAttachment.cpp:76
double m_sampleRate
Definition KAttachment.h:187
RangedAudioParameter * m_cachedParameterPtr
Definition KAttachment.h:166
Mode
Definition KAttachment.h:154
@ Continuous
Definition KAttachment.h:156
@ Discrete
Definition KAttachment.h:155
const std::function< void(float)> m_updateFunction
Definition KAttachment.h:192
void parameterGestureChanged(int, bool) override
Definition KAttachment.h:160
KAttachment(std::shared_ptr< KParameter > paramToAttach, std::function< void(float)> updateFunction=nullptr)
Definition KAttachment.cpp:3
const Mode m_attachmentMode
Definition KAttachment.h:169
int m_maxBlockSize
Definition KAttachment.h:188
float m_smoothingTimeSeconds
Definition KAttachment.h:173
void parameterValueChanged(int, float newValue) override
Definition KAttachment.cpp:220
bool needsUpdate() const
Definition KAttachment.cpp:218
~KAttachment() override
Definition KAttachment.cpp:45
void removeModulator(Modulator *m)
Definition KAttachment.cpp:183
float m_parameterValue
Definition KAttachment.h:167
std::weak_ptr< RangedAudioParameter > const m_parameterPtr
Definition KAttachment.h:165
int m_updateRate
Definition KAttachment.h:193
ParameterUpdater * getUpdater()
Definition KAttachment.cpp:157
Holds a list of modulation destinations and sends events to them when the modulator output is updated...
Definition ModulationSource.h:20
Definition AirAbsorptionFilter.cpp:2
Definition KAttachment.h:180
Polarity polarity
Definition KAttachment.h:182
float value
Definition KAttachment.h:181
Definition ModulationSource.h:23