Choosing random start position in randomly selected buffer

I have a dictionary filled with arrays of samples which I’m reading into buffers. The buffers are randomly selected for playback in a Pbind, so I know I can use Pkey to share which buffer has been selected within the Pbind, but I don’t know how I can check the length/numFrames of the currently selected buffer to choose a startpoint that isn’t either past the end or too close to the end of the sample for it to play for the entire duration of the Pbind step.

I’ve tried using dictionaryName[\folderNameAsSymbol][arrayIndex].numFrames and other things along those lines but haven’t had any luck. At the moment I’m sort of limited to a start position which is about half of my shortest sample, and they range from thirty seconds to four and a half minutes, so it’s really not ideal!

Any suggestions?

1 Like


in Pbind you can do

\buf, ...,
\numFrames, Pkey(\buf).collect(_.numFrames)

Also the Pfunc convention is practical

\buf, ...,
\startPos,  Pfunc { |e| e[\buf].numFrames ... }


1 Like

Thank you! This is exactly what I was looking for. I’ll test it out today.