Opcodes
cabbageSet
This opcode sets a widget property, i.e,colour.fill, visible, opacity, etc. It can run at init-time or k-time. The k-time variant must use a trigger to initiate the update (see below).
Syntax
Section titled “Syntax”cabbageSet:i(SChannel, SProperty, iValue)cabbageSet:i(SChannel, SProperty, iValue[])cabbageSet:i(SChannel, SProperty, SValue)cabbageSet:k(kTrig, SChannel, SProperty, SValue)cabbageSet:k(kTrig, SChannel, SProperty, kValue)cabbageSet:k(kTrig, SChannel, SProperty, kValue[])Initialization
Section titled “Initialization”- SChannel – the name of the channel to query
- SProperty - the property you wish to update. If the property is part of a JSON object, such as
"bounds:{"left":0}you can use dot notation, i.e., “bounds.left” - iValue / iValue[] - a value to set the widget property to
Performance
Section titled “Performance”- kValue / kValue[] - a value to set the widget property to
- SValue - a string value to set the widget property to
- kTrig - used to trigger updates at k-rate
The k-rate variant of cabbageSet must use a k-rate trigger to initiate updates. This is to prevent the UI from being saturated with changes. If you need continuous updates, use a metro() opcode, for example: cabbageSet metro(5) …
However, even when sending frequent updates, such as 20 changes per second, the frontend may only process a subset of them. This is because the UI runs at a much slower frame rate than the audio thread.
Example
Section titled “Example”<Cabbage>{ "pluginId" : "def1", "enableDevTools": true, "channelConfig" : [ {"name": "0 in 2 out", "ins": "0", "outs": "2"} ], "widgets" : [ { "type": "form", "caption": "GetSet Opcodes", "size": {"height": 500, "width": 580} }, { "type" : "rotarySlider", "channel": "gain", "bounds" : {"left": 150, "top": 10, "width": 100, "height": 100}, "range" : {"min": 0, "max": 2, "defaultValue": 1, "skew": 1, "increment": 0.1}, "text" : "Gain" }, { "type" : "button", "channel": "button1", "bounds" : {"left": 0, "top": 10, "width": 100, "height": 30}, "colour" : { "on" : { "fill": [255, 0, 0] }, "off": { "fill": "#0000ff" } }, "text" : {"on": "I am on", "off": "I am off"} }, { "type" : "textEditor", "bounds" : {"left": 17, "top": 169, "width": 341, "height": 40}, "channel" : "infoText", "readOnly" : 1, "wrap" : 1, "scrollbars": 1, "text" : "This instrument shows an example..." }, { "type" : "comboBox", "bounds" : {"left": 200, "top": 200, "width": 100, "height": 30}, "channels": [ {"id": "combo1", "event": "valueChanged", "range": {}} ], "items" : ["One", "Two", "Three"] } ]}
</Cabbage><CsoundSynthesizer><CsOptions>-dm0 -n -+rtmidi=NULL -M0 --midi-key=4 --midi-velocity=5</CsOptions><CsInstruments>; sr set by hostksmps = 64nchnls = 20dbfs = 1
/*Test various string variants of cabbageSet opcodes.These opcodes provide an interface to widget properties.*/instr TestStringSetOpcodes switch:k = metro(10) if p4 == 0 then cabbageSet("button1", "text.off", "p4 is 0") elseif p4 == 1 then cabbageSet("button1", "text.off", "p4 is 1") elseif p4 == 2 then cabbageSet("infoText", "text", "p4 is 2") elseif p4 == 3 then cabbageSet("infoText", sprintf({{"text":"%s"}}, "p4 is 3")) elseif p4 == 4 then cabbageSet(switch, "infoText", "text", "p4 is 4") elseif p4 == 5 then cabbageSet(switch, "infoText", sprintf({{"text":"%s"}}, "p4 is 5")) elseif p4 == 6 then cabbageSet("button1", "colour.off.fill", "#00ff00") endifendin
/*Test various MYFLT variants of cabbageSet opcodes.These opcodes provide an interface to widget properties.*/instr TestMYFLTSetOpcodes switch:k = metro(10) toggle:k = (oscili:k(1, 2) > 0 ? 1 : 0) if p4 == 0 then cabbageSet(switch, "gain", "bounds.left", abs(randi:k(400, 10))) elseif p4 == 1 then cabbageSet(switch, "gain", "visible", toggle:k) elseif p4 == 2 then cabbageSet("gain", "bounds.left", 10) elseif p4 == 3 then cabbageSet("gain", sprintf({{"visible":%d}}, 0)) elseif p4 == 4 then cabbageSet("gain", sprintf({{"visible":%d}}, 1)) endifendin
</CsInstruments><CsScore>i"TestStringSetOpcodes" 0 1 0i"TestStringSetOpcodes" + 1 1i"TestStringSetOpcodes" + 1 2i"TestStringSetOpcodes" + 1 3i"TestStringSetOpcodes" + 1 4i"TestStringSetOpcodes" + 1 5i"TestStringSetOpcodes" + 1 6f0 z</CsScore></CsoundSynthesizer>