Find the length of a sample

I have a long sample that I want to play so I am using the following command

 r1 >> loop('rain',0,dur=100)  

But I have to work out how many beats the sample is made up of and I am doing this by trial and error. I can make life easier by using

seconds = Clock.seconds_to_beats
r1 >> loop('rain',0,dur=seconds(10))  

and then just putting in the length of the sample in seconds. This then makes me immune to any changes in bpm but is too much like hard work.

Ideally I want to be able to get the duration information directly from the sample. Is there a way of doing this ??

Currently that information isn’t available. The wave module could be used to find that information though by opening the file, reading the number of frames and dividing it by the sample rate. It could be done on loading samples tbf but I’m not doing any development at the moment.

No worries, just being lazy I can find out the length seconds and then translate to number of beats