Krotos Modules 3
Loading...
Searching...
No Matches
KwidgetProcessor.cpp
Go to the documentation of this file.
1namespace krotos
2{
3 KwidgetProcessor::KwidgetProcessor(Kwidget& owner) : m_owner(owner) {}
4
5 void KwidgetProcessor::prepareToPlay(double sampleRate, int samplePerBlock)
6 {
7 prepare(sampleRate, samplePerBlock);
8
9 // TODO: add the ability to select number of output & input channels
10 const int numIns = 2;
11 const int numOuts = 2;
12 setPlayConfigDetails(numIns, numOuts, sampleRate, samplePerBlock);
13
14 for (auto& attachment : m_attachments)
15 attachment->prepare(sampleRate, samplePerBlock);
16 }
17
18 void KwidgetProcessor::processBlock(AudioBuffer<float>& buffer, MidiBuffer&) { process(buffer); }
19
20 void KwidgetProcessor::noteOn(int midiNoteNumber, float velocity, int) { ignoreUnused(midiNoteNumber, velocity); }
21
22 void KwidgetProcessor::noteOff(float velocity) { ignoreUnused(velocity); }
23
24 bool KwidgetProcessor::isActive() { return false; }
25
26 std::shared_ptr<KAttachment> KwidgetProcessor::getAttachment(const String& paramID)
27 {
28 jassert(m_attachmentMap.count(paramID) == 1);
29 return m_attachmentMap.at(paramID);
30 }
31
32 int KwidgetProcessor::getNumModulators() const { return m_modulators.size(); }
33
35 {
36 jassert(isPositiveAndBelow(index, m_modulators.size()));
37 return m_modulators.getUnchecked(index);
38 }
39
40 const String& KwidgetProcessor::getKwidgetType() const { return m_owner.getKwidgetType(); }
41
42 const String& KwidgetProcessor::getKwidgetID() const { return m_owner.getKwidgetID(); }
43
45 {
46 for (auto att : m_attachments)
47 att->applyPendingUpdates();
48 }
49
50 void KwidgetProcessor::nextBlock(int numSamples)
51 {
52 m_activeUpdaters.resize(0);
53
54 for (auto& attachment : m_attachments)
55 if (attachment->nextBlock(numSamples))
56 m_activeUpdaters.push_back(attachment->getUpdater());
57 }
58
60 {
61 for (auto& updater : m_activeUpdaters)
62 updater->next();
63 }
64
65 void KwidgetProcessor::addParameterAttachments(std::vector<AttachmentInfo> attachments)
66 {
67 for (auto& att : attachments)
68 {
69 jassert((att.updateRate == -1 && att.updateFunction == nullptr) || att.updateFunction != nullptr);
70
71 // gets parameter object
72 auto param = m_owner.getParameterToAttach(att.paramID);
73
74 // pointer is passed to attachment object
75
76 if (att.updateRate == 0)
77 m_attachments.push_back(std::make_shared<KAttachment>(param, std::move(att.updateFunction)));
78 else
79 m_attachments.push_back(std::make_shared<KAttachment>(param, static_cast<float>(m_smoothingTimeSeconds),
80 att.updateRate, std::move(att.updateFunction)));
81
82 m_attachmentMap[att.paramID] = m_attachments.back();
83 }
84 }
85
86 void KwidgetProcessor::addParameterCallback(const String& paramID, std::function<void(float)> callback)
87 {
89 new KParameter::AudioListenerObject(m_owner.getParameterToAttach(paramID), std::move(callback)));
90 }
91} // namespace krotos
Definition Kwidget.h:8
const String & getKwidgetType() const
Definition Kwidget.cpp:365
const String & getKwidgetID() const
Definition Kwidget.cpp:367
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
std::vector< KAttachment::ParameterUpdater * > m_activeUpdaters
Definition KwidgetProcessor.h:189
virtual void process(AudioBuffer< float > &buffer)=0
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
const double m_smoothingTimeSeconds
Definition KwidgetProcessor.h:183
const String & getKwidgetType() const
Definition KwidgetProcessor.cpp:40
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
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
int getNumModulators() const
Definition KwidgetProcessor.cpp:32
virtual void noteOn(int midiNoteNumber, float velocity, int voiceIndex=-1)
Definition KwidgetProcessor.cpp:20
KwidgetProcessor(Kwidget &owner)
Definition KwidgetProcessor.cpp:3
void nextSample()
Definition KwidgetProcessor.cpp:59
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
OwnedArray< Modulator > m_modulators
Definition KwidgetProcessor.h:193
void addParameterCallback(const String &paramID, std::function< void(float)> callback)
Definition KwidgetProcessor.cpp:86
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
A KParameter Listener which can be used to trigger a callback syncrhonously.
Definition KParameter.h:30