AudioProcessorParameterInt problem

Hey all, 

 

I am using a few audio processor parameter classes and I think I have found a problem or am not understanding something. I noticed this with my AudioProcessorParameterInt however looking at the code I think this exists in all types.

In the operator= function for each parameter this block of code exists:

const float normalisedValue = range.convertTo0to1 (newValue); 
if (value != normalisedValue) 
    setValueNotifyingHost (normalisedValue);

This makes sense as the incoming value gets made into a 0 to 1 float and compared against the value member which is (supposedly) a 0 to 1 float. However, if you look where the value variable is set:

setValue (float newValue) { value = range.convertFrom0to1 (newValue); }

so the value variable is actually converted from a 0 to 1 into whatever the object is. This is still fine because we are using setvaluenotifyinghost however it does render the != operator meaningless (because value is not 0 to 1 and normalised value is 0 to 1). This is very aparent in the AudioParameterInt class when you try to change from 1 to the maximum value, it will not change because in that case, value == normalisedValue. An easy fix for this is to change the operator= function to this:

const float normalisedValue = range.convertTo0to1 (newValue);
if (range.convert0to1(value) != normalisedValue) 
    setValueNotifyingHost (normalisedValue);

or compare value and newValue.

 

I notice this problem is simmilar with the other types of processor parameters however int is the most likely to run into the problem as it is discrete quantities.

I'm DEFINITELY running into crazy results with AudioParameterInt. 

I've created one like this:

addParameter(transposeParm = new AudioParameterInt("transpose", "Transpose", -2, 2, 0));

which I would expect the allowable range to be from -2 to 2. 

I'm using a ComboBox menu to change this value like this:

void MyAudioProcessorEditor::comboBoxChanged(juce::ComboBox *box)
{
    int index = box->getSelectedItemIndex();
    printf("index: %d, ", index);

    if(box == &transposeCombo)
    {
        *transposeParm = (index - 2);
        printf("parm: %d\n", transposeParm->get());
    }
}

When I run this and choose each menu item one at a time, I get this:

index: 0, parm: 0      <---- parm should be -2
index: 1, parm: -1
index: 2, parm: 0
index: 3, parm: 1
index: 4, parm: 1      <---- parm should be 2

and if I choose them all again:

index: 0, parm: -2     <---- for some reason, this is correct now
index: 1, parm: -1 
index: 2, parm: 0 
index: 3, parm: 1 
index: 4, parm: 1      <---- parm should be 2

What on earth is going on?

Thanks for the heads-up, there did seem to be some broken comparisons going on in the operator= methods - try it again now!

When you say "Try it again now", are you referring to updating the juce modules to the latest tip on Github or via IntroJucer? 

Always talking about github. We don't update the introjucer zip thing very often.

All better now, Jules. Thanks.