Cabbage Logo
Back to Cabbage Site

Trigger and keep Csound rendering without a collider

Hi guys,

A group of us is trying to develop a VR game in Unity with Csound. We basically want to control the parameters in Csound through gestures, but we cannot find a way to turn on Csound and keep it running rather than keep updating the “on” values that makes Csound stuck at turning on infinitely (which just results in glitching). We were only able to collide an object that triggers Csound once or call an event from the score. Has anyone found a way to turn on and keep Csound running as a real-time instrument so that we can allow the players to control the other parameters at the same time?

Thanks a lot and we would really appreciate it if someone could help and support :smiley:

All the best,
Chen Liu.

First thing I would check is how many activations of Csound you are sending with the gestures. There’s the chance that those calls are happening several times in a row, which will surely result in some glitching. Just use a bool to check if you already tried to start Csound.

If you need to turn on a Csound instance at a specific moment, I suggest you to wait for it to be initialized before sending events.
You have a IsInitialized property (http://rorywalsh.github.io/CsoundUnity/html/class_csound_unity.html#ae2c648d0f6245fb84c5f9ec5176079ff)
or you can subscribe to the event OnCsoundInitialized (http://rorywalsh.github.io/CsoundUnity/html/class_csound_unity.html#a066fb6573f60c343aebb79f7a202cac5).
You can find some examples of how to use those here:
https://rorywalsh.github.io/CsoundUnity/#/controlling_csound_from_unity

You can also check if the PerformanceFinished bool (http://rorywalsh.github.io/CsoundUnity/html/class_csound_unity.html#ace353e383daabe78e1648989319d2121) is true. If it is, it means that no instrument in your Csd is running, so Csound stopped its performance and needs to be restarted. This is something that you shouldn’t be doing. Instead, I suggest you to add this line in the score:

f0 z

this will keep the Csound performance running indefinitely.

If you need to start/stop instruments at specific moments, you can use SendScoreEvent
http://rorywalsh.github.io/CsoundUnity/html/class_csound_unity.html#a67eb0ef59ebe2b06a17cbfe362d03122 in the form: "“i instrNumber start duration
if you send a negative instrument number the instrument will stop.

[Edit]: So for example when using colliders, you can send a “i 1 0 -1” event in the OnCollisionEnter method, and a “i -1 0 -1” event in the OnCollisionExit method. When a duration of “-1” is specified, the instrument keep running indefinitely. The duration can be any value when deactivating the instrument with the other string. Please notice that you can easily stop instruments with events only if they are named with a number (so sending the event with the negative instr number).

I hope I answered some of your doubts. If not, feel free to add more details so that I can help you more :smiley:

1 Like

Yes, as @giovannibedetti points out, you can just start your instrument when the game loads. Then instead of sending score statements on each collision, just use SetChannel() to update the instrument’s parameters in real time.

1 Like