Cabbage Logo
Back to Cabbage Site

Dynamically loading listbox string

I have a listbox that is dynamically loading a string value - in this case ‘SpresetList[1]’

cabbageSet 1, "Sample", sprintfk("populate(\"*.txt\", \"%s\"), value(\"%s\")", gSpresetPath,SpresetList[1])

It highlights the correct value but the value isn’t sent back to cabbage. For instance, here, the print value doesn’t reflect what is dynamically selected with cabbageSet. Any suggestions?

> cabbageSet 1, "Sample", sprintfk("populate(\"*.txt\", \"%s\"), value(\"%s\")", gSpresetPath,SpresetList[1])
>                 gSpreset=chnget:S("Sample")
>                 printks "gSpreset=%s", 0.3, gSpreset

I think I know why this is, It’s obviously a bug. Let me take a look…

Thanks, also, is it possible to dynamically change an image?
cabbageSet "bgimage", sprintf("file(\"%s\")", gSartPath)

I’ve pushed a fix for this. Can you check it out. It’s in the latest Azure build.

Yes, this works fine. I just tested, but I didn’t use a global variable. I refuse to use globals :crazy_face:

Cool, thanks! I guess my string is off then…

Mind if I just cram a bunch of unrelated topics into a single thread? :stuck_out_tongue_winking_eye:good!

trying to populate a combobox with .snaps from a directory.

`combobox bounds(200, 20, 200, 30), populate("*.snaps", "Directory"), channelType("string"), colour(30,30,30,0), highlightColour("52, 152, 219,100"), fontColour(40,40,40)` 

there’s a .snaps file in that folder but cabbage still loads the default location there the .csd is.
If I change the filetype to something else (i.e. “*.txt”) it works correctly, populating the txt files in the specified folder.

You can name the snaps file. But trying to dynamically load various snaps files is not possible or at least it shouldn’t be :laughing:

I think it makes sense - let’s say I have a bank of 50 Synth snapshots and another for Bass etc… It would be too many to have in a single dropdown menu. I wonder if there’s some sort of workaround…

Hmmm - not happening for me here for some reason- even with a direct file ref…

<Cabbage>
form caption("Untitled") size(400, 300), guiMode("queue"), pluginId("def1")
image bounds(0, 0, 400, 300), channel("wallpaper"), file("test")

</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

;instrument will be triggered by keyboard widget

instr 1
    cabbageSet "wallpaper", "file(\"PATH TO IMAGE\")"
endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
i1 0 500
</CsScore>
</CsoundSynthesizer>

I’d say your path is not correct. This loads the meter_black png which is in the current directory:

<Cabbage>
form caption("Untitled") size(400, 300), guiMode("queue") pluginId("def1")
image bounds(94, 8, 306, 270) channel("image1")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1
    cabbageSet "image1", "file(\"meter_black.png\")"
endin

</CsInstruments>
<CsScore>
i1 0 z
</CsScore>

Works in the current directory - does it work if you point it to a different dir?

Just to clarify - I’m simply suggesting the capability of loading individual .snaps files - not multiple concurrently. Of course I see the caveat there with accidentally loading a snaps file that doesn’t correspond with the controls - but I assume there’s others too…

it works if it is pointing to a directory within the current dir, but it doesn’t seem to work when you wish to go back out of the current dir. This is a bug. It should work. I’ll get that sorted.

Yes. This is possible. See this post for details.

Got it - it’s working well! however, the loaded .snaps file renders the combobox empty until something is selected from the dropdown. Is it possible for it to automatically load the first snap?

Any chance you could prepare a simple example for me? I hacked the PresetNamed.csd example in the Misc folder to load a named preset and it loads fine. Is that example working Ok for you?

I think I understand what you’re looking for now. Note that the preset combobox should display the first items if it opens for the first time, although it won’t update any widgets. If the user saves a session with the first snapshot selected, then the next time they open the session that preset will be loaded. If you have a default state, that should be coded into the widget’s value identifier.

The best solution here would be to create a protectedItems() preset that matches tabula rasa for the plugin. When the plugin loads for the first time all widgets will be set to default, which also matches the first preset, which users can’t overwrite. At any point during a session users can return to this state via the preset combobox. @hdale does this in his Graindrop plugin and it works very well.

Yes, this is what I usually do for default loading - set the default widget val is the same as the 1st snap… however I think we are talking about something different here - unless I’m not understanding… the 1st snap isn’t loading at all when .snaps are dynamically replaced:
https://recordit.co/3NTJMVckCb

I have to manually select it from the dropdown menu otherwise it’s empty.

Any chance you can prepare a simple example?

Actually, this is working fine for me here? My test yesterday had an error in it. This is the instrument I tested with:

<Cabbage>
form caption("Untitled") size(400, 300), guiMode("queue") pluginId("def1")
image bounds(10, 10, 200, 40), channel("image1"), outlineThickness(4), corners(5), outlineColour("white")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d 
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1


instr 1
cabbageSet "image1",  "file(\"../buttonOn.png\")"
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>

Sure. A simple .csd is attached
See here. I choose - “snap1” and the snap1.snaps is loaded but it doesn’t load the first snap. Same with “snap2”
https://recordit.co/AaafDg2KSn

snaps.zip (1.6 KB)