VST parameter values and negatives

According to the VST specs the setParameter getParameter functions work on the float range of 0.0f to 1.0f for the value of the parameter. My components have negative values and i know i need to map the to that range of 0.0f to 1.0f i was wondering if anyone has a piece of code to handle such translations (performance is an issue here too). How to map the negative range: -64 - 63/128 values to 0.0f - 1.0f and the other way around. I know it’s simple math but i’m not sure i’m doing it the right way.

If you just need a linear mapping, the calculations should be as simple as this:

float zplControllableLib::LinearAutomationNormalizer::normalizeValue ( 
    const double& value, const double& minValue, const double& maxValue )
{
    jassert(maxValue > minValue);

    float normalized = (float)((value - minValue) / (maxValue - minValue));
    jassert(normalized >= 0.0f && normalized <= 1.0f);
    return normalized;
}

double zplControllableLib::LinearAutomationNormalizer::denormalizeValue ( 
    const float& normalized, const double& minValue, const double& maxValue )
{
    jassert(normalized >= 0.0f && normalized <= 1.0f);
    jassert(maxValue > minValue);

    return minValue + normalized * (maxValue - minValue);
}

This should work in all cases as long as maxValue is > minValue, of course you’ll need to add the rounding for your usecase.

These methods are part of a fairly complex set of classes that deal with parameter automation, serialization, validation. I have been thinking about sharing these as a 3rd party module (see (http://www.rawmaterialsoftware.com/viewtopic.php?f=8&t=7964), but there didn’t seem to be so much demand, probably since most people have come up with their own solution.

sorry i posted something stupid, nevermind :slight_smile:

Hi steffen,

<but there didn’t seem to be so much demand<

I don’t know why you think so. I think it would be great if you share your parameter classes.
All the new people need it and the one who made their own can compare if their missing somthing.
There have been viewtopics with wishes for parameter classes in juce.

I’ll try to find some time on the weekend then to give an example of how to work with those classes, so you and others can decide if they seem useful.

Since it would be quite some work to clean them up before publishing, I’d like to make sure they won’t become useless or obsolete with the changes and improvements others have been thinking about or have already implemented. (My classes don’t replace the way parameters are handled by the wrappers, but rather build up on that)

Here’s some functions for manipulating parameters. Use the inverse functions in ‘getParameter’ and ‘setParameterNotifyingHost’ and the non-inverse in ‘setParamer’. The warp functions, borrowed from JUCE’s slider class allow you to set a value you wish to be represented by 0.5 - useful for frequency control for example. The intStep functions allow integers to be represented and the Bool is self explanatory. Hope these help.

float warp(float x, float max, float min, float mid)
{
	float sf = warpCoefficients(max, min, mid);

    float y = exp (log (x) / sf);
    
    return min + (max - min) * y;;
}

float inverseWarp(float x, float max, float min, float mid)
{
    float sf = warpCoefficients(max, min, mid);

    float n = (x - min) / (max - min);
    
    return pow (n, sf);
}

float warpCoefficients(float max, float min, float mid)
{
    float  skewFactor = log (0.5f) / log ((mid - min)
                                        / (max - min));

	return skewFactor;
}

float linear(float x, float max, float min)
{  
    return min + (max - min) * x;
}

float inverseLinear(float x, float max, float min)
{  
    return (x - min) / (max - min);
}

int intStep(float x, int max, int min)
{
    return min + (int)((float)(max - min) * x + 0.5f);
}

float inverseIntStep(int x, int max, int min)
{  
    return (float)(x - min) / (float)(max - min);
}

bool boolStep(float x)
{
    if (x < 0.5)
		return false;
	else
		return true;
}

float inverseBoolStep(bool x)
{  
    if (x)
		return 1.0;
	else
		return 0.0;
}