Cabbage Logo
Back to Cabbage Site

Problem with ftload from Cabbage

I wanted to make some small change to “Anykey” which I wrote some time ago, but then went down a deep-deep rabbit hole. First I discovered that the dreaded combobox did not populate. But that I fixed after reading the forum post by going to version 2.9 (and 6.18 of csound).

But then it did not load the “keys” files anymore. First, I thought there were some path issues. (I still don’t know which path ftload uses: The path of the csd? And what if run from a DAW as vst3?) But after trying a lot of possibilities (relative, absolute, “\”, “/”…) I ended up running the attached minimal test. But even that gets the message “unable to open file”.

But when I ran the same file in csound from terminal (Windows Powershell) it produces correctly: “Length of table: 287”.

What is the reason? Does cabbage change the path where ftload looks from the path where the csd resides?

ftload-test.zip (1017 Bytes)

Cabbage used to set the current directory to that of the .csd file. But I had to change it because hosts don’t like this. It was bad practice from the the start and shouldn’t have ever been that way. But unfortunately I didn’t know enough about this stuff when I started writing this software more than 20 years ago. The fix is simple, just grab the csd path, and use that to build an absolute path:

<Cabbage>
form size(500, 300), caption("Untitled")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-odac -d
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 44100
nchnls = 2
0dbfs = 1

instr 1
    SFile sprintf "%s/BWV_639-2.keys", chnget:S("CSD_PATH")
    ftload SFile, 1, 1
    ilen = ftlen(1)
    prints "Length of table: %i\n", ilen
endin

</CsInstruments>
<CsScore>
f 1 0 2048 -7 0 2048 0
i1 0 10 
</CsScore>
</CsoundSynthesizer>

Thanks for this (as always) quick and helpful answer. I implemented it and it works, standalone and in the DAW.

Also thanks for showing me the elegant way to use sprintf with the functional form of chnget. I already feared I need a dozen extra variables and strcats.

What I also noticed is that my test file was not testing the real case. I did not know that the Cabbage section is essential. I thought running the ordinary csound file from Cabbage would be sufficient.

I will post the updated version of Anykey on gitlab after giving it some tests.

I got caught out with this too. :rofl: I was wondering why CSD_PATH wasn’t returning a valid string until I noticed there was no Cabbage section. :man_facepalming: