How to Call an external sample as if it was a built-in sample?

I noticed at many of @samaaron live performance that he calls external samples like “ebit_bass”, “ebit_pad” as a build-in samples like this:

live_loop :hello, sync: :foo do
sample ebit_pad, “120”, “Cm”, amp: 2
sample ebit_bass, “120”, “Cm”, amp: 1
sleep 8

How did Sam make it?

Hi @AhmadMRagab,

basically you can set a variable like

ebit_pad = "/the/path/to/my/samples/"

You can do that at the top of the buffer or in your init.rb, which resides in the directory .sonic-pi (under Linux this is in your home directory, not sure where to look for it under Windows). This file will get loaded anytime you start SP and the contained variables will get initialized.

Furthermore have a look at the chapter 3.6 and 3.7 to see how you can reference samples on your harddisk (keywords: indexing and filtering samples).

So Sam calls a directory via ebit_pad and filters the contained sample filenames via two strings “120” and “Cm”.

Hope that helps.


Hi @Martin,

Thanks for your answer it’s very helpful!
I know how to add a sample as a variable but it was odd for my to watch Sam writing directly the sample’s name without noticing any variables on the top of buffer.


Hi there,

Actually, in this case I wasn’t using a variable, rather a function via define :slight_smile:

1 Like

Oh, yeah, my mistake. Thanks for the clarification. Actually I have the same in my init.rb :wink:

Thanks, Sam :slight_smile: