Name of a sample that has been randomly picked up

Hello everybody,

I am writing instructions to randomly choose a sample into a file collection. Once it has been chosen, I would like to store the name of this file in a variable called : Name.
I see the name of the file in the console but I can’t figure out how to get hold of it in my code.
This is what I have written so far :
collection = “/home/fred/Desktop/tracks/”
use_random_seed Time.now.to_i
Rr = rrand_i(1,120)
sample collection, Rr
sleep 1
Puts = collection, Rr

It returns this in the console :

{run: 1, time: 0.0}

└─ sample “~/Desktop/tracks”,

“033-ZanMar-Mel3-AC&.wav”

#{run: 1, time: 1.0}
#└─ “/home/fred/Desktop/tracks/” 21

But I can’t find a way to write the complete filename “033-ZanMar-Mel3-AC&.wav” in my Name variable.

Can someone have a tip ?

Best regards,

Fred

sample_name = collection, Rr   # store reference to sample
puts sample_name               # output sample name
sample sample_name             # play sample

should do it

Thanks R2L,
But unfortunately that doesn’t help here.
The output of
puts sample_name
is

{run: 2, time: 1.0}

└─ [“/home/fred/Desktop/tracks/”, 5]
That is “file path to collection” + Rr"
But not what I am looking for : the real sample name.
My sample names show the type of instrument and the key in which they are playing.
I want to use this information to overlap with other samples.
Best regards,
Fred

Try this:

sample_name = (sample_paths collection, Rr)[0]
puts sample_name
sample sample_name

sample_paths takes the same arguments as sample but returns a ring of paths. The [0] on the end is to get the first (and only) element of that ring, since in this case it will always be a ring of length one.

Thank you for your reply, emlyn,
This is the solution.
Now that I have the full file name, I will be able to build on top of it to launch the next samples.
Great :wink:

1 Like