Skip to content

Commit

Permalink
Add Parameter support in DataThreads
Browse files Browse the repository at this point in the history
  • Loading branch information
anjaldoshi committed Sep 22, 2023
1 parent c87e6f6 commit c13e1dd
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Source/Processors/DataThreads/DataThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() { }

Expand All @@ -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
// ---------------------
Expand Down
7 changes: 5 additions & 2 deletions Source/Processors/GenericProcessor/GenericProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Source/Processors/Parameter/ParameterEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
6 changes: 6 additions & 0 deletions Source/Processors/ProcessorGraph/ProcessorGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
11 changes: 11 additions & 0 deletions Source/Processors/SourceNode/SourceNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ void SourceNode::initialize(bool signalChainIsLoading)
dataThread->initialize(signalChainIsLoading);
}

void SourceNode::registerParameters()
{
dataThread->registerParameters();
}


void SourceNode::requestSignalChainUpdate()
{
Expand Down Expand Up @@ -147,6 +152,12 @@ void SourceNode::updateSettings()
}


void SourceNode::parameterValueChanged(Parameter* parameter)
{
dataThread->parameterValueChanged(parameter);
}


float SourceNode::getSampleRate(int streamId) const
{
if (dataThread != nullptr)
Expand Down
6 changes: 6 additions & 0 deletions Source/Processors/SourceNode/SourceNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>& buffer) override;

Expand Down Expand Up @@ -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:

Expand Down

0 comments on commit c13e1dd

Please sign in to comment.