Slider probleme

Hello.
I have a problem and I don’t know How to solve it !
I would like to add slider into another class. Not the maincomponent class and displays it.
Thanks.

Have you gone through the Main Component and after that the Parent and child Component tutorial to get an idea how the main component and components holding other components work?

If so, Slider inherits Component, so you can pass it to all the functions that take a Component& as parameter like addAndMakeVisible as well as call all the Component functions on your slider, like mySlider.setBounds (...). Does this help you at least to get an idea of how to make your slider visible in a child component in the first place?

If not, it would be helpful if you would specify what issue you are facing or what you already tried?

First Thank you for your help !
I have done the introduction to dsp Tutorial on juce Web site and I would like to add a slider directly on my custom oscillator class but this class isn’t connected to the audioprocessor.
So I don’t know how to do that…
Thank you !

You have to separate the processing functionality (Oscillator) from the GUI (Slider)… one Has to be in the processor, one has to be in the AudioProcessorEditor. The oscillator has to work with no editor present.

Have a look at the AudioProcessorValueTreeState and the tutorial, how to connect parameters…

I see. I think you are best off doing a bit more tutorials…

Generally speaking you need to understand one core concept: DSP processing and GUI should always live in two separate classes and you will need so set up a link between those two. The tutorial you did does not tell you anything regarding the GUI part to keep you focused on the DSP part. However, you’ll find the DSPTutorialAudioProcessorEditor if you scroll down in the code. There you see

addAndMakeVisible (midiKeyboardComponent);
addAndMakeVisible (scopeComponent);

Which makes the keyboard and scope you see on your tutorial GUI visible. And you’ll see a lot of other stuff that will look quite confusing to you if you are just getting started. This would be the place to add your slider, but you should better start with a simpler tutorial like https://docs.juce.com/master/tutorial_code_basic_plugin.html where you learn how to set up a very simple GUI with one slider controlling the processing before trying to understand the GUI section of the DSP tutorial

Yes I know that but I don’t understant how to connect the slider directly to the gain of the oscillator !

The AudioProcessorValueTreeState serves as model. Your oscillator gets the parameter value from there, your slider controls the value, and the host automation takes over the control when necessary, where you don’t have to do anything yourself for.

The AudioProcessorValueTreeState example explains it hot to do it.

OK I check !
Thank you both of you for your time !!!

So I don’t really understant. Could i connect a slider in the audioeditor to a slider in the custom oscillator clar using valuetreestate ?

The Slider is a GUI element, so it makes no sense to have a Slider in your custom oscillator. You don’t want your effect or instrument go silent, when the editor is not present (and a Slider makes only sense in an Editor, otherwise no one would see it.

But your oscillator would be connected to the AudioParameterFloat, where your Slider is connected to as well. This is done using tree.getRawProcessorParameter ("param"). See the tutorials on how to do that.

OK Thank you ! Do you have the link of the Tutorial ?

Sure, the one I linked above: https://docs.juce.com/master/tutorial_audio_processor_value_tree_state.html

Specifically the section “performing the gain processing” should be of interest. That is, what you would do in your oscillator as well…

Hello.
I am sorry for all these questions but I am a beginner ! So if I understant well to solve my probleme I have to link my slider in a valuetreestate and send it to the voice where i Can fix the oscillator volume with the slider Thanks to the value tree state ?
Thank you !

No worries.

The AudioParameters are confusing, because there are many moving parts involved:

  • the processor, that uses the value in it’s processing
  • the plugin GUI, namely AudioProcessorEditor and it’s contents, where the user can change the value
  • the host, that replays recorded automation or sends data from a control surface

To make all that work, you need a single source of truth, which are the AudioParameters. They are organised most conveniently in an AudioProcessorValueTreeState. That takes already care of the communication between host and processor.

The Sliders in the ProcessorEditor are connected using the AudioProcessorValueTreeState::SliderAttachment, so that part works without creating listeners and such

Now your processor needs to read the variable as well and somehow forward that value to your voice instance. There are different ways, how that can be done, easiest using the AudioProcessorValueTreeState::Listener and react to the parameterChanged() callback. Each of your voices could be a listener to the state.

Thank you very much I am working hard !!!

That works perfectly ! Thank you very very very much !!!