Cabbage Logo
Back to Cabbage Site

Loading samples (was Backgroundcolour not working)

I’m a very faster replier of messages, don’t take it personally :rofl: can you simply as the entire .csd file as an attachment for me? Thanks :+1:

First synth.csd (2.0 KB)

Thanks for looking into this.

So it seems that something has broken the ftsamplebank opcode :rage: Anyhow, no worries, we have lots of other options. Attached is an instrument that should do something similar to what you wanted, only instead of loading all function tables in a single move, it simply loads the one it needs for the current note.

First synth.csd (1.9 KB)

Have a look through the file. If there is anything you don’t understand just ask. Btw, don’t forget to change the path back to your sample directory in the combobox declaration. Let me know.

p.s. I fixed that issue in ftsamplebank ( looks like I was the cause of that myself :joy:) It will be available in the next release of Csound, or if you can’t wait, you can grab the latest beta installer for Csound on Windows and use that.

1 Like

Thank you so much! I’ll keep experimenting and see if I’ll be able to figure out the rest of what I need. And sorry for such a late reply.

@rorywalsh where can I get the latest installer for the ftsamplebank fix? or do I have to build?

cheers

I actually created a continuous deployment build for Csound on MacOS. You can find it here. Note that it’s a pretty minimal version, but if you’re not using too many plugin opcodes you should be fine :wink: I wouldn’t go removing your current install. Just rename it, it’s in the system /Library/Frameworks folder.

Thanks Rory, I installed that fine - terminal reports 6.14

However the Misc/SampleLoadAndPlayback example still prints gkNumTables as 0. I also tried the example from the Csound manual, and got the same result.

Bizarro

Hmm, I jut checked the current Csound source and it doesn’t look like my changes was pushed through. Let me see what’s going on…

Try this one. My changes hasn’t been pushed through to the main Csound repo, but I have it included in this fork. Let me know if it does the trick.

really weird, that 0 is the gkNumTables print

perhaps I’m doing something wrong

But it is loading? Can you try using the i-rate version, there is little point in using the k rate in this instance. I’m think the k variable might not be valid at time 0? Just a hunch. Or try
printk 1, gkNumTables

I’m really not having too much luck with this!

The files load into the soundfilers fine, but the tables aren’t filled with data. I tried tried the i-rate version and there’s no difference; no value other than 0 prints for iNumTables

Are using the LoadingSamples example from the Cabbage misc/examples folder? It’s working fine for me here?

SampleLoadAndPlayback?

<Cabbage>
form caption("Sample load and playback") size(635,430), pluginid("SLaP"), colour("whitesmoke")
soundfiler bounds(10, 10, 150, 80) identchannel("soundfiler1") tablenumber(-1) 
soundfiler bounds(165, 10, 150, 80) identchannel("soundfiler2") tablenumber(-1) 
soundfiler bounds(320, 10, 150, 80) identchannel("soundfiler3") tablenumber(-1) 
soundfiler bounds(475, 10, 150, 80) identchannel("soundfiler4") tablenumber(-1) 
soundfiler bounds(10, 95, 150, 80) identchannel("soundfiler5") tablenumber(-1) 
soundfiler bounds(165, 95, 150, 80) identchannel("soundfiler6") tablenumber(-1) 
soundfiler bounds(320, 95, 150, 80) identchannel("soundfiler7") tablenumber(-1) 
soundfiler bounds(475, 95, 150, 80) identchannel("soundfiler8") tablenumber(-1) 
soundfiler bounds(10, 180, 150, 80) identchannel("soundfiler9") tablenumber(-1) 
soundfiler bounds(165, 180, 150, 80) identchannel("soundfiler10") tablenumber(-1) 
soundfiler bounds(320, 180, 150, 80) identchannel("soundfiler11") tablenumber(-1) 
soundfiler bounds(475, 180, 150, 80) identchannel("soundfiler12") tablenumber(-1) 
keyboard bounds(10, 266, 615, 86) mouseoeverkeycolour(255, 255, 0, 128) 
filebutton bounds(10, 356, 148, 40) channel("sampleFolderButton"), mode("directory") text("Open sample folder", "Open sample folder") 
label bounds(162, 356, 237, 16) text("Samples are triggered from C4") fontcolour:0(91, 91, 91, 255) 
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 --midi-key=4 --midi-velocity-amp=5 -m0d
</CsOptions>

<CsInstruments>
;sr is set by the host
ksmps = 32
nchnls = 2
0dbfs = 1

gSSamplePath init ""

;---------------------------------------------------------
;always on instrument that waits for user to specify sample folder
instr 100
   SFilepath chnget "sampleFolderButton"
   if changed:k(SFilepath) == 1 then
       gSSamplePath = SFilepath
       printks SFilepath, 0
       event "i", 101, 0, 1
   endif
endin

;---------------------------------------------------------
;when user has selected folder, load them into function tables
instr 101
   prints "Loading files to function tables\n"
   iFirstTableNumber = 100
   SFilepath chnget "sampleFolderButton"
  ; kTrig = 1   ;using k-rate version because of bug with i-rate version
   
   iNumTables ftsamplebank SFilepath, iFirstTableNumber, 0, 0, 0
   print iNumTables
   
   gSFiles[] directory SFilepath, ".wav"
   event_i "i", 102, 1, 0
endin

;---------------------------------------------------------
;once files have been loaded to tables, update soundfilers
instr 102
   iCnt init 0
   while iCnt<12 do
       SMessage sprintf "file(\"%s\")", gSFiles[iCnt]
       SChannel sprintf "soundfiler%d", iCnt+1
       chnset SMessage, SChannel
       iCnt+=1
   od
endin

;---------------------------------------------------------
;this instrument get triggered by the keyboard. It listens for
;a keypress and then trigger instr 2 to play the associated sample
instr 1
   iTable = (p4-72)+100
   iNumSamples = ftlen(iTable)
   event_i "i", 2, 0, iNumSamples/sr, p4
endin

;--------------------------------------------------------
;gets triggered from instr 1. Plays sample and updates scrubber position
instr 2
   iTable = (p4-72)+100
   iNumSamples = ftlen(iTable)
   aPhasor phasor sr/iNumSamples
   aSig tab aPhasor, iTable, 1
   outs aSig, aSig

   if(metro(64)==1) then
       kScrubber	downsamp	aPhasor
       Smessage sprintfk "scrubberposition(%d)", kScrubber*iNumSamples
       SChannel sprintfk "soundfiler%d", p4-72+1 
       chnset Smessage, SChannel
   endif
endin

</CsInstruments>
<CsScore>
i100 0 z
</CsScore>
</CsoundSynthesizer>

modified to use i-rate version of ftsamplebank

So it works ok?

No, it’s not working for me, does what I posted work for you?

Is there a dependency somehow missing for me? I installed that what you sent me and confirmed the version number is 6.14

Yup, it’s working for me. I am way from my mac for the next week or so. I’ll check when I return to Ireland. It could well be an issue with the build I published, but it’s had to say when I can’t test it myself. For what it’s worth, iNumTables is not returning a value for me either. But the table are being loaded and I can play them on the keyboard.

That must be something to do with it, ah well. So no need to rush I created a little udo in the meantime that accomplished the same feat. Can post it if it’s useful to anyone having the same issues. Thanks again

Please do. It’s always good to have alternative ways of doing these things.

No probs, here it is