Some of my controls, such as this button, have context menu options that don’t make much sense. In this case, Initialize and Fine Adjust serve no obvious purpose. Is there any way for me to remove these context menu items?
Thanks!
Bret
Some of my controls, such as this button, have context menu options that don’t make much sense. In this case, Initialize and Fine Adjust serve no obvious purpose. Is there any way for me to remove these context menu items?
Thanks!
Bret
Please show us the code … it looks like your button is a knob.
There’s a lot of inheritance that would make displaying all of the code a bit overwhelming. However, it all boils down to an SvgSwitch.
I’ll walk through it anyhow…
Here’s where those buttons are added to the module’s widget:
// Sequence selection buttons
addParam(createParamCentered<VoxglitchRoundToggleLampSwitch>(themePos("SEQUENCER_1_BUTTON"), module, DigitalSequencer::SEQUENCER_SELECTION_BUTTONS + 0));
addParam(createParamCentered<VoxglitchRoundToggleLampSwitch>(themePos("SEQUENCER_2_BUTTON"), module, DigitalSequencer::SEQUENCER_SELECTION_BUTTONS + 1));
addParam(createParamCentered<VoxglitchRoundToggleLampSwitch>(themePos("SEQUENCER_3_BUTTON"), module, DigitalSequencer::SEQUENCER_SELECTION_BUTTONS + 2));
addParam(createParamCentered<VoxglitchRoundToggleLampSwitch>(themePos("SEQUENCER_4_BUTTON"), module, DigitalSequencer::SEQUENCER_SELECTION_BUTTONS + 3));
addParam(createParamCentered<VoxglitchRoundToggleLampSwitch>(themePos("SEQUENCER_5_BUTTON"), module, DigitalSequencer::SEQUENCER_SELECTION_BUTTONS + 4));
addParam(createParamCentered<VoxglitchRoundToggleLampSwitch>(themePos("SEQUENCER_6_BUTTON"), module, DigitalSequencer::SEQUENCER_SELECTION_BUTTONS + 5));
Here’s the definition of VoxglitchRoundToggleLampSwitch, which inherits from VoxglitchRoundLampSwitch and sets “momentary” to false:
struct VoxglitchRoundToggleLampSwitch : VoxglitchRoundLampSwitch {
VoxglitchRoundToggleLampSwitch() {
momentary = false;
}
};
Here’s VoxglitchRoundLampSwitch, which inherits from VoxglitchSwitch:
struct VoxglitchRoundLampSwitch : VoxglitchSwitch {
ImageWidget* bg;
ImageWidget* voxglitch_shadow;
VoxglitchRoundLampSwitch()
{
addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/components/round_light_off.svg")));
addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/components/round_light_on.svg")));
// Add the shadow below everything
voxglitch_shadow = new ImageWidget("res/themes/default/round_shadow.png", 10.0, 10.0, 0.8);
this->addChildBottom(voxglitch_shadow);
voxglitch_shadow->setPosition(Vec(-5.5, -3.3));
// Set box size. This affects the center position
box.size = Vec(15.5,15.5);
// Turn off Rack shadow
this->shadow->opacity = 0;
}
void draw(const DrawArgs& args) override
{
SvgSwitch::draw(args);
if(module)
{
//
// Draw glow effect
//
ParamQuantity *param_quantity = getParamQuantity();
if(! (param_quantity->getValue() == param_quantity->getMinValue()))
{
math::Vec c = box.size.div(2);
c.x += 1.46; // offset a little bit to correct for small box size
c.y += 1.46;
float radius = std::min(box.size.x, box.size.y) / 2.0;
float oradius = radius + std::min(radius * 1.5f, 4.5f); // was 2.5 f max
nvgBeginPath(args.vg);
nvgRect(args.vg, c.x - oradius, c.y - oradius, 2 * oradius, 2 * oradius);
NVGcolor icol = nvgRGBA(255, 208, 183, 60);
NVGcolor ocol = nvgRGBA(0, 0, 0, 0);
NVGpaint paint = nvgRadialGradient(args.vg, c.x, c.y, radius, oradius, icol, ocol);
nvgFillPaint(args.vg, paint);
nvgFill(args.vg);
}
}
}
};
And finally, here’s VoxglitchSwitch:
struct VoxglitchSwitch : SvgSwitch {
// there is some optional debug code in here that's usually not active
};
oooohhhh… perhaps I should be using SvgButton.
Ah, that’s right. I thought of that, but SVG buttons currently don’t support “toggling” (in other words, NOT momentary). See Simple LEDButton used as a toggle instead of a momentary switch? - #14 by Vortico
Seems quite a few people get this wrong:
In your module constructor, use configButton()
or configSwitch()
instead of configParam()
.
In my module Metronome I use a big switch that is initialized with configSwitch()
and produces the following context menu:
Here’s the code:
Yeah now I know about config swirch I will update all the surge switches too
Excellent, thanks everyone!
Oh super!
All my modules have a shared base class, so it was made even easier by adding this
template<typename T=rack::SwitchQuantity>
T *configOnOff(int paramId, float defaultValue, std::string name)
{
return configSwitch<T>(paramId, 0, 1, defaultValue, name, {"Off", "On"});
}
to that class (and replacing the OnOffParamQuantity I had written to stop it being 1/0)
On and I edited it to pass along to configSwitch of course duh.
@baconpaul I’m not well versed in C++ templates and I’m having some trouble with your code. Have a moment to help me out?
struct VoxglitchSwitch : SvgSwitch {
template<typename T=rack::SwitchQuantity>; <== I added a semicolon here
T *configOnOff(int paramId, float defaultValue, std::string name)
{
return configSwitch<T>(paramId, 0, 1, defaultValue, name, {"Off", "On"});
}
Here’s the error:
src/Common/components/VoxglitchSwitches.hpp:11:3: error: 'T' does not name a type
11 | T *configOnOff(int paramId, float defaultValue, std::string name)
| ^
Thanks!
That semicolon is wrong. Don’t add it.
but also this doesn’t belong in the switch; it belongs in the module.
I added this to the base class of all my modules.
Ah, got it. I have it working.