print "
 This is a program that calculates four octaves in
 the Pythagorean, Equal-Tempered and Just major scales...
 ";

print "beginning upon (Hz)...";
$root = <STDIN>;
chomp ($root);
print "JUST TEMPERAMENT, with root='$root' \n";

$JC[0] = $root;
$JD[0] = ($root*9)/8;
$JE[0] = ($root*5)/4;
$JF[0] = ($root*4)/3;
$JG[0] = ($root*3)/2;
$JA[0] = ($root*5)/3;
$JB[0] = ($root*15)/8;

$JC[1] = $JC[0]*2;
$JD[1] = $JD[0]*2;
$JE[1] = $JE[0]*2;
$JF[1] = $JF[0]*2;
$JG[1] = $JG[0]*2;
$JA[1] = $JA[0]*2;
$JB[1] = $JB[0]*2;

$JC[2] = 2*$JC[1];
$JD[2] = 2*$JD[1];
$JE[2] = 2*$JE[1];
$JF[2] = 2*$JF[1];
$JG[2] = 2*$JG[1];
$JA[2] = 2*$JA[1];
$JB[2] = 2*$JB[1];

$JC[3] = 2*$JC[2];
$JD[3] = 2*$JD[2];
$JE[3] = 2*$JE[2];
$JF[3] = 2*$JF[2];
$JG[3] = 2*$JG[2];
$JA[3] = 2*$JA[2];
$JB[3] = 2*$JB[2];

$arc = 0;



while ($arc <= 3) {
  $which = $arc+1;
  printf( "#define C%d #%.3f#\n", $which, $JC[$arc] );
  printf( "#define D%d #%.3f#\n", $which, $JD[$arc] );
  printf( "#define E%d #%.3f#\n", $which, $JE[$arc] );
  printf( "#define F%d #%.3f#\n", $which, $JF[$arc] );
  printf( "#define G%d #%.3f#\n", $which, $JG[$arc] );
  printf( "#define A%d #%.3f#\n", $which, $JA[$arc] );
  printf( "#define B%d #%.3f#\n", $which, $JB[$arc] );
  $arc += 1;
}

print "EQUAL TEMPERAMENT\n";


#
# tempered tuning
#
# if $F = fundamental, $n'th half-step up
# in equal temperament has frequency
#  $Ftemp = $F * 2.0**($n/12.0)
#
# This is a math identity:
#    Log_B( A ) = Log_Z( A ) / Log_Z( B ) 
# for example,
#    Log_2 ( 64 ) =  log(64)/log(2)
# and
#    log(1000)/log(10) = Log_10 (1000) = 3
#

