https://docs.juce.com/master/tutorial_synth_db_level_control.html
Following this tutorial, but all my components are separated out so tutorial is almost useless…
I honestly don’t even know how to word this question, but, here it goes…
I want to create a slider that adjusts the master volume of my synth.
I have a MasterVolume.h and .cpp that will be the component for this. It is inheriting from Component (because I read online that you should only have one AudioAppComponent, which MainComponent is already inheriting.)
In MasterVolume, I have declared in instance of a DecibelSlider class and its constructor has this code…
decibelSlider.setRange (-100, -12);
decibelSlider.setTextBoxStyle (juce::Slider::TextBoxRight, false, 100, 20);
decibelSlider.onValueChange = [this] { level = juce::Decibels::decibelsToGain ((float) decibelSlider.getValue()); };
decibelSlider.setValue (juce::Decibels::gainToDecibels (level));
decibelLabel.setText (“Noise Level in dB”, juce::dontSendNotification);addAndMakeVisible (decibelSlider);
addAndMakeVisible (decibelLabel);
But in MainComponent’s getNextAudioBlock, I assume I put this code…
auto currentLevel = level;
auto levelScale = currentLevel * 2.0f;
for (auto channel = 0; channel < bufferToFill.buffer->getNumChannels(); ++channel)
{
auto* buffer = bufferToFill.buffer->getWritePointer (channel, bufferToFill.startSample);
for (auto sample = 0; sample < bufferToFill.numSamples; ++sample)
buffer[sample] = random.nextFloat() * levelScale - currentLevel;
}
But, is that right? How would I get my decibel slider to get the value from MainComponent if I am instantiating an instance of MasterVolume inside of MainComponent? Do I pass buffer[sample] to the instance of MasterVolume? Just really confused how to make the slider, which is not inheriting anything from MainComponent, display the audio data that MainComponent is reading in getNextAudioBlock
Also… This forum design is terrrrrrible. Had a heck of a time writing this post with code…Are people more frequent here or reddit?