Cabbage Logo
Back to Cabbage Site

Save presets with soundfiler widget


I would like to ask a question about the drag&drop function of the “soundfiler” widgets. I’ve been watching this video and reading information on the “Soundfiler” widget getting ideas from there to do something that I think it’s interesting if it could be done. Using the “The next power of 2” example I shared earlier instead of using a “filebutton” to load the file I have replaced it with a “soundfiler” to be able to drag&drop. I have then limited the mouse coordinates where that screen is located to drag the samples into the screen and it has worked fine.

What I could not do is save the presets. They are saved and loaded without any error in the console but it seems that the reference to the directory is not saved. I think this has some logic because the last file that was dragged on the screen is the information that remains working but the path of the file that was being used when the preset was saved is not saved. I’m not sure if this is a bug becasuse probably I´m missing something also. I wanted to ask if there is a way to do this? that is to say that the file path is saved when saving the preset and that when loading the preset the screen is also updated. I have tried several ways but I have not succeeded. With the “filebutton” saving the presets worked fine but with the “soundfiler” it seems to be different. I attach a simple example with this issue (the first). I also attach and example with “filebuttons” that works fine. This is what I would like to do with the “soundfiler” drag&drop, in that case it saves the presets and updates the screen.

Thank you very much and greetings.

Drag&drop.csd (1.9 KB)
Drag&Drop filebutton (OK).csd (1.9 KB)

Thanks for the sample files. I was able to track down the issue and I just push some code that should sort this. Can you test and let me know? I only had time to test and debug in plugin mode with a DAW, so let me know if you have any issues in the Cabbage IDE.

Thanks for looking at this issue. I have tried it in the Cabbage IDE and in a Daw and I have not noticed a difference. What I have noticed on both platforms is that now the presets do save the information of the samples regarding to the screen and update the screen correctly but these do not save the information of the audio files regarding to the sound reproduction. This means that when loading a saved preset the screen is updated but the sound does not change and the sound of the last sample that the user had loaded remains. If the plugin is opened from scratch in Cabbage or a daw and no audio file is dragged onto the screen the presets do not load the audios files, they just show the waveform on the screen. Unlike what happens in the second example (Drag&Drop+filebutton (OK).csd) that I uploaded, it uses a filebutton to load the sample. In that example both the screen and the sound of the audio samples are updated when loading the preset. I think that the best thing would be that, as in the example with the filebutton, the audio files for playback will also be updated when loading the presets.
I’m going to mention another little issue with soundfilers that I didn’t mention in the first post since it seemed minor compared to the issue with the presets but I’ll take the opportunity to mention it here. What I noticed is that when dragging the samples onto the screen if by mistake a sample is dragged off the screen then that same file cannot be dragged onto the screen again, in such a case it is necessary to drop it back onto the screen a sample with another name and then it is loaded correctly.

Right, my bad, I have to admit to marking this as fixed once I saw the waveform appear on session load :man_facepalming: I’ll take another look when I get a chance, most likely Monday at some point. :+1:

1 Like

I think this is issue is not with presets but how your trying to recall them. You’re trying to recall data based on a last_file_dropped event, which doesn’t get saved with the session and preset data. The solution here is to set the soundfiler “file” identifier each time the audio is updated. These file will be saved, and will be recalled. Can you try this modified version of you instrument?

CabbagePluginSynth.csd (2.0 KB)

Thank you very much for taking time to fix bugs and solve these kinds of doubts, I really appreciate it.
I suspected that it could be something like that but I had made several attempts and I would not have known how to solve it. I tested and it works now as I expected. Being able to drag and drop samples onto a screen feels cool and modern.
I think the only thing missing now to be perfect is what I mentioned before that if a file is dragged off the screen it can’t be loaded again until another file is loaded. Will there be chances that you can take a look at that when you have time? I suspect it´s a bug but I´m not sure if it is not something wrong in my code. Sorry for insisting on those little things but i’m a zodiac sign virgo and sometimes I can’t help it. :sweat_smile:

It’s kind of a bug because the file-dropped event is only picked up when there is a change. I’ll take a look. It might not be that easy but I’ll look into it. :+1:

Thanks, have a good week.

I just took a look at this. The issue is that whenever the same file is dropped twice, we don’t get achanged event. The trick is to reset the “LAST_FILE_DROPPED” channel everytime the file is dragged outside of the soundfiler. See how I do it here:

instr Screen

    gSfile, kLoadFile cabbageGetValue "LAST_FILE_DROPPED"
    if kLoadFile == 1 then
        if chnget:k("MOUSE_X") >= 76 && chnget:k("MOUSE_X") <= 312 && chnget:k("MOUSE_Y") >= 106 && chnget:k("MOUSE_Y") <= 265 then 
          cabbageSet kLoadFile, "soundfiler1", "file", gSfile
          event "i", 2, 0, .1
            chnset "", "LAST_FILE_DROPPED"


Thanks for checking it out, I’ve tested it and it works. I´m glad you found a trick to make it work fine.

Hello! I ask again in this topic since a question that I could not solve has arisen. I’m making an instrument that uses this type of mechanism to load audio. The possibility of uploading by drag&drop on the screen works perfectly after the last suggestion that was made to modify a part of the code.

I I have found that the other way to upload audio files via the “soundfiler” menu has a certain problem which is why I want to ask. "Pressing ‘Open file’ and then ‘Cancel’ results in the previously loaded file disappearing from the screen and the table. It seems to me that this could be related to the way the logic is handled and would like to ask if it can be fixed from the code. I have tried but could not find a solution. If it weren’t for that detail I think it still works very well.

The code to upload the audio is just this:

instr Screen

gSfile, kLoadFile cabbageGetValue “loadfile”

if kLoadFile == 1 then

cabbageSet kLoadFile, “soundfiler1”, “file”, gSfile



I attach the simple example in .csd

Load audio.csd (1.8 KB)

This example is working fine for me here. Or does this issue only happen when trying the instrument as a plugin? Are you using one of the recent develop snapshots? If not can you try, you can access them here

Seems like kLoadFile is also triggered when pressing cancel or exit.

But in your screenshot, the previously loaded file didn’t disappear? I thought this was the issue @Alejo reported. In any case, it looks like you are right, a change is triggered with a cancel. So the best would be to check that gSfile exists first:

gSfile, kLoadFile cabbageGetValue "loadfile"
if kLoadFile == 1 && filevalid:k(gSfile) == 1 then

@rorywalsh the problem happens both in Cabbage Ide and in pluggin mode. I was on version 2.9.53. Then I tried with the latest version 2.9.94 and there is a difference with the screen, with that version the waveform image does not disappear from the screen when I press “cancel” but when I touch the keyboard an error appears on the console “INIT ERROR in instr 1 (opcode filelen) line 45: diskinfo cannot open
from file C:\Users\ALE\Desktop\CSOUND FILES\Audio upload\Load Audio.csd (1),ilen filelen gSfile 1
INIT ERROR in instr 1 (opcode filesr) line 46: diskinfo cannot open
from file C:\Users\ALE\Desktop\CSOUND FILES\Audio upload\Load Audio.csd (1),isr filesr gSfile 1
INIT ERROR in instr 1 (opcode filenchnls) line 47: diskinfo cannot open
from file C:\Users\ALE\Desktop\CSOUND FILES\Audio upload\Load Audio.csd (1),ich filenchnls gSfile 1
soundin cannot open : No Error.ftable 102: Failed to open file
f102 0.00 1.00 1.00 “” …
INIT ERROR in instr 1 (opcode ftgen.iS) line 63: ftgen error
from file C:\Users\ALE\Desktop\CSOUND FILES\Audio upload\Load Audio.csd (1),ifno1 ftgen.iS 0 0 i_ipow2 1 gSfile 0 0 0
T 7.739 - note deleted. instr 1 had 4 init errors.” It seems that the file is deleted from the table. I have also tried with
“if kLoadFile == 1 && filevalid:k(gSfile) == 1” it solves the screen issue but no the table issue. Rory you say that the example works well for you, but have you tried playing the keyboard?
@hdale94 I have tried your code, in version 2.9.53 that I had before, it solves the screen issue but the same error that I mentioned before occurs when touching the keyboard. Is it okay for you if you play the keyboard? In the video I can’t see if you then play. Trying the same code in version 2.9.94 it makes no difference whether to include it or not since, as I said before, this version by itself solves the issue of the screen but not the deletion of the table file. Taking into account these tests with version 2.9.94 and the code from hdale94, maybe this could be a bug?

Seems like the fix Rory suggested does not fix it completely.

Yes, I would also describe this as a bug. The expected behavior when pressing cancel is that gSfile would stay the same, but currently, I think it clears out the file path?

what’s this line about?

kSValue cabbageGetValue gSfile

That’s not right. It’s expecting a channel, not a filename. What you should do here is use the code I posted above to ensure the soundfiler only get updated when a users has selected a file. Then in instrument 1, retrieve the name of that file at init time. Then I don’t see how it can go wrong.

I’ve attached a modified version of your instrument that works fine for me.
Load audio.csd (1.9 KB)


I just pushed a change to the behaviour of the filebutton, it will no longer broadcast a change trigger when a user presses cancel :slight_smile:


Yes, you are right Rory. The last solution you posted works right here too and the file do not dissapear now. I confirm it works also in the older version 2.9.53. I had not realized that this line was not right. Thank you both @rorywalsh and @hdale94 for the help.

1 Like