Passing additional compile time info into valueToText function

I really hope someone with C++ knowledge can help me.

We have a defined value to text function in the parameter class. It looks like this when I call it:

[this](float value, int maxLength) { return getRateText(newValue); })

I create the parameters inside two loops with counters i and j (the parameter exists 64 times). I have dynamically generated parameter names that contain i and j.

I need to know if another parameter is true or false to get the rate text (the sync parameter).
To read this parameter I need to know the current parameter name or the i and j values I used to create the parameter name.

I could now create 64 different methods. For example getRateText0101()… but I’m sure there is a better solution.

Is it possible to do this with a template or something? I thought about following:

[RateText<i,j, this>](float value, int maxLength) { return getRateText(newValue); })

where the template looks like this:

template<int i, int j, MyClass> struct RateText
{
    juce::String getRateText(float value)
    {
        return juce::String(getParemeterWithIndex(i, j), 2); // getParemeterWithIndex is a function from this
    }
};

Unfortunately, this does not work and my C++ skills are very limited.

Any help is welcome :slight_smile:

In addition to “this”, you can capture the local loop variables by copy into the lambda (that is important, you should not usually capture local variables by reference) :

[this,i,j](float value, int maxLength) 
{ 
  // i and j can now be used here...
  return getRateText(newValue); 
})

Thanks a lot. That worked! You saved my life.