Cabbage Logo
Back to Cabbage Site

Strange behaviour of groupbox

Hello Rory,

I am struggling with the behaviour of widget inside groupbox when the group box property is changed from visible(0) to visible(1).

When the state of the group box is changed, the children state is also changed… which is strange. Once would expect the children widget to remain within their previous state. (I must say I spent hours today to understand why my synth was resetting the GEN table when I was switching between groupboxes)
Is this a bug or a feature ?
Here is an ugly demo showing that.

<Cabbage> 
form caption("Untitled") size(400, 300), colour(58, 110, 182), pluginID("def1")

groupbox bounds(40, 18, 100, 100) { 
button bounds(0, 20, 80, 20) channel("but0") value(1) text("Push me", "Push me") colour:1(51, 214, 13, 255) colour:0(161, 17, 17, 255) radiogroup(1) 
button bounds(0, 50, 80, 20) channel("but1") text("Push me", "Push me") colour:1(51, 214, 13, 255) colour:0(161, 17, 17, 255) radiogroup(1) 
 }
 
 groupbox bounds(140, 40, 100, 100) identchannel("gb1") visible(1) { 
 checkbox bounds(0, 20, 20, 20) channel("chk0")value(1) radiogroup(2) 
 checkbox bounds(40, 20, 20, 20) channel("chk1") radiogroup(2) 
 }
 
keyboard bounds(8, 158, 381, 95) mouseoeverkeycolour(255, 255, 0, 128) 
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1


instr 2 

k_active active "chk_change"
if changed:k(chnget:k("but0"))==1 then 
    if chnget:k("but0")==1 then
        chnset "visible(1)", "gb1"
        if k_active=0 then 
            event "i","chk_change",0,-3600
        endif
     else
        turnoff2 "chk_change",0,0 
        chnset "visible(0)", "gb1"  
    endif
endif

endin 

instr chk_change

 k_Changed = changed:k(chnget:k( "chk0"))
 printk2 k_Changed

endin


;instrument will be triggered by keyboard widget
instr 1
kEnv madsr .1, .2, .6, .4
aOut vco2 p5, p4
outs aOut*kEnv, aOut*kEnv
endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
i 2 0 z 
</CsScore>
</CsoundSynthesizer>

In the parent child hierarchy, if a parent is not visible its children won’t be either. I’ll try your code tomorrow when I’m back at my PC.

I think this has to do with the init phase of Csound.
I desperately look for a way to skip the init pass of an instrument… but I don’t see how.

I’m just trying this code now. When I make the groupbox on the right invisible, all its children become invisible too. This behaviour is expected. Parents own their children. When they become invisible, so do their children.

Sorry, I was not clear.
My struggle was about the init phase and the state of the children widgets.
Any time a groupbox is hidden and then brought back to visible, then the children widget state is “changed” in my example… This was puzzling me as the chexbox state ( being checked or not) does not change within a cycle visible->invisible->visible so I was wondering why does the state of the checkbox change ?

But in fact, my mistake was (I think) : when turning an instrument on / off, then “on” again, there is an init phase as soon the instrument is turned on … therefore, the state of all widget changes.

Hope I am clear … (difficult to explain)

I’m not seeing this. If I turn on a checkbox, it stays on no matter how many times I toggle the visibility of the parent groupbox?