ComboBoxAttachment: changing value to visual order correlation


#1

I have a ComboBox connected to a AudioProcessorValueTreeState via a ComboxBoxAttachment. Currently it has 3 items:

Old School Warm (value: 0)
Modern Hot      (value: 1)
Modern Hotter   (value: 2)

I’d like to add another item to the menu without breaking current presets and values which would normally be:

Old School Warm (value: 0)
Modern Hot      (value: 1)
Modern Hotter   (value: 2)
Old School Hot  (value: 3)

But I’d rather arrange it visually on the menu like this, which make more sense to the user:

Old School Warm (value: 0)
Old School Hot  (value: 3)
Modern Hot      (value: 1)
Modern Hotter   (value: 2)

Is there any way to modify the value to visual order arrangement and get what I want?


#2

The ComboboxAttachment takes the itemId, see here:

So you should be able to add your options in the order you need, just avoid itemId = 0, that is not allowed (i.e. nothing will happen, if you select that one).

However, when reading the source, I wonder, why setValue calls
combo.setSelectedItemIndex (roundToInt (newValue), sendNotificationSync);
instead of
combo.setSelectedId (roundToInt (newValue), sendNotificationSync);?

@t0m / @jules: was that intentional? maybe I missed something…

But for the first question, as it is stored normalised to 0…1, I’m afraid you will need some kind of migration strategy. Maybe add an information (e.g. version number) to the state, that wasn’t present before and update the numbers in that case.

HTH


#3

Yep, the current incarnation of the ComboBoxAttacment is severely restricted because of that strange design as I have noted here:

I needed a more flexible ComboBoxAttachment and so I have created my own version. If you don’t mind using hacked versions of some Juce files You will find that it allows to easily create a Combobox with all the features outlined above.


#4

Ah yes, I remembered “there was something”, but I didn’t look it up, sorry…
Thanks for linking it here, I will answer in your original thread.


#5

I have to correct myself. Reconsidering your requirements I found that you would need to write your own custom attachment to enable non incremental ordering of items. This would actually be not a difficult task. I am afraid though the access restrictions implemented in the AudioProcessorValueTreeState class make it impossible to build your own specialized version of the attachment.
You could use my version as a starting point, since here I have given public access to all the required classes.