ComboBox and AudioParameterChoice

#1

Hi all :slight_smile:

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.

class A
{
public:
     A () : comboBoxAttachment(correspondingParameter, comboBox),
     {
        addAndMakeVisible(comboBox);
        comboBox.addItemList(Globals::itemsList, 1);
     }
private:
    ComboBox comboBox;
}

The solution I came up with works, but it isn’t very elegant.

class A
{
public:
     A () : comboBox(),
            dummy(setItems()),
            comboBoxAttachment(correspondingParameter, comboBox)
     {
        addAndMakeVisible(comboBox);
     }

     int setItems()
     {
         comboBox.addItemList(Globals::itemsList, 1);
         return 0;
     }
private:
    int dummy;
    ComboBox 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? :stuck_out_tongue_winking_eye:

Thanks R

0 Likes

#2

One alternative is to heap allocate the attachment so the constructor is called when you actually need it:

// With: std::unique_ptr<ComboBoxAttachment> comboBoxAttachment
A ()
{
    comboBox.addItemList(...);
    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 AudioParameterChoice

It would be similar to how SliderAttachment sets up the slider’s range, skew, text/value functions, etc. when you create the attachment

0 Likes

#3

+1 for this!

0 Likes