How to [easily] snap knob to integer values

I have a param which I configure as below

configParam(PARAM_ID, -5.0f, 5.0f, 0.0f, “Octave”);

This mostly works. I spin the associated knob and the tooltip shows decimal values between -5 and 5. But I want the values to just be integers. Source for other modules seems like they are doing exactly the same thing (no derived ParamQuantity, no [sg]etDisplayValue) and “it just works”. But I get the decimal values. How do I get it to display (and return) just integers.

I am using 2.0.6.

What about this?

configParam(PARAM_ID, -5.0f, 5.0f, 0.0f, “Octave”);
paramQuantities[PARAM_ID]->snapEnabled = true;

params are floats, to make them be polymorphic would be a huge undertaking, and one I don’t think would be that compelling.

Yup. Just found that myself. I found that the source I was looking at was using custom knobs and was doing the snap there. snapEnabled does the trick.

oh, that’s probably what OP was looking for. Yeah, we all do that.

I have to confess that I have derived my own knob just to set the snap in the constructor, just like those custom ones. Not exactly difficult, but setting snap enabled seems like a more direct (smarter) way.

1 Like

Depending on your religion, the constructor seems more “object oriented” than directly accessing the public attributes on the param quantities. Burying it in the constructor also makes your mainline code prettier :slight_smile:

1 Like

haha, yes the old “what is object oriented”. I think now has been replaced by “are these unit tests or integration tests”? I have to say the VCV “style” is very far from my “style”, but I like it - it makes it easy to do things. For example, VCV never uses the keyword class and all members tend to be public. Having everything public enables things you would not otherwise be able to to. Of course they won’t all necessary work, but at least you can try it.