How To Calculate Delay By Bpm And Speed (tempo) ?

Hello, forum!
I want to calculate duration of one song position (in ms). How to do it having BPM and Speed (Tempo)?

BPM is the number of beats per minute, obviously, so to find the length of 1 beat in seconds, we do:
60 seconds / BPM = X seconds

Generally speaking (unless you are doing some weird speed doubling trick or something else), when using speed 06 in Renoise, 1 beat should be 4 pattern rows long.
So to find the length of 1 pattern row in milliseconds, we do:
MS = (X seconds / 4 rows) * 1000

For example, 120 bpm @ speed 06:
60 sec / 120 bpm = 0.5 sec
0.5 sec / 4 rows = 0.125 sec
0.125 sec * 1000 = 125 ms

130bpm @ speed 03 (speed 03 is twice as fast, so 1 beat = 8 rows):
60 sec / 130 bpm = 0.4615 sec
0.4615 sec / 8 rows = 0.0576875 sec
0.0576875 sec * 1000 = 57.6 ms

.