Cabbage Logo
Back to Cabbage Site

Creating images during runtime

Hello,

I am programing a small synth and want to modify the GUI during runtime. I have a global array (length 64, so handling each slot manually would be very annoying) and want to loop through the array and create images on the GUI based on the content of each index. The content of the array changes over time, so I need to be able to trigger a new rendering pass.

My first instinct was to use the cabbageCreate opcode. But it can’t add new widgets during performance (only at time 0 of the score, not time 0 of the allocation of the instrument that performs the rendering pass). It also does not seem to be able to create any images at all (even at time 0).

Then I tried using buttons with imgFile(), but I was not able to show the image instead of the button (I think I am misunderstanding how imgFile() is supposed to be used, it is hard to tell from the documentation what it does, since the image files used aren’t shown, so I am not sure to what extent imgFile() can replace the visuals of a button and which arguments are needed).

Can anyone give me any hints how to solve my problem?

Can you not just create a single image in your UI and dynamically display whatever image you want based on the current index of the array? In pseudo code:

image bounds(0, 0, 100, 100), channel("image1")
...
SImages[] init 64
SImages[0] = "image1.png"
SImages[1] =  "images2.png"
...

cabbageSet changed(kIndex), "image1", sprintfk("file(\"%s\")", SImages[kIndex])

The other way you could do it is to create a filmstrip with all 64 images, attach it to a slider with the range 1-64 and then each time you change the slider value your current image will update. So yeah, there are quite a few ways to do this. :+1:

Ah yes, it works. I must have missed the warning that I have to enable guiMode(“queue”) a hundred times :sweat_smile:

:rofl: I’m glad you got it sorted, but which way are you doing it? I think the film strip is the most efficient way of doing it as Cabbage does all the heavy lifting, rather than Csound.