I’m trying to use a AudioParameterChoice in combination with a ComboBox, which seems to be a pretty logical combination.
They both get their choices/items from an external file (Globals.h)
To connect the two I’d like to use a comboBoxAttachment.
In the following example, there won’t be an initial value in the comboBox. This is because the comboBoxAttachment sends an initial update, before the ComboBox has its items.
A () : comboBoxAttachment(correspondingParameter, comboBox),
The solution I came up with works, but it isn’t very elegant.
A () : comboBox(),
This way the comboBox will be initialised and have its items before the attachment sends the initial update.
It seems quite quirky though. Am I doing something completely wrong?
One alternative is to heap allocate the attachment so the constructor is called when you actually need it:
// With: std::unique_ptr<ComboBoxAttachment> comboBoxAttachment
comboBoxAttachment = std::make_unique<ComboBoxAttachment>(parameter, comboBox);
Another option (that I wish the attachment class supported by default!) is to make your own attachment type that sets the comboBox menu up itself in its own constructor based on a supplied
It would be similar to how
SliderAttachment sets up the slider’s range, skew, text/value functions, etc. when you create the attachment
Just to connect the dots:
I suggested once to populate this automatically but they wanted to keep existing behaviour.
But it can be solved with an “one-liner”:
auto* parameter = valueTreeState.getParameter ("type");
filterChoice->addItemList (parameter->getAllValueStrings(), 1);
// and I prefer make_unique, makes no technical difference though in this case:
filterChoiceAttachment = std::make_unique<juce::AudioProcessorValueTreeState::ComboBoxAttachment> (valueTreeState, "type", filter…