i’m trying to use cabbageGetStateValue
and cabbageSetStateValue` to save the value of stuff in the DAW without needing to keep track of a JSON file (which is the downside of the opcodes that save all widget channel values).
But it seems my build of Cabbage, which is your latest dev build, doesn’t have these opcodes.
I copied your code verbatim (except I had to add guiMode("queue")
to the form)
<Cabbage>
form caption("State example") size(400, 300), colour(60, 60, 60), guiMode("queue"), pluginId("def1")
rslider bounds(14, 14, 100, 100), channel("sliderValue"), range(0, 1, 0.5, 1, 0.01), text("SliderValue"), trackerColour(0, 255, 0, 255), outlineColour(0, 0, 0, 50), textColour(0, 0, 0, 255)
button bounds(122, 16, 120, 40), channel("showData"), text("Print State Data")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d
</CsOptions>
<CsInstruments>
; Initialize the global variables.
ksmps = 32
nchnls = 2
0dbfs = 1
instr 1
a1 oscili 1, 200
outs a1, a1
endin
instr 2
kSlider chnget "sliderValue"
if changed2(kSlider) == 1 then
event "i", "SetFloatValue", 0, 0
endif
if changed:k(chnget:k("showData")) == 1 then
event "i", "ShowData", 0, 0
endif
endin
instr UpdateData
iRes cabbageWriteStateData 1, "{\"happy\": true, \"pi\": 1.141, \"test\": \"hello\", \"list\":[1, 0, 2, 3, 4, 5, 2, 3, 6],\"stringList\":[\"hi\", \"who\", \"goes\", \"there\"]"
if iRes == -1 then
prints "Couldn't write JSON data"
endif
if iRes == -1 then
prints "Couldn't write JSON data"
endif
endin
instr ShowData
prints cabbageReadStateData()
endin
instr GetFloatValue
kVal cabbageGetStateValue "pi"
printk2 kVal
endin
instr GetFloatArrayValue
kVal[] cabbageGetStateValue "list"
printarray kVal, 1, "%d"
endin
instr GetStringValue
SVal cabbageGetStateValue "test"
prints SVal
endin
instr GetStringArrayValue
SVal[] cabbageGetStateValue "stringList"
printarray SVal, 1, "%s"
endin
instr SetFloatValue
iRes cabbageSetStateValue "pi", chnget:i("sliderValue")
endin
instr SetFloatArrayValue
kArr[] fillarray 1, 2, 3, 4
kRes cabbageSetStateValue "list", kArr
endin
instr SetStringArrayValue
SArr[] fillarray "1", "2", "3", "4"
kRes cabbageSetStateValue "stringList", SArr
endin
</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
i2 0 z
;starts instrument 1 and runs it for a week
;i"WriteData" 0 1
;i"ShowData" + 1
i"UpdateData" 0 1
;i"ShowData" 2 1
;i"GetFloatValue" 3 1
;i"GetFloatArrayValue" 4 1
;i"GetStringValue" 5 1
;i"GetStringArrayValue" 6 1
;i"SetFloatValue" 2 1
i"SetStringArrayValue" 1 1
i"ShowData" 3 1
i"GetStringArrayValue" 4 1
</CsScore>
</CsoundSynthesizer>
And when I hit save I get this in the console:
STARTING FILE
Creating options
Creating orchestra
closing tag
Creating score
rtaudio: PortAudio module enabled ...
using callback interface
error: syntax error, unexpected T_OPCODE0 (token "cabbageWriteStateData") from file FILEPATH (1)
line 36:
>>> iRes cabbageWriteStateData <<<
Unexpected untyped word iRes when expecting a variable
Parsing failed due to invalid input!
Stopping on parser failure
cannot compile orchestra
I don’t know if this is related, but I also think that after installing your latest build (and I always have the installer install Csound when I do this), I lost a few opcodes, including sterrain
. It’s not there when I check csound -z
and I know I had it working in a project I was working on right before installing your dev build. (I installed your dev build recently for the new MIDI opcodes).
I think there was another opcode I noticed was oddly missing from my Csound too, I can’t remember what it is now. Why would installing Cabbage with Csound delete opcodes from Csound?