Cabbage Logo
Back to Cabbage Site

Retrieving all items in a combobox as a string

Is there any way to retrieve the items of a combobox as a comma separated string, so I can manipulate the items during runtime?

I populate a combobox with sound files in a folder, working all ok. Then I want to add other items to this combobox, like this:
soundfile1.wav
soundfile2.wav
… (all populated from the sound files in a folder), then I want to append for example:
Sine
Square
Saw
live_sampled_sound1
live_sampled_sound2
… etc

I managed to kludge my way around by retrieving the items one by one, building a string with comma separated items, then appending my other items to this string and using the identchannel to set the contents of the combobox. One problem is that during retrieval of the items, I trigger the actions that the combobox should trigger during normal operation, and also the whole process seems to offset the contents(items) by one, so that I select “soundfile2.wav” but the combobox sends out the string “soundfile1.wav”. I guess I can kludge my way further, but it seems I’m going about it in a very backwards fashion. Hoping there is an easier way. Suggestions welcome!

You may need to talk me through this:

Are these sounds in the directory? Or do you just wish to add new items to the combobox? Or are you trying to do both, have samples from a dir, and append non directory items?

Perhaps you could use a file with the items you need in there. As of the latest Cabbage, Combo boxes can now read the contents of text file. You could write items to this file with Csound, and then update the combobox using the file() identifier with an unique identifier channel. There is also the new directory opcode in Csound that will load the names of all files of a set type in a directory to a string array. Perhaps that might also be of some help?

Also in the latest version there is a new updatefiles() method that you can call (again through an identifier channel) that will update the items in the combo box if you are reading items from a directory? Any of this sound like it might help?

Thanks for the tips, it looks as it the directory opcode will be very useful in building the list if items.
I do want to have both samples from the dir and aother (non dorectory) items. Some of the extra items are dynamic in nature (created as a result of user interaction), so I need to be able to append to the list of items dynamically.
When I tested with the directory opcode in CLI Csound, I can do what I need. But strangely I can’t get the directory opcode to work in Cabbage. I also tried to copy the csound64.dll from the canonical Csound install, in case that would allow me to use the new opcode. Still no luck. The Csound console in Cabbbage says
error: syntax error, unexpected T_IDENT, expecting T_OPCODE or T_FUNCTION or ‘,’ (token “directory”) from file C:\Program Files (x86)\Hadron\test.csd (1)
line 19:

SFilenames[] directory <<<
Parsing failed due to invalid input!

Hi Oeyvind,

Are you using Linux? Have you tried exporting LD_LIBRARY_PATH and OPCODE6DIR64?

For example, before running Cabbage I do:

export LD_LIBRARY_PATH=/opt/csound-6.06/lib:${LD_LIBRARY_PATH} && export OPCODE6DIR64=/opt/csound-6.06/lib/csound/plugins64-6.0

edit: Sorry, I’ve just seen the Program Files directory there! Have you tried changing the Environment settings?

Thanks for the quick reply, but this is currently on Windows, and I can find the other plugins. But I also thought the directlry opcodes was not a separate lib(?) Could not find a dll name where I expected to find it, so I assumed it was in csound64.dll

Copy the ftsamplebank.dll file, that’ll do it. I had it as a separate library, but Victor bundled it with ftsamplebank. I guess he’s trying to contain my mess!

Yes, that was it. Thanks