How to save context menu result to a parameter

Reading this old forum post from @Squinky I started thinking if a parameter could be set with context menu option. But what’s the syntax?

menu->addChild(createIndexPtrSubmenuItem("Channels", {"first 10","last 10"}, &module->params[CONTEXT_INDEXCHAN].value));
// yes, I know that example above is incorrect

The Rack 2 API makes this easy for you. You just need to use configSwitch(…) in your module constructor and add the required switch options there. They will then appear as selection items in the parameter context menu.

configSwitch(SYNC_PARAM, 0, 1, 0, "Sync mode", {"Soft", "Hard"});
1 Like

That sounds amazing! What about creating the element outside of the panel dimension? (Just to keep it invisible…)

// adding this to "enum ParamIds"
OFFSET_PARAM,	

// adding this to the "LFO()" section
configSwitch(OFFSET_PARAM, 0.f,1.f,0.f, "Offset", {"-5v to 5v", "0v-10v"});

// adding this to the "ModulWidget" section
addParam(createParam<CKSS>(Vec(222, 222), module, BPMLFO::OFFSET_PARAM))

(Just for the record: I couldn’t make it work yet. :slight_smile: )

What I described is for handling the parameter context menu. If the parameter is positioned outside the panel boundaries, it will not be visible and therefore you won’t have access to it’s context menu.

I think I see what you are tying to achieve here now. You are trying to add a context menu for the user to set the range of the control, not adding the display values for a switch. That’s a different thing entirely. For that you need to use the panel context stuff and store the result in a variable within your module, not use a parameter.

The Fundamental Merge module has a good example of this; look at how MergeChannelsItem and MergeChannelItem are implemented.

https://github.com/VCVRack/Fundamental/blob/v2/src/Merge.cpp

1 Like

Both of your advices me showed me the way to go and led to invaluable resources. Thank you @CountModula!

1 Like