Cabbage Logo
Back to Cabbage Site

Simple logic puzzle with radioGroup

I have three buttons: clear, record, and play. I want the three to act as a radio group in that they are all exclusive. The additional feature that I want is that if record is clicked a second time, then I want to switch to play.

I had assumed that a second click of record would send a trigger that I could use, but maybe that isn’t the case?

Any clever ways to handle this?

Thank you!

It won’t send a trigger because the value won’t have changed within the large group. Might be best to construct your own group, that will give you the most options?

Ok. Is there a group attribute that buttons can share?

No, I’m talking about building up a radioGroup from the ground up. I think I posted something here a while back. Let me look…

I couldn’t find that example I mentioned earlier, although I’m sure I implemented a radiogroup from scratch at one point. Here is some code that might help. I’m using radioGroup() on each button, but the middle button has latched(0) set. So it will actually trigger each time it’s pressed.

<Cabbage>
form caption("queue"), size(500, 240), guiMode("queue"), colour(20,20,20)
button bounds(60, 48, 80, 40) channel("button1"), text("Clear"), colour:1(0, 200, 0), value(1), radioGroup(1)
button bounds(150, 48, 80, 40) channel("button2"), items("Record"), radioGroup(1), latched(0)
button bounds(240, 48, 80, 40) channel("button3"), text("Play"), colour:1(0, 200, 0), radioGroup(1)
</Cabbage>          
<CsoundSynthesizer>  
<CsOptions>                                                     
-dm0 -n
</CsOptions>                  
<CsInstruments>
; sr set by host
ksmps        =        16
nchnls       =        2
0dbfs        =        1


instr    1
    k1, kTrig1 cabbageGetValue "button1"
    k2, kTrig2 cabbageGetValue  "button2"
    k3, kTrig3 cabbageGetValue  "button3"
    kClicked init 0

    if kTrig3+kTrig1 > 0 then
        cabbageSet 1, "button2", "colour:0(0, 0, 0)"
        kClicked = 0
    endif
    
    if changed:k(k2) == 1 then
        if kClicked == 1 then
            cabbageSet 1, "button2", "colour:0(0, 200, 0)"
        elseif kClicked == 3 then
            cabbageSetValue "button3", 1, 1
            cabbageSet 1, "button2", "colour:0(0, 0, 0)"
            kClicked = -1
        endif
        kClicked += 1
    endif    

endin

</CsInstruments>
<CsScore>
i 1 0 z
</CsScore>  
</CsoundSynthesizer>

“changed:k(k2)” is new to me.

I do wonder if I could just use a trigger with an unlatched button. Hmm.

There is definitely more than one way to skin a Cabbage as they say :rofl:

Now if I could just get it to look right. Having to trick the unlatched button so that it looks latched is proving annoying.

Is there a notion of “button press” and “button release” in Cabbage?

I’m assuming not, but maybe I just missed it. Thanks!

I got my transport working, but it would have been simpler if there were a “trig on click” and a “trig on release.”

If you set latched to 0 you will get a 1 for push, and a 0 for release. Or is it latched(1), I never can remember :joy:

Definitely not latched(0), which sends on both press and release. I’ll try latched(1).

Why won’t a regular button work?

I’m trying to remember. I think there was one behavior that I needed that wasn’t going to get a signal. But I’m really not sure what it was.