Don't worry!
First of all you need to load the following code in supercollider and execute it by selecting it and pressing CTRL + Enter:
(
OSCdef.new(
\sampleLength,
{
arg msg, time, addr, port;
var name, number, address, length;
address = NetAddr.new("localhost", 6010);
name = msg[1].asSymbol;
number = msg[2];
length = ~dirt.soundLibrary.buffers[name][number].duration.round(0.01);
address.sendMsg("/ctrl", name.asString ++ number.asString, length);
},
'/sampleLength'
);
)
Next you open a .tidal file in Atom and execute the line
import qualified Sound.OSC as O
then execute
get_length:: String -> Int -> IO ()
get_length sampleName n = do sendO False (sListen tidal) (head $ sCxs tidal) $ O.Message "/sampleLength" [O.string sampleName, O.int32 n]
You need to do these steps every time you startup SuperCollider and Tidal. Now, this is how you use it:
Let's say you want to use the lengths of the first three samples in the samplefolder bsperc. To get them you can execute the line
get_length "bsperc" 0
get_length "bsperc" 1
get_length "bsperc" 2
one after the other in Tidal (note that we begin to count at 0). There will be no confirmation that anything happened, but you will now be able to use "^bsperc0", "^bsperc1","^bsperc2"as a placeholders that stores the lengths of your samples. Try to play the following after completing the above steps:
d1 $ s "bsperc bsperc:1 bsperc:2" # speed ("<^bsperc0 ^bsperc1 ^bsperc2>")
So in the first cycle, the speed will be adjusted according to the length of the first sample, in the second cycle according to second one and in the third cycle according to the third one.
Hope this helps! Feel free to ask if you have any questions, I'm happy to help
Edit: I just read through your original question again, where you specifically asked for a way to know how long your sample is so you can set the cps right. This will be better to try on a longer sample so first get the length of the sample (I'll use the pad sample):
get_length "pad" 0
then set the cps to 1 divided by the length of the sample:
setcps (1/"^pad0")
and try it out:
d1 $ s "pad"