Hi!
I’ve just started experimenting with mouse events and I’m having some issues getting things in the processblock to respond to them.
Everything works fine with gui stuff, but it seems to be a different story in the processor.
Here’s what I’ve got:
Processor header:
Vol vll;
for (int channel = 0; channel < totalNumInputChannels; ++channel)
{
auto* channelData = buffer.getWritePointer(channel);
for (int i = 0; i < buffer.getNumSamples(); i++) {
channelData[i] = channelData[i] + vll.Ddrag;
}
}
I’ve declared it in the AudioProcessor, AudioProcessorEditor, addAndMakeVisible in the Editor, but the value of Ddrag is always zero in the processblock. I have the same variable modulating positions of graphics and it works fine. What am I doing wrong?
cheers for any help!
The Vol vll that you declared in the Processor is a separate instance to the one in the Editor.
You need to pass the value from the Editor instance of Vol to the Processor (taking care of thread safety whilst you do) and you do not need an instance of Vol in the Processor at all.
Unrelated, but by adding vll.Ddrag to the channel data you are just adding a DC offset to the signal. I’m guessing by the name of the class that it’s a volume control? In which case you’d want to multiply the audio data by Ddrag, but be aware that you’ll get louder output when Ddrag > 1.0, and if you don’t take care to scale it to sensible values you might get very loud output!
How do I pass values between the Editor and Processor? I can’t access the editor instance of Vol directly from the Processor, and it won’t let me make an Editor object to call a function returning the value.
And yeah, its just for playing with while I learn, not meant to serve any real purpose. Thank you!
i’d like to add to richie’s statement about multiplying the value to change the volume that if you wanna use actual db-values from the parameter you can convert them to the value that can be multiplied with this formular: pow(10, x / 20);
so when your parameter is on 0 it would multiply the samples by 1 (nothing happens).
if your parameter is on -6 it would multiply with .5 and so on.
can’t help you with your actual question unfortunately. i managed to do that a bit in one project but i’m not sure if everything was right yet because it kinda glitched out sometimes
Maybe easiest to make the child component directly access the processor (not the best code design, but if you just want it working for now) :
class Vol : public: Component
public:
Vol (MyAudioProcessorNameHere& p_) : p(p_)
{
}
void mouseDrag (const MouseEvent& event) override
{
// you don't really of course want it exactly like this, you need to scale the GUI value to some sensible value for the audio processing
p.dvol = event.getDistanceFromDragStart();
}
};
MyAudioProcessorNameHere& p;
You probably need to move the implementation of mouseDrag into a .cpp file, if you haven’t yet done so.