Cabbage Logo
Back to Cabbage Site

I & K times

Rory gave me a link to a description of i & k times https://flossmanual.csound.com/csound-language/initialization-and-performance-pass , and for the most part, I this I understand how to use them locally within an instrument, but when it comes to globals, I’ve found the need to use these things at both i & k times. So, exactly which rate to declare isn’t immediately obvious to me.

Plus, it isn’t always cut and dry when you can actually perform certain operations. For instance, a global array (giArray) that stores numbers can’t be written at k-rate, but if that same arrays holds function tables, the function table are writable at any time, but you can only assign a new function table to that global array at i-time.

Guess I’m just wondering if there is a basic rules for beginners to follow, and then expand from there.

I always avoid globals. If I need to move data around I between instruments I use channels which are more or less global anyway. And they can be read at both i or k time. Consider this:

instr 1
    printk2 chnget:k("button")
endin

instr 2
    iTest init 1
    chnset iTest, "button"
endin

instr 3
    kTest init 10
    chnset kTest, "button"
endin

We can read and write to the channel “button” at i or k time. On the other hand, once you declare a global it’s fixed at whatever rate you set.

Function tables are rate agnostic. You can read/write to them at i-rate, a-rate or k rate. I guess that’s why I still use them over arrays for many things.

So, just so I understand this… The chnget/set opcodes are just a part of a larger suite of opcodes that for the “channel” system. Those were also what Cabbage used to communicate with the widgets, but Cabbage now uses it’s own means of communicating with widgets. But the whole channel system is intact, it just no longer communicates with widgets.

I’m just trying to wrap my head around this…

Cabbage orchestras retrieve widget values from channels using chnget. The new cabageGet.. opcodes just wrap chnget. You can still use chnget with cabbage widgets to retrieve values but it might be cleaner to use the cabbageGet opcodes.

On the other hand, chnset no longer works for updating widgets when in guiMode(“queue”). This new mode was added because the older mechanism was quite a performance hog. If you wanted to update the value of a slider in older Cabbage you would use
chnset kValue, "mySlider"
Cabbage would then query every single widget on every k-cycle to see if something has changed on its channel. The new cabbageSet.. opcodes just add an update message to a queue, which gets flushed on each k-cycle.

The channel system in Csound is really powerful. I use it all the time regardless of whether or not I’m working with Cabbage.

Another curious question. Is the channel system based on the things that from the zak system? I never really used zak, but in my reading it sounds like it has similar features, except it is still tied to rates.

They are similar, but the channel system can be used to communicate with host applications, whereas Zak cannot.

I’m curious, are those channels one way (host setting values) or can the plugin set these value and the host can pass them on to another process? I just got into this for the audio synthesis, but I’m starting to wonder about other things…