Overriding the randomize behavior

Hello! I’m hoping to completely override the randomize feature [CTRL-r] in my module. A similar discussion was posted here, and @Coirt suggested that it’s possible to achieve this with code similar to:

void randomize() override {}

Here’s my situation: I’ve received a request from @secretcinema to change how randomization works in Digital Sequencer. Digital Sequencer has custom controls on the front panel for setting the CV sequence and gate sequence. I’d like to only randomize those two features using custom code. Parameters, such as sequence length, should be left alone.

When I add:

void onRandomize() override 
    for(int sequencer_number=0; sequencer_number<NUMBER_OF_SEQUENCERS; sequencer_number++)
      for(int i=0; i<MAX_SEQUENCER_STEPS; i++)

The code above works to an extent. It randomizes what I need, but it doesn’t stop everything else from randomizing as well.

Any suggestions? Thanks!

I’m pretty sure there is no way to do exactly what you want. Once again, looking at the Rack source code easily shows why:

void ModuleWidget::randomizeAction() {

	// history::ModuleChange
	history::ModuleChange* h = new history::ModuleChange;
	h->name = "randomize module";
	h->moduleId = module->id;
	h->oldModuleJ = toJson();

	for (ParamWidget* param : params) {

	h->newModuleJ = toJson();

You can’t override this function, it is what gets called when you select randomize. The only way to do what you want (I think) is to have all the controls that you DON’T want randomized override ParamWidget::ranodmize(). so each knob, switch, etc that you use will need to implement that function and do nothing.

Ah, now I understand. But there’s still a piece to this puzzle that I don’t know. I’ve always defined my parameters using configParam, like:

configParam(LENGTH_KNOB, 1, MAX_STEPS, MAX_STEPS, "SeqLengthKnob");

How can I override ParamWidget::Randomize? Would I need to create my parameters differently, and if so, is there an example or conversation to show me how to do that?


yes, I think I see the confusion. You don’t do this in configParam, you do it in your module widget consructors, where you add all the widgets like knobs. so it’s like the knobs themselved that need to get the overriden widget.

Unfortunately my code uses too many helpers and has too much legacy baggace to see easily, but:

void CompressorWidget::addControls(CompressorModule *module, std::shared_ptr<IComposite> icomp) {
        //Vec(knobX, knobY + 0 * dy),
        Vec(8, 174),
        module, Comp::ATTACK_PARAM));

If you ignore my baggage, this is in the main constructor for my whole UI widget. You will have your own ModuleWidget::addParam() calls, and you will be using some class of widget (in my case it’s a Blue30Knob).

So in my case I would make a new widget:

class KnobNoRandom : public Blue30Knob {
    void randomize() override {} // do nothing. base class would actually randomize

then use that widget when I’m making my module widget / UI.


Thanks, that explained it perfectly! I got it working. :slight_smile:


It’s such a pleasure to see how everyone is collaborating and helping each other out. Cheers!!