Hello there.
I wrote a program that creates an AudioProcessorGraph
, permitting to the user to add several audio tracks and to manage them through an UI.
Each time that a node is added to my AudioProcessorGraph
, my program store the Node::Ptr
of that specific node, in order to access it later for changing volume and other parameters stored inside that node.
I’m trying to manage the volume of the nodes: first, a node is instantiated and then the UI is set subsequently, by creating a lambda function which calls an onValueChange
on the relative slider:
void MixerPluginProjectEditor::settingTheUI(juce::String itemText, int indexToAdd,
juce::AudioProcessorGraph::Node::Ptr newNode)
{
// ... ... ///
auto nodeId = newNode->nodeID;
sliders[indexToAdd]->setName(juce::String(indexToAdd));
sliders[indexToAdd]->setRange(-50.0, 0.0);
sliders[indexToAdd]->setValue(-10.0);
sliders[indexToAdd]->onValueChange = [this, newNode, indexToAdd] {volumeChange(newNode, sliders[indexToAdd]); };
// ... ... //
}
The function volumeChange
:
void MixerPluginProjectFinaleAudioProcessorEditor::volumeChange(juce::AudioProcessorGraph::Node::Ptr node, juce::Slider* slider)
{
auto params = node->getProcessor()->getParameters();
auto currentValue = slider->getValue();
params[0]->setValueNotifyingHost(currentValue);
}
The parameter params[0]
represent the Volume
argument contained in each node of my “mixer”:
class AudioChannel : public ProcessorBase
{
public:
AudioChannel(juce::File audioPath)
{
addParameter(volume = new juce::AudioParameterFloat("volume", "Volume", juce::NormalisableRange<float> (-50.0f, 0.0f), -10.0f));
// ... ... //
}
void processBlock(juce::AudioSampleBuffer& buffer, juce::MidiBuffer&) override
{
auto totalNumInputChannels = getTotalNumInputChannels();
auto totalNumOutputChannels = getTotalNumOutputChannels();
for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
buffer.clear(i, 0, buffer.getNumSamples());
juce::AudioSourceChannelInfo bufferToFill(buffer);
bufferToFill.clearActiveBufferRegion();
transportPtr->getNextAudioBlock(bufferToFill);
float gain = juce::Decibels::decibelsToGain(volume->get());
transportPtr->setGain(gain);
}
juce::AudioParameterFloat* volume;
}
However, when I set the volume through the onValueChange
function, the Volume
number changes from 0.0
to -50.0
, and it remains stuck on -50
, making the audio of the node completely silent!
I don’t understand where I’m wrong. Any suggestions? Thank you in advance