From c13e1ddfd5723fe71e6f194a28e85c182650a721 Mon Sep 17 00:00:00 2001 From: Anjal Doshi Date: Thu, 21 Sep 2023 18:07:44 -0700 Subject: [PATCH] Add Parameter support in DataThreads --- Source/Processors/DataThreads/DataThread.h | 6 ++++++ .../Processors/GenericProcessor/GenericProcessor.cpp | 7 +++++-- Source/Processors/Parameter/ParameterEditor.cpp | 2 ++ Source/Processors/ProcessorGraph/ProcessorGraph.cpp | 6 ++++++ Source/Processors/SourceNode/SourceNode.cpp | 11 +++++++++++ Source/Processors/SourceNode/SourceNode.h | 6 ++++++ 6 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Source/Processors/DataThreads/DataThread.h b/Source/Processors/DataThreads/DataThread.h index 94e0e0bf1..577dd31db 100755 --- a/Source/Processors/DataThreads/DataThread.h +++ b/Source/Processors/DataThreads/DataThread.h @@ -88,6 +88,9 @@ class PLUGIN_API DataThread : public Thread // VIRTUAL METHODS // --------------------- + /**Create & register parameters for the DataThread */ + virtual void registerParameters() {}; + /** Called when the chain updates, to add, remove or resize the sourceBuffers' DataBuffers as needed*/ virtual void resizeBuffers() { } @@ -104,6 +107,9 @@ class PLUGIN_API DataThread : public Thread /** Allows the DataThread to set its default state, depending on whether the signal chain is loading */ virtual void initialize(bool signalChainIsLoading) { } + /** Called when a parameter value is updated, to allow plugin-specific responses */ + virtual void parameterValueChanged(Parameter*) { } + // --------------------- // NON-VIRTUAL METHODS // --------------------- diff --git a/Source/Processors/GenericProcessor/GenericProcessor.cpp b/Source/Processors/GenericProcessor/GenericProcessor.cpp index a28ecbf69..0ed07787e 100755 --- a/Source/Processors/GenericProcessor/GenericProcessor.cpp +++ b/Source/Processors/GenericProcessor/GenericProcessor.cpp @@ -960,7 +960,10 @@ void GenericProcessor::update() messageChannel->addProcessor(this); messageChannel->setDataStream(AccessClass::getMessageCenter()->getMessageStream()); - if (!isSource()) + // If Source call updateSettings immediately + if (isSource()) + updateSettings(); + else isEnabled = false; LOGD(getNodeId(), " connected to Message Center"); @@ -1140,7 +1143,7 @@ void GenericProcessor::update() LOGG(" Copied parameters in ", MS_FROM_START, " milliseconds"); - if (!isMerger()) + if (!isMerger() && !isSource()) updateSettings(); // allow processors to change custom settings, // including creation of streams / channels and // setting isEnabled variable diff --git a/Source/Processors/Parameter/ParameterEditor.cpp b/Source/Processors/Parameter/ParameterEditor.cpp index 83338cbe7..7fd12c3a6 100755 --- a/Source/Processors/Parameter/ParameterEditor.cpp +++ b/Source/Processors/Parameter/ParameterEditor.cpp @@ -115,6 +115,8 @@ void TextBoxParameterEditor::labelTextChanged(Label* label) { if(param->getType() == Parameter::FLOAT_PARAM) param->setNextValue(label->getText().getFloatValue()); + else if(param->getType() == Parameter::INT_PARAM) + param->setNextValue(label->getText().getIntValue()); else param->setNextValue(label->getText()); } diff --git a/Source/Processors/ProcessorGraph/ProcessorGraph.cpp b/Source/Processors/ProcessorGraph/ProcessorGraph.cpp index d7b679829..6e136ece9 100644 --- a/Source/Processors/ProcessorGraph/ProcessorGraph.cpp +++ b/Source/Processors/ProcessorGraph/ProcessorGraph.cpp @@ -820,9 +820,15 @@ void ProcessorGraph::restoreParameters() } } + // Create message center event channel (necessary for DataThreads) + getMessageCenter()->addSpecialProcessorChannels(); + // load source node parameters for (auto p : rootNodes) { + if(p->getPluginType() == Plugin::Type::DATA_THREAD) + p->update(); + p->loadFromXml(); } diff --git a/Source/Processors/SourceNode/SourceNode.cpp b/Source/Processors/SourceNode/SourceNode.cpp index f8b034715..88efbaaf4 100644 --- a/Source/Processors/SourceNode/SourceNode.cpp +++ b/Source/Processors/SourceNode/SourceNode.cpp @@ -104,6 +104,11 @@ void SourceNode::initialize(bool signalChainIsLoading) dataThread->initialize(signalChainIsLoading); } +void SourceNode::registerParameters() +{ + dataThread->registerParameters(); +} + void SourceNode::requestSignalChainUpdate() { @@ -147,6 +152,12 @@ void SourceNode::updateSettings() } +void SourceNode::parameterValueChanged(Parameter* parameter) +{ + dataThread->parameterValueChanged(parameter); +} + + float SourceNode::getSampleRate(int streamId) const { if (dataThread != nullptr) diff --git a/Source/Processors/SourceNode/SourceNode.h b/Source/Processors/SourceNode/SourceNode.h index 6b53456b7..062d72c9b 100755 --- a/Source/Processors/SourceNode/SourceNode.h +++ b/Source/Processors/SourceNode/SourceNode.h @@ -50,6 +50,9 @@ class PLUGIN_API SourceNode : public GenericProcessor /* Create a custom editor. */ AudioProcessorEditor* createEditor() override; + /** Registers the parameters for a given processor */ + void registerParameters() override; + /* Copies samples from the DataThread's DataBuffer into the GUI's processing buffers. */ void process (AudioBuffer& buffer) override; @@ -98,6 +101,9 @@ class PLUGIN_API SourceNode : public GenericProcessor /** Passes initialize command to the DataThread*/ void initialize(bool signalChainIsLoading) override; + + /** Called when a parameter value is updated, to allow plugin-specific responses*/ + void parameterValueChanged(Parameter*) override; private: