Cabbage Logo
Back to Cabbage Site

Dynamically loading listbox string

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)

Ok, now I see what you’re at. But no, you can’t pick and choose Cabbage presets this way. In fact, Cabbage is likely to crap its pants if you even try selecting one of these presets considering the current GUI doesn’t contain all of these widgets/channels.

If you want to do this kind of thing you’re need to roll your own preset system. There is quite a discussion about this here. The tr;dr is that you will need to manage your own presets if you want this kind of flexibility. But there are some opcodes that can help, namely cabbageChannelStateSave and cabbageChannelStateRecall. Together with various file/string opcodes you should be able to put together a fairly robust preset system. But you have to ask yourself is it worth the effort because, it does quite a bit of complexity to the system.

I see - OK, will have to think about that. It will just be a strange UX in my particular case, for the user to choose a new library and the list of presets associated w it doesn’t show up by default… Yes, in this example, the widgets don’t align with the snap but in my working files it does… indeed cabbage crashes if you try and select one :slight_smile:

Hmm still struggling with this… maybe i’m missing something in the syntax…

// This one loads the image
cabbageSet "Wallpaper", "file(\"Flare_2000.png\")" 

// This one does not load even though the file is in the images folder
;cabbageSet "Wallpaper", "file(\"images/Flare_2000.png\")" 

endin

Change the images folder to imoges and it works :rofl: Sorry. Bug. Fixed. I didn’t catch it before because my folder didn’t contain the name of widgets. I was optimising some code yesterday and stupidly introduced this.

Ahhh - there’s nothing like a beautiful imog :laughing: