How to update Param from filter? - VU Strip

I have a vu meter that I have in a 101 frame png strip. But where do I update the parameter for it? Here’s what I have so far:

#include "PluginProcessor.h"
#include "PluginEditor.h"

//==============================================================================
JuceDemoPluginAudioProcessorEditor::JuceDemoPluginAudioProcessorEditor (JuceDemoPluginAudioProcessor* ownerFilter)
    : AudioProcessorEditor (ownerFilter)
{

	internalCachedBackgroundImage = ImageCache::getFromMemory(stbg_png, stbg_pngSize);

	cachedImage_bungkno_png = ImageCache::getFromMemory (bungkno_png, bungkno_pngSize);

	addAndMakeVisible(gainSlider = new FilmStripKnob(cachedImage_bungkno_png, cachedImage_bungkno_png->getHeight() /cachedImage_bungkno_png->getWidth(), false));

    gainSlider->addListener (this);
    gainSlider->setRange (0.0, 1.0, 0.01);
	

	addAndMakeVisible (hiPassSlider = new Slider ("hipass"));
	hiPassSlider->setTextBoxStyle (Slider::TextBoxLeft, false, 80, 20);
	hiPassSlider->setSliderStyle (Slider::Rotary);
	hiPassSlider->addListener (this);
	hiPassSlider->setRange (0.0,1.0,0.01);
	

    Label* l = new Label ("", "Throughput level:");
    l->attachToComponent (gainSlider, false);
    l->setFont (Font (11.0f));

    addAndMakeVisible (delaySlider = new Slider ("delay"));
    delaySlider->setSliderStyle (Slider::Rotary);
    delaySlider->addListener (this);
    delaySlider->setRange (0.0, 1.0, 0.01);
    l = new Label ("", "Delay:");
    l->attachToComponent (delaySlider, false);
    l->setFont (Font (11.0f));

    
    // add a label that will display the current timecode and status..
    addAndMakeVisible (infoLabel = new Label (String::empty, String::empty));
    infoLabel->setColour (Label::textColourId, Colours::blue);

    // add the triangular resizer component for the bottom-right of the UI
    addAndMakeVisible (resizer = new ResizableCornerComponent (this, &resizeLimits));
    resizeLimits.setSizeLimits (150, 150, 800, 300);

    // set our component's initial size to be the last one that was stored in the filter's settings
    setSize (ownerFilter->lastUIWidth,
             ownerFilter->lastUIHeight);

    startTimer (50);
}

JuceDemoPluginAudioProcessorEditor::~JuceDemoPluginAudioProcessorEditor()
{
    deleteAllChildren();
}

//==============================================================================
void JuceDemoPluginAudioProcessorEditor::paint (Graphics& g)
{
   g.fillAll (Colour::greyLevel (0.9f));

    g.drawImage (internalCachedBackgroundImage, 0, 0, 562, 177,
												0, 0, internalCachedBackgroundImage->getWidth(), internalCachedBackgroundImage->getHeight());

}

void JuceDemoPluginAudioProcessorEditor::resized()
{
    infoLabel->setBounds (10, 4, 400, 25);
    gainSlider->setBounds (20, 60, cachedImage_bungkno_png->getWidth(), cachedImage_bungkno_png->getWidth());
    delaySlider->setBounds (200, 60, 150, 40);
	hiPassSlider->setBounds (88, 128, 150, 40);

    resizer->setBounds (getWidth() - 16, getHeight() - 16, 16, 16);
}

// This timer periodically checks whether any of the filter's parameters have changed...
void JuceDemoPluginAudioProcessorEditor::timerCallback()
{
    JuceDemoPluginAudioProcessor* ourProcessor = getProcessor();

    gainSlider->setValue (ourProcessor->gain, false);
    delaySlider->setValue (ourProcessor->delay, false);
	hiPassSlider->setValue (ourProcessor->hipass,false);
}

void JuceDemoPluginAudioProcessorEditor::sliderValueChanged (Slider* slider)
{
    if (slider == gainSlider)   getProcessor()->setParameterNotifyingHost (JuceDemoPluginAudioProcessor::GAIN,(float) gainSlider->getValue());
    if (slider == delaySlider)  getProcessor()->setParameterNotifyingHost (JuceDemoPluginAudioProcessor::DELAY,(float) delaySlider->getValue());
	if (slider == hiPassSlider) getProcessor()->setParameterNotifyingHost (JuceDemoPluginAudioProcessor::HIPASS,(float)hiPassSlider->getValue());
}

Do I have to put in the ::updateParametersFromFilter() ? Trying to get the compressor gain reduction that is calculated in the processing function, to update the filmstrip control…

Any Idears?

~RR.

Just noticed in the newer JUCE, has ::timerCallback() replaced updateParametersFromFilter() ? Or should I not use timerCallback() and just use updateParametersFromFilter() ?

I guess I could do this: getProcessor()->setParameterNotifyingHost(JuceDemoPluginAudioProcessor::VUMETER,gainReduction);

But how do i get the variable gainReduction into that from the processing function? or do I put that code inside the processing function…

EDIT: Tried this, crashes: Inside the process function

JuceDemoPluginAudioProcessor* updVU; updVU->setParameterNotifyingHost(DELAY,0.3);

~Rob.

The Juce demo-plugin uses the timerCallback() to set the values of GUI element to the matching AudioProcessor parameters. I think that is the most convenient way; simply have a public member for the GR value in you AudipProcessor and read that in timerCallback() of the AudioProcessorEditor to set the GR-Meter.

Do you mean AudioProcessor::processBlock() with process function? I don’t think it’s a good idea to call that while doing the likely time-critical processing.
Or do you create a new object and if so, where?

Chris

Thank you, yeah I was gonna put the rms code and that right inside what call the processing function, where the process double replacing etc happens. Still not quite used to the different sections of JUCE yet. I will try this. Actually on second thought I guess I could put the rms code right in the processor and send that GR out to the callback. lol, sorry to seem so scatter brained :slight_smile:

One Issue I’m having also is setting up a new instance of my EQ filter. In Iplug we have “onparamchange” which only happens when a control is touched. I tried to put it into the new instance (eq setup params) in the Sliderchanged method. It just blows up when I move a control:

[code]void JuceDemoPluginAudioProcessorEditor::sliderValueChanged (Slider* slider)
{
if (slider == hiPassSlider){ getProcessor()->setParameterNotifyingHost (JuceDemoPluginAudioProcessor::HIPASS,(float)hiPassSlider->getValue());
//test ::
if (slider == hiPassSlider) {filter->calc_filter_coeffs(7,500.0,44100.0,1.0,1.0,0);}
}

[/code]

Where should I put things like that take set, or update from a control? like compressor.setRatio(hipass); ?

EDIT: hmmm I ended up seting up my filter per block and really doesn’t seem too taxing: 0.4%, but its still inside the processing block:

[code]void JuceDemoPluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
const int numSamples = buffer.getNumSamples();

float *spl0 = buffer.getSampleData(0);
float *spl1 = buffer.getSampleData(1);

filter.calc_filter_coeffs(6,500.0,44100.0,2.0,8.0,1);

for(int i=0; i<buffer.getNumSamples();spl0++,spl1++,i++)
{   

	*spl0 = filter.filter(*spl0);
	*spl1 = filter.filter(*spl1);
	
	*spl0 *= gain;
	*spl1 *= gain;

}

}
[/code]

~Rob.

ckk Thank you, the Gain reduction works :slight_smile: