Cabbage Logo
Back to Cabbage Site

CsoundUnity Mixer Plugin

I think the Csound score can be of use here. If you set your instruments up to work with p-fields you can achieve a quick way of triggering instruments in particular states. Look at the following instruments:

instr 1
kPartials = 0
if chnget:k("trigger")==1 then
	if metro(chnget:k("speed"))==1 then
		event "i", "BellSound", 0, chnget:k("duration"), chnget:k("modIndex"), chnget:k("crossFade")

It triggers the sound of a bell using score statements, and all the p-fields can be updated in real-time. The p-fields in this case are all controlled by sliders that the artists can tweak. If the sound designer finds a sound they like they could then save that sound, as a score statement, to a simple text file. It could then be recalled at the push of a button.

Saving real-time slider data could also be implemented. I remember Matt Ingalls showing me an instrument that wrote k values to a file. They could then be recalled later. I actually wrote my own version of a while after. I must see if I could find it. The nice thing is these presets could be triggered from a button in the CsundUnity inspector. And it could all be done on the Csound side without having to write any C# code.

I just found this Csound UDO I wrote many years ago that will write k values to file and read them back later. This could easily be adapted for use here. The code below is a standard Csound file, but I could easily modify it for use Cabbage.

-odevaudio -b10 -idevaudio
sr = 44100  
ksmps = 64
nchnls = 1

opcode dataRW, k, Ski  
Sname, kvalue, iRW   xin
kout init 0
       if (iRW==0) then     
              dumpk  kvalue, Sname, 8, 0
              kout = kvalue
              kres readk Sname, 8, 0              
              kout = kres       
       xout kout                  

instr 1
kline init 0
kline line 0, p3, p3
k1 init 0
if(kline < 5) then
k1 dataRW "test2.txt", kline, 0
printks "writing: %f\n", 0, k1
elseif(kline > 7 && kline < 13) then  
k1 dataRW "test2.txt", 1, 1
printks "reading: %f\n", 0, k1
printk 1, 9999999

f1 0 1024 10 1
i1 0 25   

Thanks! I’ll dig into this.

i think that a text file with the info is the way go whether you go with sending to Csound directly or to Unity and then Csound. i prefer the latter approach if you have on screen controls that should inform the user that something’s changed, even if it’s just a preset dot, but especially if it’s an array of configurable controls. then make any changes to your onscreen controls automatically update the Csound script. this way you can have the read settings from the text file update it, say when first loading, but afterwards it can be tweaked onscreen by the same method. any state update would update Csound, and then the state of those controls can be serialized and stored via a Save button onscreen.

I’ll try to prepare a Csound driven way of doing it and we can see if it is worth pursuing.