Updating a few csds to CsoundUnity

Heads up for anyone porting Cabbage .csd patches to CsoundUnity.

I’ve been adapting some of Iain McCurdy’s examples (River, Electricity, etc.) and ran into two issues that took me a while to debug.

1. Widget defaults don’t initialize channels in CsoundUnity

In Cabbage, widget defaults from range(...) automatically populate channels.

In CsoundUnity, chnget returns 0 until something explicitly writes to the channel.

This means many patches stay silent until you touch a slider.

Fix: initialize the channels manually with chnset at the top of the instrument:

chnset 1,    "Gulp"
chnset 3,    "GulpLev"
chnset 80,   "GulpPitch"

After Unity starts sending values, those defaults get overridden normally.

2. cabbageSet / cabbageGet won’t compile

CsoundUnity doesn’t include Cabbage-specific opcodes, so anything like:

cabbageSet "IDRiver1", "tableNumber", 1

needs to be removed or handled from the Unity side.

In my case these were only updating graphics widgets, so deleting them was fine.

Also: keep the <Cabbage> block. CsoundUnity uses it to auto-generate inspector sliders.

After those two fixes, River worked perfectly in Unity with full inspector control.

Happy to share the converted .csd if useful.

2 Likes

Hey Mateo! Great to hear from you, it’s been a while!
Really glad to see you’re back working with CsoundUnity!

Thanks for the writeup, useful stuff. Quick one on point 1, which version are you on?
We reworked channel init in 4.0.0, defaults should be set at startup now.
Btw channel defaults should actually be set at startup even in 3.5.2, so something else might be going on.
Maybe you could try and see if on the release_4_0_0 branch the defaults are working as expected.
You can add it directly in Unity via Package Manager → Add package from git URL:

https://github.com/rorywalsh/CsoundUnity.git#release_4_0_0

We’re getting close to release and more testing is always welcome.
About cabbageSet and cabbageGet, you’re right. I’m considering adding a way to replace them updating the csd once it’s set. Do you have any suggestion on how you would expect that feature to work?

And yes please, share that River patch!
It would be awesome to add a few more samples to the package :raising_hands:

1 Like