Hi, I’m trying to set an audio parameter choice for different oscillator types in a plugin to be selected. What I’m struggling with is my set of oscillator types to be chosen from are class objects from a separate oscillator header. This means I can’t use them as atomic floats using the audio parameter value tree state. Any ideas on how different classes can be used as audio parameter choices? Thank you
Just have each index of the choice parameter represent a different oscillator type, and create the actual oscillator object based on what index is chosen.
I’d also recommend to do a conversion through the index. If you have actually different types, you can use a
std::tuple. If you are talking different instances of the same type, you can use a
std::array. Both shouldn’t require any runtime allocations which makes it easy to use in a realtime context.
You can also use a template to determine the type based on the index, ie:
struct Sine; struct Square; struct Triangle; template<std::size_t Idx> using OscType = std::conditional_t<std::bool_constant<Idx == 0>, Sine, std::conditional_t<std::bool_constant<Idx == 1>, Square, Triangle>>;
I have created a class with all the parameters organized in structures, with the IDs as constexpr static and their corresponding atomics floats*. From the processor I access the floats with the class object, and from the editor I access the values with the ID and the index or instance number.
Within that class I also have my custom static methods in which the IDs are also built by concatenating the index as a string. So I only have to worry about creating the parameter or array of parameters with a common ID, when I add parameters to the array the individual ID is built automatically through the index.
Thank you for all the replies, very helpful… I think indexing them first has been helpful, but I’m exploring your further suggestions as well