[SOLVED ] Make Two sliders as Gain input control and Output Monitor

How to make two volumes controls with sliders as in Gain Input control and Output Monitor?
I called and created two sliders with separate gain blocks which work just fine, but they interact wrong with each other. One I use one of the sliders, say the monitor output, I don’t get twice the audio signal but The value set by the first slider gets ignored or cancelled and goes back to 0. Any thoughts? I can share some code lines. Thank you all

Not really sure what you are trying from reading your post… What do you mean by “Output Monitor”? Maybe some lines of codes and a screenshot or video clip of your GUI misbehaving would make things more clear!

Thank you for your quick reply, sure! That’s what I have under the processor editor:

   Slider mGainControlSlider; //Input Gain
   Slider mGainInputSlider; //Master Output Fader

I have under Audio Processor Editor:

auto& params = processor.getParameters();
AudioParameterFloat *gainParameter = (AudioParameterFloat*)params.getUnchecked(0);
mGainControlSlider.setBounds(0, 0, 200, 200); // slider size
mGainControlSlider.setSliderStyle(Slider::SliderStyle::RotaryHorizontalDrag);
mGainControlSlider.setTextBoxStyle(Slider::TextBoxBelow, true, 90, 60);
mGainControlSlider.setRange(gainParameter->range.start, gainParameter->range.end);
mGainControlSlider.setValue(*gainParameter);
mGainControlSlider.addListener(this);
addAndMakeVisible(mGainControlSlider); 

//+++++++++++++++++++++ SECOND SLIDER +++++++++++++++++++++++
mGainInputSlider.setBounds(200, 120, 140, 140); // slider size
mGainInputSlider.setSliderStyle(Slider::SliderStyle::RotaryHorizontalDrag);
mGainInputSlider.setTextBoxStyle(Slider::TextBoxRight, true, 70, 40);
mGainInputSlider.setRange(gainParameter->range.start, gainParameter->range.end);
mGainInputSlider.setValue(*gainParameter);
mGainInputSlider.addListener(this);
addAndMakeVisible(mGainInputSlider); 

Than under paint:

auto& params = processor.getParameters();
if (slider == &mGainControlSlider) {

    AudioParameterFloat* gainParameter = (AudioParameterFloat*)params.getUnchecked(0);
    *gainParameter = mGainControlSlider.getValue();

    DBG("Change Parameter has changed");
}


//+++++++++++++++++++++ SECOND SLIDER +++++++++++++++++++++++

if (slider == &mGainInputSlider) {
    
    AudioParameterFloat* inputgainParameter = (AudioParameterFloat*)params.getUnchecked(0);
    *inputgainParameter = mGainInputSlider.getValue();
    
    DBG("Change Parameter has changed");
} 

This under the Audio Processor:

AudioParameterFloat* mGainParameter;

float mGainSmoothed;

Under the audio processor on .cpp file:

    addParameter(mGainParameter = new AudioParameterFloat("gain",      // String parameterID
                                                      "Gain",     // String name
                                                      0.0f,      // float minValue
                                                      1.0f,     // float maxValue
                                                      0.0f));  // float defaultValue

mGainSmoothed = mGainParameter->get();

And in the process block:

for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
    buffer.clear (i, 0, buffer.getNumSamples());

auto* channelLeft = buffer.getWritePointer(0);
auto* channelRight = buffer.getWritePointer(1);

for (int sample = 0; sample < buffer.getNumSamples(); sample++)
    {

        mGainSmoothed = mGainSmoothed - 0.04*(mGainSmoothed-mGainParameter->get());
        //+++++++++++++++++++ SECOND SLIDER +++++++++++++++++++++++++++
        //mInputGainSmoothed = mInputGainSmoothed - 0.04*(mInputGainSmoothed-mInputGainParam->get());
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        
        channelLeft[sample] *= mGainSmoothed;
        channelRight[sample] *= mGainSmoothed;

And finally under the has editor:

AudioProcessorEditor* FocusriteBeginDemoAudioProcessor::createEditor()

I apologise for the question but I am new in learning c++ and juce especially.
Thank you very much for your help!

nvm

You apparently have just 1 parameter in the plugin, so I don’t really get what you are trying to achieve with the 2 sliders? If you want separate input and output gains, you need to add plugin parameters for both.

1 Like

Thank you very much! I have tried with having separate parameters for both sliders but I am getting a wrong output as in whenever i move the first slider as soon as I move the second one the volume gets automatically reset to the value of the second slider ignoring the value previously set with the first slider. What am I missing? Do I need to set the parameters so that the two sliders take two different samples from the buffer?

Sorry, I am having problems understanding what are you actually attempting to do? The processBlock code you’ve shown so far doesn’t look like you would even need separate gain controls. Why are you trying to have 2 gain parameters with that code? (Separate input and output gains could make sense if your code did something like distortion or compression…)

essentially I am trying to emulate a mic preamp that has an input gain for the signal coming from the mic and a monitor knob as a second volume control to set the volume coming out of the preamp which could be sent to a set of speakers or in case of a DAW to the master fader. I’m sorry if this is confusing I hope I explained well enough. Thank you again for your precious help

Well, I can’t say anything else but check that your code is setting and using the correct parameters in the right places in the code.

You need to call this in each processBlock call otherwise your gain will be zero all the time.
You should also ake a look at SliderAttachment, this will make things easier. I suppose there are many tutorials in which they are used.

1 Like