How to load random audio files in Supercollider ?

Hi,
I’m looking for a way to load several audio files into SC buffers randomly selected from a given directory on my computer.

Let’s say I’ll have 20 buffers I’m gonna work with in SC, I want to fill them with 20 different wav audio files with a single function.

How would you do that in Super Collider?

Is there a way to do this directly in SuperCollider? Or should I create an external program/script that would create a JSON containing all the paths (something similar to the jar maps used in programs like Reaktor ?) and use that in SC ?

That’s just an idea, I don’t even know if that’s possible, I’ve seen many tutorials on sound synthesis in SC, but not many about sound files and file management…

What’s the best approach ?

Thanks!

Not near a computer at the moment but I believe you could use the PathName object and its .files method:

PathName.new(“myFolder”).files.scramble.copyFromStart(20)

3 Likes

Yes, it’s working! It fills up an array with 20 paths and filenames. That’s exactly what I was looking for. Thank you very much @duckpow

I’ll have a closer look at all these methods, loads of interesting possibilities. Perhaps there’s a way even to make it recursive when there are a lot of sub-folders, or to add selection filters. I’ll dive in the documentation and report here if I find something.
Thanks again ! :slight_smile:

v = PathName.new("/Users/Shared/Lone Forest Library/Samples/Drums/Kick").files.scramble.copyFromStart(20);
v[0];
v[19];

Edit:
To make it recursive, I simply added an asterisk after the parent folder.
I was about to try using a “for loop” with the list of folders but this works just fine.

e = PathName.new("/Users/Shared/Lone Forest Library/Samples/Drums/*").files.scramble.copyFromStart(20);
e[12];