Viewbuilder Components And Decimals


Is there a good way to limit the amount of decimals for the value returned by for example a vb:slider.

I realize I can do some handling in the notifier function, but then the binding is pretty useless if I have to do the handling manually anyway.

Consider this:

vb:slider {  
 id = "slider_dco1_lfo_mod_depth",  
 min = 0,  
 max = 127,  
 value = 64,  
 width = 170,  
 bind = instrument.dco1_lfo_mod_depth,  
 notifier = function(value)  
 send_sysex(sysex_dco1_lfo_mod_depth, value)  
 bind = instrument.dco1_lfo_mod_depth  

So, the value from the slider is to be sent via sysex, and it it also bound to a variable in a document object (“instrument”).

But I want the value to be without decimals, both the value that is sent via sysex, the value stored in the document, and the value displayed by the vb:value.

Is there a good way to do this?


Since you’re dealing with MIDI/SysEx and you’re only interested in sending a whole integer value…

You can simply round the value down using math.floor():

send_sysex(sysex_dco1_lfo_mod_depth, math.floor(value))  

If you prefer to round up instead of down, you can use math.ceil()

If you prefer to round up or down depending on the value, Lua does not have a native function for this, but you can roll your own quite easily:

function round(value)  
 return math.floor(value + 0.5)  

round(1.4999) will return 1
round(1.5) will return 2

You can obviously tweak the function, depending on the particular type of rounding you prefer to have.

Hope some of this helps.

I’m not at home with Renoise but I know I did something to bind my Lines slider to show and output values with no decimals, or at least I think I remember doing so. Maybe not to the full extent you want but it’s only a small tool so maybe have a look see if you can pull out something useful.

I have to say that GUI in general, especially syncing sliders, value boxes and parameters, has been my biggest struggle with the API so far.

Thanks guys!

What I’m trying to do is a tool for editing parameters in a synth. So I have the idea to store the instruments you create in a document, so that you can exchange sounds with others.

So I thought it would be nice if the variables stored were the actual value displayed in the interface and the value send by sysex, ie

60 not 60.234234234

But, if i let that demand go, I could add an observable to each document variable, and when it is changed I send sysex from that notifier (instead of the ui notifier), that way, when you load a document (instrument) all the parameters are automatically sent to the synth.

And if I add the same rounding to the vb:value field then I’m home I think.

Thanks, I think you helped me move on…