Cabbage Logo
Back to Cabbage Site

Radiogroup - chnset one button ON doesn't turn other buttons OFF

When I use chnset on a selected button channel (member of a radiogroup) to change button state to 1, the states of other buttons remain unchanged. Shouldn’t other buttons automatically change to 0 when they are members of the same radiogroup?
The radiogroup behaves as expected when clicking on button widgets though.
Please let me know if I’m doing something wrong.

<Cabbage>
form caption("test radiogroup") size(200, 100), pluginid("trg1") style("legacy")

button bounds(80, 8, 50, 40) latched(1) channel("button0") identchannel("button0_ID") text("0") value(1)  radiogroup("group1") corners(3) colour:0(0, 255, 0, 255) colour:1(255, 255, 0, 255) fontcolour:0(0, 0, 0, 255) fontcolour:1(160, 0, 0, 255)
button bounds(134, 8, 50, 40) latched(1) channel("button1") identchannel("button1_ID") text("1") value(0)  radiogroup("group1") corners(3) colour:0(0, 255, 0, 255) colour:1(255, 255, 0, 255) fontcolour:0(0, 0, 0, 255) fontcolour:1(160, 0, 0, 255)
button bounds(80, 52, 50, 40) latched(1) channel("button2") identchannel("button2_ID") text("2") value(0)  radiogroup("group1") corners(3) colour:0(0, 255, 0, 255) colour:1(255, 255, 0, 255) fontcolour:0(0, 0, 0, 255) fontcolour:1(160, 0, 0, 255)
button bounds(134, 52, 50, 40) latched(1) channel("button3") identchannel("button3_ID") text("3") value(0)  radiogroup("group1") corners(3) colour:0(0, 255, 0, 255) colour:1(255, 255, 0, 255) fontcolour:0(0, 0, 0, 255) fontcolour:1(160, 0, 0, 255)

</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -m0d -+rtmidi=NULL 
</CsOptions>
<CsInstruments>

ksmps = 16
nchnls = 2
0dbfs = 1

instr 1

kcnt init 0
if metro(1)==1 then
    ksel = kcnt % 4
    /* 
    chnset k(0), "button0" ; adding this block resolves the problem
    chnset k(0), "button1"
    chnset k(0), "button2"
    chnset k(0), "button3"
    */    
    Ssel sprintfk  "button%d", ksel
    chnset k(1), Ssel 
    kcnt += 1
endif

k0 chnget "button0"
k1 chnget "button1"
k2 chnget "button2"
k3 chnget "button3"

Sout sprintfk "%d, %d, %d, %d \n", k0, k1, k2, k3
printks Sout,1

endin

</CsInstruments>
<CsScore>
f0 z
i 1 0 [3600*24*7]
</CsScore>
</CsoundSynthesizer>

Thanks. It works fine when you manually select the button values, but not when you try to programmatically change them in your code. It’s safe to call this a bug. I’ll add it to the list. :wink: