How can I load in sample libraries consistently?

EDIT: I think I answered my own question, after shutting down Sonic Pi and booting it up again it seems to now use the appropriate index values. I think it was because I altered the contents of the folder my code was pointing to.

I’m having a bit of a problem loading in sample libraries where sometimes it works and sometimes it doesn’t. Right now when I debug the code it’s saying “no match found, skipping.”

What I’m attempting to do is add something to the top of my code that loads up the folders which contain my homemade samples:

#LOAD IN SAMPLE LIBRARIES:

sampDrum = “/Users/sheamkennedy/Desktop/Sonic Pi Files/SPi - Samples/Acoustic Drums”
sampSFX = “/Users/sheamkennedy/Desktop/Sonic Pi Files/SPi - Samples/Retro SFX”

live_loop :kick do
sample sampDrum, 3
sleep 0.25
end

live_loop :sfx do
sample sampSFX, 0
sleep 1
end

Currently I hear no sound. I know that my drum folder contains five samples so I’d assume that their index values would be 0-4. And I know I have 10 samples in the SFX folder so I’d assume their index numbers would be 0-10. This does not seem to be the case. In past projects I have similarly loaded up a folder and used the values 0 to (#number of samples - 1) in order to find my samples so I don’t know why this isn’t working now…

I should point out that I know I can specify the sample name that I’m looking for. I do not want to do this. I prefer to work with number values so I can easily swap out samples by changing their number value since I can’t be bothered to remember hundreds of sample names.

I wonder if this has something to do with me added, replacing and removing samples from these folders…?

Hi,

in my experience, any changes to the referenenced folder will only be applied after restart of Sonic Pi. I guess a sample path is being cached. So restart SP and test if something has changed.

You are right about the indexes; this should work.

Easiest way on Mac to get the right path: just drag the sample containing folder into a SP buffer, there you have the path as a string.

1 Like

Alright perfect. That tip on dragging the sample will save me some time too.

1 Like

Martin is right that SP caches the sample path folder(s) and thus if you alter them after they have been accessed, changes will not be found. Rather than rebooting Sonic Pi by quitting and restarting it you can use:

reboot
stop

inserted at the start of your buffer, run it, then comment it out and rerun your program. SP will then pick up the changes. reboot reiniitialises the sound system. Warning it stops all other jobs.

1 Like

Thanks that’ll speed up the process.