Hi, I’ve recently discovered cabbage and I have been creating a synth. I’m loving how easy it is but I came across a strange issue when trying to use cabbageSetStateValue to save some data across DAW sessions. Basically, I can only get cabbageSetStateValue to work if used in the main instrument (which only executes when a note plays). If I try to use the opcode in another instrument to save some data at some other point (e.g. when a button is pressed or upon opening the synth) it doesn’t seem to work. I’m using cabbage 2.8.0, Windows 10, and trying to use the Synth in Bitwig 2.2.2.
I managed to write a simple script that reproduces the issue without the rest of the synth stuff:
<Cabbage>
form caption("Untitled") size(400, 300), guiMode("queue"), pluginId("def1")
keyboard bounds(8, 5, 381, 95)
csoundoutput bounds(5, 120, 390, 170) fontSize(16), scrollbars(1), wrap(1), fontColour("black"), colour("tan")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; Initialize the global variables.
ksmps = 32
nchnls = 2
0dbfs = 1
;instrument will be triggered by keyboard widget
instr 1
kEnv madsr .1, .2, .6, .4
aOut vco2 p5, p4
outs aOut*kEnv, aOut*kEnv
endin
instr 2
prints "reading data:\n"
prints cabbageReadStateData()
kNoSmps init 0
if kNoSmps == 0 then
event "i", "SaveData", 0, 0
endif
kNoSmps += 1
endin
instr SaveData
cabbageSetStateValue "Data", "SomeSavedData"
prints "data just written:\n"
prints cabbageReadStateData()
endin
</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
i2 0 z
</CsScore>
</CsoundSynthesizer>
When you first open the synth within a DAW instrument 2 simply prints all saved data, saves some data and then prints all saved data again. To reproduce the issue, first export the above script as a VST and load it into a DAW. You should see from the csoundoutput widget that the synth attempts to print all saved data using cabbageReadStateData and outputs a “No Data…” message since this is the first time the synth is opened. Then on the first k cycle it saves some data using cabbageSetStateValue and then prints all saved data successfully in the csoundoutput. Now save the session, close the DAW and reopen the DAW session and synth. Since the synth’s first job is to print all saved data, I would expect it to print the saved data from the previous session. But instead, I get the “No Data…” message again at the start. If I move the code from instrument 2 into instrument 1 then the saved data is printed successfully before and after the data is saved, but only when a note is received.
It seems counterintuitive to only enable state saving/loading logic to execute whilst playing audio so this seems like a bug to me. But I am new so perhaps I’m simply misunderstanding how to use cabbageSetStateValue or csound/cabbage generally. Any ideas?