Krotos Modules 3
Loading...
Searching...
No Matches
KwidgetProcessor.h
Go to the documentation of this file.
1namespace krotos
2{
3 //==============================================================================
7 class KwidgetProcessor : public AudioProcessor
8 {
9 public:
12
14 ~KwidgetProcessor() override = default;
15
17 void prepareToPlay(double, int) override final;
18
20 void processBlock(AudioBuffer<float>& buffer, MidiBuffer&) override final;
21
23 virtual void prepare(double sampleRate, int samplesPerBlock) = 0;
24
26 virtual void process(AudioBuffer<float>& buffer) = 0;
27
38 virtual void noteOn(int midiNoteNumber, float velocity, int voiceIndex = -1);
39
44 virtual void noteOff(float velocity);
45
46 virtual bool isActive();
47
49 virtual void noteCleared() {}
50
52 std::shared_ptr<KAttachment> getAttachment(const String& paramID);
53
55 int getNumModulators() const;
56
58 Modulator* getModulator(int index);
59
61 const String& getKwidgetType() const;
62
64 const String& getKwidgetID() const;
65
78 void updateAttachments();
79
80 protected:
85 {
87 String paramID;
88
98 std::function<void(float)> updateFunction;
99
105 };
106
128 void nextBlock(int numSamples);
129
131 void nextSample();
132
139 void addModulator(bool useAudioRate) { m_modulators.add(new Modulator(useAudioRate)); }
140
154 void addParameterAttachments(std::vector<AttachmentInfo>);
155
161 void addParameterCallback(const String& paramID, std::function<void(float)> callback);
162
164 Kwidget& getOwner() const { return m_owner; }
165
166 private:
167 // Probably no need to override these as we are not using this part of the class.
168 const String getName() const override { return {}; }
169 AudioProcessorEditor* createEditor() override { return nullptr; }
170 bool hasEditor() const override { return false; }
171 double getTailLengthSeconds() const override { return 0; }
172 bool acceptsMidi() const override { return false; }
173 bool producesMidi() const override { return false; }
174 int getNumPrograms() override { return 0; }
175 int getCurrentProgram() override { return 0; }
176 void setCurrentProgram(int) override {}
177 const String getProgramName(int) override { return {}; }
178 void changeProgramName(int, const String&) override {}
179 void getStateInformation(MemoryBlock&) override {}
180 void setStateInformation(const void*, int) override {}
181 void releaseResources() override {}
182
183 const double m_smoothingTimeSeconds{20e-3f};
184
186
187 std::vector<std::shared_ptr<KAttachment>> m_attachments;
188 std::unordered_map<String, std::shared_ptr<KAttachment>> m_attachmentMap;
189 std::vector<KAttachment::ParameterUpdater*> m_activeUpdaters;
190
191 OwnedArray<KParameter::AudioListenerObject> m_parameterCallbacks;
192
193 OwnedArray<Modulator> m_modulators;
194 };
195} // namespace krotos
Definition Kwidget.h:8
An interface for an audio processor designed for modular use.
Definition KwidgetProcessor.h:8
std::vector< KAttachment::ParameterUpdater * > m_activeUpdaters
Definition KwidgetProcessor.h:189
bool acceptsMidi() const override
Definition KwidgetProcessor.h:172
~KwidgetProcessor() override=default
virtual void process(AudioBuffer< float > &buffer)=0
void changeProgramName(int, const String &) override
Definition KwidgetProcessor.h:178
bool hasEditor() const override
Definition KwidgetProcessor.h:170
const String getName() const override
Definition KwidgetProcessor.h:168
Kwidget & m_owner
Definition KwidgetProcessor.h:185
void updateAttachments()
Definition KwidgetProcessor.cpp:44
virtual bool isActive()
Definition KwidgetProcessor.cpp:24
void processBlock(AudioBuffer< float > &buffer, MidiBuffer &) override final
Definition KwidgetProcessor.cpp:18
Modulator * getModulator(int index)
Definition KwidgetProcessor.cpp:34
AudioProcessorEditor * createEditor() override
Definition KwidgetProcessor.h:169
const double m_smoothingTimeSeconds
Definition KwidgetProcessor.h:183
const String & getKwidgetType() const
Definition KwidgetProcessor.cpp:40
int getNumPrograms() override
Definition KwidgetProcessor.h:174
std::shared_ptr< KAttachment > getAttachment(const String &paramID)
Definition KwidgetProcessor.cpp:26
std::unordered_map< String, std::shared_ptr< KAttachment > > m_attachmentMap
Definition KwidgetProcessor.h:188
double getTailLengthSeconds() const override
Definition KwidgetProcessor.h:171
int getCurrentProgram() override
Definition KwidgetProcessor.h:175
void nextBlock(int numSamples)
Definition KwidgetProcessor.cpp:50
virtual void prepare(double sampleRate, int samplesPerBlock)=0
void addParameterAttachments(std::vector< AttachmentInfo >)
Definition KwidgetProcessor.cpp:65
void releaseResources() override
Definition KwidgetProcessor.h:181
void getStateInformation(MemoryBlock &) override
Definition KwidgetProcessor.h:179
int getNumModulators() const
Definition KwidgetProcessor.cpp:32
virtual void noteOn(int midiNoteNumber, float velocity, int voiceIndex=-1)
Definition KwidgetProcessor.cpp:20
const String getProgramName(int) override
Definition KwidgetProcessor.h:177
KwidgetProcessor(Kwidget &owner)
Definition KwidgetProcessor.cpp:3
Kwidget & getOwner() const
Definition KwidgetProcessor.h:164
void nextSample()
Definition KwidgetProcessor.cpp:59
void setStateInformation(const void *, int) override
Definition KwidgetProcessor.h:180
virtual void noteOff(float velocity)
Definition KwidgetProcessor.cpp:22
OwnedArray< KParameter::AudioListenerObject > m_parameterCallbacks
Definition KwidgetProcessor.h:191
void prepareToPlay(double, int) override final
Definition KwidgetProcessor.cpp:5
const String & getKwidgetID() const
Definition KwidgetProcessor.cpp:42
std::vector< std::shared_ptr< KAttachment > > m_attachments
Definition KwidgetProcessor.h:187
void addModulator(bool useAudioRate)
Definition KwidgetProcessor.h:139
bool producesMidi() const override
Definition KwidgetProcessor.h:173
OwnedArray< Modulator > m_modulators
Definition KwidgetProcessor.h:193
void addParameterCallback(const String &paramID, std::function< void(float)> callback)
Definition KwidgetProcessor.cpp:86
virtual void noteCleared()
Definition KwidgetProcessor.h:49
void setCurrentProgram(int) override
Definition KwidgetProcessor.h:176
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
Holds the info required to create a new KAttachment for a Kwidget parameter.
Definition KwidgetProcessor.h:85
std::function< void(float)> updateFunction
Definition KwidgetProcessor.h:98
String paramID
Definition KwidgetProcessor.h:87
int updateRate
Definition KwidgetProcessor.h:104