Show source: /guitar/tempo_calculator.php
<?php
$title = "Tempo Calculator";
require_once("btm_config.php");
print btm_print_top();
?>
<table border="1" cellspacing="0" cellpadding="3">
<?php
$header_row = "
<tr>
<th>BPM</th>
<th>1/2 note</th>
<th>1/4 note</th>
<th>1/8 note</th>
<th>1/16 note</th>
<th>Dotted<br />1/4</th>
<th>Dotted<br />1/8</th>
<th>Dotted<br />1/16</th>
<th>Triplet<br />1/4</th>
<th>Triplet<br />1/8</th>
<th>Triplet<br />1/16</th>
</tr>
";
$sec_vars = array(
"half_sec" => "",
"quarter_sec" => "",
"eighth_sec" => "",
"sixteenth_sec" => "",
"dotted_quarter_sec" => "",
"dotted_eighth_sec" => "",
"dotted_sixteenth_sec" => "",
"triplet_quarter_sec" => "",
"triplet_eighth_sec" => "",
"triplet_sixteenth_sec" => ""
);
$hz_vars = array(
"half_hz" => "",
"quarter_hz" => "",
"eighth_hz" => "",
"sixteenth_hz" => "",
"dotted_quarter_hz" => "",
"dotted_eighth_hz" => "",
"dotted_sixteenth_hz" => "",
"triplet_quarter_hz" => "",
"triplet_eighth_hz" => "",
"triplet_sixteenth_hz" => ""
);
for($bpm = 60; $bpm <= 179; $bpm++) {
// Calculate values in seconds
$sec_vars["half_sec"] = 120 / $bpm;
$sec_vars["quarter_sec"] = 60 / $bpm;
$sec_vars["eighth_sec"] = 30 / $bpm;
$sec_vars["sixteenth_sec"] = 15 / $bpm;
$sec_vars["dotted_quarter_sec"] = 90 / $bpm;
$sec_vars["dotted_eighth_sec"] = 45 / $bpm;
$sec_vars["dotted_sixteenth_sec"] = 22.5 / $bpm;
$sec_vars["triplet_quarter_sec"] = 40 / $bpm;
$sec_vars["triplet_eighth_sec"] = 20 / $bpm;
$sec_vars["triplet_sixteenth_sec"] = 10 / $bpm;
// Round to 3 decimal places
foreach(array_keys($sec_vars) as $x) {
$sec_vars[$x] = round($sec_vars[$x], 3);
}
// Calculate values in Hertz
$hz_vars["half_hz"] = $bpm / 120;
$hz_vars["quarter_hz"] = $bpm / 60;
$hz_vars["eighth_hz"] = $bpm / 30;
$hz_vars["sixteenth_hz"] = $bpm / 15;
$hz_vars["dotted_quarter_hz"] = $bpm / 90;
$hz_vars["dotted_eighth_hz"] = $bpm / 45;
$hz_vars["dotted_sixteenth_hz"] = $bpm / 22.5;
$hz_vars["triplet_quarter_hz"] = $bpm / 40;
$hz_vars["triplet_eighth_hz"] = $bpm / 20;
$hz_vars["triplet_sixteenth_hz"] = $bpm / 10;
// Round to 3 decimal places
foreach(array_keys($hz_vars) as $y) {
$hz_vars[$y] = round($hz_vars[$y], 3);
}
$row_data = <<<EOM
<tr>
<th>$bpm</th>
<td><pre class="code">$sec_vars[half_sec] sec.
$hz_vars[half_hz] Hz</pre></td>
<td><pre class="code">$sec_vars[quarter_sec] sec.
$hz_vars[quarter_hz] Hz</pre></td>
<td style="background:#224411"><pre class="code">$sec_vars[eighth_sec] sec.
$hz_vars[eighth_hz] Hz</pre></td>
<td><pre class="code">$sec_vars[sixteenth_sec] sec.
$hz_vars[sixteenth_hz] Hz</pre></td>
<td><pre class="code">$sec_vars[dotted_quarter_sec] sec.
$hz_vars[dotted_quarter_hz] Hz</pre></td>
<td style="background:#224411"><pre class="code">$sec_vars[dotted_eighth_sec] sec.
$hz_vars[dotted_eighth_hz] Hz</pre></td>
<td><pre class="code">$sec_vars[dotted_sixteenth_sec] sec.
$hz_vars[dotted_sixteenth_hz] Hz</pre></td>
<td><pre class="code">$sec_vars[triplet_quarter_sec] sec.
$hz_vars[triplet_quarter_hz] Hz</pre></td>
<td><pre class="code">$sec_vars[triplet_eighth_sec] sec.
$hz_vars[triplet_eighth_hz] Hz</pre></td>
<td><pre class="code">$sec_vars[triplet_sixteenth_sec] sec.
$hz_vars[triplet_sixteenth_hz] Hz</pre></td>
</tr>
EOM;
// Print the table headers every ten rows
if(($bpm % 10) == 0) { print $header_row; }
print $row_data;
}
?>
</table>
<p><a href="tempo_explanation.php">How to do the math</a></p>
<p><a href="/source.php?url=<?=$_SERVER['PHP_SELF']?>">View PHP source</a></p>
<?php print btm_print_bottom(); ?>