One reason you may get an odd looking order is that the sample path,index method is case sensitive. This means that a sample named Moo.wav would actually play before a sample named cow.wav as it will read Uppercase BEFORE lowercase.
I guess you might be wanting to play a folder of sample continuously end to end. The problem with that is that it is not obvious how to get the sample name to use in
sleep sample_duration <name>
to let you sleep the length of each sample before the next one starts.
I played around with some of the other commands in Sonic Pi and came up with a solution which utilises the commands
i first ran the program:
puts sample_info path,index
This looked at my samples folder and produced some information about the matching sample
├─ #<SampleBuffer @id=38, @num_chans=2, @num_frames=282241, @sample_rate=44100.0, @duration=6.400022675736961>
Quite a lot of information, but significantly including the sample duration at the end.
Changing this to:
puts sample_duration sample_info path,index
produced the sample duration
In then built up stage by stage a command to extract the sample name:
puts (sample_paths sample_info path,index) #gets info as a ring
puts (sample_paths sample_info path,index) #changes back to a string
puts (sample_paths sample_info path,index).split("/") #splits to a list of strings
puts (sample_paths sample_info path,index).split("/")[-1] #extract the last element which is the name
├─ (ring "/Users/rbn/Desktop/samples/MK03.wav")
├─ ["", "Users", "rbn", "Desktop", "samples", "MK03.wav"]
I then put all of this together, and defined two additional methods to enable these to be used together:
path="/Users/rbn/Desktop/Sonatina Symphonic Orchestra/Samples/Percussion/"
define :getSampleName do |path,index=0|
k=(sample_paths sample_info path,index).split("/")[-1]
define :getSampleDuration do |path,index=0|
k=sample_duration sample_info path,index
return 0.1 #return small number if no sample found
live_loop :splay do
This final example played all the percussion samples in the Sonatina Symphonic Orchestra percussion folder repeatedly. I added some error handling so it wouldn’t crash if a sample wasn’t found.