nstilt1 / mofo-repo

Repo for the Mofo Mojo
0 stars 0 forks source link

Clean up the code #2

Open nstilt1 opened 5 months ago

nstilt1 commented 5 months ago

Noah, I know this is your first JUCE audio plugin, but you really need to organize the code a little bit more. Here are some pointers:

// Performs a unit bias calculation.
float bias(float volumeRatio, float tension) {
    if (tension == 0.5f)
        return volumeRatio;
    if (volumeRratio == 0.f || volumeRatio == 1.f) return volumeRatio;
    return (tension * volumeRatio) / (1 - tension - volumeRatio + (2 * volumeRatio * tension));
}

// Computes an envelope
float envelope(float volumeRatio, float tension, float min, float max, float lowerBound, float upperBound, int direction)
{
    if (max == lowerBound) return min;

    float envelopeBias = bias(volumeRatio, tension);

    if (max + min > upperBound) max = upperBound;
    else max = min + max;

    if (direction) return max - ((max - min) * envelopeBias);
    return min + ((max - min) * envelopeBias);
}
nstilt1 commented 5 months ago

I will need to rename a lot of variables. Especially the generic "chainSettings.shape", as well as replacing all instances of "shape" with "tension". I wrote most of this code 2 years ago, on a laptop that had a backspace button that didn't work, and a comma button that would double the commas. I didn't do much revising outside of debugging.