Cabbage Logo
Back to Cabbage Site

CabbageSet vs chnset

Hello! For now I’m still using Cabbage 2; when I have time, I’ll go back to trying Cabbage 3.
I’d like to ask something about cabbageSet and chnset. I did some tests based on examples to visualize a table in gentable being modified in real-time (something I plan to use with an envelope).
With cabbageSet I saw that it can be done, but it becomes unstable (based on the “Gentable Example”) and always ends up crashing. I found Iain McCurdy’s “GEN07” example where chnset is used. I did a test with chnset and it didn’t crash, but then I discovered that combining it with tablecopy works smoothly without crashes.Is there any way to do the same with cabbageSet and achieve the same stability?
It seems that the problem is the high update rate. At one point I tried to reduce it with a metro:

if (kChanged == 1 && kMetro == 1) then…

…but it became very slow and missed some updates.
I’m asking if it’s possible to do something similar in a correct way with cabbageSet, because using chnset implies not using guiMode(“queue”), which means cabbageSet and cabbageGet cannot coexist with chnset, and I have several useful things that I do with them.

Here’s the small test code — everything runs smoothly here with chnset:

form caption("Untitled") size(400, 500), colour (0,0,0) gentable bounds( 15, 30, 225, 120), tableNumber(1), tableColour("blue"), tableBackgroundColour("black"), tableGridColour(230,230,230,50), identChannel("table"), ampRange(0,1,1), zoom(-1), active(1) keyboard bounds(10, 334, 381, 95) rslider bounds(42, 226, 60, 60) identChannel("value") range(1, 1024, 1024, 1, 1) valueTextBox(1) channel("rslider6") -n -d -+rtmidi=NULL -M0 --midi-key-cps=4 --midi-velocity-amp=5 -m0d ; Initialize the global variables. ksmps = 32 nchnls = 2 0dbfs = 1

gkValue init 1024

instr 1

kEnv madsr .1, .2, .6, .4

aOut oscili p5, p4, 1

outs aOut0.5kEnv, aOut0.5kEnv
endin

instr Update

gkValue chnget “rslider6”
kChanged changed gkValue

if (kChanged ==1) then
tablecopy 1, 2
chnset    "tableNumber(1)", "table"    ; update table display
reinit    UPDATE
endif

UPDATE:
i2 ftgen 2, 0, 1024, 7, 0, i(gkValue), 1
rireturn

endin
;------------------------------------

f 1 0 1024 7 0 1024 1 i "Update" 0 z f0 z

Hi @Alejo, are you using the latest beta package? This instrument works fine for me here. What version number are you on?

I’m testing with version 2.20.7. There may have been some confusion, since the attached code actually works fine.
More specifically, now I added two code snippets to draw a madsr envelope using a gentable. The version that uses chnset works correctly (I’m happy with the result, and it doesn’t seem to consume many resources).
The cabbageSet, does not work. That said, could it be that chnset is somehow better suited—or perhaps faster—for this kind of task that requires constant updates?

gentable envelope cabbageSet (MADSR).csd (3.1 KB) gentable envelope chnset (MADSR ok).csd (3.0 KB)

Interesting. The older chnset system will work well so long as you didn’t have a lot of widgets. If it works well this way I’d stick with it.

Yes. I saw that everything I was doing with cabbageSet I can do with chnset maybe with a little more work but possible. Things like alpha knobs at 0.5 when not in use, hiding knobs, loading audio files, etc. And I think in that case it’s better to use identChannel only on the widgets where it’s necessary