Hello there.
I’m trying to develop an app which permits to the user to instantiate several audio tracks, in order to generate a mixer by sampling audio files placed inside a folder.
I’m not sure how to set an AudioParameterChoice
for handling the reproduction state of an audio file (i.e.: put an audio file to pause if it is playing, stop it and so on).
This is my AudioChannel
, based on the AudioProcessor
class
class AudioChannel : public AudioProcessor
{
public:
AudioChannel(juce::File audioPath)
{
addParameter(reproductionState = new juce::AudioParameterChoice("state", "State", states, 0));
// ... ... //
}
void prepareToPlay(double sampleRate, int samplesPerBlock) override
{
reproductionState->setValueNotifyingHost(float(5));
transportPtr->prepareToPlay(samplesPerBlock, sampleRate);
}
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());
reproductionStateChanged();
juce::AudioSourceChannelInfo bufferToFill(buffer);
bufferToFill.clearActiveBufferRegion();
transportPtr->getNextAudioBlock(bufferToFill);
float gain = juce::Decibels::decibelsToGain(volume->get());
transportPtr->setGain(gain);
}
void reproductionStateChanged()
{
auto newState = reproductionState->getCurrentValueAsText();
if (newState != actualState)
{
actualState = newState;
}
}
juce::StringArray states{ "Stopped", "Starting", "Stopping", "Pausing", "Paused", "Playing" };
juce::AudioParameterChoice* reproductionState;
juce::String actualState = "Awakening";
juce::AudioParameterFloat* volume;
}
And this is the function in the PluginEditor, which is in charge of changing the reproduction state of an audio file:
void PluginEditor::playButtonClicked(juce::AudioProcessorGraph::Node::Ptr node,
juce::TextButton* button)
{
auto params = node->getProcessor()->getParameters();
params[1]->beginChangeGesture();
params[1]->setValueNotifyingHost(float(5));
params[1]->endChangeGesture();
button->setEnabled(false);
}
However, the code doesn’t work, since setValueNotifyingHost
only accepts values between 0.0
and 1.0
. Is there any chance to change the value of the AudioProcessorChoice
directly from the editor? Which function should be used for the scope?
Thanks in advance for any answer