Here’s an example of how to write the contents of an array to a state variable, and load it when next you launch your session. This may need to be manually loaded after your session loads, but it’s very simple and you can save any data you like:
<Cabbage>
form caption("State Save") size(370, 380), guiMode("queue") pluginId("MPre")
button bounds(210, 8, 109, 27) channel("writeState"), text("Update Text")
button bounds(10, 8, 115, 30) channel("loadState"), text("Load state")
csoundoutput bounds(12, 48, 355, 319) channel("csoundoutput10002")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d
</CsOptions>
<CsInstruments>
; Initialize the global variables.
;sr is set by the host
ksmps = 32
nchnls = 2
0dbfs = 1
instr 1
kStateWrite, kStateWriteTrig cabbageGetValue "writeState"
if(kStateWriteTrig) == 1 then
event "i", 2, 0, 0.1
endif
kStateLoad, kStateLoadTrig cabbageGetValue "loadState"
if(kStateLoadTrig) == 1 then
event "i", 3, 0, 0.1
endif
endin
instr 2
SArr[] init 16
SString init ""
iIndex = 0
while iIndex < 16 do
SArr[iIndex] = random:i(0, 100)
SString strcat SString, SArr[iIndex]
iIndex += 1
od
printarray SArr
cabbageSetStateValue "stringOfNumbers", SArr
endin
instr 3
prints "Reading data"
SData[] cabbageGetStateValue "stringOfNumbers"
printarray SData
endin
</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
i1 0 z
</CsScore>
</CsoundSynthesizer>
p.s. I’m not sure why I used a string array here, numbers would have been simpler…