# Convert Music beats to seconds

## Recommended Posts

I am trying to convert something in the notation of "Measures : Beats : Division" into seconds. I have the key signature as well as the BPM and the Division just my script is returning wrong values. I believe part of the problem is that all 3 categories are not there every time, for example:

16: 1:  0
2:  0
3:  0
24
48

if \$tempstring <> "   1: 1:  0 " Then
\$tempstring = StringReplace(\$tempstring, " ", "")
\$tempstring = StringReplace(\$tempstring, "  ", "")
\$tempstring = StringSplit( \$tempstring, ":")
if \$tempstring[0] = 1 Then
\$beatdif = \$tempstring[1] - \$beat3
if \$beatdif < 0 then \$beatdif = \$division + \$beatdif
\$beat3 = \$tempstring[1]
\$tempstring = ((\$beatdif/\$division)*\$BPM)/60
ElseIf \$tempstring[0] = 2 Then
\$beatdif = (\$tempstring[1] - \$beat2) &":"& (\$tempstring[2] - \$beat3)
\$beatdif = StringSplit(\$beatdif, ":")
\$beat2 = \$tempstring[1]
\$beat3 = \$tempstring[2]
if \$beatdif[1] < 0 then \$beatdif[1] = StringLeft(\$keysig, 1) + \$beatdif
if \$beatdif[2] < 0 then \$beatdif[2] = \$division + \$beatdif
\$tempstring = ((\$beatdif[1] + \$beatdif[2]/\$division)*\$BPM)/60
ElseIf \$tempstring[0] = 3 then
\$beatdif = \$tempstring[1] & ":"& (\$tempstring[2] - \$beat2) &":"& (\$tempstring[3] - \$beat3)
\$beatdif = StringSplit(\$beatdif, ":")
\$beat = \$tempstring[1]
\$beat2 = \$tempstring[2]
\$beat3 = \$tempstring[3]
if \$beatdif[2] < 0 then \$beatdif[2] = StringLeft(\$keysig, 1) + \$beatdif
if \$beatdif[3] < 0 then \$beatdif[3] = 192 + \$beatdif
\$tempstring = (((\$beatdif[1] * StringRight(\$keysig, 1)-\$beat) + \$beatdif[2] + \$beatdif[3]/\$division)*\$BPM)/60
EndIf
EndIf

##### Share on other sites

I'm still playing with it and trying to fully understand what you're after here, but perhaps using StringRegExp would help for those lines where not all categories are there.

##### Share on other sites

Basically im trying to get the seconds where the "Measures" * \$keysig = Beats, Beats / BPM = seconds (i think my math is wrong there), and Division = Division/\$Division Beats

Its kinda complicated I know but I hope that helps clear it up

##### Share on other sites

Basically im trying to get the seconds where the "Measures" * \$keysig = Beats, Beats / BPM = seconds (i think my math is wrong there), and Division = Division/\$Division Beats

Its kinda complicated I know but I hope that helps clear it up

Let me see if I understand this right, though I'm still not quite sure I understand divisions (is that like 8ths or 16ths?). For example:

Time signature (not key signature ) = 4/4

Tempo (BPM) = 120 BPM

120 BPM = 120 beats per 60 seconds (120/60) = 2 BPS (beats per second), so 1 BEAT = 0.5 sec.

16:1:0 = (16 * 4) + 1 * 0.5 = 65 beats in 32.5 sec.

Clear as mud?

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...