First: Thanks for coping with me!
I don’t think what I want is too outlandish.
I want to create a LabelAttachment for the AudioProcessorValueTreeState that works very much in line with the existing framework. The Label would show the text that corresponds to the parameter value as defined in AudioProcessorValueTreeState::createAndAddParameter.
here is an example from my current project:
static const String& tuneChoices(int idx) {
static const StringArray tuneChoices = { "D/D", "A/E", "C/G" };
idx = jmin(2, jmax(0, idx));
return tuneChoices[idx];
}
(...)
createAndAddParameter("instrumentTuning", "instrumentTuning", "Tuning",
NormalisableRange<float>(0.0f, 2.0f, 1.f), 0.f,
[](float value) { // value to text function
return tuneChoices((int)value);
},
[](const String& text) { // text to value function
for (int i = 0; i < 3; ++i) {
if (text == tuneChoices(i)) {
return (float)i;
}
}
return 0.f;
}
);
This would also be the same text that is published to the plugin host.
like here: (from juce_VST3_Wrapper.cpp)
void toString (Vst::ParamValue value, Vst::String128 result) const override
{
if (AudioProcessorParameter* p = owner.getParameters()[paramIndex])
toString128 (result, p->getText ((float) value, 128));
else
// remain backward-compatible with old JUCE code
toString128 (result, owner.getParameterText (paramIndex, 128));
}
bool fromString (const Vst::TChar* text, Vst::ParamValue& outValueNormalized) const override
{
if (AudioProcessorParameter* p = owner.getParameters()[paramIndex])
{
outValueNormalized = p->getValueForText (getStringFromVstTChars (text));
return true;
}
return false;
}
To get the desired results I need to access the Parameter::range member as I have pointed out in my last post.
While the getText and getValueForText member functions are not inaccessible they are also not quite usable when the AudioProcessorValueTreeState is used. (because there is no way to access the Parameter::range member)
I simply want to display the string that represents the parameter value as the label text. The user should also be able to insert the a label text to change the parameter value.
Solving this problem will also allow some further nifty additions that I already have in the pipeline:
- change togglebutton label text according to toggle status.
- populate a combobox with values produced by the getText function,
I am now going to create a fork of the juce_audio_processors module that will provide the described functionality. (to be released soon)