Cabbage Logo
Back to Cabbage Site

cabbageSet

Hi Rory,

Is there a way to make the following code shorter / more efficient?

if kBank == 1 then
            cabbageSet kBankTrig, "Key1B1", "visible(1)"
            cabbageSet kBankTrig, "Key2B1", "visible(1)"
            cabbageSet kBankTrig, "Key3B1", "visible(1)"
            cabbageSet kBankTrig, "Key4B1", "visible(1)"
            cabbageSet kBankTrig, "Key5B1", "visible(1)"
            cabbageSet kBankTrig, "Key6B1", "visible(1)"
            cabbageSet kBankTrig, "Key7B1", "visible(1)"
            cabbageSet kBankTrig, "Key8B1", "visible(1)"
            cabbageSet kBankTrig, "Key9B1", "visible(1)"
            cabbageSet kBankTrig, "Key10B1", "visible(1)"
            cabbageSet kBankTrig, "Key11B1", "visible(1)"
            cabbageSet kBankTrig, "Key12B1", "visible(1)"
        else
            cabbageSet kBankTrig, "Key1B1", "visible(0)"
            cabbageSet kBankTrig, "Key2B1", "visible(0)"
            cabbageSet kBankTrig, "Key3B1", "visible(0)"
            cabbageSet kBankTrig, "Key4B1", "visible(0)"
            cabbageSet kBankTrig, "Key5B1", "visible(0)"
            cabbageSet kBankTrig, "Key6B1", "visible(0)"
            cabbageSet kBankTrig, "Key7B1", "visible(0)"
            cabbageSet kBankTrig, "Key8B1", "visible(0)"
            cabbageSet kBankTrig, "Key9B1", "visible(0)"
            cabbageSet kBankTrig, "Key10B1", "visible(0)"
            cabbageSet kBankTrig, "Key11B1", "visible(0)"
            cabbageSet kBankTrig, "Key12B1", "visible(0)"
        endif

I tried inserting it into a while / do loop but it wouln´t work…

if kBank == 1 then
    iCount init 1
    while iCount < 13 do
        SChannel "Key%dB1", iCount
        cabbageSet kBankTrig, SChannel, "visible(1)"
        iCount += 1
    od
    // repeat process for "visible(0)
endif

I´m hoping to add a number of `12 Widget´ sets (x 8 banks) to my GUI and I´m afraid my code will get kinda long unnecessarily?

[EDIT1] Another related question: should I use toFront() instead? Is there CPU considerations if a widget is not visible Vs. in the background (i.e. not being used)?

Thanks for your time!!

There are a few ways to go with this, but the simplest is probably to put them all in a group and then just toggle the visibility of that :thinking:

Mm, I tried using groupbox with the example given in the docs, but setting it to visible(0) didn´t work for me…

groupbox bounds(10, 10, 200, 130) channel("group1"), fontColour(0, 0, 0), outlineColour(0, 0, 0), text("ADSR Envelope"),  colour(0, 0, 0, 0), visible(0)
rslider bounds(20, 40, 40, 40), channel("att"), range(0, 1, 0.01, 1, 0.001)
rslider bounds(60, 40, 40, 40), channel("dec"), range(0, 1, 0.4, 1, 0.001)
rslider bounds(100, 40, 40, 40), channel("sus"), range(0, 1, 0.7, 1, 0.001)
rslider bounds(140, 40, 40, 40), channel("rel"), range(0, 1, 0.8, 1, 0.001)

And if I use a plant, I wouln´t know how to incorporate it into my UDO for generating the widgets – I´m using a “while do / cabbageCreate / od” loop to generate [(12 x 8) x n] widgets, if that makes sense? Could I possibly add a line-break with a cabbageCreate instruction? as in…

while do 
    SPlant sprintf "bounds(0, 0, 100, 30), channel(\"MyPlant\"), LINEBREAK, {, INSERT-MORE-CODE-HERE, LINEBREAK, }"
    cabbageCreate "image", SPlant
od

I just don´t see how I could insert another cabbageCreate-loop inside a `sprintf´ definition with the multiple vsliders that I need, if that makes sense?

In that case, I wonder if the better solution would be to just type up all my widgets manually at the top (in the Cabbage section) and inside Csound only call each plant-channel to make it visible or not?

Thanks!

Looks like you’re missing the opening closing curly brackets there? Check out this example: quickTest.csd (1.1 KB)

Use the parent() identifier to specify what widget is the parent for any widgets you create with cabbageCreate. Both of these options should work fine.

1 Like

Ah, just tried it with the parent(), I think that´ll do it! Will keep you posted :wink: Thank you!

1 Like