Yes, but because I neglected to add the the option of passing arrays to cabbageSet
it is a little long winded. We also have to write our own IndexOf
UDO for finding the index of a string within an array. Nevertheless, here is an example that lets users populate a combobox with text they type into a texteditor
. It will also give you the correct index whenever the combobox is updated or changed.
<Cabbage>
form caption("Untitled") size(400, 300), guiMode("queue") pluginId("def1")
combobox bounds(26, 74, 143, 20) channel("combo1"), channelType("string") items("AM", "FM", "PM", "LMN"), value("AM")
texteditor bounds(26, 38, 142, 30) channel("texteditor1")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d
</CsOptions>
<CsInstruments>
; Initialize the global variables.
ksmps = 32
nchnls = 2
0dbfs = 1
opcode IndexOf, k,SS[]
SString, SStrings[] xin
kCount = 0
kIndex init 0
kSize = lenarray:k(SStrings)
while kCount < kSize do
if strcmpk(SString, SStrings[kCount]) == 0 then
kIndex = kCount
endif
kCount +=1
od
xout kIndex
endop
instr 1
SNewItem, kNewItemTrig cabbageGetValue "texteditor1"
SCurrentItems[] cabbageGet "combo1", "text"
if kNewItemTrig == 1 then
event "i", "UpdateCombo", 0, 0.01
endif
SCombo, kComboTrig cabbageGetValue "combo1"
printf SCombo, kComboTrig
printarray SCurrentItems, kComboTrig
printk2 IndexOf(SCombo, SCurrentItems)
endin
instr UpdateCombo
SItem cabbageGetValue "texteditor1"
SCurrentItems[] cabbageGet "combo1", "text"
iNewArraySize = lenarray(SCurrentItems)+1
SNewList init "items("
iIndex = 0
while iIndex < iNewArraySize-1 do
SNewList strcat SNewList, strcat("\"", strcat(SCurrentItems[iIndex], "\", "))
iIndex += 1
od
SNewList strcat SNewList, strcat("\"", strcat(SItem, "\")"))
;we only need to do this when the instrument is released...
cabbageSet release(), "combo1", SNewList
cabbageSet release(), "combo1", strcat("value(\"", strcat(SItem, "\")"))
endin
</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
;starts instrument 1 and runs it for a week
i1 0 [60*60*24*7]
</CsScore>
</CsoundSynthesizer>
</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
;starts instrument 1 and runs it for a week
i1 0 [60*60*24*7]
</CsScore>
</CsoundSynthesizer>