240 / BPM = duration of 1 measure (1 bar or 1 loop) in seconds, regardless of meter. If it seems too fast or too slow, double or half it.

Multiply times 1000 for milliseconds since 1 second = 1000 milliseconds. The result is the duration of 1 measure in milliseconds. Divide that by 8 to get the duration in milliseconds of 8ths of a measure if there are 8 beats per measure.

Similarly, 240 / duration of 1 measure (in seconds) = BPM regardless of meter.

Beware of tools and formulas that assume the meter is 4/4. If the meter is 7/4 or 6/4 or 12/8 or whatnot you are screwed with those. With the 240 divided by scheme, it works no matter what because it's not tied to quarters of measures nor quarter notes (which aren't always quarters of measures!!!!!) but to the actual value of a measure which is always 1.