Hi,
I’d like to have a slider (rslider) that can be set to different resolution, depending on selecting in another widget. For example to have a combobox with items “1/2”, “1/3”, “1/4”, “1/5” and so on. If I select 1/2, the rslider should snap to multiples of 0.5, if I select 1/3 it should snap to multiples of 1/3.
I can do this by processing the values that come out of the rslider, but it is confusing for the user that the rslider still can reach all of those unquantized values.
I tried to use CabbageSetValue to write the quantized values back to the GUI, but it seems it will not update. I am guessing that it is not updated beecause I am still holding it with the mouse, which makes sense, …but also prevents me from displaying the quantized value. I’m currently displaying it in another nslider, which works but not as nice and intuitive as I would like it to be.
I wondered about inserting a delay before calling cabbageSetValue, so that my last action when releasing the mouse will be updated in the GUI, but it seems like a bit of a hack, and I figured I’d ask if anyone has a better solution.
Here’s an example of what I’m doing now:
<Cabbage>
form size(200, 100), caption("Quantize test"), pluginId("qtst"), colour(23,38,45), guiMode("queue")
rslider channel("Value"), bounds(5, 5, 70, 70), text("Value"), range(0, 4, 0)
combobox channel("Quantize"), bounds(80, 20, 60, 16), text("off", "1/2", "1/3", "1/4", "1/5", "1/6", "1/7", "1/8", "1/9", "1/10"), value(1)
label bounds(83, 40, 60, 12), text("Quantize"), align("left") channel("label37")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -m0 -+rtmidi=null -M0
</CsOptions>
<CsInstruments>
instr 1
kquantize chnget "Quantize"
iQuantize[] fillarray 1,2,3,4,5,6,7,8,9,10
kquantizeval = iQuantize[kquantize-1]
kvalue chnget "Value"
if kquantizeval > 1 then
kvalue_quantized = floor(kvalue*kquantizeval)/kquantizeval
else
kvalue_quantized = kvalue
endif
printk2 kvalue_quantized
cabbageSetValue "Value", kvalue_quantized, changed(kvalue_quantized)
endin
</CsInstruments>
<CsScore>
i1 0 86400 ; gui handling
</CsScore>
</CsoundSynthesizer>