Cabbage Logo
Back to Cabbage Site

Passing a string (or any other variable) to a function table

Hello! I’m just getting started with Csound. I’m trying to visualize a waveform using the gentable widget using a Function Table and the GEN1 routine to read from a file. It works for me to directly send a filepath to view a single file, but I’m trying to make it update the table when I select a different file from a combo box. Is there a way I can send a variable (in this case a string) to a parameter of a Function Table or otherwise update the values of the table on the fly?

Welcome Alkali!

I’m literally just sitting down to dinner, so I can’t take to long drafting a helpful reply… but the secret here lies in “reinit”.

You need to treat your strings at krate (there are special string functions like strcatk, strcpyk, etc.)
You need to detect a change, and then trigger a reinit.
After the reinit, read the same combobox as an irate.

Sorry if that’s confusing, it’s a bit rushed… but hopefully with a little poking around you can find the answer? I’m pretty sure it’s on the forums, or in the examples… “reinit” will probably help you find the way :nerd_face:

Good luck!

Take a look at the soundfiler misc. example. It might be a little overly complicated, but should get you started. It uses reinit, as @t_grey suggested, but you don’t need that. When a user changes the name in the combobx, you can call an instrument that just updates the file, for example:

instr 1
if changed(chnget:s("combo1")) == 1 then
    event "i", 2, 0, 0

instr 2
SFile chnget "combo1"
iTableNumber = 1
i1	ftgen	iTableNumber,0,0,1,SFile,0,0,0
//update gentable/soundfiler.....

If you do it this way you don’t have to worry about k/i rate issues.